diff options
Diffstat (limited to 'SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m')
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m | 428 |
1 files changed, 203 insertions, 225 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m index fa08d2e38..100acc9c2 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleConfigurationSpec.m @@ -1,3 +1,10 @@ +// +// SDLLifecycleConfigurationSpec.m +// SmartDeviceLinkTests +// +// Copyright © 2018 smartdevicelink. All rights reserved. +// + #import <Quick/Quick.h> #import <Nimble/Nimble.h> @@ -8,263 +15,234 @@ #import "SDLSpeechCapabilities.h" #import "SDLTTSChunk.h" + +@interface SDLLifecycleConfiguration() + ++ (NSString *)sdlex_shortAppIdFromFullAppId:(NSString *)fullAppId; + +@end + + QuickSpecBegin(SDLLifecycleConfigurationSpec) -describe(@"a lifecycle configuration", ^{ +describe(@"A lifecycle configuration", ^{ __block SDLLifecycleConfiguration *testConfig = nil; - - context(@"that is created with default settings", ^{ - __block NSString *someAppName = nil; - __block NSString *someAppId = nil; - - beforeEach(^{ - someAppName = @"An App Name"; - someAppId = @"00542596432764329684352896423679"; - - testConfig = [SDLLifecycleConfiguration defaultConfigurationWithAppName:someAppName appId:someAppId]; - }); - - it(@"should have properly set properties", ^{ - expect(testConfig.appName).to(match(someAppName)); - expect(testConfig.appId).to(match(someAppId)); - expect(@(testConfig.tcpDebugMode)).to(beFalsy()); - expect(testConfig.tcpDebugIPAddress).to(match(@"192.168.0.1")); - expect(@(testConfig.tcpDebugPort)).to(equal(@12345)); - expect(@([testConfig.appType isEqualToEnum:SDLAppHMITypeDefault])).to(equal(@YES)); - expect(testConfig.additionalAppTypes).to(beNil()); - expect(@(testConfig.isMedia)).to(beFalsy()); - expect(@([testConfig.language isEqualToEnum:SDLLanguageEnUs])).to(equal(@YES)); - expect(@([[testConfig.languagesSupported firstObject] isEqualToEnum:SDLLanguageEnUs])).to(equal(@YES)); - expect(testConfig.shortAppName).to(beNil()); - expect(testConfig.ttsName).to(beNil()); - expect(testConfig.voiceRecognitionCommandNames).to(beNil()); - expect(testConfig.resumeHash).to(beNil()); + __block NSString *testAppName = @"An App Name"; + __block NSString *testAppId = @"00542596"; + __block NSString *testFullAppId = @"-ab--987-adfa651kj-212346h3kjkaju"; + __block NSString *expectedGeneratedAppId = @"ab987adfa6"; + + beforeEach(^{ + testConfig = nil; + }); + + context(@"created with a default configuration", ^{ + context(@"should be successfully initialized", ^{ + it(@"defaultConfigurationWithAppName:appId:", ^{ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testConfig = [SDLLifecycleConfiguration defaultConfigurationWithAppName:testAppName appId:testAppId]; + + expect(testConfig.appId).to(match(testAppId)); + expect(testConfig.fullAppId).to(beNil()); + #pragma clang diagnostic pop + }); + + it(@"defaultConfigurationWithAppName:fullAppId:", ^{ + testConfig = [SDLLifecycleConfiguration defaultConfigurationWithAppName:testAppName fullAppId:testFullAppId]; + + expect(testConfig.appId).to(match(expectedGeneratedAppId)); + expect(testConfig.fullAppId).to(match(testFullAppId)); + }); + + afterEach(^{ + expect(testConfig.appName).to(match(testAppName)); + expect(testConfig.tcpDebugMode).to(beFalse()); + expect(testConfig.tcpDebugIPAddress).to(match(@"192.168.0.1")); + expect(@(testConfig.tcpDebugPort)).to(equal(@12345)); + expect(testConfig.appType).to(match(SDLAppHMITypeDefault)); + expect(testConfig.additionalAppTypes).to(beNil()); + expect(testConfig.isMedia).to(beFalse()); + expect(testConfig.language).to(match(SDLLanguageEnUs)); + expect(testConfig.languagesSupported.firstObject).to(match(SDLLanguageEnUs)); + expect(testConfig.shortAppName).to(beNil()); + expect(testConfig.ttsName).to(beNil()); + expect(testConfig.voiceRecognitionCommandNames).to(beNil()); + expect(testConfig.resumeHash).to(beNil()); + }); }); - - describe(@"after setting properties manually", ^{ - __block NSString *someShortAppName = nil; - __block SDLTTSChunk *someTTSChunk = nil; - __block NSArray<SDLTTSChunk *> *someTTSName = nil; - __block NSArray<NSString *> *someSynonyms = nil; - __block NSString *someResumeHashString = nil; - + + context(@"If customized", ^{ + __block NSString *testShortAppName = nil; + __block SDLTTSChunk *testTTSChunk = nil; + __block NSArray<SDLTTSChunk *> *testTTSName = nil; + __block NSArray<NSString *> *testSynonyms = nil; + __block NSString *testResumeHashString = nil; + beforeEach(^{ - someTTSChunk = [[SDLTTSChunk alloc] init]; - someTTSChunk.text = @"some tts name"; - someTTSChunk.type = SDLSpeechCapabilitiesText; - - someTTSName = @[someTTSChunk]; - someShortAppName = @"Short Name"; - someSynonyms = @[@"Test 1", @"Test 2", @"Test 3", @"Test 4"]; - someResumeHashString = @"testing"; - + testConfig = [SDLLifecycleConfiguration defaultConfigurationWithAppName:testAppName fullAppId:testFullAppId]; + }); + + it(@"it should get and set correctly", ^{ + testShortAppName = @"Short Name"; + testTTSChunk = [[SDLTTSChunk alloc] initWithText:@"test tts name" type:SDLSpeechCapabilitiesText]; + testTTSName = @[testTTSChunk]; + testSynonyms = @[@"Test 1", @"Test 2", @"Test 3", @"Test 4"]; + testResumeHashString = @"testing"; + testConfig.appType = SDLAppHMITypeMedia; testConfig.additionalAppTypes = @[SDLAppHMITypeProjection]; testConfig.language = SDLLanguageArSa; testConfig.languagesSupported = @[SDLLanguageArSa, SDLLanguageEnAu, SDLLanguageEnUs]; - testConfig.shortAppName = someShortAppName; - testConfig.ttsName = someTTSName; - testConfig.voiceRecognitionCommandNames = someSynonyms; - testConfig.resumeHash = someResumeHashString; + testConfig.shortAppName = testShortAppName; + testConfig.ttsName = testTTSName; + testConfig.voiceRecognitionCommandNames = testSynonyms; + testConfig.resumeHash = testResumeHashString; }); - - it(@"should have properly set properties", ^{ - expect(testConfig.appName).to(match(someAppName)); - expect(testConfig.appId).to(match(someAppId)); - expect(@(testConfig.tcpDebugMode)).to(beFalsy()); + + afterEach(^{ + expect(testConfig.appName).to(match(testAppName)); + expect(testConfig.shortAppName).to(match(testShortAppName)); + expect(testConfig.fullAppId).to(match(testFullAppId)); + expect(testConfig.appId).to(match(expectedGeneratedAppId)); + expect(testConfig.tcpDebugMode).to(beFalse()); expect(testConfig.tcpDebugIPAddress).to(match(@"192.168.0.1")); expect(@(testConfig.tcpDebugPort)).to(equal(@12345)); - expect(@([testConfig.appType isEqualToEnum:SDLAppHMITypeMedia])).to(equal(@YES)); + expect(testConfig.appType).to(match(SDLAppHMITypeMedia)); expect(testConfig.additionalAppTypes.firstObject).to(match(SDLAppHMITypeProjection)); - expect(@(testConfig.isMedia)).to(beTruthy()); - expect(@([testConfig.language isEqualToEnum:SDLLanguageArSa])).to(equal(@YES)); + expect(testConfig.isMedia).to(beTrue()); + expect(testConfig.language).to(match(SDLLanguageArSa)); expect(testConfig.languagesSupported).to(haveCount(@3)); - expect(testConfig.shortAppName).to(match(someShortAppName)); - expect(testConfig.ttsName).to(contain(someTTSChunk)); + expect(testConfig.ttsName).to(contain(testTTSChunk)); expect(testConfig.ttsName).to(haveCount(@1)); - expect(testConfig.voiceRecognitionCommandNames).to(haveCount(@(someSynonyms.count))); - expect(testConfig.resumeHash).to(match(someResumeHashString)); + expect(testConfig.voiceRecognitionCommandNames).to(haveCount(@(testSynonyms.count))); + expect(testConfig.resumeHash).to(match(testResumeHashString)); }); }); }); - context(@"that is created with debug settings", ^{ - __block NSString *someAppName = nil; - __block NSString *someAppId = nil; - __block NSString *someIPAddress = nil; - __block UInt16 somePort = 0; + context(@"created with a debug configuration", ^{ + __block NSString *testIPAddress = nil; + __block UInt16 testPort = 0; beforeEach(^{ - someAppName = @"An App Name"; - someAppId = @"00542596432764329684352896423679"; - someIPAddress = @"1.1.1.1"; - somePort = 42; - - testConfig = [SDLLifecycleConfiguration debugConfigurationWithAppName:someAppName appId:someAppId ipAddress:someIPAddress port:somePort]; + testIPAddress = @"1.1.1.1"; + testPort = 42; }); - - it(@"should have properly set properties", ^{ - expect(testConfig.appName).to(match(someAppName)); - expect(testConfig.appId).to(match(someAppId)); - expect(@(testConfig.tcpDebugMode)).to(beTruthy()); - expect(testConfig.tcpDebugIPAddress).to(match(someIPAddress)); - expect(@(testConfig.tcpDebugPort)).to(equal(@(somePort))); - expect(@([testConfig.appType isEqualToEnum:SDLAppHMITypeDefault])).to(equal(@YES)); - expect(testConfig.additionalAppTypes).to(beNil()); - expect(@([testConfig.language isEqualToEnum:SDLLanguageEnUs])).to(equal(@YES)); - expect(@([[testConfig.languagesSupported firstObject] isEqualToEnum:SDLLanguageEnUs])).to(equal(@YES)); - expect(testConfig.shortAppName).to(beNil()); - expect(testConfig.ttsName).to(beNil()); - expect(testConfig.voiceRecognitionCommandNames).to(beNil()); - expect(testConfig.resumeHash).to(beNil()); + + context(@"should be successfully initialized", ^{ + it(@"debugConfigurationWithAppName:appId:ipAddress:port:", ^{ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testConfig = [SDLLifecycleConfiguration debugConfigurationWithAppName:testAppName appId:testAppId ipAddress:testIPAddress port:testPort]; + + expect(testConfig.appId).to(match(testAppId)); + expect(testConfig.fullAppId).to(beNil()); + #pragma clang diagnostic pop + }); + + it(@"debugConfigurationWithAppName:fullAppId:ipAddress:port:", ^{ + testConfig = [SDLLifecycleConfiguration debugConfigurationWithAppName:testAppName fullAppId:testFullAppId ipAddress:testIPAddress port:testPort]; + + expect(testConfig.appId).to(match(expectedGeneratedAppId)); + expect(testConfig.fullAppId).to(match(testFullAppId)); + }); + + afterEach(^{ + expect(testConfig.appName).to(match(testAppName)); + expect(testConfig.tcpDebugMode).to(beTrue()); + expect(testConfig.tcpDebugIPAddress).to(match(testIPAddress)); + expect(@(testConfig.tcpDebugPort)).to(equal(@(testPort))); + expect(testConfig.appType).to(match(SDLAppHMITypeDefault)); + expect(testConfig.additionalAppTypes).to(beNil()); + expect(testConfig.language).to(match(SDLLanguageEnUs)); + expect(testConfig.languagesSupported.firstObject).to(match(SDLLanguageEnUs)); + expect(testConfig.shortAppName).to(beNil()); + expect(testConfig.ttsName).to(beNil()); + expect(testConfig.voiceRecognitionCommandNames).to(beNil()); + expect(testConfig.resumeHash).to(beNil()); + }); }); - - describe(@"after setting properties manually", ^{ - __block NSString *someShortAppName = nil; - __block SDLTTSChunk *someTTSChunk = nil; - __block NSArray<SDLTTSChunk *> *someTTSName = nil; - __block NSArray<NSString *> *someSynonyms = nil; - __block NSString *someResumeHashString = nil; - + + context(@"If customized", ^{ + __block NSString *testShortAppName = nil; + __block SDLTTSChunk *testTTSChunk = nil; + __block NSArray<SDLTTSChunk *> *testTTSName = nil; + __block NSArray<NSString *> *testSynonyms = nil; + __block NSString *testResumeHashString = nil; + beforeEach(^{ - someTTSChunk = [[SDLTTSChunk alloc] init]; - someTTSChunk.text = @"some tts name"; - someTTSChunk.type = SDLSpeechCapabilitiesText; - - someShortAppName = @"Short Name 2"; - someTTSName = @[someTTSChunk]; - someSynonyms = @[@"Test 1", @"Test 2"]; - - testConfig.appType = SDLAppHMITypeMedia; + testConfig = [SDLLifecycleConfiguration debugConfigurationWithAppName:testAppName fullAppId:testFullAppId ipAddress:testIPAddress port:testPort]; + }); + + it(@"it should get and set correctly", ^{ + testShortAppName = @"Test Short Name"; + testTTSChunk = [[SDLTTSChunk alloc] initWithText:@"test tts name" type:SDLSpeechCapabilitiesText]; + testTTSName = @[testTTSChunk]; + testSynonyms = @[@"Test 1", @"Test 2", @"Test 3", @"Test 4"]; + testResumeHashString = @"testing"; + + testConfig.appType = SDLAppHMITypeInformation; + testConfig.additionalAppTypes = @[SDLAppHMITypeProjection]; testConfig.language = SDLLanguageArSa; testConfig.languagesSupported = @[SDLLanguageArSa, SDLLanguageEnAu, SDLLanguageEnUs]; - testConfig.shortAppName = someShortAppName; - testConfig.ttsName = someTTSName; - testConfig.voiceRecognitionCommandNames = someSynonyms; - testConfig.resumeHash = someResumeHashString; + testConfig.shortAppName = testShortAppName; + testConfig.ttsName = testTTSName; + testConfig.voiceRecognitionCommandNames = testSynonyms; + testConfig.resumeHash = testResumeHashString; }); - - it(@"should have properly set properties", ^{ - expect(testConfig.appName).to(match(someAppName)); - expect(testConfig.appId).to(match(someAppId)); - expect(@(testConfig.tcpDebugMode)).to(beTruthy()); - expect(testConfig.tcpDebugIPAddress).to(match(someIPAddress)); - expect(@(testConfig.tcpDebugPort)).to(equal(@(somePort))); - expect(@([testConfig.appType isEqualToEnum:SDLAppHMITypeMedia])).to(equal(@YES)); - expect(testConfig.additionalAppTypes).to(beNil()); - expect(@(testConfig.isMedia)).to(beTruthy()); - expect(@([testConfig.language isEqualToEnum:SDLLanguageArSa])).to(equal(@YES)); + + afterEach(^{ + expect(testConfig.appName).to(match(testAppName)); + expect(testConfig.shortAppName).to(match(testShortAppName)); + expect(testConfig.fullAppId).to(match(testFullAppId)); + expect(testConfig.appId).to(match(expectedGeneratedAppId)); + expect(testConfig.tcpDebugMode).to(beTrue()); + expect(testConfig.tcpDebugIPAddress).to(match(@"1.1.1.1")); + expect(@(testConfig.tcpDebugPort)).to(equal(@42)); + expect(testConfig.appType).to(match(SDLAppHMITypeInformation)); + expect(testConfig.additionalAppTypes.firstObject).to(match(SDLAppHMITypeProjection)); + expect(testConfig.isMedia).to(beFalse()); + expect(testConfig.language).to(match(SDLLanguageArSa)); expect(testConfig.languagesSupported).to(haveCount(@3)); - expect(testConfig.shortAppName).to(match(someShortAppName)); - expect(testConfig.ttsName).to(contain(someTTSChunk)); + expect(testConfig.ttsName).to(contain(testTTSChunk)); expect(testConfig.ttsName).to(haveCount(@1)); - expect(testConfig.voiceRecognitionCommandNames).to(haveCount(@(someSynonyms.count))); + expect(testConfig.voiceRecognitionCommandNames).to(haveCount(@(testSynonyms.count))); + expect(testConfig.resumeHash).to(match(testResumeHashString)); }); }); }); - - context(@"that configuration update properties are set", ^{ - describe(@"after using default init", ^{ - __block SDLLifecycleConfigurationUpdate *update = nil; - - beforeEach(^{ - update = [[SDLLifecycleConfigurationUpdate alloc] init]; - }); - - it(@"should have all properties to nil", ^{ - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set app name", ^{ - NSString *test = @"Some Test String"; - update.appName = test; - expect(update.appName).to(match(test)); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set short app name", ^{ - NSString *test = @"Some Test String"; - update.shortAppName = test; - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(match(test)); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set tts app name", ^{ - NSArray<SDLTTSChunk *> *test = [SDLTTSChunk textChunksFromString:@"Some Test String"]; - update.ttsName = test; - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(equal(test)); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set vr synonyms", ^{ - NSArray<NSString *> *test = @[@"Some Test String"]; - update.voiceRecognitionCommandNames = test; - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(equal(test)); - }); - }); - - describe(@"after using default init", ^{ - it(@"should have all properties to nil", ^{ - SDLLifecycleConfigurationUpdate *update = [[SDLLifecycleConfigurationUpdate alloc] initWithAppName:nil shortAppName:nil ttsName:nil voiceRecognitionCommandNames:nil]; - - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set app name", ^{ - NSString *test = @"Some Test String"; - SDLLifecycleConfigurationUpdate *update = [[SDLLifecycleConfigurationUpdate alloc] initWithAppName:test shortAppName:nil ttsName:nil voiceRecognitionCommandNames:nil]; - - expect(update.appName).to(match(test)); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set short app name", ^{ - NSString *test = @"Some Test String"; - SDLLifecycleConfigurationUpdate *update = [[SDLLifecycleConfigurationUpdate alloc] initWithAppName:nil shortAppName:test ttsName:nil voiceRecognitionCommandNames:nil]; - - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(match(test)); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set tts app name", ^{ - NSArray<SDLTTSChunk *> *test = [SDLTTSChunk textChunksFromString:@"Some Test String"]; - SDLLifecycleConfigurationUpdate *update = [[SDLLifecycleConfigurationUpdate alloc] initWithAppName:nil shortAppName:nil ttsName:test voiceRecognitionCommandNames:nil]; - - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(equal(test)); - expect(update.voiceRecognitionCommandNames).to(beNil()); - }); - - it(@"should set vr synonyms", ^{ - NSArray<NSString *> *test = @[@"Some Test String"]; - SDLLifecycleConfigurationUpdate *update = [[SDLLifecycleConfigurationUpdate alloc] initWithAppName:nil shortAppName:nil ttsName:nil voiceRecognitionCommandNames:test]; - - expect(update.appName).to(beNil()); - expect(update.shortAppName).to(beNil()); - expect(update.ttsName).to(beNil()); - expect(update.voiceRecognitionCommandNames).to(equal(test)); - }); - }); +}); + +describe(@"When generating the `appId` from the `fullAppId`", ^{ + it(@"should return nil if full app id is nil", ^{ + NSString *testFullAppId = nil; + NSString *appId = [SDLLifecycleConfiguration sdlex_shortAppIdFromFullAppId:testFullAppId]; + expect(appId).to(beNil()); + }); + + it(@"should return an empty string if the full app id is empty", ^{ + NSString *testFullAppId = @""; + NSString *appId = [SDLLifecycleConfiguration sdlex_shortAppIdFromFullAppId:testFullAppId]; + expect(appId).to(beEmpty()); + }); + + it(@"should return a string truncated to the first non-dash 10 characters", ^{ + NSString *testFullAppId = @"34-uipe--k-rtqwedeftg-1"; + NSString *appId = [SDLLifecycleConfiguration sdlex_shortAppIdFromFullAppId:testFullAppId]; + expect(appId).to(match(@"34uipekrtq")); + }); + + it(@"should return a string if the full app id is less than 10 characters", ^{ + NSString *testFullAppId = @"a"; + NSString *appId = [SDLLifecycleConfiguration sdlex_shortAppIdFromFullAppId:testFullAppId]; + expect(appId).to(match(@"a")); + }); + + it(@"should return an empty string if the full app id only has dash characters", ^{ + NSString *testFullAppId = @"-"; + NSString *appId = [SDLLifecycleConfiguration sdlex_shortAppIdFromFullAppId:testFullAppId]; + expect(appId).to(beEmpty()); }); }); |