summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-07-29 14:57:06 -0400
committerJoel Fischer <joeljfischer@gmail.com>2019-07-29 14:57:06 -0400
commitd6d61887c7631238b0a19b934a24aa1e0021f0fb (patch)
treeb7a0bbf8fdbd6f3965bd032f32d3b8cd22ac6925
parent37b76fd1221c2f93f50c6881947d5a0d82d952f1 (diff)
downloadsdl_ios-d6d61887c7631238b0a19b934a24aa1e0021f0fb.tar.gz
Update example apps to use alert icon
* Add tests
-rw-r--r--Example Apps/Example ObjC/AlertManager.h2
-rw-r--r--Example Apps/Example ObjC/AlertManager.m7
-rw-r--r--Example Apps/Example ObjC/AudioManager.m4
-rw-r--r--Example Apps/Example ObjC/ButtonManager.m8
-rw-r--r--Example Apps/Example ObjC/MenuManager.m12
-rw-r--r--Example Apps/Example ObjC/VehicleDataManager.m10
-rw-r--r--Example Apps/Example Swift/AlertManager.swift6
-rw-r--r--Example Apps/Example Swift/ButtonManager.swift6
-rw-r--r--SmartDeviceLink/SDLAlert.h22
-rw-r--r--SmartDeviceLink/SDLAlert.m44
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m380
11 files changed, 365 insertions, 136 deletions
diff --git a/Example Apps/Example ObjC/AlertManager.h b/Example Apps/Example ObjC/AlertManager.h
index 1d4471b95..bd803cec0 100644
--- a/Example Apps/Example ObjC/AlertManager.h
+++ b/Example Apps/Example ObjC/AlertManager.h
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface AlertManager : NSObject
+ (SDLAlert *)alertWithMessage:(NSString *)textField1 textField2:(nullable NSString *)textField2;
-+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2;
++ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName;
@end
diff --git a/Example Apps/Example ObjC/AlertManager.m b/Example Apps/Example ObjC/AlertManager.m
index cab877a5e..ddc3aad72 100644
--- a/Example Apps/Example ObjC/AlertManager.m
+++ b/Example Apps/Example ObjC/AlertManager.m
@@ -6,6 +6,7 @@
// Copyright © 2018 smartdevicelink. All rights reserved.
//
+#import "AppConstants.h"
#import "AlertManager.h"
#import "SmartDeviceLink.h"
@@ -21,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
* @return An SDLAlert object
*/
+ (SDLAlert *)alertWithMessage:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
- return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 duration:5000];
+ return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2];
}
/**
@@ -31,8 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
* @param textField2 The second line of a message to display in the alert
* @return An SDLAlert object
*/
-+ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 {
- return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil duration:5000 softButtons:@[[self sdlex_okSoftButton]]];
++ (SDLAlert *)alertWithMessageAndCloseButton:(NSString *)textField1 textField2:(nullable NSString *)textField2 iconName:(nullable NSString *)iconName {
+ return [[SDLAlert alloc] initWithAlertText1:textField1 alertText2:textField2 alertText3:nil ttsChunks:nil playTone:NO progressIndicator:NO duration:5000 softButtons:@[[self sdlex_okSoftButton]] alertIcon:[[SDLImage alloc] initWithName:iconName isTemplate:YES]];
}
+ (SDLSoftButton *)sdlex_okSoftButton {
diff --git a/Example Apps/Example ObjC/AudioManager.m b/Example Apps/Example ObjC/AudioManager.m
index 6d1b66c48..cd6ec4ecf 100644
--- a/Example Apps/Example ObjC/AudioManager.m
+++ b/Example Apps/Example ObjC/AudioManager.m
@@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startRecording {
if (self.speechRecognitionAuthState != SpeechRecognitionAuthStateAuthorized) {
SDLLogW(@"This app does not have permission to access the Speech Recognition API");
- [self.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You must give this app permission to access Speech Recognition" textField2:nil]];
+ [self.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You must give this app permission to access Speech Recognition" textField2:nil iconName:nil]];
return;
}
@@ -155,7 +155,7 @@ NS_ASSUME_NONNULL_BEGIN
// The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
SDLLogD(@"Audio Pass Thru ended successfully");
NSString *alertMessage = [NSString stringWithFormat:@"You said: %@", weakSelf.speechTranscription.length == 0 ? @"No speech detected" : weakSelf.speechTranscription];
- [weakSelf.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertMessage textField2:nil]];
+ [weakSelf.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertMessage textField2:nil iconName:nil]];
} else if ([resultCode isEqualToEnum:SDLResultAborted]) {
// The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
SDLLogD(@"Audio recording canceled");
diff --git a/Example Apps/Example ObjC/ButtonManager.m b/Example Apps/Example ObjC/ButtonManager.m
index 4befdf726..efa13ee36 100644
--- a/Example Apps/Example ObjC/ButtonManager.m
+++ b/Example Apps/Example ObjC/ButtonManager.m
@@ -73,14 +73,18 @@ NS_ASSUME_NONNULL_BEGIN
}
- (SDLSoftButtonObject *)sdlex_softButtonAlertWithManager:(SDLManager *)manager {
- SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:CarBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG]];
+ SDLSoftButtonState *alertImageAndTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonImageState text:AlertSoftButtonText artwork:[SDLArtwork artworkWithImage:[[UIImage imageNamed:CarBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] name:CarBWIconImageName asImageFormat:SDLArtworkImageFormatPNG]];
SDLSoftButtonState *alertTextState = [[SDLSoftButtonState alloc] initWithStateName:AlertSoftButtonTextState text:AlertSoftButtonText image:nil];
__weak typeof(self) weakself = self;
SDLSoftButtonObject *alertSoftButton = [[SDLSoftButtonObject alloc] initWithName:AlertSoftButton states:@[alertImageAndTextState, alertTextState] initialStateName:alertImageAndTextState.name handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) {
if (buttonPress == nil) { return; }
- [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil]];
+ [weakself.sdlManager.fileManager uploadArtwork:[SDLArtwork artworkWithImage:[UIImage imageNamed:CarBWIconImageName] asImageFormat:SDLArtworkImageFormatPNG] completionHandler:^(BOOL success, NSString * _Nonnull artworkName, NSUInteger bytesAvailable, NSError * _Nullable error) {
+ [weakself.sdlManager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"You pushed the soft button!" textField2:nil iconName:@"ABCDEFG"] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
+ NSLog(@"ALERT req: %@, res: %@, err: %@", request, response, error);
+ }];
+ }];
SDLLogD(@"Star icon soft button press fired");
}];
diff --git a/Example Apps/Example ObjC/MenuManager.m b/Example Apps/Example ObjC/MenuManager.m
index b0b8c2138..41458da3b 100644
--- a/Example Apps/Example ObjC/MenuManager.m
+++ b/Example Apps/Example ObjC/MenuManager.m
@@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (SDLMenuCell *)sdlex_menuCellDialNumberWithManager:(SDLManager *)manager {
return [[SDLMenuCell alloc] initWithTitle:ACDialPhoneNumberMenuName icon:[SDLArtwork artworkWithImage:[[UIImage imageNamed:PhoneBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] voiceCommands:@[ACDialPhoneNumberMenuName] handler:^(SDLTriggerSource _Nonnull triggerSource) {
if (![RPCPermissionsManager isDialNumberRPCAllowedWithManager:manager]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to dial a number" textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to dial a number" textField2:nil iconName:nil]];
return;
}
@@ -98,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutNonMedia];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (![response.resultCode isEqualToEnum:SDLResultSuccess]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
}
}];
}];
@@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLSetDisplayLayout* display = [[SDLSetDisplayLayout alloc] initWithPredefinedLayout:SDLPredefinedLayoutGraphicWithText];
[manager sendRequest:display withResponseHandler:^(SDLRPCRequest *request, SDLRPCResponse *response, NSError *error) {
if (![response.resultCode isEqualToEnum:SDLResultSuccess]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:errorMessage textField2:nil iconName:nil]];
}
}];
}];
@@ -122,7 +122,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray *submenuItems = [NSMutableArray array];
for (int i = 0; i < 75; i++) {
SDLMenuCell *cell = [[SDLMenuCell alloc] initWithTitle:[NSString stringWithFormat:@"%@ %i", ACSubmenuItemMenuName, i] icon:[SDLArtwork artworkWithImage:[[UIImage imageNamed:MenuBWIconImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] asImageFormat:SDLArtworkImageFormatPNG] voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"You selected %@ %i", ACSubmenuItemMenuName, i] textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"You selected %@ %i", ACSubmenuItemMenuName, i] textField2:nil iconName:nil]];
}];
[submenuItems addObject:cell];
}
@@ -134,13 +134,13 @@ NS_ASSUME_NONNULL_BEGIN
+ (SDLVoiceCommand *)sdlex_voiceCommandStartWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStop] handler:^{
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStop] textField2:nil iconName:nil]];
}];
}
+ (SDLVoiceCommand *)sdlex_voiceCommandStopWithManager:(SDLManager *)manager {
return [[SDLVoiceCommand alloc] initWithVoiceCommands:@[VCStart] handler:^{
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:[NSString stringWithFormat:@"%@ voice command selected!", VCStart] textField2:nil iconName:nil]];
}];
}
diff --git a/Example Apps/Example ObjC/VehicleDataManager.m b/Example Apps/Example ObjC/VehicleDataManager.m
index cc2ee46fa..54ff9642f 100644
--- a/Example Apps/Example ObjC/VehicleDataManager.m
+++ b/Example Apps/Example ObjC/VehicleDataManager.m
@@ -137,7 +137,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)getAllVehicleDataWithManager:(SDLManager *)manager triggerSource:(SDLTriggerSource)triggerSource vehicleDataType:(NSString *)vehicleDataType {
SDLLogD(@"Checking if app has permission to access vehicle data...");
if (![manager.permissionManager isRPCAllowed:@"GetVehicleData"]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"This app does not have the required permissions to access vehicle data" textField2:nil iconName:nil]];
return;
}
@@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
[manager sendRequest:getAllVehicleData withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error || ![response isKindOfClass:SDLGetVehicleDataResponse.class]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Something went wrong while getting vehicle data" textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"Something went wrong while getting vehicle data" textField2:nil iconName:nil]];
return;
}
@@ -176,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN
alertMessage = [TextValidator validateText:alertMessage length:200];
if ([triggerSource isEqualToEnum:SDLTriggerSourceMenu]) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertTitle textField2:alertMessage]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:alertTitle textField2:alertMessage iconName:nil]];
} else {
NSString *spokenAlert = alertMessage ?: alertTitle;
[manager sendRequest:[[SDLSpeak alloc] initWithTTS:spokenAlert]];
@@ -258,7 +258,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLLogD(@"Checking phone call capability");
[manager.systemCapabilityManager updateCapabilityType:SDLSystemCapabilityTypePhoneCall completionHandler:^(NSError * _Nullable error, SDLSystemCapabilityManager * _Nonnull systemCapabilityManager) {
if (!systemCapabilityManager.phoneCapability) {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The head unit does not support the phone call capability" textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The head unit does not support the phone call capability" textField2:nil iconName:nil]];
return;
}
@@ -266,7 +266,7 @@ NS_ASSUME_NONNULL_BEGIN
SDLLogD(@"Dialing phone number %@", phoneNumber);
[self sdlex_dialPhoneNumber:phoneNumber manager:manager];
} else {
- [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The dial number feature is unavailable for this head unit" textField2:nil]];
+ [manager sendRequest:[AlertManager alertWithMessageAndCloseButton:@"The dial number feature is unavailable for this head unit" textField2:nil iconName:nil]];
}
}];
}
diff --git a/Example Apps/Example Swift/AlertManager.swift b/Example Apps/Example Swift/AlertManager.swift
index c463e7d36..490002406 100644
--- a/Example Apps/Example Swift/AlertManager.swift
+++ b/Example Apps/Example Swift/AlertManager.swift
@@ -21,7 +21,7 @@ class AlertManager {
/// - textField2: The second line of a message to display in the alert
/// - Returns: An SDLAlert object
class func alertWithMessage(_ textField1: String, textField2: String? = nil) -> SDLAlert {
- return SDLAlert(alertText1: textField1, alertText2: nil, alertText3: nil)
+ return SDLAlert(alertText1: textField1, alertText2: nil)
}
/// Creates an alert with up to two lines of text and a close button that will dismiss the alert when tapped
@@ -30,7 +30,7 @@ class AlertManager {
/// - textField1: The first line of a message to display in the alert
/// - textField2: The second line of a message to display in the alert
/// - Returns: An SDLAlert object
- class func alertWithMessageAndCloseButton(_ textField1: String, textField2: String? = nil) -> SDLAlert {
- return SDLAlert(alertText1: textField1, alertText2: textField2, alertText3: nil, duration: 5000, softButtons: [AlertManager.okSoftButton])
+ class func alertWithMessageAndCloseButton(_ textField1: String, textField2: String? = nil, iconName: String? = nil) -> SDLAlert {
+ return SDLAlert(alertText1: textField1, alertText2: textField2, alertText3: nil, ttsChunks: nil, playTone: false, progressIndicator: false, duration: 5000, softButtons: [AlertManager.okSoftButton], alertIcon: (iconName != nil) ? SDLImage(name: iconName!, isTemplate: true) : nil)
}
}
diff --git a/Example Apps/Example Swift/ButtonManager.swift b/Example Apps/Example Swift/ButtonManager.swift
index 2a7b7ccf7..e0953accc 100644
--- a/Example Apps/Example Swift/ButtonManager.swift
+++ b/Example Apps/Example Swift/ButtonManager.swift
@@ -70,8 +70,10 @@ private extension ButtonManager {
let textSoftButtonState = SDLSoftButtonState(stateName: AlertSoftButtonTextState, text: AlertSoftButtonText, image: nil)
return SDLSoftButtonObject(name: AlertSoftButton, states: [imageSoftButtonState, textSoftButtonState], initialStateName: imageSoftButtonState.name) { (buttonPress, buttonEvent) in
guard buttonPress != nil else { return }
- let alert = AlertManager.alertWithMessageAndCloseButton("You pressed the button!")
- manager.send(alert)
+ manager.fileManager.upload(artwork: SDLArtwork(image: UIImage(named: CarBWIconImageName)!, persistent: false, as: .PNG), completionHandler: { (success, artworkName, bytesAvailable, err) in
+ let alert = AlertManager.alertWithMessageAndCloseButton("You pressed the button!", iconName: artworkName)
+ manager.send(alert)
+ })
}
}
diff --git a/SmartDeviceLink/SDLAlert.h b/SmartDeviceLink/SDLAlert.h
index 082dd7124..a0a8329c5 100644
--- a/SmartDeviceLink/SDLAlert.h
+++ b/SmartDeviceLink/SDLAlert.h
@@ -40,27 +40,29 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLAlert : SDLRPCRequest
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 duration:(UInt16)duration __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 duration:(UInt16)duration;
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3;
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration;
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons;
+- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 playTone:(BOOL)playTone duration:(UInt16)duration __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithTTS:(nullable NSString *)ttsText playTone:(BOOL)playTone;
+- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration __deprecated_msg("Use initWithAlertText1:alertText2: instead");
-- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 playTone:(BOOL)playTone duration:(UInt16)duration;
+- (instancetype)initWithTTS:(nullable NSString *)ttsText playTone:(BOOL)playTone __deprecated_msg("Use initWithTTSChunks:playTone: instead");
-- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration;
+- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons __deprecated_msg("Use initWithAlertText1:alertText2:alertText3:ttsChunks:playTone:progressIndicator:duration:softButtons:alertIcon: instead");
-- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone;
+- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons __deprecated_msg("Use initWithAlertText1:alertText2:alertText3:ttsChunks:playTone:progressIndicator:duration:softButtons:alertIcon: instead");;
-- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons;
+- (instancetype)initWithAlertText1:(NSString *)alertText1 alertText2:(nullable NSString *)alertText2;
-- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons;
+- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone;
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 ttsChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone progressIndicator:(BOOL)showProgressIndicator duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons alertIcon:(nullable SDLImage *)icon;
/**
* The String to be displayed in the first field of the display during the Alert
diff --git a/SmartDeviceLink/SDLAlert.m b/SmartDeviceLink/SDLAlert.m
index 6d708ab56..31cb2cbac 100644
--- a/SmartDeviceLink/SDLAlert.m
+++ b/SmartDeviceLink/SDLAlert.m
@@ -9,7 +9,7 @@
#import "SDLSoftButton.h"
#import "SDLTTSChunk.h"
-static UInt16 const SDLDefaultDuration = 5000;
+static UInt16 const DefaultAlertDuration = 5000;
NS_ASSUME_NONNULL_BEGIN
@@ -25,55 +25,65 @@ NS_ASSUME_NONNULL_BEGIN
#pragma clang diagnostic pop
- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 {
- return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 duration:SDLDefaultDuration];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:nil playTone:NO progressIndicator:NO duration:DefaultAlertDuration softButtons:nil alertIcon:nil];
}
- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 duration:(UInt16)duration {
- return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:nil duration:duration];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:nil ttsChunks:nil playTone:NO progressIndicator:NO duration:duration softButtons:nil alertIcon:nil];
+
}
- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration {
- return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 duration:duration softButtons:nil];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:nil playTone:NO progressIndicator:NO duration:duration softButtons:nil alertIcon:nil];
}
- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons {
- return [self initWithTTSChunks:nil alertText1:alertText1 alertText2:alertText2 alertText3:alertText3 playTone:NO duration:duration softButtons:softButtons];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:nil playTone:NO progressIndicator:NO duration:duration softButtons:softButtons alertIcon:nil];
}
- (instancetype)initWithTTS:(nullable NSString *)ttsText playTone:(BOOL)playTone {
- return [self initWithTTS:ttsText alertText1:nil alertText2:nil playTone:playTone duration:SDLDefaultDuration];
+ return [self initWithAlertText1:nil alertText2:nil alertText3:nil ttsChunks:[SDLTTSChunk textChunksFromString:ttsText] playTone:playTone progressIndicator:NO duration:DefaultAlertDuration softButtons:nil alertIcon:nil];
}
- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 playTone:(BOOL)playTone duration:(UInt16)duration {
- return [self initWithTTS:ttsText alertText1:alertText1 alertText2:alertText2 alertText3:nil playTone:playTone duration:duration];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:nil ttsChunks:[SDLTTSChunk textChunksFromString:ttsText] playTone:playTone progressIndicator:NO duration:duration softButtons:nil alertIcon:nil];
}
- (instancetype)initWithTTS:(nullable NSString *)ttsText alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration {
- NSArray *ttsChunks = [SDLTTSChunk textChunksFromString:ttsText];
- return [self initWithTTSChunks:ttsChunks alertText1:alertText1 alertText2:alertText2 alertText3:alertText3 playTone:playTone duration:duration softButtons:nil];
-}
-
-- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone {
- return [self initWithTTSChunks:ttsChunks alertText1:nil alertText2:nil alertText3:nil playTone:playTone duration:SDLDefaultDuration softButtons:nil];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:[SDLTTSChunk textChunksFromString:ttsText] playTone:playTone progressIndicator:NO duration:duration softButtons:nil alertIcon:nil];
}
- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons {
- return [self initWithTTSChunks:ttsChunks alertText1:alertText1 alertText2:alertText2 alertText3:alertText3 playTone:playTone duration:SDLDefaultDuration softButtons:softButtons];
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:ttsChunks playTone:playTone progressIndicator:NO duration:DefaultAlertDuration softButtons:softButtons alertIcon:nil];
}
- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks alertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 playTone:(BOOL)playTone duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons {
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:alertText3 ttsChunks:ttsChunks playTone:playTone progressIndicator:NO duration:duration softButtons:softButtons alertIcon:nil];
+}
+
+- (instancetype)initWithAlertText1:(NSString *)alertText1 alertText2:(nullable NSString *)alertText2 {
+ return [self initWithAlertText1:alertText1 alertText2:alertText2 alertText3:nil ttsChunks:nil playTone:NO progressIndicator:NO duration:DefaultAlertDuration softButtons:nil alertIcon:nil];
+}
+
+- (instancetype)initWithTTSChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone {
+ return [self initWithAlertText1:nil alertText2:nil alertText3:nil ttsChunks:ttsChunks playTone:playTone progressIndicator:NO duration:DefaultAlertDuration softButtons:nil alertIcon:nil];
+}
+
+- (instancetype)initWithAlertText1:(nullable NSString *)alertText1 alertText2:(nullable NSString *)alertText2 alertText3:(nullable NSString *)alertText3 ttsChunks:(nullable NSArray<SDLTTSChunk *> *)ttsChunks playTone:(BOOL)playTone progressIndicator:(BOOL)showProgressIndicator duration:(UInt16)duration softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons alertIcon:(nullable SDLImage *)icon {
self = [self init];
if (!self) {
return nil;
}
- self.ttsChunks = [ttsChunks mutableCopy];
+ self.ttsChunks = [ttsChunks copy];
self.alertText1 = alertText1;
self.alertText2 = alertText2;
self.alertText3 = alertText3;
self.playTone = @(playTone);
+ self.progressIndicator = @(showProgressIndicator);
self.duration = @(duration);
- self.softButtons = [softButtons mutableCopy];
+ self.softButtons = [softButtons copy];
+ self.alertIcon = icon;
return self;
}
@@ -143,7 +153,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)setAlertIcon:(nullable SDLImage *)alertIcon {
- [self.parameters setObject:alertIcon forKey:SDLRPCParameterNameAlertIcon];
+ [self.parameters sdl_setObject:alertIcon forName:SDLRPCParameterNameAlertIcon];
}
- (nullable SDLImage *)alertIcon {
diff --git a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m
index d3571a08a..5be603e35 100644
--- a/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/RequestSpecs/SDLAlertSpec.m
@@ -19,100 +19,310 @@ QuickSpecBegin(SDLAlertSpec)
SDLTTSChunk *tts = [[SDLTTSChunk alloc] init];
SDLSoftButton *button = [[SDLSoftButton alloc] init];
-SDLImage *testImage = [[SDLImage alloc] init];
-
-describe(@"Getter/Setter Tests", ^ {
- it(@"Should set and get correctly", ^ {
- SDLAlert* testRequest = [[SDLAlert alloc] init];
-
- testRequest.alertText1 = @"alert#1";
- testRequest.alertText2 = @"alert#2";
- testRequest.alertText3 = @"alert#3";
- testRequest.ttsChunks = @[tts];
- testRequest.duration = @4357;
- testRequest.playTone = @YES;
- testRequest.progressIndicator = @NO;
- testRequest.softButtons = @[button];
- testRequest.alertIcon = testImage;
-
- expect(testRequest.alertText1).to(equal(@"alert#1"));
- expect(testRequest.alertText2).to(equal(@"alert#2"));
- expect(testRequest.alertText3).to(equal(@"alert#3"));
- expect(testRequest.ttsChunks).to(equal(@[tts]));
- expect(testRequest.duration).to(equal(@4357));
- expect(testRequest.playTone).to(equal(@YES));
- expect(testRequest.progressIndicator).to(equal(@NO));
- expect(testRequest.softButtons).to(equal(@[button]));
- expect(testRequest.alertIcon).to(equal(testImage));
- });
-
- it(@"Should get correctly when initialized", ^ {
- NSMutableDictionary<NSString *, id> *dict = @{SDLRPCParameterNameRequest:
- @{SDLRPCParameterNameParameters:
- @{SDLRPCParameterNameAlertText1: @"alert#1",
- SDLRPCParameterNameAlertText2: @"alert#2",
- SDLRPCParameterNameAlertText3: @"alert#3",
- SDLRPCParameterNameTTSChunks: @[tts],
- SDLRPCParameterNameDuration: @4357,
- SDLRPCParameterNamePlayTone: @YES,
- SDLRPCParameterNameProgressIndicator: @NO,
- SDLRPCParameterNameSoftButtons: @[button],
- SDLRPCParameterNameAlertIcon: testImage
- },
- SDLRPCParameterNameOperationName: SDLRPCFunctionNameAlert
- }
- };
+SDLImage *testImage = [[SDLImage alloc] initWithName:@"testImage" isTemplate:YES];
+
+describe(@"Alert spec", ^{
+ UInt16 defaultDuration = 5000;
+
+ NSString *testText1 = @"Test Text 1";
+ NSString *testText2 = @"Test Text 2";
+ NSString *testText3 = @"Test Text 3";
+ NSString *testTTSString = @"Test TTS";
+ BOOL testPlayTone = YES;
+ BOOL testProgressIndicator = YES;
+ UInt16 testDuration = 7847;
+
+ describe(@"initializer tests", ^{
+ it(@"should initialize correctly with initWithAlertText1:alertText2:duration:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 duration:testDuration];
#pragma clang diagnostic pop
-
- expect(testRequest.alertText1).to(equal(@"alert#1"));
- expect(testRequest.alertText2).to(equal(@"alert#2"));
- expect(testRequest.alertText3).to(equal(@"alert#3"));
- expect(testRequest.ttsChunks).to(equal([@[tts] mutableCopy]));
- expect(testRequest.duration).to(equal(@4357));
- expect(testRequest.playTone).to(equal(@YES));
- expect(testRequest.progressIndicator).to(equal(@NO));
- expect(testRequest.softButtons).to(equal([@[button] mutableCopy]));
- });
- it(@"Should handle NSNull", ^{
- NSMutableDictionary* dict = @{SDLRPCParameterNameRequest:
- @{SDLRPCParameterNameParameters:
- @{SDLRPCParameterNameAlertText1: @"alert#1",
- SDLRPCParameterNameAlertText2: @"alert#2",
- SDLRPCParameterNameAlertText3: @"alert#3",
- SDLRPCParameterNameTTSChunks: @[tts],
- SDLRPCParameterNameDuration: @4357,
- SDLRPCParameterNamePlayTone: @YES,
- SDLRPCParameterNameProgressIndicator: @NO,
- SDLRPCParameterNameSoftButtons: [NSNull null],
- SDLRPCParameterNameAlertIcon: testImage
- },
- SDLRPCParameterNameOperationName:SDLRPCFunctionNameAlert}
- };
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(beNil());
+ expect(testAlert.ttsChunks).to(beNil());
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(beFalse());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(beNil());
+ expect(testAlert.duration).to(equal(defaultDuration));
+ expect(testAlert.playTone).to(beFalse());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:duration:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 duration:testDuration];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(beNil());
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(beFalse());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithAlertText1:alertText2:alertText3:duration:softButtons:", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 duration:testDuration softButtons:@[button]];
#pragma clang diagnostic pop
- expectAction(^{
- NSArray<SDLSoftButton *> *softButtons = testRequest.softButtons;
- }).to(raiseException());
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(beNil());
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(beFalse());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(haveCount(1));
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTS:alertText1:alertText2:playTone:duration:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString alertText1:testText1 alertText2:testText2 playTone:testPlayTone duration:testDuration];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(beNil());
+ expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(beTrue());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTS:alertText1:alertText2:alertText3:playTone:duration:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone duration:testDuration];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTS:playTone:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTS:testTTSString playTone:testPlayTone];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(beNil());
+ expect(testAlert.alertText2).to(beNil());
+ expect(testAlert.alertText3).to(beNil());
+ expect(testAlert.ttsChunks.firstObject.text).to(equal(testTTSString));
+ expect(testAlert.duration).to(equal(defaultDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTSChunks:alertText1:alertText2:alertText3:playTone:softButtons:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone softButtons:@[button]];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(haveCount(1));
+ expect(testAlert.duration).to(equal(defaultDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(haveCount(1));
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTSChunks:alertText1:alertText2:alertText3:playTone:duration:softButtons:", ^{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] alertText1:testText1 alertText2:testText2 alertText3:testText3 playTone:testPlayTone duration:testDuration softButtons:@[button]];
+#pragma clang diagnostic pop
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(haveCount(1));
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(haveCount(1));
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithAlertText1:alertText2:", ^{
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2];
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(beNil());
+ expect(testAlert.ttsChunks).to(beNil());
+ expect(testAlert.duration).to(equal(defaultDuration));
+ expect(testAlert.playTone).to(beFalse());
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTSChunks:playTone:", ^{
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithTTSChunks:@[tts] playTone:testPlayTone];
+
+ expect(testAlert.alertText1).to(beNil());
+ expect(testAlert.alertText2).to(beNil());
+ expect(testAlert.alertText3).to(beNil());
+ expect(testAlert.ttsChunks).to(haveCount(1));
+ expect(testAlert.duration).to(equal(defaultDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beFalse());
+ expect(testAlert.softButtons).to(beNil());
+ expect(testAlert.alertIcon).to(beNil());
+ });
+
+ it(@"should initialize correctly with initWithTTSChunks:alertText1:alertText2:alertText3:playTone:duration:softButtons:", ^{
+ SDLAlert *testAlert = [[SDLAlert alloc] initWithAlertText1:testText1 alertText2:testText2 alertText3:testText3 ttsChunks:@[tts] playTone:testPlayTone progressIndicator:testProgressIndicator duration:testDuration softButtons:@[button] alertIcon:testImage];
+
+ expect(testAlert.alertText1).to(equal(testText1));
+ expect(testAlert.alertText2).to(equal(testText2));
+ expect(testAlert.alertText3).to(equal(testText3));
+ expect(testAlert.ttsChunks).to(haveCount(1));
+ expect(testAlert.duration).to(equal(testDuration));
+ expect(testAlert.playTone).to(equal(testPlayTone));
+ expect(testAlert.progressIndicator).to(beTrue());
+ expect(testAlert.softButtons).to(haveCount(1));
+ expect(testAlert.alertIcon.value).to(equal(testImage.value));
+ });
});
-
- it(@"Should return nil if not set", ^ {
- SDLAlert* testRequest = [[SDLAlert alloc] init];
-
- expect(testRequest.alertText1).to(beNil());
- expect(testRequest.alertText2).to(beNil());
- expect(testRequest.alertText3).to(beNil());
- expect(testRequest.ttsChunks).to(beNil());
- expect(testRequest.duration).to(beNil());
- expect(testRequest.playTone).to(beNil());
- expect(testRequest.progressIndicator).to(beNil());
- expect(testRequest.softButtons).to(beNil());
+
+ describe(@"Getter/Setter Tests", ^ {
+ it(@"Should set and get correctly", ^ {
+ SDLAlert* testRequest = [[SDLAlert alloc] init];
+
+ testRequest.alertText1 = @"alert#1";
+ testRequest.alertText2 = @"alert#2";
+ testRequest.alertText3 = @"alert#3";
+ testRequest.ttsChunks = @[tts];
+ testRequest.duration = @4357;
+ testRequest.playTone = @YES;
+ testRequest.progressIndicator = @NO;
+ testRequest.softButtons = @[button];
+ testRequest.alertIcon = testImage;
+
+ expect(testRequest.alertText1).to(equal(@"alert#1"));
+ expect(testRequest.alertText2).to(equal(@"alert#2"));
+ expect(testRequest.alertText3).to(equal(@"alert#3"));
+ expect(testRequest.ttsChunks).to(equal(@[tts]));
+ expect(testRequest.duration).to(equal(@4357));
+ expect(testRequest.playTone).to(equal(@YES));
+ expect(testRequest.progressIndicator).to(equal(@NO));
+ expect(testRequest.softButtons).to(equal(@[button]));
+ expect(testRequest.alertIcon).to(equal(testImage));
+ });
+
+ it(@"Should get correctly when initialized", ^ {
+ NSDictionary<NSString *, id> *dict = @{SDLRPCParameterNameRequest:
+ @{SDLRPCParameterNameParameters:
+ @{SDLRPCParameterNameAlertText1: @"alert#1",
+ SDLRPCParameterNameAlertText2: @"alert#2",
+ SDLRPCParameterNameAlertText3: @"alert#3",
+ SDLRPCParameterNameTTSChunks: @[tts],
+ SDLRPCParameterNameDuration: @4357,
+ SDLRPCParameterNamePlayTone: @YES,
+ SDLRPCParameterNameProgressIndicator: @NO,
+ SDLRPCParameterNameSoftButtons: @[button],
+ SDLRPCParameterNameAlertIcon: testImage
+ },
+ SDLRPCParameterNameOperationName: SDLRPCFunctionNameAlert
+ }
+ };
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
+#pragma clang diagnostic pop
+
+ expect(testRequest.alertText1).to(equal(@"alert#1"));
+ expect(testRequest.alertText2).to(equal(@"alert#2"));
+ expect(testRequest.alertText3).to(equal(@"alert#3"));
+ expect(testRequest.ttsChunks).to(equal([@[tts] mutableCopy]));
+ expect(testRequest.duration).to(equal(@4357));
+ expect(testRequest.playTone).to(equal(@YES));
+ expect(testRequest.progressIndicator).to(equal(@NO));
+ expect(testRequest.softButtons).to(equal([@[button] mutableCopy]));
+ });
+
+ it(@"Should handle NSNull", ^{
+ NSDictionary* dict = @{SDLRPCParameterNameRequest:
+ @{SDLRPCParameterNameParameters:
+ @{SDLRPCParameterNameAlertText1: @"alert#1",
+ SDLRPCParameterNameAlertText2: @"alert#2",
+ SDLRPCParameterNameAlertText3: @"alert#3",
+ SDLRPCParameterNameTTSChunks: @[tts],
+ SDLRPCParameterNameDuration: @4357,
+ SDLRPCParameterNamePlayTone: @YES,
+ SDLRPCParameterNameProgressIndicator: @NO,
+ SDLRPCParameterNameSoftButtons: [NSNull null],
+ SDLRPCParameterNameAlertIcon: testImage
+ },
+ SDLRPCParameterNameOperationName:SDLRPCFunctionNameAlert}
+ };
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ SDLAlert* testRequest = [[SDLAlert alloc] initWithDictionary:dict];
+#pragma clang diagnostic pop
+ expectAction(^{
+ NSArray<SDLSoftButton *> *softButtons = testRequest.softButtons;
+ }).to(raiseException());
+ });
+
+ it(@"Should return nil if not set", ^ {
+ SDLAlert* testRequest = [[SDLAlert alloc] init];
+
+ expect(testRequest.alertText1).to(beNil());
+ expect(testRequest.alertText2).to(beNil());
+ expect(testRequest.alertText3).to(beNil());
+ expect(testRequest.ttsChunks).to(beNil());
+ expect(testRequest.duration).to(beNil());
+ expect(testRequest.playTone).to(beNil());
+ expect(testRequest.progressIndicator).to(beNil());
+ expect(testRequest.softButtons).to(beNil());
+ });
});
});
+
QuickSpecEnd