Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix SDLAddCommand initializer can't take a nil image #856

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SmartDeviceLink/SDLAddCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands handler:(nullable SDLRPCCommandNotificationHandler)handler;

- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler;
- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(nullable SDLRPCCommandNotificationHandler)handler;

- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler;
- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(nullable NSString *)iconValue iconType:(nullable SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler;

/**
* A handler that will let you know when the button you created is subscribed.
Expand Down
8 changes: 5 additions & 3 deletions SmartDeviceLink/SDLAddCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSStri
return self;
}

- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler {
- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName handler:(nullable SDLRPCCommandNotificationHandler)handler {
self = [self initWithId:commandId vrCommands:vrCommands handler:handler];
if (!self) {
return nil;
Expand All @@ -54,7 +54,7 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSStri
return self;
}

- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler {
- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSString *> *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(nullable NSString *)iconValue iconType:(nullable SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler {
self = [self initWithId:commandId vrCommands:vrCommands menuName:menuName handler:handler];
if (!self) {
return nil;
Expand All @@ -63,7 +63,9 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray<NSStri
self.menuParams.parentID = @(parentId);
self.menuParams.position = @(position);

self.cmdIcon = [[SDLImage alloc] initWithName:iconValue ofType:iconType];
if (iconValue != nil && iconType != nil) {
self.cmdIcon = [[SDLImage alloc] initWithName:iconValue ofType:iconType];
}

return self;
}
Expand Down
81 changes: 78 additions & 3 deletions SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAddCommandSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

QuickSpecBegin(SDLAddCommandSpec)

SDLMenuParams* menu = [[SDLMenuParams alloc] init];
SDLImage* image = [[SDLImage alloc] init];

describe(@"Getter/Setter Tests", ^ {
SDLMenuParams* menu = [[SDLMenuParams alloc] init];
SDLImage* image = [[SDLImage alloc] init];

it(@"Should set and get correctly", ^ {
SDLAddCommand* testRequest = [[SDLAddCommand alloc] init];

Expand Down Expand Up @@ -60,4 +60,79 @@
});
});

describe(@"initializers", ^{
__block SDLAddCommand *testCommand = nil;
__block UInt32 commandId = 1234;
__block NSArray<NSString *> *vrCommands = @[@"commands"];
__block NSString *menuName = @"Menu Name";
void (^handler)(SDLOnCommand *) = ^(SDLOnCommand *command) {};

beforeEach(^{
testCommand = nil;
});

context(@"initWithHandler", ^{
it(@"should initialize correctly", ^{
testCommand = [[SDLAddCommand alloc] initWithHandler:handler];

expect(testCommand).toNot(beNil());
expect(testCommand.vrCommands).to(beNil());
expect(testCommand.menuParams).to(beNil());
expect(testCommand.cmdIcon).to(beNil());
});
});

context(@"initWithId:vrCommands:handler:", ^{
it(@"should initialize correctly", ^{
testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands handler:nil];

expect(testCommand.cmdID).to(equal(commandId));
expect(testCommand.vrCommands).to(equal(vrCommands));
expect(testCommand.menuParams).to(beNil());
expect(testCommand.cmdIcon).to(beNil());
});
});

context(@"initWithId:vrCommands:menuName:handler:", ^{
it(@"should initialize correctly", ^{
testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName handler:nil];

expect(testCommand.cmdID).to(equal(commandId));
expect(testCommand.vrCommands).to(equal(vrCommands));
expect(testCommand.menuParams).toNot(beNil());
expect(testCommand.cmdIcon).to(beNil());
});
});

context(@"initWithId:vrCommands:menuName:parentId:position:iconValue:iconType:handler:", ^{
__block UInt32 parentId = 1234;
__block UInt16 position = 2;

it(@"should initialize with an image", ^{
NSString *iconValue = @"Icon";
SDLImageType imageType = SDLImageTypeDynamic;

testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName parentId:parentId position:position iconValue:iconValue iconType:imageType handler:nil];

expect(testCommand.cmdID).to(equal(commandId));
expect(testCommand.vrCommands).to(equal(vrCommands));
expect(testCommand.menuParams.menuName).toNot(beNil());
expect(testCommand.menuParams.parentID).to(equal(parentId));
expect(testCommand.menuParams.position).to(equal(position));
expect(testCommand.cmdIcon).toNot(beNil());
});

it(@"should initialize without an image", ^{
testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName parentId:parentId position:position iconValue:nil iconType:nil handler:nil];

expect(testCommand.cmdID).to(equal(commandId));
expect(testCommand.vrCommands).to(equal(vrCommands));
expect(testCommand.menuParams.menuName).toNot(beNil());
expect(testCommand.menuParams.parentID).to(equal(parentId));
expect(testCommand.menuParams.position).to(equal(position));
expect(testCommand.cmdIcon).to(beNil());
});
});
});

QuickSpecEnd