summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m
blob: cab6d58670cc9f7736a19d7fa6e63c5abcda9b34 (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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//
//  SDLShowSpec.m
//  SmartDeviceLink


#import <Foundation/Foundation.h>

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

#import "SDLImage.h"
#import "SDLMetadataTags.h"
#import "SDLMetadataType.h"
#import "SDLNames.h"
#import "SDLShow.h"
#import "SDLSoftButton.h"
#import "SDLTextAlignment.h"

QuickSpecBegin(SDLShowSpec)

SDLImage* image1 = [[SDLImage alloc] init];
SDLImage* image2 = [[SDLImage alloc] init];
SDLSoftButton* button = [[SDLSoftButton alloc] init];

NSArray<SDLMetadataType> *formatArray = @[SDLMetadataTypeMediaArtist,SDLMetadataTypeMediaTitle];
SDLMetadataTags* testMetadata = [[SDLMetadataTags alloc] initWithTextFieldTypes:formatArray mainField2:formatArray mainField3:formatArray mainField4:formatArray];

describe(@"Getter/Setter Tests", ^ {
    it(@"Should set and get correctly", ^ {
        SDLShow* testRequest = [[SDLShow alloc] init];

        testRequest.mainField1 = @"field1";
        testRequest.mainField2 = @"field2";
        testRequest.mainField3 = @"field3";
        testRequest.mainField4 = @"field4";
        testRequest.alignment = SDLTextAlignmentLeft;
        testRequest.statusBar = @"status";
        testRequest.mediaClock = @"TheTime";
        testRequest.mediaTrack = @"In The Clear";
        testRequest.graphic = image1;
        testRequest.secondaryGraphic = image2;
        testRequest.softButtons = [@[button] mutableCopy];
        testRequest.customPresets = [@[@"preset1", @"preset2"] mutableCopy];
        testRequest.metadataTags = testMetadata;

        expect(testRequest.mainField1).to(equal(@"field1"));
        expect(testRequest.mainField2).to(equal(@"field2"));
        expect(testRequest.mainField3).to(equal(@"field3"));
        expect(testRequest.mainField4).to(equal(@"field4"));
        expect(testRequest.alignment).to(equal(SDLTextAlignmentLeft));
        expect(testRequest.statusBar).to(equal(@"status"));
        expect(testRequest.mediaClock).to(equal(@"TheTime"));
        expect(testRequest.mediaTrack).to(equal(@"In The Clear"));
        expect(testRequest.graphic).to(equal(image1));
        expect(testRequest.secondaryGraphic).to(equal(image2));
        expect(testRequest.softButtons).to(equal([@[button] mutableCopy]));
        expect(testRequest.customPresets).to(equal([@[@"preset1", @"preset2"] mutableCopy]));
        expect(testRequest.metadataTags).to(equal(testMetadata));

    });

    it(@"Should return nil if not set", ^{
        SDLShow* testRequest = [[SDLShow alloc] init];

        expect(testRequest.mainField1).to(beNil());
        expect(testRequest.mainField2).to(beNil());
        expect(testRequest.mainField3).to(beNil());
        expect(testRequest.mainField4).to(beNil());
        expect(testRequest.alignment).to(beNil());
        expect(testRequest.statusBar).to(beNil());
        expect(testRequest.mediaClock).to(beNil());
        expect(testRequest.mediaTrack).to(beNil());
        expect(testRequest.graphic).to(beNil());
        expect(testRequest.secondaryGraphic).to(beNil());
        expect(testRequest.softButtons).to(beNil());
        expect(testRequest.customPresets).to(beNil());
        expect(testRequest.metadataTags).to(beNil());
    });

    describe(@"initializing", ^{
        __block NSString *testString1 = @"Test 1";
        __block NSString *testString2 = @"Test 2";
        __block NSString *testString3 = @"Test 3";
        __block NSString *testString4 = @"Test 4";
        __block NSString *testStatusBarString = @"Test Status";
        __block NSString *testMediaClockString = @"Test Clock";
        __block NSString *testMediaTrackString = @"Test Track";
        __block SDLImage *testGraphic = nil;
        __block NSArray<NSString *> *testCustomPresets = nil;
        __block SDLSoftButton *testButton = nil;
        __block NSArray<SDLSoftButton *> *testSoftButtons = nil;
        __block SDLMetadataType testType1 = SDLMetadataTypeHumidity;
        __block SDLMetadataType testType2 = SDLMetadataTypeRating;
        __block SDLMetadataType testType3 = SDLMetadataTypeMediaYear;
        __block SDLMetadataType testType4 = SDLMetadataTypeWeatherTerm;
        __block SDLTextAlignment testAlignment = SDLTextAlignmentCenter;
        __block SDLMetadataTags *testTags = nil;

        beforeEach(^{
            testGraphic = [[SDLImage alloc] initWithName:@"test name" isTemplate:false];
            testCustomPresets = @[testString1];
            testButton = [[SDLSoftButton alloc] initWithType:SDLSoftButtonTypeText text:@"Test Button" image:nil highlighted:NO buttonId:0 systemAction:nil handler:nil];
            testSoftButtons = @[testButton];
            testTags = [[SDLMetadataTags alloc] initWithTextFieldTypes:@[testType1] mainField2:@[testType2] mainField3:@[testType3] mainField4:@[testType4]];
        });

        it(@"should initialize with initWithMainField1:mainField2:alignment:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField2:testString2 alignment:testAlignment];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField2:nil alignment:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"should initialize correctly with initWithMainField1:mainField1Type:mainField2:mainField2Type:alignment:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField1Type:testType1 mainField2:testString2 mainField2Type:testType2 alignment:testAlignment];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags.mainField1).to(contain(testType1));
            expect(testShow.metadataTags.mainField2).to(contain(testType2));
            expect(testShow.metadataTags.mainField3).to(beNil());
            expect(testShow.metadataTags.mainField4).to(beNil());

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField1Type:nil mainField2:nil mainField2Type:nil alignment:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"should initialize correctly with initWithMainField1:mainField2:mainField3:mainField4:alignment:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField2:testString2 mainField3:testString3 mainField4:testString4 alignment:testAlignment];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(equal(testString3));
            expect(testShow.mainField4).to(equal(testString4));
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags.mainField1).to(beNil());
            expect(testShow.metadataTags.mainField2).to(beNil());
            expect(testShow.metadataTags.mainField3).to(beNil());
            expect(testShow.metadataTags.mainField4).to(beNil());

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField2:nil mainField3:nil mainField4:nil alignment:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"should initialize correctly with initWithMainField1:mainField1Type:mainField2:mainField2Type:mainField3:mainField3Type:mainField4:mainField4Type:alignment:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField1Type:testType1 mainField2:testString2 mainField2Type:testType2 mainField3:testString3 mainField3Type:testType3 mainField4:testString4 mainField4Type:testType4 alignment:testAlignment];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(equal(testString3));
            expect(testShow.mainField4).to(equal(testString4));
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags.mainField1).to(contain(testType1));
            expect(testShow.metadataTags.mainField2).to(contain(testType2));
            expect(testShow.metadataTags.mainField3).to(contain(testType3));
            expect(testShow.metadataTags.mainField4).to(contain(testType4));

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField1Type:nil mainField2:nil mainField2Type:nil mainField3:nil mainField3Type:nil mainField4:nil mainField4Type:nil alignment:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"should initialize correctly with initWithMainField1:mainField2:alignment:statusBar:mediaClock:mediaTrack:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField2:testString2 alignment:testAlignment statusBar:testStatusBarString mediaClock:testMediaClockString mediaTrack:testMediaTrackString];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(equal(testStatusBarString));
            expect(testShow.mediaClock).to(equal(testMediaClockString));
            expect(testShow.mediaTrack).to(equal(testMediaTrackString));
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags.mainField1).to(beNil());
            expect(testShow.metadataTags.mainField2).to(beNil());
            expect(testShow.metadataTags.mainField3).to(beNil());
            expect(testShow.metadataTags.mainField4).to(beNil());

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField2:nil alignment:nil statusBar:nil mediaClock:nil mediaTrack:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"should initialize correctly with initWithMainField1:mainField2:mainField3:mainField4:alignment:statusBar:mediaClock:mediaTrack:graphic:softButtons:customPresets:textFieldMetadata:", ^{
            SDLShow *testShow = [[SDLShow alloc] initWithMainField1:testString1 mainField2:testString2 mainField3:testString3 mainField4:testString4 alignment:testAlignment statusBar:testStatusBarString mediaClock:testMediaClockString mediaTrack:testMediaTrackString graphic:testGraphic softButtons:testSoftButtons customPresets:testCustomPresets textFieldMetadata:testTags];
            expect(testShow.mainField1).to(equal(testString1));
            expect(testShow.mainField2).to(equal(testString2));
            expect(testShow.mainField3).to(equal(testString3));
            expect(testShow.mainField4).to(equal(testString4));
            expect(testShow.alignment).to(equal(testAlignment));
            expect(testShow.statusBar).to(equal(testStatusBarString));
            expect(testShow.mediaClock).to(equal(testMediaClockString));
            expect(testShow.mediaTrack).to(equal(testMediaTrackString));
            expect(testShow.graphic).to(equal(testGraphic));
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(contain(testButton));
            expect(testShow.customPresets).to(contain(testString1));
            expect(testShow.metadataTags.mainField1).to(contain(testType1));
            expect(testShow.metadataTags.mainField2).to(contain(testType2));
            expect(testShow.metadataTags.mainField3).to(contain(testType3));
            expect(testShow.metadataTags.mainField4).to(contain(testType4));

            testShow = [[SDLShow alloc] initWithMainField1:nil mainField2:nil mainField3:nil mainField4:nil alignment:nil statusBar:nil mediaClock:nil mediaTrack:nil graphic:nil softButtons:nil customPresets:nil textFieldMetadata:nil];
            expect(testShow.mainField1).to(beNil());
            expect(testShow.mainField2).to(beNil());
            expect(testShow.mainField3).to(beNil());
            expect(testShow.mainField4).to(beNil());
            expect(testShow.alignment).to(beNil());
            expect(testShow.statusBar).to(beNil());
            expect(testShow.mediaClock).to(beNil());
            expect(testShow.mediaTrack).to(beNil());
            expect(testShow.graphic).to(beNil());
            expect(testShow.secondaryGraphic).to(beNil());
            expect(testShow.softButtons).to(beNil());
            expect(testShow.customPresets).to(beNil());
            expect(testShow.metadataTags).to(beNil());
        });

        it(@"Should get correctly when initialized with a dictionary", ^ {
            NSMutableDictionary* dict = [@{SDLNameRequest:
                                               @{SDLNameParameters:
                                                     @{SDLNameMainField1:@"field1",
                                                       SDLNameMainField2:@"field2",
                                                       SDLNameMainField3:@"field3",
                                                       SDLNameMainField4:@"field4",
                                                       SDLNameAlignment:SDLTextAlignmentLeft,
                                                       SDLNameStatusBar:@"status",
                                                       SDLNameMediaClock:@"TheTime",
                                                       SDLNameMediaTrack:@"In The Clear",
                                                       SDLNameGraphic:image1,
                                                       SDLNameSecondaryGraphic:image2,
                                                       SDLNameSoftButtons:[@[button] mutableCopy],
                                                       SDLNameCustomPresets:[@[@"preset1", @"preset2"] mutableCopy],
                                                       SDLNameMetadataTags:testMetadata},
                                                 SDLNameOperationName:SDLNameShow}} mutableCopy];
            SDLShow* testRequest = [[SDLShow alloc] initWithDictionary:dict];

            expect(testRequest.mainField1).to(equal(@"field1"));
            expect(testRequest.mainField2).to(equal(@"field2"));
            expect(testRequest.mainField3).to(equal(@"field3"));
            expect(testRequest.mainField4).to(equal(@"field4"));
            expect(testRequest.alignment).to(equal(SDLTextAlignmentLeft));
            expect(testRequest.statusBar).to(equal(@"status"));
            expect(testRequest.mediaClock).to(equal(@"TheTime"));
            expect(testRequest.mediaTrack).to(equal(@"In The Clear"));
            expect(testRequest.graphic).to(equal(image1));
            expect(testRequest.secondaryGraphic).to(equal(image2));
            expect(testRequest.softButtons).to(equal([@[button] mutableCopy]));
            expect(testRequest.customPresets).to(equal([@[@"preset1", @"preset2"] mutableCopy]));
            expect(testRequest.metadataTags).to(equal(testMetadata));
        });
    });
});

QuickSpecEnd