diff options
author | lapinskijw <jlapinski.dev@gmail.com> | 2020-06-23 08:14:48 -0400 |
---|---|---|
committer | lapinskijw <jlapinski.dev@gmail.com> | 2020-06-23 08:14:48 -0400 |
commit | 344c69646d1c2fcbc340d52b61e27899696d43db (patch) | |
tree | 57dc4335ee19f4bce2209bbe5b6e48a36c44e7f3 | |
parent | a2ff87a424d0cd1e9e88e1073951114625c8a28f (diff) | |
download | sdl_ios-344c69646d1c2fcbc340d52b61e27899696d43db.tar.gz |
added nscopying and adjusted permission filter spec tests
-rw-r--r-- | SmartDeviceLink/SDLPermissionElement.h | 5 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionElement.m | 9 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionFilter.h | 13 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionFilter.m | 6 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.h | 2 | ||||
-rw-r--r-- | SmartDeviceLink/SDLPermissionManager.m | 4 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m | 41 |
7 files changed, 49 insertions, 31 deletions
diff --git a/SmartDeviceLink/SDLPermissionElement.h b/SmartDeviceLink/SDLPermissionElement.h index 4db915a95..d8409eb4e 100644 --- a/SmartDeviceLink/SDLPermissionElement.h +++ b/SmartDeviceLink/SDLPermissionElement.h @@ -8,13 +8,12 @@ #import <Foundation/Foundation.h> +#import "SDLParameterPermissions.h" #import "SDLRPCFunctionNames.h" -@class SDLParameterPermissions; - NS_ASSUME_NONNULL_BEGIN -@interface SDLPermissionElement : NSObject +@interface SDLPermissionElement : NSObject <NSCopying> /** Name of the individual RPC in the policy table. diff --git a/SmartDeviceLink/SDLPermissionElement.m b/SmartDeviceLink/SDLPermissionElement.m index 05f8db320..eb49f40f6 100644 --- a/SmartDeviceLink/SDLPermissionElement.m +++ b/SmartDeviceLink/SDLPermissionElement.m @@ -28,4 +28,13 @@ return self.parameterPermissions; } +#pragma mark - NSCopying + +- (id)copyWithZone:(nullable NSZone *)zone { + + SDLPermissionElement *newElement = [[self.class allocWithZone:zone] initWithRPCName:[_rpcName copyWithZone:zone] parameterPermissions:[_parameterPermissions copyWithZone:zone]]; + + return newElement; +} + @end diff --git a/SmartDeviceLink/SDLPermissionFilter.h b/SmartDeviceLink/SDLPermissionFilter.h index ec79dace7..c4e8411bc 100644 --- a/SmartDeviceLink/SDLPermissionFilter.h +++ b/SmartDeviceLink/SDLPermissionFilter.h @@ -31,10 +31,15 @@ NS_ASSUME_NONNULL_BEGIN */ @property (assign, nonatomic, readonly) SDLPermissionGroupType groupType; +///** +// * The block that will be called on status changes to this filter group. +// */ +//@property (copy, nonatomic, readonly) SDLPermissionsChangedHandler handler; + /** * The block that will be called on status changes to this filter group. */ -@property (copy, nonatomic, readonly) SDLPermissionsChangedHandler handler; +@property (copy, nonatomic, readonly) SDLPermissionElementsChangedHandler handler; /** * All of the permission elements in this filter group. @@ -50,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return An instance of `SDLPermissionFilter`. */ -- (instancetype)initWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionElementsChangedHandler)handler NS_DESIGNATED_INITIALIZER; /** * Create a new permission filter group. @@ -61,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return An instance of `SDLPermissionFilter`. */ -+ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler NS_SWIFT_UNAVAILABLE("Use the initializer"); ++ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionElementsChangedHandler)handler NS_SWIFT_UNAVAILABLE("Use the initializer"); /** * Whether the current filter is equivalent with another filter or not. @@ -73,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isEqualToFilter:(SDLPermissionFilter *)otherFilter; - +// to do clean up //- (instancetype)initWithPermissionElements:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionElementsChangedHandler)handler NS_DESIGNATED_INITIALIZER; // //+ (instancetype)filterWithPermissionElements:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)handler NS_SWIFT_UNAVAILABLE("Use the initializer"); diff --git a/SmartDeviceLink/SDLPermissionFilter.m b/SmartDeviceLink/SDLPermissionFilter.m index 2a2a40d4c..1b3a5ee81 100644 --- a/SmartDeviceLink/SDLPermissionFilter.m +++ b/SmartDeviceLink/SDLPermissionFilter.m @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (instancetype)initWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer { +- (instancetype)initWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionElementsChangedHandler)observer { self = [super init]; if (!self) { return nil; @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN return self; } -+ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionsChangedHandler)observer { ++ (instancetype)filterWithRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames groupType:(SDLPermissionGroupType)groupType observer:(SDLPermissionElementsChangedHandler)observer { return [[self alloc] initWithRPCNames:rpcNames groupType:groupType observer:observer]; } @@ -62,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - NSCopying - (id)copyWithZone:(nullable NSZone *)zone { - SDLPermissionFilter *newFilter = [[self.class allocWithZone:zone] initWithRPCNames:[_rpcNames copyWithZone:zone] groupType:_groupType observer:[_handler copyWithZone:zone]]; + SDLPermissionFilter *newFilter = [[self.class allocWithZone:zone] initWithRPCNames:[_permissionElements copyWithZone:zone] groupType:_groupType observer:[_handler copyWithZone:zone]]; newFilter->_identifier = _identifier; return newFilter; diff --git a/SmartDeviceLink/SDLPermissionManager.h b/SmartDeviceLink/SDLPermissionManager.h index 5639867bf..b5d485dac 100644 --- a/SmartDeviceLink/SDLPermissionManager.h +++ b/SmartDeviceLink/SDLPermissionManager.h @@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return A dictionary specifying if the passed in RPC names are currently allowed or not */ -- (NSDictionary<SDLRPCFunctionName, NSNumber *> *)statusesOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames; +- (NSDictionary<SDLPermissionElement *, NSNumber *> *)statusesOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames; /** * Add an observer for specified RPC names, with a callback that will be called whenever the value changes, as well as immediately with the current status. diff --git a/SmartDeviceLink/SDLPermissionManager.m b/SmartDeviceLink/SDLPermissionManager.m index ed0703afe..45d3f2616 100644 --- a/SmartDeviceLink/SDLPermissionManager.m +++ b/SmartDeviceLink/SDLPermissionManager.m @@ -136,7 +136,7 @@ NS_ASSUME_NONNULL_BEGIN return [self statusesOfRPCNames:[self sdl_createPermissionElementFromRPCNames:rpcNames]]; } -- (NSDictionary<SDLRPCFunctionName,NSNumber *> *)statusesOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames { +- (NSDictionary<SDLPermissionElement*, NSNumber *> *)statusesOfRPCNames:(NSArray<SDLPermissionElement *> *)rpcNames { NSMutableDictionary<SDLRPCFunctionName, NSNumber *> *permissionAllowedDict = [NSMutableDictionary dictionary]; for (SDLRPCFunctionName rpcName in rpcNames) { @@ -182,7 +182,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)sdl_callFilterObserver:(SDLPermissionFilter *)filter { SDLPermissionGroupStatus permissionStatus = [self groupStatusOfRPCNames:filter.permissionElements]; - NSDictionary<SDLPermissionRPCName, NSNumber *> *allowedDict = [self statusesOfRPCNames:filter.permissionElements]; + NSDictionary<SDLPermissionElement *, NSNumber *> *allowedDict = [self statusesOfRPCNames:filter.permissionElements]; filter.handler(allowedDict, permissionStatus); } diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m index be190c40d..d40a1812e 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLPermissionFilterSpec.m @@ -2,44 +2,49 @@ #import <Nimble/Nimble.h> #import "SDLPermissionConstants.h" +#import "SDLPermissionElement.h" #import "SDLPermissionFilter.h" QuickSpecBegin(SDLPermissionFilterSpec) -describe(@"A filter", ^{ +fdescribe(@"A filter", ^{ __block NSString *testRPCName1 = nil; __block NSString *testRPCName2 = nil; + __block SDLPermissionElement *testPermissionElement1 = nil; + __block SDLPermissionElement *testPermissionElement2 = nil; beforeEach(^{ testRPCName1 = @"testRPCName1"; testRPCName2 = @"testRPCName2"; + testPermissionElement1 = [[SDLPermissionElement alloc] initWithRPCName:testRPCName1 parameterPermissions:nil]; + testPermissionElement2 = [[SDLPermissionElement alloc] initWithRPCName:testRPCName2 parameterPermissions:nil]; }); describe(@"should initialize correctly", ^{ - __block NSArray<SDLPermissionRPCName> *testRPCNames = nil; + __block NSArray<SDLPermissionElement *> *testPermissionElements = nil; __block SDLPermissionGroupType testGroupType = SDLPermissionGroupTypeAny; __block SDLPermissionFilter *testFilter = nil; - __block NSDictionary<SDLPermissionRPCName, NSNumber<SDLBool> *> *testObserverReturnChangedDict = nil; + __block NSDictionary<SDLPermissionElement *, NSNumber<SDLBool> *> *testObserverReturnChangedDict = nil; beforeEach(^{ - testRPCNames = @[testRPCName1, testRPCName2]; + testPermissionElements = @[testPermissionElement1, testPermissionElement2]; testGroupType = SDLPermissionGroupTypeAny; }); context(@"using initWithRPCNames:changeType:observer:", ^{ beforeEach(^{ - testFilter = [[SDLPermissionFilter alloc] initWithRPCNames:testRPCNames groupType:testGroupType observer:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) { + testFilter = [[SDLPermissionFilter alloc] initWithRPCNames:testPermissionElements groupType:testGroupType observer:^(NSDictionary<SDLPermissionElement *,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) { testObserverReturnChangedDict = changedDict; }]; }); it(@"should set the rpcNames array correctly", ^{ - expect(testFilter.rpcNames).to(equal(testRPCNames)); + expect(testFilter.permissionElements).to(equal(testPermissionElements)); }); describe(@"it should set up the observer correctly", ^{ - __block NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> *testObserverChangedDict = nil; + __block NSDictionary<SDLPermissionElement*,NSNumber<SDLBool> *> *testObserverChangedDict = nil; __block NSNumber<SDLBool> *testRPCName1Bool = nil; __block NSNumber<SDLBool> *testRPCName2Bool = nil; __block SDLPermissionGroupStatus testObserverGroupStatus = SDLPermissionGroupStatusUnknown; @@ -47,8 +52,8 @@ describe(@"A filter", ^{ beforeEach(^{ testRPCName1Bool = @YES; testRPCName2Bool = @NO; - testObserverChangedDict = @{testRPCName1: testRPCName1Bool, - testRPCName2: testRPCName2Bool}; + testObserverChangedDict = @{testPermissionElement1: testRPCName1Bool, + testPermissionElement2: testRPCName2Bool}; testObserverGroupStatus = SDLPermissionGroupStatusMixed; testFilter.handler(testObserverChangedDict, testObserverGroupStatus); @@ -66,17 +71,17 @@ describe(@"A filter", ^{ context(@"using filterWithRPCNames:changeType:observer:", ^{ beforeEach(^{ - testFilter = [SDLPermissionFilter filterWithRPCNames:testRPCNames groupType:testGroupType observer:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) { + testFilter = [SDLPermissionFilter filterWithRPCNames:testPermissionElements groupType:testGroupType observer:^(NSDictionary<SDLPermissionElement *,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) { testObserverReturnChangedDict = changedDict; }]; }); it(@"should set the rpcNames array correctly", ^{ - expect(testFilter.rpcNames).to(equal(testRPCNames)); + expect(testFilter.permissionElements).to(equal(testPermissionElements)); }); describe(@"it should set up the observer correctly", ^{ - __block NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> *testObserverChangedDict = nil; + __block NSDictionary<SDLPermissionElement*,NSNumber<SDLBool> *> *testObserverChangedDict = nil; __block NSNumber<SDLBool> *testRPCName1Bool = nil; __block NSNumber<SDLBool> *testRPCName2Bool = nil; __block SDLPermissionGroupStatus testObserverGroupStatus = SDLPermissionGroupStatusUnknown; @@ -84,8 +89,8 @@ describe(@"A filter", ^{ beforeEach(^{ testRPCName1Bool = @YES; testRPCName2Bool = @NO; - testObserverChangedDict = @{testRPCName1: testRPCName1Bool, - testRPCName2: testRPCName2Bool}; + testObserverChangedDict = @{testPermissionElement1: testRPCName1Bool, + testPermissionElement2: testRPCName2Bool}; testObserverGroupStatus = SDLPermissionGroupStatusMixed; testFilter.handler(testObserverChangedDict, testObserverGroupStatus); @@ -107,7 +112,7 @@ describe(@"A filter", ^{ __block SDLPermissionFilter *testCopiedFilter = nil; beforeEach(^{ - testFilter = [SDLPermissionFilter filterWithRPCNames:@[testRPCName1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; + testFilter = [SDLPermissionFilter filterWithRPCNames:@[testPermissionElement1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionElement *,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; testCopiedFilter = [testFilter copy]; }); @@ -120,7 +125,7 @@ describe(@"A filter", ^{ }); it(@"should copy the filter array correctly", ^{ - expect(testCopiedFilter.rpcNames).to(equal(testFilter.rpcNames)); + expect(testCopiedFilter.permissionElements).to(equal(testFilter.permissionElements)); }); it(@"should copy the change type correctly", ^{ @@ -134,10 +139,10 @@ describe(@"A filter", ^{ __block SDLPermissionFilter *testDifferentFilter = nil; beforeEach(^{ - testSameFilter1 = [SDLPermissionFilter filterWithRPCNames:@[testRPCName1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; + testSameFilter1 = [SDLPermissionFilter filterWithRPCNames:@[testPermissionElement1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionElement *,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; testSameFilter2 = [testSameFilter1 copy]; - testDifferentFilter = [SDLPermissionFilter filterWithRPCNames:@[testRPCName1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionRPCName,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; + testDifferentFilter = [SDLPermissionFilter filterWithRPCNames:@[testPermissionElement1] groupType:SDLPermissionGroupTypeAny observer:^(NSDictionary<SDLPermissionElement *,NSNumber<SDLBool> *> * _Nonnull changedDict, SDLPermissionGroupStatus status) {}]; }); it(@"should say copied filters are the same", ^{ |