summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLVideoStreamingRangeSpec.m
blob: 83888ba8924421b0031946ea1fe754934228c6e5 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
//  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 *minResolution = [[SDLImageResolution alloc] initWithWidth:10 height:50];
    SDLImageResolution *maxResolution = [[SDLImageResolution alloc] initWithWidth:100 height:500];
    const float minimumAspectRatio = 2.5;
    const float maximumAspectRatio = 7.1;
    const float minimumDiagonal = 3.3;

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

    describe(@"initialization", ^{
        context(@"init", ^{
            beforeEach(^{
                testRange = [SDLVideoStreamingRange disabled];
            });

            it(@"expect object to be created with empty fields", ^{
                expect(testRange).toNot(beNil());
                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));
            });

            it(@"expect object to be created and properties are set properly", ^{
                testRange.minimumResolution = minResolution;
                testRange.maximumResolution = maxResolution;
                testRange.minimumDiagonal = minimumDiagonal;
                testRange.minimumAspectRatio = minimumAspectRatio;
                testRange.maximumAspectRatio = maximumAspectRatio;

                expect(testRange).toNot(beNil());
                expect(testRange.minimumResolution).to(equal(minResolution));
                expect(testRange.maximumResolution).to(equal(maxResolution));
                expect(testRange.minimumAspectRatio).to(equal(minimumAspectRatio));
                expect(testRange.maximumAspectRatio).to(equal(maximumAspectRatio));
                expect(testRange.minimumDiagonal).to(equal(minimumDiagonal));
            });
        });

        context(@"initWithMinimumResolution:maximumResolution:", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:minResolution maximumResolution:maxResolution];
            });

            it(@"expect min and max resolution to be set and others are defaults", ^{
                expect(testRange).toNot(beNil());
                expect(testRange.minimumResolution).to(equal(minResolution));
                expect(testRange.maximumResolution).to(equal(maxResolution));
                expect(testRange.minimumAspectRatio).to(equal(defaultMinimumAspectRatio));
                expect(testRange.maximumAspectRatio).to(equal(defaultMaximumAspectRatio));
                expect(testRange.minimumDiagonal).to(equal(defaultMinimumDiagonal));
            });
        });

        context(@"initWithMinimumResolution:maximumResolution:minimumAspectRatio:maximumAspectRatio:minimumDiagonal:", ^{
            beforeEach(^{
                testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:minResolution maximumResolution:maxResolution minimumAspectRatio:minimumAspectRatio maximumAspectRatio:maximumAspectRatio minimumDiagonal:minimumDiagonal];
            });

            it(@"expect min and max resolution to be set and others are defaults", ^{
                expect(testRange).toNot(beNil());
                expect(testRange.minimumResolution).to(equal(minResolution));
                expect(testRange.maximumResolution).to(equal(maxResolution));
                expect(testRange.minimumAspectRatio).to(equal(minimumAspectRatio));
                expect(testRange.maximumAspectRatio).to(equal(maximumAspectRatio));
                expect(testRange.minimumDiagonal).to(equal(minimumDiagonal));
            });
        });
    });

    describe(@"setting float parameters", ^{
        beforeEach(^{
            testRange = [[SDLVideoStreamingRange alloc] initWithMinimumResolution:minResolution maximumResolution:maxResolution];;
        });

        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 = minimumAspectRatio;
                    expect(testRange.minimumAspectRatio).to(equal(minimumAspectRatio));
                });
            });
        });

        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 = maximumAspectRatio;
                    expect(testRange.maximumAspectRatio).to(equal(maximumAspectRatio));
                });
            });
        });

        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 = minimumDiagonal;
                    expect(testRange.minimumDiagonal).to(equal(minimumDiagonal));
                });
            });
        });
    });

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

        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:minResolution maximumResolution:nil];
            });

            it(@"should return YES when above the minimum resolution", ^{
                expect([testRange isImageResolutionInRange:[[SDLImageResolution alloc] initWithWidth:12 height:52]]).to(beTrue());
            });
        });

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

            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:12 height:52]]).to(beTrue());
            });
        });
    });

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

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

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

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

            it(@"should set the minimum to 1.0", ^{
                expect(testRange.minimumAspectRatio).to(equal(1.0));
            });
        });

        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:6.0]).to(beTrue());
            });
        });
    });
});

QuickSpecEnd