summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Gluck <justin.gluck@livio.io>2019-07-31 14:42:18 -0400
committerJustin Gluck <justin.gluck@livio.io>2019-07-31 14:42:18 -0400
commit4b6a8554ecc9bae94664ac23cf1986614c79a7b8 (patch)
tree729116a33783866c76fdaa589edf60a9c4aa5ca5
parent899c408688e42190f299e50314885ba52f551849 (diff)
downloadsdl_ios-4b6a8554ecc9bae94664ac23cf1986614c79a7b8.tar.gz
move tests from screen manager to the menu manager, added unit tests. added documentation, fixing PR issues
-rw-r--r--SmartDeviceLink/SDLMenuManager.h5
-rw-r--r--SmartDeviceLink/SDLMenuManager.m33
-rw-r--r--SmartDeviceLink/SDLScreenManager.h10
-rw-r--r--SmartDeviceLink/SDLScreenManager.m12
-rw-r--r--SmartDeviceLink/SDLShowAppMenu.h9
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m94
-rw-r--r--SmartDeviceLinkTests/SDLScreenManagerSpec.m47
7 files changed, 117 insertions, 93 deletions
diff --git a/SmartDeviceLink/SDLMenuManager.h b/SmartDeviceLink/SDLMenuManager.h
index bc0ebdf44..475c4195d 100644
--- a/SmartDeviceLink/SDLMenuManager.h
+++ b/SmartDeviceLink/SDLMenuManager.h
@@ -37,8 +37,9 @@ typedef void(^SDLMenuUpdateCompletionHandler)(NSError *__nullable error);
@property (assign, nonatomic) SDLDynamicMenuUpdatesMode dynamicMenuUpdatesMode;
-- (void)openMenu;
-- (void)openSubmenu:(SDLMenuCell *)cell;
+- (BOOL)openMenu;
+
+- (BOOL)openSubmenu:(SDLMenuCell *)cell;
@end
diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m
index b0707acba..722906fc4 100644
--- a/SmartDeviceLink/SDLMenuManager.m
+++ b/SmartDeviceLink/SDLMenuManager.m
@@ -18,6 +18,7 @@
#import "SDLDisplayCapabilities+ShowManagerExtensions.h"
#import "SDLError.h"
#import "SDLFileManager.h"
+#import "SDLGlobals.h"
#import "SDLImage.h"
#import "SDLLogMacros.h"
#import "SDLMenuCell.h"
@@ -32,6 +33,7 @@
#import "SDLSetDisplayLayoutResponse.h"
#import "SDLScreenManager.h"
#import "SDLShowAppMenu.h"
+#import "SDLVersion.h"
#import "SDLVoiceCommand.h"
NS_ASSUME_NONNULL_BEGIN
@@ -639,28 +641,43 @@ UInt32 const MenuCellIdMin = 1;
}
}
-- (void)openMenu {
- [self.connectionManager sendConnectionRequest:[[SDLShowAppMenu alloc] init] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
+- (BOOL)openMenu {
+ if([SDLGlobals.sharedGlobals.rpcVersion isLessThanVersion:[[SDLVersion alloc] initWithMajor:6 minor:0 patch:0]]) {
+ return NO;
+ }
+
+ SDLShowAppMenu *openMenu = [[SDLShowAppMenu alloc] init];
+
+ [self.connectionManager sendConnectionRequest:openMenu withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
SDLLogE(@"Error opening application menu: %@", error);
- return;
}
}];
+
+ return YES;
}
-- (void)openSubmenu:(SDLMenuCell *)cell {
- if (cell.subCells == 0) {
- SDLLogW(@"The cell does not contain any sub cells, RPC will not be sent");
- return;
+- (BOOL)openSubmenu:(SDLMenuCell *)cell {
+ if(cell.subCells == 0) {
+ SDLLogW(@"The cell does not contain any sub cells, so no submenu can be opened");
+ return NO;
+ }else if([SDLGlobals.sharedGlobals.rpcVersion isLessThanVersion:[[SDLVersion alloc] initWithMajor:6 minor:0 patch:0]]) {
+ SDLLogW(@"The RPC Version does not support Open Menu. Please make sure you have the most up to date version");
+ return NO;
+ }else if(![self.menuCells containsObject:cell]) {
+ SDLLogW(@"This cell has not been sent to the head unit, so no submenu can be opened. Make sure that the cell exists in the SDLManager.menu array");
+ return NO;
}
SDLShowAppMenu *subMenu = [[SDLShowAppMenu alloc] initWithMenuID:cell.cellId];
[self.connectionManager sendConnectionRequest:subMenu withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
- SDLLogE(@"Error opening application menu: %@", error);
+ SDLLogE(@"Error opening application to submenu cell: %@, with error: %@", cell, error);
}
}];
+
+ return YES;
}
@end
diff --git a/SmartDeviceLink/SDLScreenManager.h b/SmartDeviceLink/SDLScreenManager.h
index 30b9da0e7..a811bf910 100644
--- a/SmartDeviceLink/SDLScreenManager.h
+++ b/SmartDeviceLink/SDLScreenManager.h
@@ -278,8 +278,16 @@ If set to `SDLDynamicMenuUpdatesModeForceOff`, menu updates will work the legacy
- (void)presentKeyboardWithInitialText:(NSString *)initialText delegate:(id<SDLKeyboardDelegate>)delegate;
#pragma mark Menu
-
+/**
+ Present the application menu. This method should be called if the menu needs to be opened programmatically because the built in menu button is hidden.
+ */
- (BOOL)openMenu;
+
+/**
+ Present the application menu. This method should be called if the menu needs to be opened programmatically because the built in menu button is hidden. You must update the menu with the proper cells before calling this method. This RPC will fail if the cell does not exist, is not a sub menu or is not in the menu array.
+
+@param cell The submenu cell that should be opened
+ */
- (BOOL)openSubmenu:(SDLMenuCell *)cell;
@end
diff --git a/SmartDeviceLink/SDLScreenManager.m b/SmartDeviceLink/SDLScreenManager.m
index fcc84f0b1..fcc07e19d 100644
--- a/SmartDeviceLink/SDLScreenManager.m
+++ b/SmartDeviceLink/SDLScreenManager.m
@@ -268,19 +268,11 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Menu
- (BOOL)openMenu {
- if([SDLGlobals.sharedGlobals.rpcVersion isLessThanVersion:[[SDLVersion alloc] initWithMajor:6 minor:0 patch:0]]) {
- return NO;
- }
- [self.menuManager openMenu];
- return YES;
+ return [self.menuManager openMenu];
}
- (BOOL)openSubmenu:(SDLMenuCell *)cell {
- if([SDLGlobals.sharedGlobals.rpcVersion isLessThanVersion:[[SDLVersion alloc] initWithMajor:6 minor:0 patch:0]]) {
- return NO;
- }
- [self.menuManager openSubmenu:cell];
- return YES;
+ return [self.menuManager openSubmenu:cell];
}
diff --git a/SmartDeviceLink/SDLShowAppMenu.h b/SmartDeviceLink/SDLShowAppMenu.h
index f75cd1547..b6d0ebd7d 100644
--- a/SmartDeviceLink/SDLShowAppMenu.h
+++ b/SmartDeviceLink/SDLShowAppMenu.h
@@ -16,11 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLShowAppMenu : SDLRPCRequest
/**
- * Convenience init for setting menuID
- *
- * @param menuID Menu id of requsted sub menu
- *
- * @return A SDLShowAppMenu object
+ Creates an open sub menu RPC
+
+ @param menuID The ID of the sub menu to open
+ @return SDLShowAppMenu RPCRequest
*/
- (instancetype)initWithMenuID:(UInt32)menuID;
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
index c435f7b4e..ba91df0d6 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
@@ -6,6 +6,7 @@
#import "SDLMenuManager.h"
#import "TestConnectionManager.h"
+#import "SDLGlobals.h"
@interface SDLMenuCell()
@@ -610,35 +611,88 @@ describe(@"menu manager", ^{
});
});
- describe(@"Opening Menu", ^{
- it(@"should send showAppMenu RPC", ^{
- [testManager openMenu];
+ describe(@"ShowMenu RPC", ^{
+ beforeEach(^{
+ testManager.currentHMILevel = SDLHMILevelFull;
+ testManager.currentSystemContext = SDLSystemContextMain;
+ testManager.displayCapabilities = [[SDLDisplayCapabilities alloc] init];
+ });
+
+ context(@"when open menu RPC can be sent", ^{
+ beforeEach(^{
+ SDLVersion *oldVersion = [SDLVersion versionWithMajor:6 minor:0 patch:0];
+ id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
+ OCMStub([globalMock rpcVersion]).andReturn(oldVersion);
+ });
- NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
- NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+ it(@"should send showAppMenu RPC", ^{
+ BOOL canSendRPC = [testManager openMenu];
- expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
- expect(openMenu).to(haveCount(0));
- });
+ NSPredicate *showMenu = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:showMenu];
- it(@"should send showAppMenu RPC with cellID ", ^ {
- [testManager openSubmenu:submenuCell];
+ expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
+ expect(openMenu).to(haveCount(1));
+ expect(canSendRPC).to(equal(YES));
+ });
- NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
- NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+ it(@"should send showAppMenu RPC with cellID", ^ {
+ testManager.menuCells = @[submenuCell];
+ [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+ [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
- expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
- expect(openMenu).to(haveCount(1));
+ BOOL canSendRPC = [testManager openSubmenu:submenuCell];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
+ expect(openMenu).to(haveCount(1));
+ expect(canSendRPC).to(equal(YES));
+ });
});
- it(@"should not send a showAppMenu RPC when cellID is invalid ", ^ {
- [testManager openSubmenu:textOnlyCell];
+ context(@"when open menu RPC can not be sent", ^{
+ it(@"should not send a showAppMenu RPC when cell has no subcells", ^ {
+ BOOL canSendRPC = [testManager openSubmenu:textOnlyCell];
- NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
- NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
- expect(mockConnectionManager.receivedRequests).to(beEmpty());
- expect(openMenu).to(haveCount(0));
+ expect(mockConnectionManager.receivedRequests).to(beEmpty());
+ expect(openMenu).to(haveCount(0));
+ expect(canSendRPC).to(equal(NO));
+ });
+
+ it(@"should not send a showAppMenu RPC when RPC verison is not at least 6.0.0", ^ {
+ SDLVersion *oldVersion = [SDLVersion versionWithMajor:5 minor:0 patch:0];
+ id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
+ OCMStub([globalMock rpcVersion]).andReturn(oldVersion);
+
+ BOOL canSendRPC = [testManager openSubmenu:submenuCell];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).to(beEmpty());
+ expect(openMenu).to(haveCount(0));
+ expect(canSendRPC).to(equal(NO));
+ });
+
+ it(@"should not send a showAppMenu RPC when the cell is not in the menu array", ^ {
+ SDLVersion *oldVersion = [SDLVersion versionWithMajor:6 minor:0 patch:0];
+ id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
+ OCMStub([globalMock rpcVersion]).andReturn(oldVersion);
+
+ BOOL canSendRPC = [testManager openSubmenu:submenuCell];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).to(beEmpty());
+ expect(openMenu).to(haveCount(0));
+ expect(canSendRPC).to(equal(NO));
+ });
});
});
diff --git a/SmartDeviceLinkTests/SDLScreenManagerSpec.m b/SmartDeviceLinkTests/SDLScreenManagerSpec.m
index 71fb9acd6..02882be78 100644
--- a/SmartDeviceLinkTests/SDLScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/SDLScreenManagerSpec.m
@@ -49,7 +49,6 @@ describe(@"screen manager", ^{
__block TestConnectionManager *mockConnectionManager = nil;
__block SDLFileManager *mockFileManager = nil;
__block SDLScreenManager *testScreenManager = nil;
- __block SDLMenuManager *mockMenuManger = nil;
__block NSString *testString1 = @"test1";
__block NSString *testString2 = @"test2";
@@ -151,52 +150,6 @@ describe(@"screen manager", ^{
expect(testScreenManager.softButtonManager.softButtonObjects.firstObject.name).to(equal(testSBObjectName));
});
});
-
- describe(@"open menu when spec versioning is not supported", ^{
- beforeEach(^{
- SDLVersion *oldVersion = [SDLVersion versionWithMajor:5 minor:0 patch:0];
- id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
- OCMStub([globalMock rpcVersion]).andReturn(oldVersion);
- });
-
- it(@"should return NO if spec versioning is not supported when openMenu is called", ^{
- BOOL canSendRPC = [testScreenManager openMenu];
- expect(canSendRPC).to(equal(NO));
- });
-
- it(@"should return NO if spec versioning is not supported when openSubMenu is called", ^{
- SDLMenuCell *cell = [[SDLMenuCell alloc] init];
- BOOL canSendRPC = [testScreenManager openSubmenu:cell];
- expect(canSendRPC).to(equal(NO));
- });
-
- });
-
- describe(@"open menu when spec versioning supported", ^{
- beforeEach(^{
- SDLVersion *oldVersion = [SDLVersion versionWithMajor:6 minor:0 patch:0];
- id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
- OCMStub([globalMock rpcVersion]).andReturn(oldVersion);
-
- mockMenuManger = OCMClassMock([SDLMenuManager class]);
- testScreenManager.menuManager = mockMenuManger;
- });
-
- it(@"should return YES if spec versioning is supported when openMenu is called", ^{
- BOOL canSendRPC = [testScreenManager openMenu];
-
- expect(canSendRPC).to(equal(YES));
- OCMVerify([mockMenuManger openMenu]);
- });
-
- it(@"should return YES if spec versioning is supported when openSubMenu is called", ^{
- SDLMenuCell *cell = [[SDLMenuCell alloc] init];
- BOOL canSendRPC = [testScreenManager openSubmenu:cell];
-
- OCMVerify([mockMenuManger openSubmenu:[OCMArg any]]);
- expect(canSendRPC).to(equal(YES));
- });
- });
});
QuickSpecEnd