summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/SDLSystemCapabilityManagerSpec.m
blob: 4989a95f574621c989e5025cfb4f4aa8360521b3 (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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>

#import "SDLAppServiceCapability.h"
#import "SDLAppServiceManifest.h"
#import "SDLAppServiceRecord.h"
#import "SDLAppServicesCapabilities.h"
#import "SDLAudioPassThruCapabilities.h"
#import "SDLButtonCapabilities.h"
#import "SDLDisplayCapabilities.h"
#import "SDLDisplayCapability.h"
#import "SDLGetSystemCapability.h"
#import "SDLGetSystemCapabilityResponse.h"
#import "SDLGlobals.h"
#import "SDLHMICapabilities.h"
#import "SDLImageField.h"
#import "SDLImageResolution.h"
#import "SDLMediaServiceManifest.h"
#import "SDLNavigationCapability.h"
#import "SDLNotificationConstants.h"
#import "SDLOnHMIStatus.h"
#import "SDLOnSystemCapabilityUpdated.h"
#import "SDLPhoneCapability.h"
#import "SDLPredefinedWindows.h"
#import "SDLPresetBankCapabilities.h"
#import "SDLRegisterAppInterfaceResponse.h"
#import "SDLRemoteControlCapabilities.h"
#import "SDLRPCNotificationNotification.h"
#import "SDLRPCResponseNotification.h"
#import "SDLScreenParams.h"
#import "SDLSetDisplayLayoutResponse.h"
#import "SDLSoftButtonCapabilities.h"
#import "SDLSystemCapability.h"
#import "SDLSystemCapabilityObserver.h"
#import "SDLSystemCapabilityManager.h"
#import "SDLTextField.h"
#import "SDLVersion.h"
#import "SDLVideoStreamingCapability.h"
#import "SDLWindowCapability.h"
#import "SDLWindowTypeCapabilities.h"
#import "TestConnectionManager.h"
#import "TestSystemCapabilityObserver.h"

typedef NSString * SDLServiceID;

@interface SDLSystemCapabilityManager ()

@property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager;

@property (nullable, strong, nonatomic, readwrite) NSArray<SDLDisplayCapability *> *displays;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@property (nullable, strong, nonatomic, readwrite) SDLDisplayCapabilities *displayCapabilities;
#pragma clang diagnostic pop
@property (nullable, strong, nonatomic, readwrite) SDLHMICapabilities *hmiCapabilities;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLSoftButtonCapabilities *> *softButtonCapabilities;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLButtonCapabilities *> *buttonCapabilities;
@property (nullable, strong, nonatomic, readwrite) SDLPresetBankCapabilities *presetBankCapabilities;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLHMIZoneCapabilities> *hmiZoneCapabilities;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLSpeechCapabilities> *speechCapabilities;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLPrerecordedSpeech> *prerecordedSpeechCapabilities;
@property (nonatomic, assign, readwrite) BOOL vrCapability;
@property (nullable, copy, nonatomic, readwrite) NSArray<SDLAudioPassThruCapabilities *> *audioPassThruCapabilities;
@property (nullable, strong, nonatomic, readwrite) SDLAudioPassThruCapabilities *pcmStreamCapability;
@property (nullable, strong, nonatomic, readwrite) SDLNavigationCapability *navigationCapability;
@property (nullable, strong, nonatomic, readwrite) SDLPhoneCapability *phoneCapability;
@property (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability;
@property (nullable, strong, nonatomic, readwrite) SDLRemoteControlCapabilities *remoteControlCapability;
@property (nullable, strong, nonatomic, readwrite) SDLSeatLocationCapability *seatLocationCapability;
@property (nullable, strong, nonatomic, readwrite) SDLDriverDistractionCapability *driverDistractionCapability;

@property (nullable, strong, nonatomic) NSMutableDictionary<SDLServiceID, SDLAppServiceCapability *> *appServicesCapabilitiesDictionary;

@property (assign, nonatomic, readwrite) BOOL supportsSubscriptions;
@property (strong, nonatomic) NSMutableDictionary<SDLSystemCapabilityType, NSMutableArray<SDLSystemCapabilityObserver *> *> *capabilityObservers;
@property (strong, nonatomic) NSMutableDictionary<SDLSystemCapabilityType, NSNumber<SDLBool> *> *subscriptionStatus;

@property (nullable, strong, nonatomic) SDLSystemCapability *lastReceivedCapability;

@property (assign, nonatomic) BOOL shouldConvertDeprecatedDisplayCapabilities;
@property (strong, nonatomic) SDLHMILevel currentHMILevel;

@end


QuickSpecBegin(SDLSystemCapabilityManagerSpec)

describe(@"System capability manager", ^{
    __block SDLSystemCapabilityManager *testSystemCapabilityManager = nil;
    __block TestConnectionManager *testConnectionManager = nil;

    __block NSArray<SDLDisplayCapability *> *testDisplayCapabilityList = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    __block SDLDisplayCapabilities *testDisplayCapabilities = nil;
#pragma clang diagnostic pop
    __block NSArray<SDLSoftButtonCapabilities *> *testSoftButtonCapabilities = nil;
    __block NSArray<SDLButtonCapabilities *> *testButtonCapabilities = nil;
    __block SDLPresetBankCapabilities *testPresetBankCapabilities = nil;
    
    beforeEach(^{
        testConnectionManager = [[TestConnectionManager alloc] init];
        testSystemCapabilityManager = [[SDLSystemCapabilityManager alloc] initWithConnectionManager:testConnectionManager];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        testDisplayCapabilities = [[SDLDisplayCapabilities alloc] init];
#pragma clang diagnostic pop
        testDisplayCapabilities.graphicSupported = @NO;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
        testDisplayCapabilities.displayType = SDLDisplayTypeGeneric;
        testDisplayCapabilities.displayName = SDLDisplayTypeGeneric;
#pragma clang diagnostic pop
        SDLTextField *textField = [[SDLTextField alloc] init];
        textField.name = SDLTextFieldNameMainField1;
        textField.characterSet = SDLCharacterSetUtf8;
        textField.width = @(123);
        textField.rows = @(1);
        testDisplayCapabilities.textFields = @[textField];
        SDLImageField *imageField = [[SDLImageField alloc] init];
        imageField.name = SDLImageFieldNameAppIcon;
        imageField.imageTypeSupported = @[SDLFileTypePNG];
        imageField.imageResolution = [[SDLImageResolution alloc] initWithWidth:42 height:4711];
        testDisplayCapabilities.imageFields = @[imageField];
        testDisplayCapabilities.mediaClockFormats = @[];
        testDisplayCapabilities.templatesAvailable = @[@"DEFAULT", @"MEDIA"];
        testDisplayCapabilities.numCustomPresetsAvailable = @(8);

        SDLSoftButtonCapabilities *softButtonCapability = [[SDLSoftButtonCapabilities alloc] init];
        softButtonCapability.shortPressAvailable = @YES;
        softButtonCapability.longPressAvailable = @NO;
        softButtonCapability.upDownAvailable = @NO;
        softButtonCapability.imageSupported = @YES;
        testSoftButtonCapabilities = @[softButtonCapability];
        
        SDLButtonCapabilities *buttonCapabilities = [[SDLButtonCapabilities alloc] init];
        buttonCapabilities.name = SDLButtonNameOk;
        buttonCapabilities.shortPressAvailable = @YES;
        buttonCapabilities.longPressAvailable = @YES;
        buttonCapabilities.upDownAvailable = @YES;
        testButtonCapabilities = @[buttonCapabilities];
        
        testPresetBankCapabilities = [[SDLPresetBankCapabilities alloc] init];
        testPresetBankCapabilities.onScreenPresetsAvailable = @NO;

        SDLWindowTypeCapabilities *windowTypeCapabilities = [[SDLWindowTypeCapabilities alloc] initWithType:SDLWindowTypeMain maximumNumberOfWindows:1];
        SDLDisplayCapability *displayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:testDisplayCapabilities.displayName];
        displayCapability.windowTypeSupported = @[windowTypeCapabilities];
        SDLWindowCapability *defaultWindowCapability = [[SDLWindowCapability alloc] init];
        defaultWindowCapability.windowID = @(SDLPredefinedWindowsDefaultWindow);
        defaultWindowCapability.buttonCapabilities = testButtonCapabilities.copy;
        defaultWindowCapability.softButtonCapabilities = testSoftButtonCapabilities.copy;
        defaultWindowCapability.templatesAvailable = testDisplayCapabilities.templatesAvailable.copy;
        defaultWindowCapability.numCustomPresetsAvailable = testDisplayCapabilities.numCustomPresetsAvailable.copy;
        defaultWindowCapability.textFields = testDisplayCapabilities.textFields.copy;
        defaultWindowCapability.imageFields = testDisplayCapabilities.imageFields.copy;
        defaultWindowCapability.imageTypeSupported = @[SDLImageTypeStatic];
        displayCapability.windowCapabilities = @[defaultWindowCapability];
        testDisplayCapabilityList = @[displayCapability];
    });

    afterEach(^{
        if (testSystemCapabilityManager) {
            // just in case unsubscribe from notifications and dealloc the manager
            [[NSNotificationCenter defaultCenter] removeObserver:testSystemCapabilityManager];
            testSystemCapabilityManager = nil;
        }
    });

    it(@"should initialize the system capability manager properties correctly", ^{
        expect(testSystemCapabilityManager.displays).to(beNil());
        expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
        expect(testSystemCapabilityManager.displayCapabilities).to(beNil());
        expect(testSystemCapabilityManager.softButtonCapabilities).to(beNil());
        expect(testSystemCapabilityManager.buttonCapabilities).to(beNil());
        expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop
        expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
        expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
        expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
        expect(testSystemCapabilityManager.vrCapability).to(beFalse());
        expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
        expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());
        expect(testSystemCapabilityManager.phoneCapability).to(beNil());
        expect(testSystemCapabilityManager.navigationCapability).to(beNil());
        expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
        expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
        expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
        expect(testSystemCapabilityManager.seatLocationCapability).to(beNil());
        expect(testSystemCapabilityManager.driverDistractionCapability).to(beNil());
        expect(testSystemCapabilityManager.currentHMILevel).to(equal(SDLHMILevelNone));
    });

    describe(@"isCapabilitySupported method should work correctly", ^{
        __block SDLHMICapabilities *hmiCapabilities = nil;

        beforeEach(^{
            hmiCapabilities = [[SDLHMICapabilities alloc] init];
        });

        context(@"when there's a cached phone capability and hmiCapabilities is nil", ^{
            beforeEach(^{
                testSystemCapabilityManager.phoneCapability = [[SDLPhoneCapability alloc] initWithDialNumber:YES];
            });

            it(@"should return true", ^{
                expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypePhoneCall]).to(beTrue());
            });
        });

        context(@"when there's no cached capability", ^{
            describe(@"pulling a phone capability when HMICapabilites.phoneCapability is false", ^{
                beforeEach(^{
                    hmiCapabilities.phoneCall = @NO;
                    testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                });

                it(@"should return NO", ^{
                    expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypePhoneCall]).to(beFalse());
                });
            });

            describe(@"pulling a phone capability when HMICapabilites.phoneCapability is true", ^{
                beforeEach(^{
                    hmiCapabilities.phoneCall = @YES;
                    testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                });

                it(@"should return NO", ^{
                    expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypePhoneCall]).to(beTrue());
                });
            });

            describe(@"pulling a phone capability when HMICapabilites.phoneCapability is nil", ^{
                it(@"should return NO", ^{
                    expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypePhoneCall]).to(beFalse());
                });
            });

            describe(@"pulling an app services capability", ^{
                context(@"on RPC connection version 5.1.0 and HMICapabilities.appServices is false", ^{
                    beforeEach(^{
                        [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"5.1.0"];
                        hmiCapabilities.appServices = @NO;
                        testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                    });

                    it(@"should return true", ^{
                        expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeAppServices]).to(beTrue());
                    });
                });

                context(@"on RPC connection version 5.2.0 and HMICapabilities.appServices is false", ^{
                    beforeEach(^{
                        [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"5.2.0"];
                        hmiCapabilities.appServices = @NO;
                        testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                    });

                    it(@"should return false", ^{
                        expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeAppServices]).to(beFalse());
                    });
                });
            });

            describe(@"pulling a video streaming capability", ^{
                context(@"on RPC connection version 2.0.0 and HMICapabilities is nil", ^{
                    beforeEach(^{
                        [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"2.0.0"];
                    });

                    it(@"should return false", ^{
                        expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beFalse());
                    });
                });

                context(@"on RPC connection version 3.0.0 and HMICapabilities is nil", ^{
                    beforeEach(^{
                        [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"3.0.0"];
                    });

                    context(@"when displayCapabilities.graphicSupported is true", ^{
                        beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
                            testSystemCapabilityManager.displayCapabilities = [[SDLDisplayCapabilities alloc] init];
#pragma clang diagnostic pop
                            testSystemCapabilityManager.displayCapabilities.graphicSupported = @YES;
                        });

                        it(@"should return true", ^{
                            expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beTrue());
                        });
                    });

                    context(@"when displayCapabilities.graphicSupported is false", ^{
                        beforeEach(^{
                            testSystemCapabilityManager.displayCapabilities.graphicSupported = @NO;
                        });

                        it(@"should return true", ^{
                            expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beFalse());
                        });
                    });
                });

                context(@"on RPC connection version 5.1.0", ^{
                    beforeEach(^{
                        [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"5.1.0"];
                    });

                    context(@"when HMICapabilites.videoStreaming is false", ^{
                        beforeEach(^{
                            hmiCapabilities.videoStreaming = @NO;
                            testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                        });

                        it(@"should return false", ^{
                            expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beFalse());
                        });
                    });

                    context(@"when HMICapabilites.videoStreaming is true", ^{
                        beforeEach(^{
                            hmiCapabilities.videoStreaming = @YES;
                            testSystemCapabilityManager.hmiCapabilities = hmiCapabilities;
                        });

                        it(@"should return true", ^{
                            expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beTrue());
                        });
                    });

                    context(@"when HMICapabilites.videoStreaming is nil", ^{
                        it(@"should return false", ^{
                            expect([testSystemCapabilityManager isCapabilitySupported:SDLSystemCapabilityTypeVideoStreaming]).to(beFalse());
                        });
                    });
                });
            });
        });
    });

    context(@"When notified of a register app interface response", ^{
        __block SDLRegisterAppInterfaceResponse *testRegisterAppInterfaceResponse = nil;
        __block SDLHMICapabilities *testHMICapabilities = nil;
        __block NSArray<SDLHMIZoneCapabilities> *testHMIZoneCapabilities = nil;
        __block NSArray<SDLSpeechCapabilities> *testSpeechCapabilities = nil;
        __block NSArray<SDLPrerecordedSpeech> *testPrerecordedSpeechCapabilities = nil;
        __block NSArray<SDLVRCapabilities> *testVRCapabilities = nil;
        __block NSArray<SDLAudioPassThruCapabilities *> *testAudioPassThruCapabilities = nil;
        __block SDLAudioPassThruCapabilities *testPCMStreamCapability = nil;

        beforeEach(^{
            testHMICapabilities = [[SDLHMICapabilities alloc] init];
            testHMICapabilities.navigation = @NO;
            testHMICapabilities.phoneCall = @YES;
            testHMICapabilities.videoStreaming = @YES;

            testHMIZoneCapabilities = @[SDLHMIZoneCapabilitiesFront, SDLHMIZoneCapabilitiesBack];
            testSpeechCapabilities = @[SDLSpeechCapabilitiesText, SDLSpeechCapabilitiesSilence];
            testPrerecordedSpeechCapabilities = @[SDLPrerecordedSpeechHelp, SDLPrerecordedSpeechInitial];
            testVRCapabilities = @[SDLVRCapabilitiesText];

            SDLAudioPassThruCapabilities *audioPassThruCapability = [[SDLAudioPassThruCapabilities alloc] init];
            audioPassThruCapability.samplingRate = SDLSamplingRate8KHZ;
            audioPassThruCapability.bitsPerSample = SDLBitsPerSample8Bit;
            audioPassThruCapability.audioType = SDLAudioTypePCM;
            testAudioPassThruCapabilities = @[audioPassThruCapability];
            testPCMStreamCapability = audioPassThruCapability;

            testRegisterAppInterfaceResponse = [[SDLRegisterAppInterfaceResponse alloc] init];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
            testRegisterAppInterfaceResponse.displayCapabilities = testDisplayCapabilities;
            testRegisterAppInterfaceResponse.hmiCapabilities = testHMICapabilities;
            testRegisterAppInterfaceResponse.softButtonCapabilities = testSoftButtonCapabilities;
            testRegisterAppInterfaceResponse.buttonCapabilities = testButtonCapabilities;
            testRegisterAppInterfaceResponse.presetBankCapabilities = testPresetBankCapabilities;
#pragma clang diagnostic pop
            testRegisterAppInterfaceResponse.hmiZoneCapabilities = testHMIZoneCapabilities;
            testRegisterAppInterfaceResponse.speechCapabilities = testSpeechCapabilities;
            testRegisterAppInterfaceResponse.prerecordedSpeech = testPrerecordedSpeechCapabilities;
            testRegisterAppInterfaceResponse.vrCapabilities = testVRCapabilities;
            testRegisterAppInterfaceResponse.audioPassThruCapabilities = testAudioPassThruCapabilities;
            testRegisterAppInterfaceResponse.pcmStreamCapabilities = testPCMStreamCapability;
        });

        describe(@"If the Register App Interface request fails", ^{
            beforeEach(^{
                testRegisterAppInterfaceResponse.success = @NO;
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveRegisterAppInterfaceResponse object:self rpcResponse:testRegisterAppInterfaceResponse];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should not save any of the RAIR capabilities", ^{
                expect(testSystemCapabilityManager.displays).to(beNil());
                expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
                expect(testSystemCapabilityManager.displayCapabilities).to(beNil());
                expect(testSystemCapabilityManager.softButtonCapabilities).to(beNil());
                expect(testSystemCapabilityManager.buttonCapabilities).to(beNil());
                expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop
                expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
                expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.vrCapability).to(beFalse());
                expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
                expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());

                expect(testSystemCapabilityManager.phoneCapability).to(beNil());
                expect(testSystemCapabilityManager.navigationCapability).to(beNil());
                expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
                expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
                expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
            });
        });

        describe(@"If the Register App Interface request succeeds", ^{
            beforeEach(^{
                testRegisterAppInterfaceResponse.success = @YES;
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveRegisterAppInterfaceResponse object:self rpcResponse:testRegisterAppInterfaceResponse];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should should save the RAIR capabilities", ^{
                expect(testSystemCapabilityManager.displays).to(equal(testDisplayCapabilityList));
                expect(testSystemCapabilityManager.hmiCapabilities).to(equal(testHMICapabilities));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
                expect(testSystemCapabilityManager.displayCapabilities).to(equal(testDisplayCapabilities));
                expect(testSystemCapabilityManager.softButtonCapabilities).to(equal(testSoftButtonCapabilities));
                expect(testSystemCapabilityManager.buttonCapabilities).to(equal(testButtonCapabilities));
                expect(testSystemCapabilityManager.presetBankCapabilities).to(equal(testPresetBankCapabilities));
#pragma clang diagnostic pop
                expect(testSystemCapabilityManager.hmiZoneCapabilities).to(equal(testHMIZoneCapabilities));
                expect(testSystemCapabilityManager.speechCapabilities).to(equal(testSpeechCapabilities));
                expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(equal(testPrerecordedSpeechCapabilities));
                expect(testSystemCapabilityManager.vrCapability).to(beTrue());
                expect(testSystemCapabilityManager.audioPassThruCapabilities).to(equal(testAudioPassThruCapabilities));
                expect(testSystemCapabilityManager.pcmStreamCapability).to(equal(testPCMStreamCapability));

                expect(testSystemCapabilityManager.phoneCapability).to(beNil());
                expect(testSystemCapabilityManager.navigationCapability).to(beNil());
                expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
                expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
                expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
            });
        });
    });

    context(@"When notified of a SetDisplayLayout Response", ^ {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        __block SDLSetDisplayLayoutResponse *testSetDisplayLayoutResponse = nil;
#pragma clang diagnostic pop

        beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
            testSetDisplayLayoutResponse = [[SDLSetDisplayLayoutResponse alloc] init];
#pragma clang diagnostic pop
            testSetDisplayLayoutResponse.displayCapabilities = testDisplayCapabilities;
            testSetDisplayLayoutResponse.buttonCapabilities = testButtonCapabilities;
            testSetDisplayLayoutResponse.softButtonCapabilities = testSoftButtonCapabilities;
            testSetDisplayLayoutResponse.presetBankCapabilities = testPresetBankCapabilities;
        });

        describe(@"If the SetDisplayLayout request fails", ^{
            beforeEach(^{
                testSetDisplayLayoutResponse.success = @NO;
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveSetDisplayLayoutResponse object:self rpcResponse:testSetDisplayLayoutResponse];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should not save any capabilities", ^{
                expect(testSystemCapabilityManager.displays).to(beNil());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
                expect(testSystemCapabilityManager.displayCapabilities).to(beNil());
                expect(testSystemCapabilityManager.softButtonCapabilities).to(beNil());
                expect(testSystemCapabilityManager.buttonCapabilities).to(beNil());
                expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop

                expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
                expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
                expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.vrCapability).to(beFalse());
                expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
                expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());
                expect(testSystemCapabilityManager.phoneCapability).to(beNil());
                expect(testSystemCapabilityManager.navigationCapability).to(beNil());
                expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
                expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
                expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
            });
        });

        describe(@"If the SetDisplayLayout request succeeds", ^{
            beforeEach(^{
                testSetDisplayLayoutResponse.success = @YES;
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveSetDisplayLayoutResponse object:self rpcResponse:testSetDisplayLayoutResponse];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should should save the capabilities", ^{
                expect(testSystemCapabilityManager.displays).to(equal(testDisplayCapabilityList));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
                expect(testSystemCapabilityManager.displayCapabilities).to(equal(testDisplayCapabilities));
                expect(testSystemCapabilityManager.softButtonCapabilities).to(equal(testSoftButtonCapabilities));
                expect(testSystemCapabilityManager.buttonCapabilities).to(equal(testButtonCapabilities));
                expect(testSystemCapabilityManager.presetBankCapabilities).to(equal(testPresetBankCapabilities));
#pragma clang diagnostic pop

                expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
                expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
                expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
                expect(testSystemCapabilityManager.vrCapability).to(beFalse());
                expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
                expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());
                expect(testSystemCapabilityManager.phoneCapability).to(beNil());
                expect(testSystemCapabilityManager.navigationCapability).to(beNil());
                expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
                expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
                expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
            });
        });

        describe(@"if the setdisplaylayout has nil displaycapabilities", ^{
            beforeEach(^{
                testSetDisplayLayoutResponse.success = @YES;
                testSetDisplayLayoutResponse.displayCapabilities = nil;
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveSetDisplayLayoutResponse object:self rpcResponse:testSetDisplayLayoutResponse];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should should save the capabilities", ^{
                // All the text fields and image fields should be available
                expect(testSystemCapabilityManager.defaultMainWindowCapability.textFields).to(haveCount(31));
                expect(testSystemCapabilityManager.defaultMainWindowCapability.imageFields).to(haveCount(14));
            });
        });
    });
    
    context(@"when updating display capabilities with OnSystemCapabilityUpdated", ^{
        it(@"should properly update display capability including conversion two times", ^{
            // two times because capabilities are just saved in first run but merged/updated in subsequent runs
            for (int i = 0; i < 2; i++) {
                testDisplayCapabilities.displayName = [NSString stringWithFormat:@"Display %i", i];
                testDisplayCapabilities.graphicSupported = i == 0 ? @(NO) : @(YES);
                testDisplayCapabilities.templatesAvailable = @[[NSString stringWithFormat:@"Template %i", i]];
                
                SDLWindowTypeCapabilities *windowTypeCapabilities = [[SDLWindowTypeCapabilities alloc] initWithType:SDLWindowTypeMain maximumNumberOfWindows:1];
                SDLDisplayCapability *displayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:testDisplayCapabilities.displayName];
                displayCapability.windowTypeSupported = @[windowTypeCapabilities];
                SDLWindowCapability *defaultWindowCapability = [[SDLWindowCapability alloc] init];
                defaultWindowCapability.windowID = @(SDLPredefinedWindowsDefaultWindow);
                defaultWindowCapability.buttonCapabilities = testButtonCapabilities.copy;
                defaultWindowCapability.softButtonCapabilities = testSoftButtonCapabilities.copy;
                defaultWindowCapability.templatesAvailable = testDisplayCapabilities.templatesAvailable.copy;
                defaultWindowCapability.numCustomPresetsAvailable = testDisplayCapabilities.numCustomPresetsAvailable.copy;
                defaultWindowCapability.textFields = testDisplayCapabilities.textFields.copy;
                defaultWindowCapability.imageFields = testDisplayCapabilities.imageFields.copy;
                defaultWindowCapability.imageTypeSupported = testDisplayCapabilities.graphicSupported.boolValue ? @[SDLImageTypeStatic, SDLImageTypeDynamic] : @[SDLImageTypeStatic];
                displayCapability.windowCapabilities = @[defaultWindowCapability];
                NSArray<SDLDisplayCapability *> *newDisplayCapabilityList = testDisplayCapabilityList = @[displayCapability];
                
                SDLSystemCapability *newCapability = [[SDLSystemCapability alloc] initWithDisplayCapabilities:newDisplayCapabilityList];
                SDLOnSystemCapabilityUpdated *testUpdateNotification = [[SDLOnSystemCapabilityUpdated alloc] initWithSystemCapability:newCapability];
                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveSystemCapabilityUpdatedNotification object:nil rpcNotification:testUpdateNotification];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                
                expect(testSystemCapabilityManager.displays).to(equal(testDisplayCapabilityList));
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
                expect(testSystemCapabilityManager.displayCapabilities).to(equal(testDisplayCapabilities));
                expect(testSystemCapabilityManager.buttonCapabilities).to(equal(testButtonCapabilities));
                expect(testSystemCapabilityManager.softButtonCapabilities).to(equal(testSoftButtonCapabilities));
                expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop
            }
        });
    });

    context(@"When sending a updateCapabilityType request in HMI FULL", ^{
        __block SDLGetSystemCapabilityResponse *testGetSystemCapabilityResponse = nil;
        __block SDLPhoneCapability *testPhoneCapability = nil;

        beforeEach(^{
            testPhoneCapability = [[SDLPhoneCapability alloc] initWithDialNumber:YES];

            testGetSystemCapabilityResponse = [[SDLGetSystemCapabilityResponse alloc] init];
            testGetSystemCapabilityResponse.systemCapability = [[SDLSystemCapability alloc] init];
            testGetSystemCapabilityResponse.systemCapability.phoneCapability = testPhoneCapability;
            testGetSystemCapabilityResponse.systemCapability.systemCapabilityType = SDLSystemCapabilityTypePhoneCall;

            testSystemCapabilityManager.currentHMILevel = SDLHMILevelFull;
        });

        context(@"If the request failed with an error", ^{
            __block NSError *testError = nil;

            beforeEach(^{
                testGetSystemCapabilityResponse.success = @NO;
                testError = [NSError errorWithDomain:NSCocoaErrorDomain code:-234 userInfo:nil];
            });

            it(@"should should not save the capabilities", ^{
                [testSystemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
                    expect(error).to(equal(testConnectionManager.defaultError));
                    expect(systemCapabilityManager.phoneCapability).to(beNil());
                }];

                [NSThread sleepForTimeInterval:0.1]; // This still needs to be here to ensure request is sent first
                [testConnectionManager respondToLastRequestWithResponse:testGetSystemCapabilityResponse];
            });
        });

        context(@"If the request succeeded", ^{
            beforeEach(^{
                testGetSystemCapabilityResponse.success = @YES;
            });

            it(@"should save the capabilitity", ^{
                [testSystemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
                    expect(testSystemCapabilityManager.phoneCapability).to(equal(testPhoneCapability));
                    expect(error).to(beNil());
                }];

                [NSThread sleepForTimeInterval:0.1]; // This still needs to be here to ensure request is sent first
                [testConnectionManager respondToLastRequestWithResponse:testGetSystemCapabilityResponse];
            });
        });

        afterEach(^{
            // Make sure the RAIR properties and other system capabilities were not inadvertently set
            expect(testSystemCapabilityManager.displays).to(beNil());
            expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
            expect(testSystemCapabilityManager.displayCapabilities).to(beNil());
            expect(testSystemCapabilityManager.softButtonCapabilities).to(beNil());
            expect(testSystemCapabilityManager.buttonCapabilities).to(beNil());
            expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop
            expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
            expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
            expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
            expect(testSystemCapabilityManager.vrCapability).to(beFalse());
            expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
            expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());
            expect(testSystemCapabilityManager.navigationCapability).to(beNil());
            expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
            expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
            expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
        });
    });

    describe(@"updating the SCM through OnSystemCapability in HMI Full", ^{
        __block SDLPhoneCapability *phoneCapability = nil;

        beforeEach(^{
            testSystemCapabilityManager.currentHMILevel = SDLHMILevelFull;

            phoneCapability = [[SDLPhoneCapability alloc] initWithDialNumber:YES];
            SDLSystemCapability *newCapability = [[SDLSystemCapability alloc] initWithPhoneCapability:phoneCapability];
            SDLOnSystemCapabilityUpdated *update = [[SDLOnSystemCapabilityUpdated alloc] initWithSystemCapability:newCapability];
            SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveSystemCapabilityUpdatedNotification object:nil rpcNotification:update];

            [[NSNotificationCenter defaultCenter] postNotification:notification];
        });

        it(@"should properly update phone capability", ^{
            expect(testSystemCapabilityManager.phoneCapability).toEventually(equal(phoneCapability));
        });
    });

    describe(@"subscribing to capability types when HMI is full", ^{
        __block TestSystemCapabilityObserver *phoneObserver = nil;
        __block TestSystemCapabilityObserver *navigationObserver = nil;
        __block TestSystemCapabilityObserver *videoStreamingObserver = nil;
        __block TestSystemCapabilityObserver *displaysObserver = nil;
        __block NSUInteger handlerTriggeredCount = 0;

        beforeEach(^{
            testSystemCapabilityManager.currentHMILevel = SDLHMILevelFull;

            handlerTriggeredCount = 0;
            [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"5.1.0"]; // supports subscriptions

            phoneObserver = [[TestSystemCapabilityObserver alloc] init];
            [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypePhoneCall withObserver:phoneObserver selector:@selector(capabilityUpdatedWithCapability:)];
            navigationObserver = [[TestSystemCapabilityObserver alloc] init];
            [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypeNavigation withObserver:navigationObserver selector:@selector(capabilityUpdatedWithCapability:error:)];
            videoStreamingObserver = [[TestSystemCapabilityObserver alloc] init];
            [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypeVideoStreaming withObserver:videoStreamingObserver selector:@selector(capabilityUpdatedWithCapability:error:subscribed:)];
            displaysObserver = [[TestSystemCapabilityObserver alloc] init];
            [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypeDisplays withObserver:displaysObserver selector:@selector(capabilityUpdatedWithCapability:error:subscribed:)];
        });

        context(@"when observers aren't supported", ^{
            __block BOOL observationSuccess = NO;

            beforeEach(^{
                [SDLGlobals sharedGlobals].rpcVersion = [SDLVersion versionWithString:@"5.0.0"]; // no subscriptions

                observationSuccess = [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypePhoneCall withObserver:phoneObserver selector:@selector(capabilityUpdatedWithCapability:)];
            });

            it(@"should fail to subscribe", ^{
                expect(observationSuccess).to(beTrue());
            });
        });

        context(@"from a GetSystemCapabilitiesResponse", ^{
            __block id handlerObserver = nil;

            beforeEach(^{
                handlerObserver = [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypePhoneCall withUpdateHandler:^(SDLSystemCapability * _Nullable capability, BOOL subscribed, NSError * _Nullable error) {
                    handlerTriggeredCount++;
                }];

                SDLGetSystemCapabilityResponse *testResponse = [[SDLGetSystemCapabilityResponse alloc] init];
                testResponse.systemCapability = [[SDLSystemCapability alloc] initWithPhoneCapability:[[SDLPhoneCapability alloc] initWithDialNumber:YES]];
                SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveGetSystemCapabilitiesResponse object:nil rpcResponse:testResponse];

                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should not notify subscribers of new data because it was sent outside of the SCM", ^{
                expect(handlerTriggeredCount).toEventually(equal(1));

                expect(phoneObserver.selectorCalledCount).toEventually(equal(0));
                expect(navigationObserver.selectorCalledCount).toEventually(equal(0));

                expect(videoStreamingObserver.selectorCalledCount).toEventually(equal(0));
                expect(videoStreamingObserver.subscribedValuesReceived).toEventually(haveCount(0));
                expect(videoStreamingObserver.subscribedValuesReceived.firstObject).toEventually(beNil());

                expect(displaysObserver.selectorCalledCount).toEventually(equal(1));
                expect(displaysObserver.subscribedValuesReceived).toEventually(haveCount(1));
                expect(displaysObserver.subscribedValuesReceived.firstObject).toEventually(beTrue());
            });

            describe(@"unsubscribing", ^{
                beforeEach(^{
                    [testSystemCapabilityManager unsubscribeFromCapabilityType:SDLSystemCapabilityTypePhoneCall withObserver:phoneObserver];
                    [testSystemCapabilityManager unsubscribeFromCapabilityType:SDLSystemCapabilityTypePhoneCall withObserver:handlerObserver];

                    SDLGetSystemCapabilityResponse *testResponse = [[SDLGetSystemCapabilityResponse alloc] init];
                    testResponse.systemCapability = [[SDLSystemCapability alloc] initWithPhoneCapability:[[SDLPhoneCapability alloc] initWithDialNumber:YES]];
                    SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveGetSystemCapabilitiesResponse object:nil rpcResponse:testResponse];

                    [[NSNotificationCenter defaultCenter] postNotification:notification];
                });

                it(@"should not notify the subscriber of the new data", ^{
                    expect(handlerTriggeredCount).toEventually(equal(1));

                    expect(phoneObserver.selectorCalledCount).toEventually(equal(0)); // No change from above
                    expect(navigationObserver.selectorCalledCount).toEventually(equal(0));
                    expect(videoStreamingObserver.selectorCalledCount).toEventually(equal(0));

                    expect(displaysObserver.selectorCalledCount).toEventually(equal(1));
                });
            });
        });

        context(@"from an OnSystemCapabilities notification", ^{
            __block id handlerObserver = nil;

            beforeEach(^{
                handlerObserver = [testSystemCapabilityManager subscribeToCapabilityType:SDLSystemCapabilityTypePhoneCall withUpdateHandler:^(SDLSystemCapability * _Nullable capability, BOOL subscribed, NSError * _Nullable error) {
                    handlerTriggeredCount++;
                }];

                SDLOnSystemCapabilityUpdated *testNotification = [[SDLOnSystemCapabilityUpdated alloc] initWithSystemCapability:[[SDLSystemCapability alloc] initWithPhoneCapability:[[SDLPhoneCapability alloc] initWithDialNumber:YES]]];
                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveSystemCapabilityUpdatedNotification object:nil rpcNotification:testNotification];

                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should notify subscribers of the new data", ^{
                expect(handlerTriggeredCount).toEventually(equal(2));

                expect(phoneObserver.selectorCalledCount).toEventually(equal(1));
                expect(navigationObserver.selectorCalledCount).toEventually(equal(0));

                expect(videoStreamingObserver.selectorCalledCount).toEventually(equal(0));
                expect(videoStreamingObserver.subscribedValuesReceived).toEventually(haveCount(0));
                expect(videoStreamingObserver.subscribedValuesReceived.firstObject).toEventually(beNil());

                expect(displaysObserver.selectorCalledCount).toEventually(equal(1));
                expect(displaysObserver.subscribedValuesReceived).toEventually(haveCount(1));
                expect(displaysObserver.subscribedValuesReceived.firstObject).toEventually(beTrue());
            });

            describe(@"unsubscribing", ^{
                beforeEach(^{
                    [testSystemCapabilityManager unsubscribeFromCapabilityType:SDLSystemCapabilityTypePhoneCall withObserver:phoneObserver];

                    SDLGetSystemCapabilityResponse *testResponse = [[SDLGetSystemCapabilityResponse alloc] init];
                    testResponse.systemCapability = [[SDLSystemCapability alloc] initWithPhoneCapability:[[SDLPhoneCapability alloc] initWithDialNumber:YES]];
                    SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:SDLDidReceiveGetSystemCapabilitiesResponse object:nil rpcResponse:testResponse];

                    [[NSNotificationCenter defaultCenter] postNotification:notification];
                });

                it(@"should not notify the subscriber of the new data", ^{
                    expect(phoneObserver.selectorCalledCount).toEventually(equal(1)); // No change from above
                    expect(navigationObserver.selectorCalledCount).toEventually(equal(0));
                    expect(videoStreamingObserver.selectorCalledCount).toEventually(equal(0));
                    expect(displaysObserver.selectorCalledCount).toEventually(equal(1));
                });
            });
        });
    });

    describe(@"merging app services capability changes", ^{
        __block SDLAppServicesCapabilities *baseAppServices = nil;
        __block SDLAppServiceCapability *deleteCapability = nil;
        __block SDLAppServiceCapability *updateCapability = nil;
        __block SDLAppServiceCapability *newCapability = nil;

        beforeEach(^{
            SDLAppServiceManifest *deleteCapabilityManifest = [[SDLAppServiceManifest alloc] initWithMediaServiceName:@"Delete me" serviceIcon:nil allowAppConsumers:YES maxRPCSpecVersion:nil handledRPCs:nil mediaServiceManifest:[[SDLMediaServiceManifest alloc] init]];
            SDLAppServiceRecord *deleteCapabilityRecord = [[SDLAppServiceRecord alloc] initWithServiceID:@"1234" serviceManifest:deleteCapabilityManifest servicePublished:YES serviceActive:YES];
            deleteCapability = [[SDLAppServiceCapability alloc] initWithUpdatedAppServiceRecord:deleteCapabilityRecord];

            SDLAppServiceManifest *updateCapabilityManifest = [[SDLAppServiceManifest alloc] initWithMediaServiceName:@"Update me" serviceIcon:nil allowAppConsumers:YES maxRPCSpecVersion:nil handledRPCs:nil mediaServiceManifest:[[SDLMediaServiceManifest alloc] init]];
            SDLAppServiceRecord *updateCapabilityRecord = [[SDLAppServiceRecord alloc] initWithServiceID:@"2345" serviceManifest:updateCapabilityManifest servicePublished:YES serviceActive:NO];
            updateCapability = [[SDLAppServiceCapability alloc] initWithUpdatedAppServiceRecord:updateCapabilityRecord];

            baseAppServices = [[SDLAppServicesCapabilities alloc] initWithAppServices:@[deleteCapability, updateCapability]];
            SDLSystemCapability *appServiceCapability = [[SDLSystemCapability alloc] initWithAppServicesCapabilities:baseAppServices];
            SDLOnSystemCapabilityUpdated *update = [[SDLOnSystemCapabilityUpdated alloc] initWithSystemCapability:appServiceCapability];
            SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveSystemCapabilityUpdatedNotification object:nil rpcNotification:update];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
        });

        it(@"should have the correct base services", ^{
            expect(testSystemCapabilityManager.appServicesCapabilities).to(equal(baseAppServices));
        });

        describe(@"when sending the merge update", ^{
            it(@"should correctly merge", ^{
                deleteCapability.updateReason = SDLServiceUpdateReasonRemoved;
                deleteCapability.updatedAppServiceRecord.servicePublished = @NO;
                deleteCapability.updatedAppServiceRecord.serviceActive = @NO;

                updateCapability.updateReason = SDLServiceUpdateReasonActivated;
                updateCapability.updatedAppServiceRecord.serviceActive = @YES;

                SDLAppServiceManifest *newCapabilityManifest = [[SDLAppServiceManifest alloc] initWithMediaServiceName:@"New me" serviceIcon:nil allowAppConsumers:YES maxRPCSpecVersion:nil handledRPCs:nil mediaServiceManifest:[[SDLMediaServiceManifest alloc] init]];
                SDLAppServiceRecord *newCapabilityRecord = [[SDLAppServiceRecord alloc] initWithServiceID:@"3456" serviceManifest:newCapabilityManifest servicePublished:YES serviceActive:NO];
                newCapability = [[SDLAppServiceCapability alloc] initWithUpdateReason:SDLServiceUpdateReasonPublished updatedAppServiceRecord:newCapabilityRecord];

                SDLAppServicesCapabilities *appServicesUpdate = [[SDLAppServicesCapabilities alloc] initWithAppServices:@[deleteCapability, updateCapability, newCapability]];
                SDLSystemCapability *appServiceCapability = [[SDLSystemCapability alloc] initWithAppServicesCapabilities:appServicesUpdate];
                SDLOnSystemCapabilityUpdated *update = [[SDLOnSystemCapabilityUpdated alloc] initWithSystemCapability:appServiceCapability];
                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveSystemCapabilityUpdatedNotification object:nil rpcNotification:update];
                [[NSNotificationCenter defaultCenter] postNotification:notification];

                expect(testSystemCapabilityManager.appServicesCapabilities.appServices).toNot(contain(deleteCapability));
                expect(testSystemCapabilityManager.appServicesCapabilities.appServices).to(haveCount(2));

                SDLAppServiceCapability *firstCapability = testSystemCapabilityManager.appServicesCapabilities.appServices.firstObject;
                SDLAppServiceCapability *secondCapability = testSystemCapabilityManager.appServicesCapabilities.appServices.lastObject;

                expect(firstCapability.updateReason).to(equal(SDLServiceUpdateReasonPublished));
                expect(firstCapability.updatedAppServiceRecord.serviceID).to(equal(@"3456"));

                expect(secondCapability.updateReason).to(equal(SDLServiceUpdateReasonActivated));
                expect(secondCapability.updatedAppServiceRecord.serviceID).to(equal(@"2345"));
                expect(secondCapability.updatedAppServiceRecord.serviceActive).to(beTrue());
            });
        });
    });

    describe(@"when the system capability manager is stopped after being started", ^{
        beforeEach(^{
            [testSystemCapabilityManager stop];
        });

        it(@"It should reset the system capability manager properties correctly", ^{
            expect(testSystemCapabilityManager.hmiCapabilities).to(beNil());
            expect(testSystemCapabilityManager.displays).to(beNil());
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
            expect(testSystemCapabilityManager.displayCapabilities).to(beNil());
            expect(testSystemCapabilityManager.softButtonCapabilities).to(beNil());
            expect(testSystemCapabilityManager.buttonCapabilities).to(beNil());
            expect(testSystemCapabilityManager.presetBankCapabilities).to(beNil());
#pragma clang diagnostic pop
            expect(testSystemCapabilityManager.hmiZoneCapabilities).to(beNil());
            expect(testSystemCapabilityManager.speechCapabilities).to(beNil());
            expect(testSystemCapabilityManager.prerecordedSpeechCapabilities).to(beNil());
            expect(testSystemCapabilityManager.vrCapability).to(beFalse());
            expect(testSystemCapabilityManager.audioPassThruCapabilities).to(beNil());
            expect(testSystemCapabilityManager.pcmStreamCapability).to(beNil());
            expect(testSystemCapabilityManager.phoneCapability).to(beNil());
            expect(testSystemCapabilityManager.navigationCapability).to(beNil());
            expect(testSystemCapabilityManager.videoStreamingCapability).to(beNil());
            expect(testSystemCapabilityManager.remoteControlCapability).to(beNil());
            expect(testSystemCapabilityManager.appServicesCapabilities).to(beNil());
            expect(testSystemCapabilityManager.driverDistractionCapability).to(beNil());
            expect(testSystemCapabilityManager.seatLocationCapability).to(beNil());
        });
    });
});

QuickSpecEnd