summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m
blob: 22fc58cba98086b0b7bd02657a7e437a4a56c119 (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
//
//  SDLAlertSpec.m
//  SmartDeviceLink


#import <Foundation/Foundation.h>

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

#import "SDLAlert.h"
#import "SDLImage.h"
#import "SDLTTSChunk.h"
#import "SDLSoftButton.h"
#import "SDLRPCParameterNames.h"
#import "SDLRPCFunctionNames.h"

QuickSpecBegin(SDLAlertSpec)

SDLTTSChunk *tts = [[SDLTTSChunk alloc] init];
SDLSoftButton *button = [[SDLSoftButton alloc] init];
SDLImage *testImage = [[SDLImage alloc] initWithName:@"testImage" isTemplate:YES];

describe(@"Alert spec", ^{
    UInt16 defaultDuration = 5000;

    NSString *testText1 = @"Test Text 1";
    NSString *testText2 = @"Test Text 2";
    NSString *testText3 = @"Test Text 3";
    NSString *testTTSString = @"Test TTS";
    BOOL testPlayTone = YES;
    BOOL testProgressIndicator = YES;
    UInt16 testDuration = 7847;

    describe(@"initializer tests", ^{
        it(@"should initialize correctly with initWithAlertText1:alertText2:duration:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 duration:testDuration];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(beNil());
            expect(testAlert.ttsChunks).to(beNil());
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(beFalse());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(beNil());
            expect(testAlert.duration).to(equal(defaultDuration));
            expect(testAlert.playTone).to(beFalse());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:duration:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 duration:testDuration];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(beNil());
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(beFalse());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:duration:softButtons:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 duration:testDuration softButtons:@[button]];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(beNil());
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(beFalse());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(haveCount(1));
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTS:alertText1:alertText2:playTone:duration:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString alertText1:testText1 alertText2:testText2 playTone:testPlayTone duration:testDuration];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(beNil());
            expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(beTrue());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTS:alertText1:alertText2:alertText3:playTone:duration:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone duration:testDuration];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTS:playTone:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString playTone:testPlayTone];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(beNil());
            expect(testAlert.alertText2).to(beNil());
            expect(testAlert.alertText3).to(beNil());
            expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
            expect(testAlert.duration).to(equal(defaultDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTSChunks:alertText1:alertText2:alertText3:playTone:softButtons:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone softButtons:@[button]];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(haveCount(1));
            expect(testAlert.duration).to(equal(defaultDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(haveCount(1));
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTSChunks:alertText1:alertText2:alertText3:playTone:duration:softButtons:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone duration:testDuration softButtons:@[button]];
#pragma clang diagnostic pop

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(haveCount(1));
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(haveCount(1));
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithAlertText1:alertText2:", ^{
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2];

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(beNil());
            expect(testAlert.ttsChunks).to(beNil());
            expect(testAlert.duration).to(equal(defaultDuration));
            expect(testAlert.playTone).to(beFalse());
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithTTSChunks:playTone:", ^{
            SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] playTone:testPlayTone];

            expect(testAlert.alertText1).to(beNil());
            expect(testAlert.alertText2).to(beNil());
            expect(testAlert.alertText3).to(beNil());
            expect(testAlert.ttsChunks).to(haveCount(1));
            expect(testAlert.duration).to(equal(defaultDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beFalse());
            expect(testAlert.softButtons).to(beNil());
            expect(testAlert.alertIcon).to(beNil());
        });

        it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:ttsChunks:playTone:progressIndicator:duration:softButtons:alertIcon:", ^{
            SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 ttsChunks:@[tts] playTone:testPlayTone progressIndicator:testProgressIndicator duration:testDuration softButtons:@[button] alertIcon:testImage];

            expect(testAlert.alertText1).to(equal(testText1));
            expect(testAlert.alertText2).to(equal(testText2));
            expect(testAlert.alertText3).to(equal(testText3));
            expect(testAlert.ttsChunks).to(haveCount(1));
            expect(testAlert.duration).to(equal(testDuration));
            expect(testAlert.playTone).to(equal(testPlayTone));
            expect(testAlert.progressIndicator).to(beTrue());
            expect(testAlert.softButtons).to(haveCount(1));
            expect(testAlert.alertIcon.value).to(equal(testImage.value));
        });
    });

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

            testRequest.alertText1 = @"alert#1";
            testRequest.alertText2 = @"alert#2";
            testRequest.alertText3 = @"alert#3";
            testRequest.ttsChunks = @[tts];
            testRequest.duration = @4357;
            testRequest.playTone = @YES;
            testRequest.progressIndicator = @NO;
            testRequest.softButtons = @[button];
            testRequest.alertIcon = testImage;

            expect(testRequest.alertText1).to(equal(@"alert#1"));
            expect(testRequest.alertText2).to(equal(@"alert#2"));
            expect(testRequest.alertText3).to(equal(@"alert#3"));
            expect(testRequest.ttsChunks).to(equal(@[tts]));
            expect(testRequest.duration).to(equal(@4357));
            expect(testRequest.playTone).to(equal(@YES));
            expect(testRequest.progressIndicator).to(equal(@NO));
            expect(testRequest.softButtons).to(equal(@[button]));
            expect(testRequest.alertIcon).to(equal(testImage));
        });

        it(@"Should get correctly when initialized", ^ {
            NSDictionary<NSString *, id> *dict = @{SDLRPCParameterNameRequest:
                                                       @{SDLRPCParameterNameParameters:
                                                             @{SDLRPCParameterNameAlertText1: @"alert#1",
                                                               SDLRPCParameterNameAlertText2: @"alert#2",
                                                               SDLRPCParameterNameAlertText3: @"alert#3",
                                                               SDLRPCParameterNameTTSChunks: @[tts],
                                                               SDLRPCParameterNameDuration: @4357,
                                                               SDLRPCParameterNamePlayTone: @YES,
                                                               SDLRPCParameterNameProgressIndicator: @NO,
                                                               SDLRPCParameterNameSoftButtons: @[button],
                                                               SDLRPCParameterNameAlertIcon: testImage
                                                               },
                                                         SDLRPCParameterNameOperationName: SDLRPCFunctionNameAlert
                                                         }
                                                   };
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
#pragma clang diagnostic pop

            expect(testRequest.alertText1).to(equal(@"alert#1"));
            expect(testRequest.alertText2).to(equal(@"alert#2"));
            expect(testRequest.alertText3).to(equal(@"alert#3"));
            expect(testRequest.ttsChunks).to(equal([@[tts] mutableCopy]));
            expect(testRequest.duration).to(equal(@4357));
            expect(testRequest.playTone).to(equal(@YES));
            expect(testRequest.progressIndicator).to(equal(@NO));
            expect(testRequest.softButtons).to(equal([@[button] mutableCopy]));
        });

        it(@"Should handle NSNull", ^{
            NSDictionary* dict = @{SDLRPCParameterNameRequest:
                                       @{SDLRPCParameterNameParameters:
                                             @{SDLRPCParameterNameAlertText1: @"alert#1",
                                               SDLRPCParameterNameAlertText2: @"alert#2",
                                               SDLRPCParameterNameAlertText3: @"alert#3",
                                               SDLRPCParameterNameTTSChunks: @[tts],
                                               SDLRPCParameterNameDuration: @4357,
                                               SDLRPCParameterNamePlayTone: @YES,
                                               SDLRPCParameterNameProgressIndicator: @NO,
                                               SDLRPCParameterNameSoftButtons: [NSNull null],
                                               SDLRPCParameterNameAlertIcon: testImage
                                               },
                                         SDLRPCParameterNameOperationName:SDLRPCFunctionNameAlert}
                                   };
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
#pragma clang diagnostic pop
            expectAction(^{
                NSArray<SDLSoftButton *> *softButtons = testRequest.softButtons;
            }).to(raiseException());
        });

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

            expect(testRequest.alertText1).to(beNil());
            expect(testRequest.alertText2).to(beNil());
            expect(testRequest.alertText3).to(beNil());
            expect(testRequest.ttsChunks).to(beNil());
            expect(testRequest.duration).to(beNil());
            expect(testRequest.playTone).to(beNil());
            expect(testRequest.progressIndicator).to(beNil());
            expect(testRequest.softButtons).to(beNil());
        });
    });
});

QuickSpecEnd