diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-05-18 09:30:32 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-05-18 09:30:32 -0400 |
commit | 34ed36473ac4284c5e80af7e34a0509b62176a85 (patch) | |
tree | f3c54dd3eed321617922c54828589668476a4b8c | |
parent | 16667c41bb3a8fde90b32aa454924237ff9c656b (diff) | |
download | sdl_ios-bugfix/issue_966_sdlshow_crash.tar.gz |
Additional show initializer fixbugfix/issue_966_sdlshow_crash
* Additional expanded tests
-rw-r--r-- | SmartDeviceLink/SDLShow.m | 12 | ||||
-rw-r--r-- | SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m | 160 |
2 files changed, 166 insertions, 6 deletions
diff --git a/SmartDeviceLink/SDLShow.m b/SmartDeviceLink/SDLShow.m index 98421f7c0..743e4940a 100644 --- a/SmartDeviceLink/SDLShow.m +++ b/SmartDeviceLink/SDLShow.m @@ -47,17 +47,17 @@ NS_ASSUME_NONNULL_BEGIN return [self initWithMainField1:mainField1 mainField2:mainField2 mainField3:mainField3 mainField4:mainField4 alignment:alignment statusBar:nil mediaClock:nil mediaTrack:nil graphic:nil softButtons:nil customPresets:nil textFieldMetadata:nil]; } -- (instancetype)initWithMainField1:(nullable NSString *)mainField1 mainField1Type:(nullable SDLMetadataType)mainField1Type mainField2:(nullable NSString *)mainField2 mainField2Type:(nullable SDLMetadataType)mainField2Type mainField3:(nullable NSString *)mainField3 mainField3Type:(nullable SDLMetadataType)mainField3Type mainField4:(nullable NSString *)mainField4 mainField4Type:(nullable SDLMetadataType)mainField4Type alignment:(nullable SDLTextAlignment)alignment{ +- (instancetype)initWithMainField1:(nullable NSString *)mainField1 mainField1Type:(nullable SDLMetadataType)mainField1Type mainField2:(nullable NSString *)mainField2 mainField2Type:(nullable SDLMetadataType)mainField2Type mainField3:(nullable NSString *)mainField3 mainField3Type:(nullable SDLMetadataType)mainField3Type mainField4:(nullable NSString *)mainField4 mainField4Type:(nullable SDLMetadataType)mainField4Type alignment:(nullable SDLTextAlignment)alignment { self = [self init]; if (!self) { return nil; } - NSArray<SDLMetadataType> *field1Array = @[mainField1Type]; - NSArray<SDLMetadataType> *field2Array = @[mainField2Type]; - NSArray<SDLMetadataType> *field3Array = @[mainField3Type]; - NSArray<SDLMetadataType> *field4Array = @[mainField4Type]; - SDLMetadataTags* metadataTags = [[SDLMetadataTags alloc] initWithTextFieldTypes:field1Array mainField2:field2Array mainField3:field3Array mainField4:field4Array]; + NSArray<SDLMetadataType> *field1Array = mainField1Type ? @[mainField1Type] : nil; + NSArray<SDLMetadataType> *field2Array = mainField2Type ? @[mainField2Type] : nil; + NSArray<SDLMetadataType> *field3Array = mainField3Type ? @[mainField3Type] : nil; + NSArray<SDLMetadataType> *field4Array = mainField4Type ? @[mainField4Type] : nil; + SDLMetadataTags* metadataTags = (field1Array != nil || field2Array != nil || field3Array != nil || field4Array != nil) ? [[SDLMetadataTags alloc] initWithTextFieldTypes:field1Array mainField2:field2Array mainField3:field3Array mainField4:field4Array] : nil; self.mainField1 = mainField1; self.mainField2 = mainField2; diff --git a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m index 430718d75..e41d73cc8 100644 --- a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLShowSpec.m @@ -80,9 +80,29 @@ describe(@"Getter/Setter Tests", ^ { 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"]; + 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]; @@ -151,6 +171,146 @@ describe(@"Getter/Setter Tests", ^ { 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: |