summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2020-07-27 16:22:54 -0400
committerJoel Fischer <joeljfischer@gmail.com>2020-07-27 16:22:54 -0400
commitec834b0b323a27166343bb3ca8c42066929fd47e (patch)
tree9c2599c111a70b01fd88f17513a2f6a9edadc4bf
parentd044d7b39b545de82c7ef9c9c3d6c9479366af21 (diff)
downloadsdl_ios-ec834b0b323a27166343bb3ca8c42066929fd47e.tar.gz
Implement SDL-0148 Additional SubMenus
-rw-r--r--SmartDeviceLink/SDLAddSubMenu.h66
-rw-r--r--SmartDeviceLink/SDLAddSubMenu.m62
-rw-r--r--SmartDeviceLink/SDLMenuParams.m4
-rw-r--r--SmartDeviceLink/SDLRPCParameterNames.h2
-rw-r--r--SmartDeviceLink/SDLRPCParameterNames.m2
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddSubMenuSpec.m42
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLMenuParamsSpec.m4
7 files changed, 164 insertions, 18 deletions
diff --git a/SmartDeviceLink/SDLAddSubMenu.h b/SmartDeviceLink/SDLAddSubMenu.h
index 6f289e811..f841233fb 100644
--- a/SmartDeviceLink/SDLAddSubMenu.h
+++ b/SmartDeviceLink/SDLAddSubMenu.h
@@ -1,4 +1,34 @@
-// SDLAddSubMenu.h
+/*
+* Copyright (c) 2020, SmartDeviceLink Consortium, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the SmartDeviceLink Consortium Inc. nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
#import "SDLRPCRequest.h"
@@ -25,13 +55,30 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLAddSubMenu : SDLRPCRequest
+/**
+ * @param menuID - @(menuID)
+ * @param menuName - menuName
+ * @return A SDLAddSubMenu object
+ */
+- (instancetype)initWithMenuID:(UInt32)menuID menuName:(NSString *)menuName;
+
+/**
+ * @param menuID - @(menuID)
+ * @param menuName - menuName
+ * @param position - position
+ * @param menuIcon - menuIcon
+ * @param menuLayout - menuLayout
+ * @param parentID - parentID
+ * @return A SDLAddSubMenu object
+ */
+- (instancetype)initWithMenuID:(UInt32)menuID menuName:(NSString *)menuName position:(nullable NSNumber<SDLUInt> *)position menuIcon:(nullable SDLImage *)menuIcon menuLayout:(nullable SDLMenuLayout)menuLayout parentID:(nullable NSNumber<SDLUInt> *)parentID;
/// Convenience init for creating an add submenu
///
/// @param menuId A menu id
/// @param menuName The menu name
/// @return An SDLAddSubMenu object
-- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName;
+- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName __deprecated_msg("Use initWithMenuID:menuName: instead");
/// Convenience init for creating an add submenu
///
@@ -39,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param menuName The menu name
/// @param position The position within the menu to add
/// @return An SDLAddSubMenu object
-- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position __deprecated_msg("Use initWithId:menuName:menuLayout:menuIcon:position: instead");
+- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position __deprecated_msg("Use initWithMenuID:menuName:position:menuIcon:menuLayout:parentID: instead");
/// Convenience init for creating an add submenu
///
@@ -48,7 +95,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param icon The icon to show on the menu item
/// @param position The position within the menu to add
/// @return An SDLAddSubMenu object
-- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuIcon:(nullable SDLImage *)icon position:(UInt8)position __deprecated_msg("Use initWithId:menuName:menuLayout:menuIcon:position: instead");
+- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuIcon:(nullable SDLImage *)icon position:(UInt8)position __deprecated_msg("Use initWithMenuID:menuName:position:menuIcon:menuLayout:parentID: instead");
/// Convenience init for creating an add submenu with all properties.
///
@@ -58,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param icon The icon to show on the menu item
/// @param position The position within the menu to add
/// @return An SDLAddSubMenu object
-- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuLayout:(nullable SDLMenuLayout)menuLayout menuIcon:(nullable SDLImage *)icon position:(UInt8)position;
+- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuLayout:(nullable SDLMenuLayout)menuLayout menuIcon:(nullable SDLImage *)icon position:(UInt8)position __deprecated_msg("Use initWithMenuID:menuName:position:menuIcon:menuLayout:parentID: instead");
/**
* a Menu ID that identifies a sub menu
@@ -104,6 +151,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (strong, nonatomic, nullable) SDLMenuLayout menuLayout;
+/**
+ * unique ID of the sub menu, the command will be added to. If not provided or 0, it will be provided to the top
+ * level of the in application menu.
+ * {"default_value": 0, "max_value": 2000000000, "min_value": 0}
+ *
+ * @since SDL 7.0.0
+ */
+@property (nullable, strong, nonatomic) NSNumber<SDLUInt> *parentID;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLAddSubMenu.m b/SmartDeviceLink/SDLAddSubMenu.m
index 649a10a31..91dbc11ba 100644
--- a/SmartDeviceLink/SDLAddSubMenu.m
+++ b/SmartDeviceLink/SDLAddSubMenu.m
@@ -1,4 +1,34 @@
-// SDLAddSubMenu.m
+/*
+* Copyright (c) 2020, SmartDeviceLink Consortium, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* Redistributions of source code must retain the above copyright notice, this
+* list of conditions and the following disclaimer.
+*
+* Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided with the
+* distribution.
+*
+* Neither the name of the SmartDeviceLink Consortium Inc. nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
#import "SDLAddSubMenu.h"
@@ -51,6 +81,28 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
+- (instancetype)initWithMenuID:(UInt32)menuID menuName:(NSString *)menuName {
+ self = [self init];
+ if (!self) {
+ return nil;
+ }
+ self.menuID = @(menuID);
+ self.menuName = menuName;
+ return self;
+}
+
+- (instancetype)initWithMenuID:(UInt32)menuID menuName:(NSString *)menuName position:(nullable NSNumber<SDLUInt> *)position menuIcon:(nullable SDLImage *)menuIcon menuLayout:(nullable SDLMenuLayout)menuLayout parentID:(nullable NSNumber<SDLUInt> *)parentID {
+ self = [self initWithMenuID:menuID menuName:menuName];
+ if (!self) {
+ return nil;
+ }
+ self.position = position;
+ self.menuIcon = menuIcon;
+ self.menuLayout = menuLayout;
+ self.parentID = parentID;
+ return self;
+}
+
- (void)setMenuID:(NSNumber<SDLInt> *)menuID {
[self.parameters sdl_setObject:menuID forName:SDLRPCParameterNameMenuId];
}
@@ -93,6 +145,14 @@ NS_ASSUME_NONNULL_BEGIN
return [self.parameters sdl_enumForName:SDLRPCParameterNameMenuLayout error:nil];
}
+- (void)setParentID:(nullable NSNumber<SDLUInt> *)parentID {
+ [self.parameters sdl_setObject:parentID forName:SDLRPCParameterNameParentID];
+}
+
+- (nullable NSNumber<SDLUInt> *)parentID {
+ return [self.parameters sdl_objectForName:SDLRPCParameterNameParentID ofClass:NSNumber.class error:nil];
+}
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLMenuParams.m b/SmartDeviceLink/SDLMenuParams.m
index 0fcfbd60e..85cf5880a 100644
--- a/SmartDeviceLink/SDLMenuParams.m
+++ b/SmartDeviceLink/SDLMenuParams.m
@@ -35,11 +35,11 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)setParentID:(nullable NSNumber<SDLInt> *)parentID {
- [self.store sdl_setObject:parentID forName:SDLRPCParameterNameParentId];
+ [self.store sdl_setObject:parentID forName:SDLRPCParameterNameParentID];
}
- (nullable NSNumber<SDLInt> *)parentID {
- return [self.store sdl_objectForName:SDLRPCParameterNameParentId ofClass:NSNumber.class error:nil];
+ return [self.store sdl_objectForName:SDLRPCParameterNameParentID ofClass:NSNumber.class error:nil];
}
- (void)setPosition:(nullable NSNumber<SDLInt> *)position {
diff --git a/SmartDeviceLink/SDLRPCParameterNames.h b/SmartDeviceLink/SDLRPCParameterNames.h
index e6541968a..069e9354b 100644
--- a/SmartDeviceLink/SDLRPCParameterNames.h
+++ b/SmartDeviceLink/SDLRPCParameterNames.h
@@ -445,7 +445,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameOS;
extern SDLRPCParameterName const SDLRPCParameterNameOSVersion;
extern SDLRPCParameterName const SDLRPCParameterNameParameterPermissions;
extern SDLRPCParameterName const SDLRPCParameterNameParameters;
-extern SDLRPCParameterName const SDLRPCParameterNameParentId;
+extern SDLRPCParameterName const SDLRPCParameterNameParentID;
extern SDLRPCParameterName const SDLRPCParameterNameParkBrakeActive;
extern SDLRPCParameterName const SDLRPCParameterNamePassengerAirbagDeployed;
extern SDLRPCParameterName const SDLRPCParameterNamePassengerBeltDeployed;
diff --git a/SmartDeviceLink/SDLRPCParameterNames.m b/SmartDeviceLink/SDLRPCParameterNames.m
index 85a88b1d4..f990e083b 100644
--- a/SmartDeviceLink/SDLRPCParameterNames.m
+++ b/SmartDeviceLink/SDLRPCParameterNames.m
@@ -439,7 +439,7 @@ SDLRPCParameterName const SDLRPCParameterNameOS = @"os";
SDLRPCParameterName const SDLRPCParameterNameOSVersion = @"osVersion";
SDLRPCParameterName const SDLRPCParameterNameParameterPermissions = @"parameterPermissions";
SDLRPCParameterName const SDLRPCParameterNameParameters = @"parameters";
-SDLRPCParameterName const SDLRPCParameterNameParentId = @"parentID";
+SDLRPCParameterName const SDLRPCParameterNameParentID = @"parentID";
SDLRPCParameterName const SDLRPCParameterNameParkBrakeActive = @"parkBrakeActive";
SDLRPCParameterName const SDLRPCParameterNamePassengerAirbagDeployed = @"passengerAirbagDeployed";
SDLRPCParameterName const SDLRPCParameterNamePassengerBeltDeployed = @"passengerBeltDeployed";
diff --git a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddSubMenuSpec.m b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddSubMenuSpec.m
index 5c5e98547..dcc16ef28 100644
--- a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddSubMenuSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddSubMenuSpec.m
@@ -21,18 +21,33 @@ describe(@"Getter/Setter Tests", ^ {
__block NSString *menuName = @"Welcome to the menu";
__block SDLImage *image = nil;
__block SDLMenuLayout testLayout = SDLMenuLayoutList;
+ __block NSNumber *parentID = @44;
beforeEach(^{
image = [[SDLImage alloc] initWithName:@"Test" isTemplate:false];
});
it(@"should correctly initialize with initWithId:menuName:", ^{
+ #pragma clang diagnostic push
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
SDLAddSubMenu *testRequest = [[SDLAddSubMenu alloc] initWithId:menuId menuName:menuName];
+ #pragma clang diagnostic pop
+
+ expect(testRequest.menuID).to(equal(@(menuId)));
+ expect(testRequest.position).to(beNil());
+ expect(testRequest.menuName).to(equal(menuName));
+ expect(testRequest.menuIcon).to(beNil());
+ expect(testRequest.parentID).to(beNil());
+ });
+
+ it(@"should correctly initialize with initWithMenuID:menuName:", ^{
+ SDLAddSubMenu *testRequest = [[SDLAddSubMenu alloc] initWithMenuID:menuId menuName:menuName];
expect(testRequest.menuID).to(equal(@(menuId)));
expect(testRequest.position).to(beNil());
expect(testRequest.menuName).to(equal(menuName));
expect(testRequest.menuIcon).to(beNil());
+ expect(testRequest.parentID).to(beNil());
});
it(@"should correctly initialize with initWithId:menuName:position:", ^{
@@ -44,6 +59,7 @@ describe(@"Getter/Setter Tests", ^ {
expect(testRequest.position).to(equal(@(position)));
expect(testRequest.menuName).to(equal(menuName));
expect(testRequest.menuIcon).to(beNil());
+ expect(testRequest.parentID).to(beNil());
#pragma clang diagnostic pop
});
@@ -56,6 +72,7 @@ describe(@"Getter/Setter Tests", ^ {
expect(testRequest.position).to(equal(@(position)));
expect(testRequest.menuName).to(equal(menuName));
expect(testRequest.menuIcon).to(equal(image));
+ expect(testRequest.parentID).to(beNil());
#pragma clang diagnostic pop
});
@@ -67,6 +84,18 @@ describe(@"Getter/Setter Tests", ^ {
expect(testRequest.menuName).to(equal(menuName));
expect(testRequest.menuIcon).to(equal(image));
expect(testRequest.menuLayout).to(equal(testLayout));
+ expect(testRequest.parentID).to(beNil());
+ });
+
+ it(@"should correctly initialize with initWithMenuID:menuName:menuLayout:menuIcon:position:parentID:", ^{
+ SDLAddSubMenu *testRequest = [[SDLAddSubMenu alloc] initWithMenuID:menuId menuName:menuName position:@(position) menuIcon:image menuLayout:testLayout parentID:parentID];
+
+ expect(testRequest.menuID).to(equal(@(menuId)));
+ expect(testRequest.position).to(equal(@(position)));
+ expect(testRequest.menuName).to(equal(menuName));
+ expect(testRequest.menuIcon).to(equal(image));
+ expect(testRequest.menuLayout).to(equal(testLayout));
+ expect(testRequest.parentID).to(equal(parentID));
});
it(@"Should set and get correctly", ^ {
@@ -88,13 +117,14 @@ describe(@"Getter/Setter Tests", ^ {
it(@"Should get correctly when initialized", ^ {
NSMutableDictionary<NSString *, id> *dict = [@{SDLRPCParameterNameRequest:
@{SDLRPCParameterNameParameters:
- @{SDLRPCParameterNameMenuId:@4345645,
- SDLRPCParameterNamePosition:@27,
- SDLRPCParameterNameMenuName:@"Welcome to the menu",
+ @{SDLRPCParameterNameMenuId: @(menuId),
+ SDLRPCParameterNamePosition: @(position),
+ SDLRPCParameterNameMenuName: menuName,
SDLRPCParameterNameMenuIcon: @{
- SDLRPCParameterNameValue: @"Test"
- },
- SDLRPCParameterNameMenuLayout: testLayout
+ SDLRPCParameterNameValue: image.value
+ },
+ SDLRPCParameterNameMenuLayout: testLayout,
+ SDLRPCParameterNameParentID: parentID
},
SDLRPCParameterNameOperationName:SDLRPCFunctionNameAddSubMenu}} mutableCopy];
#pragma clang diagnostic push
diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLMenuParamsSpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLMenuParamsSpec.m
index 95af8629e..2736f3500 100644
--- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLMenuParamsSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLMenuParamsSpec.m
@@ -27,9 +27,9 @@ describe(@"Initialization tests", ^{
});
it(@"should properly initialize initWithDictionary", ^{
- NSMutableDictionary* dict = [@{SDLRPCParameterNameParentId:@(testParentId),
+ NSDictionary *dict = @{SDLRPCParameterNameParentID:@(testParentId),
SDLRPCParameterNamePosition:@(testPosition),
- SDLRPCParameterNameMenuName:testMenuName} mutableCopy];
+ SDLRPCParameterNameMenuName:testMenuName};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
SDLMenuParams* testStruct = [[SDLMenuParams alloc] initWithDictionary:dict];