summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLVideoStreamingRangeSpec.m
blob: d40ed3735ed8287513f2465cfbde07e2d741c03d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//
//  SDLVideoStreamingRangeSpec.m
//  SmartDeviceLinkTests
//
//  Created by Joel Fischer on 6/21/21.
//  Copyright © 2021 smartdevicelink. All rights reserved.
//

#import <Quick/Quick.h>
#import <Nimble/Nimble.h>

#import <SmartDeviceLink/SmartDeviceLink.h>

QuickSpecBegin(SDLVideoStreamingRangeSpec)

describe(@"video streaming range", ^{
    __block SDLVideoStreamingRange *testRange = nil;
    SDLImageResolution *disabledResolution = [[SDLImageResolution alloc] initWithWidth:0 height:0];
    SDLImageResolution *lowResolution = [[SDLImageResolution alloc] initWithWidth:1 height:1];
    SDLImageResolution *highResolution = [[SDLImageResolution alloc] initWithWidth:999 height:999];

    float defaultMinimumAspectRatio = 1.0;
    float defaultMaximumAspectRatio = 9999.0;
    float defaultMinimumDiagonal = 0.0;

    float testMinimumAspectRatio = 4.0;
    float testMaximumAspectRatio = 12.0;
    float testMinimumDiagonal = 6.0;

    beforeEach(^{
        testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:lowResolution maximumResolution:highResolution];;
    });

    context(@"initialized with initWithMinimumResolution:maximumResolution", ^{
        it(@"should set all parameters correctly", ^{
            expect(testRange.minimumResolution).to(equal(lowResolution));
            expect(testRange.maximumResolution).to(equal(highResolution));
            expect(testRange.minimumAspectRatio).to(equal(1.0));
            expect(testRange.maximumAspectRatio).to(equal(9999.0));
            expect(testRange.minimumDiagonal).to(equal(0.0));
        });
    });

    context(@"initialized with initWithMinimumResolution:maximumResolution:minimumAspectRatio:maximumAspectRatio:minimumDiagonal:", ^{
        beforeEach(^{
            testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:lowResolution maximumResolution:highResolution minimumAspectRatio:testMinimumAspectRatio maximumAspectRatio:testMaximumAspectRatio minimumDiagonal:testMinimumDiagonal];
        });

        it(@"should set all parameters correctly", ^{
            expect(testRange.minimumResolution).to(equal(lowResolution));
            expect(testRange.maximumResolution).to(equal(highResolution));
            expect(testRange.minimumAspectRatio).to(equal(testMinimumAspectRatio));
            expect(testRange.maximumAspectRatio).to(equal(testMaximumAspectRatio));
            expect(testRange.minimumDiagonal).to(equal(testMinimumDiagonal));
        });
    });

    context(@"initialized with disabled", ^{
        beforeEach(^{
            testRange = [SDLVideoStreamingRange disabled];
        });

        it(@"should set all parameters correctly", ^{
            expect(testRange.minimumResolution).to(equal(disabledResolution));
            expect(testRange.maximumResolution).to(equal(disabledResolution));
            expect(testRange.minimumAspectRatio).to(equal(defaultMinimumAspectRatio));
            expect(testRange.maximumAspectRatio).to(equal(defaultMaximumAspectRatio));
            expect(testRange.minimumDiagonal).to(equal(defaultMinimumDiagonal));
        });
    });

    describe(@"setting float parameters", ^{
        describe(@"minimum aspect ratio", ^{
            context(@"below the minimum", ^{
                it(@"should be set to the minimum", ^{
                    testRange.minimumAspectRatio = -2.0;
                    expect(testRange.minimumAspectRatio).to(equal(defaultMinimumAspectRatio));
                });
            });

            context(@"above the minimum", ^{
                it(@"should set the value", ^{
                    testRange.minimumAspectRatio = testMinimumAspectRatio;
                    expect(testRange.minimumAspectRatio).to(equal(testMinimumAspectRatio));
                });
            });
        });

        describe(@"maximum aspect ratio", ^{
            context(@"below the minimum", ^{
                it(@"should be set to the minimum", ^{
                    testRange.maximumAspectRatio = -2.0;
                    expect(testRange.maximumAspectRatio).to(equal(defaultMinimumAspectRatio));
                });
            });

            context(@"above the minimum", ^{
                it(@"should set the value", ^{
                    testRange.maximumAspectRatio = testMaximumAspectRatio;
                    expect(testRange.maximumAspectRatio).to(equal(testMaximumAspectRatio));
                });
            });
        });

        describe(@"minimum diagonal", ^{
            context(@"below the minimum", ^{
                it(@"should be set to the minimum", ^{
                    testRange.minimumDiagonal = -2.0;
                    expect(testRange.minimumDiagonal).to(equal(defaultMinimumDiagonal));
                });
            });

            context(@"above the minimum", ^{
                it(@"should set the value", ^{
                    testRange.minimumDiagonal = testMinimumDiagonal;
                    expect(testRange.minimumDiagonal).to(equal(testMinimumDiagonal));
                });
            });
        });
    });

    describe(@"checking if the resolution is in a given range", ^{
        beforeEach(^{
            testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:lowResolution maximumResolution:highResolution];
        });

        context(@"when there is no minimum or maximum resolution", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:nil maximumResolution:nil];
            });

            it(@"should return NO", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:2 height:2]]).to(beFalse());
            });
        });

        context(@"when there is no maximum resolution", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:lowResolution maximumResolution:nil];
            });

            it(@"should return YES", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:2 height:2]]).to(beTrue());
            });
        });

        context(@"when there is no minimum resolution", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:nil maximumResolution:highResolution];
            });

            it(@"should return YES", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:2 height:2]]).to(beTrue());
            });
        });

        context(@"when the resolution is below the range", ^{
            it(@"should return NO", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:0 height:0]]).to(beFalse());
            });
        });

        context(@"when the resolution is above the range", ^{
            it(@"should return NO", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:34463 height:34463]]).to(beFalse());
            });
        });

        context(@"when the resolution is in the range", ^{
            it(@"should return YES", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:2 height:2]]).to(beTrue());
            });
        });
    });

    describe(@"checking if the aspect ratio is in a given range", ^{
        beforeEach(^{
            testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:nil maximumResolution:nil minimumAspectRatio:testMinimumAspectRatio maximumAspectRatio:testMaximumAspectRatio minimumDiagonal:1.0];
        });

        context(@"when there is no maximum aspect ratio", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:nil maximumResolution:nil minimumAspectRatio:testMinimumAspectRatio maximumAspectRatio:0.0 minimumDiagonal:1.0];
            });

            it(@"should return NO", ^{
                expect([testRange isAspectRatioInRange:10.0]).to(beTrue());
            });
        });

        context(@"when there is no minimum aspect ratio", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:nil maximumResolution:nil minimumAspectRatio:0.0 maximumAspectRatio:testMaximumAspectRatio minimumDiagonal:1.0];
            });

            it(@"should return NO", ^{
                expect([testRange isAspectRatioInRange:10.0]).to(beTrue());
            });
        });

        context(@"when the aspect ratio is below the range", ^{
            it(@"should return NO", ^{
                expect([testRange isAspectRatioInRange:2.0]).to(beFalse());
            });
        });

        context(@"when the aspect ratio is above the range", ^{
            it(@"should return NO", ^{
                expect([testRange isAspectRatioInRange:99.0]).to(beFalse());
            });
        });

        context(@"when the aspect ratio is in the range", ^{
            it(@"should return NO", ^{
                expect([testRange isAspectRatioInRange:10.0]).to(beTrue());
            });
        });
    });
});

QuickSpecEnd