diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-06-04 11:22:25 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-06-04 11:22:25 -0400 |
commit | f11662ac91406411aec9d0ccfca32dd1a942e3de (patch) | |
tree | ebcf75290bc03b6526b75d6c525060d747a01f32 | |
parent | 2948dd8433ac3c21702d9a4f39bbdf98678c081c (diff) | |
download | sdl_ios-f11662ac91406411aec9d0ccfca32dd1a942e3de.tar.gz |
updated tests for each new method call outside of the observer
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.h | 2 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.m | 4 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m | 337 |
3 files changed, 243 insertions, 100 deletions
diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h index 0f111d2c6..ef7d63020 100644 --- a/SmartDeviceLink/SDLPermissionManager.h +++ b/SmartDeviceLink/SDLPermissionManager.h @@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return YES if the RPC is allowed at the current HMI level, NO if not */ -- (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName; +- (BOOL)isRPCPermitted:(SDLRPCFunctionName)rpcName; /** * Determine if all RPCs are allowed for the current HMI level diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m index 02269d765..a0f43f601 100644 --- a/SmartDeviceLink/SDLPermissionManager.m +++ b/SmartDeviceLink/SDLPermissionManager.m @@ -74,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN return [item.hmiPermissions.allowed containsObject:self.currentHMILevel]; } -- (BOOL)isRPCNameAllowed:(SDLRPCFunctionName)rpcName { +- (BOOL)isRPCPermitted:(SDLRPCFunctionName)rpcName { if (self.permissions[rpcName] == nil || self.currentHMILevel == nil) { return NO; } @@ -155,7 +155,7 @@ NS_ASSUME_NONNULL_BEGIN NSMutableDictionary<SDLPermissionRPCName, NSNumber *> *permissionAllowedDict = [NSMutableDictionary dictionary]; // to do for (NSString *rpcName in rpcNames) { - BOOL allowed = [self isRPCNameAllowed:rpcName]; + BOOL allowed = [self isRPCPermitted:rpcName]; permissionAllowedDict[rpcName] = @(allowed); } diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m index 2e5f754ff..f085878d8 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionsManagerSpec.m @@ -11,6 +11,7 @@ #import "SDLPermissionFilter.h" #import "SDLPermissionItem.h" #import "SDLPermissionManager.h" +#import "SDLRPCFunctionNames.h" #import "SDLRPCNotificationNotification.h" #import "SDLRPCResponseNotification.h" @@ -133,162 +134,304 @@ describe(@"SDLPermissionsManager", ^{ describe(@"checking if a permission is allowed", ^{ __block NSString *someRPCName = nil; + __block SDLRPCFunctionName someRPCFunctionName = nil; __block BOOL testResultBOOL = NO; - + context(@"when no permissions exist", ^{ - beforeEach(^{ - someRPCName = @"some rpc name"; + context(@"deprecated isRPCAllowed: method", ^{ + beforeEach(^{ + someRPCName = @"some rpc name"; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultBOOL = [testPermissionsManager isRPCAllowed:someRPCName]; -#pragma clang diagnostic pop + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultBOOL = [testPermissionsManager isRPCAllowed:someRPCName]; + #pragma clang diagnostic pop + }); + + it(@"should not be allowed", ^{ + expect(@(testResultBOOL)).to(equal(@NO)); + }); }); - - it(@"should not be allowed", ^{ - expect(@(testResultBOOL)).to(equal(@NO)); + + context(@"isRPCPermitted: method", ^{ + beforeEach(^{ + someRPCFunctionName = @"SomeRPCFunctionName"; + testResultBOOL = [testPermissionsManager isRPCPermitted:someRPCName]; + }); + + it(@"should not be allowed", ^{ + expect(@(testResultBOOL)).to(equal(@NO)); + }); }); }); context(@"when permissions exist but no HMI level", ^{ - beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed]; -#pragma clang diagnostic pop - }); - - it(@"should not be allowed", ^{ - expect(@(testResultBOOL)).to(equal(@NO)); - }); - }); - - context(@"when permissions exist", ^{ - context(@"and the permission is allowed", ^{ + context(@"deprecated isRPCAllowed: method", ^{ beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed]; -#pragma clang diagnostic pop + #pragma clang diagnostic pop }); - - it(@"should be allowed", ^{ - expect(@(testResultBOOL)).to(equal(@YES)); + + it(@"should not be allowed", ^{ + expect(@(testResultBOOL)).to(equal(@NO)); }); }); - - context(@"and the permission is denied", ^{ + + context(@"isRPCPermitted: method", ^{ beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllDisallowed]; -#pragma clang diagnostic pop + testResultBOOL = [testPermissionsManager isRPCPermitted:someRPCName]; }); - - it(@"should be denied", ^{ + + it(@"should not be allowed", ^{ expect(@(testResultBOOL)).to(equal(@NO)); }); }); }); + + context(@"when permissions exist", ^{ + context(@"deprecated isRPCAllowed: method", ^{ + context(@"and the permission is allowed", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllAllowed]; + #pragma clang diagnostic pop + }); + + it(@"should be allowed", ^{ + expect(@(testResultBOOL)).to(equal(@YES)); + }); + }); + + context(@"and the permission is denied", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultBOOL = [testPermissionsManager isRPCAllowed:testRPCNameAllDisallowed]; + #pragma clang diagnostic pop + }); + + it(@"should be denied", ^{ + expect(@(testResultBOOL)).to(equal(@NO)); + }); + }); + }); + + context(@"isRPCPermitted: method", ^{ + context(@"and the permission is allowed", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultBOOL = [testPermissionsManager isRPCPermitted:testRPCNameAllAllowed]; + }); + + it(@"should be allowed", ^{ + expect(@(testResultBOOL)).to(equal(@YES)); + }); + }); + + context(@"and the permission is denied", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultBOOL = [testPermissionsManager isRPCPermitted:testRPCNameAllDisallowed]; + }); + + it(@"should be denied", ^{ + expect(@(testResultBOOL)).to(equal(@NO)); + }); + }); + }); + }); }); describe(@"checking the group status of RPCs", ^{ __block SDLPermissionGroupStatus testResultStatus = SDLPermissionGroupStatusUnknown; context(@"with no permissions data", ^{ - beforeEach(^{ + context(@"deprecated groupStatusOfRPCs: method", ^{ + beforeEach(^{ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; #pragma clang diagnostic pop + }); + + it(@"should return unknown", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown))); + }); }); - - it(@"should return unknown", ^{ - expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown))); + + context(@"groupStatusOfRPCNames: method", ^{ + beforeEach(^{ + testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + }); + + it(@"should return unknown", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusUnknown))); + }); }); }); context(@"for an all allowed group", ^{ - beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; - [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]]; - #pragma clang diagnostic pop + context(@"deprecated groupStatusOfRPCs: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]]; + #pragma clang diagnostic pop + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed))); + }); }); - - it(@"should return mixed", ^{ - expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed))); + + context(@"groupStatusOfRPCNames: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameFullLimitedAllowed]]; + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusAllowed))); + }); }); }); context(@"for an all disallowed group", ^{ - beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification]; - [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]]; - #pragma clang diagnostic pop + context(@"deprecated groupStatusOfRPCs: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]]; + #pragma clang diagnostic pop + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed))); + }); }); - - it(@"should return mixed", ^{ - expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed))); + + context(@"groupStatusOfRPCNames: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:backgroundHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameFullLimitedAllowed, testRPCNameAllDisallowed]]; + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusDisallowed))); + }); }); }); context(@"for a mixed group", ^{ - beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; - [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; - #pragma clang diagnostic pop + context(@"deprecated groupStatusOfRPCs: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultStatus = [testPermissionsManager groupStatusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + #pragma clang diagnostic pop + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed))); + }); }); - - it(@"should return mixed", ^{ - expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed))); + + context(@"groupStatusOfRPCNames: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultStatus = [testPermissionsManager groupStatusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + }); + + it(@"should return mixed", ^{ + expect(@(testResultStatus)).to(equal(@(SDLPermissionGroupStatusMixed))); + }); }); }); }); describe(@"checking the status of RPCs", ^{ __block NSDictionary<SDLPermissionRPCName, NSNumber *> *testResultPermissionStatusDict = nil; - context(@"with no permissions data", ^{ - beforeEach(^{ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; - #pragma clang diagnostic pop + context(@"deprecated statusOfRPCs: method", ^{ + beforeEach(^{ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + #pragma clang diagnostic pop + }); + + it(@"should return correct permission statuses", ^{ + expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO)); + expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + }); }); - - it(@"should return correct permission statuses", ^{ - expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO)); - expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + + context(@"statusOfRPCNames: method", ^{ + beforeEach(^{ + testResultPermissionStatusDict = [testPermissionsManager statusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + }); + + it(@"should return correct permission statuses", ^{ + expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@NO)); + expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + }); }); }); context(@"with permissions data", ^{ - beforeEach(^{ - [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; - [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" - testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; - #pragma clang diagnostic pop + context(@"deprecated statusOfRPCs: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + testResultPermissionStatusDict = [testPermissionsManager statusOfRPCs:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + #pragma clang diagnostic pop + }); + + it(@"should return correct permission statuses", ^{ + expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES)); + expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + }); }); - - it(@"should return correct permission statuses", ^{ - expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES)); - expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + + context(@"statusOfRPCNames: method", ^{ + beforeEach(^{ + [[NSNotificationCenter defaultCenter] postNotification:limitedHMINotification]; + [[NSNotificationCenter defaultCenter] postNotification:testPermissionsNotification]; + + testResultPermissionStatusDict = [testPermissionsManager statusOfRPCNames:@[testRPCNameAllAllowed, testRPCNameAllDisallowed]]; + }); + + it(@"should return correct permission statuses", ^{ + expect(testResultPermissionStatusDict[testRPCNameAllAllowed]).to(equal(@YES)); + expect(testResultPermissionStatusDict[testRPCNameAllDisallowed]).to(equal(@NO)); + }); }); }); }); |