summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicole Yarroch <nicole@livio.io>2021-03-12 14:51:12 -0500
committerGitHub <noreply@github.com>2021-03-12 14:51:12 -0500
commitb4ed102b7446e1811846eb367b27388dce3a1af4 (patch)
treeb5b9b77b59f5de4c014f618b6aede3e56e0dad4b
parente44d3255ef3987d9be2affded805914a9ed864fa (diff)
parent65ffc8cd42c7dc40611341fcd3bbf9eb0ba3e5e3 (diff)
downloadsdl_ios-b4ed102b7446e1811846eb367b27388dce3a1af4.tar.gz
Merge pull request #1912 from smartdevicelink/bugfix/issue_1891_fix_choice_set_default_timeout
Fix choice set default timeout behavior
-rw-r--r--SmartDeviceLink/public/SDLChoiceSet.h11
-rw-r--r--SmartDeviceLink/public/SDLChoiceSet.m34
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m75
3 files changed, 106 insertions, 14 deletions
diff --git a/SmartDeviceLink/public/SDLChoiceSet.h b/SmartDeviceLink/public/SDLChoiceSet.h
index 1eafb8bd8..83053e30e 100644
--- a/SmartDeviceLink/public/SDLChoiceSet.h
+++ b/SmartDeviceLink/public/SDLChoiceSet.h
@@ -35,7 +35,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@interface SDLChoiceSet: NSObject
/**
- Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details. If this is not set by you, it will default to 10 seconds.
+ Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details. If this is not set by you, it will default to 10 seconds. The minimum is 5 seconds, the maximum is 100 seconds. If this is set below the minimum, it will be capped at 5 seconds. If this is set above the maximum, it will be capped at 100 seconds.
*/
@property (class, assign, nonatomic) NSTimeInterval defaultTimeout;
@@ -60,7 +60,9 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@property (assign, nonatomic) SDLChoiceSetLayout layout;
/**
- Maps to PerformInteraction.timeout. This applies only to a manual selection (not a voice selection, which has its timeout handled by the system). Defaults to `defaultTimeout`.
+ Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`. If this is set below the minimum, it will be capped at 5 seconds. Minimum 5 seconds, maximum 100 seconds. If this is set above the maximum, it will be capped at 100 seconds. Defaults to 0.
+
+ @note This applies only to a manual selection (not a voice selection, which has its timeout handled by the system).
*/
@property (assign, nonatomic) NSTimeInterval timeout;
@@ -124,7 +126,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@param title The choice set's title
@param delegate The choice set delegate called after the user has interacted with your choice set
@param layout The layout of choice options (Manual/touch only)
- @param timeout The timeout of a touch interaction (Manual/touch only)
+ @param timeout The timeout of a touch interaction in seconds (Manual/touch only)
@param initialPrompt A voice prompt spoken to the user when this set is displayed
@param timeoutPrompt A voice prompt spoken to the user when the set times out (Voice only)
@param helpPrompt A voice prompt spoken to the user when the user asks for "help"
@@ -144,7 +146,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@param title The choice set's title
@param delegate The choice set delegate called after the user has interacted with your choice set
@param layout The layout of choice options (Manual/touch only)
- @param timeout The timeout of a touch interaction (Manual/touch only)
+ @param timeout The timeout of a touch interaction in seconds (Manual/touch only)
@param initialPrompt A voice prompt spoken to the user when this set is displayed
@param timeoutPrompt A voice prompt spoken to the user when the set times out (Voice only)
@param helpPrompt A voice prompt spoken to the user when the user asks for "help"
@@ -154,7 +156,6 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
*/
- (instancetype)initWithTitle:(NSString *)title delegate:(id<SDLChoiceSetDelegate>)delegate layout:(SDLChoiceSetLayout)layout timeout:(NSTimeInterval)timeout initialPrompt:(nullable NSArray<SDLTTSChunk *> *)initialPrompt timeoutPrompt:(nullable NSArray<SDLTTSChunk *> *)timeoutPrompt helpPrompt:(nullable NSArray<SDLTTSChunk *> *)helpPrompt vrHelpList:(nullable NSArray<SDLVRHelpItem *> *)helpList choices:(NSArray<SDLChoiceCell *> *)choices;
-
/**
Cancels the choice set. If the choice set has not yet been sent to Core, it will not be sent. If the choice set is already presented on Core, the choice set will be immediately dismissed. Canceling an already presented choice set will only work if connected to Core versions 6.0+. On older versions of Core, the choice set will not be dismissed.
*/
diff --git a/SmartDeviceLink/public/SDLChoiceSet.m b/SmartDeviceLink/public/SDLChoiceSet.m
index 775751381..8baf085a6 100644
--- a/SmartDeviceLink/public/SDLChoiceSet.m
+++ b/SmartDeviceLink/public/SDLChoiceSet.m
@@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLChoiceSet
+static const float TimeoutDefault = 0.0;
+static const float TimeoutMinCap = 5.0;
+static const float TimeoutMaxCap = 100.0;
static NSTimeInterval _defaultTimeout = 10.0;
static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
@@ -32,7 +35,7 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
self = [super init];
if (!self) { return nil; }
- _timeout = self.class.defaultTimeout;
+ _timeout = TimeoutDefault;
_layout = self.class.defaultLayout;
return self;
@@ -59,11 +62,6 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
return nil;
}
- if (timeout < 5 || timeout > 100) {
- SDLLogW(@"Attempted to create a choice set with a %f second timeout; Only 5 - 100 seconds is valid", timeout);
- return nil;
- }
-
if (title.length == 0 || title.length > 500) {
SDLLogW(@"Attempted to create a choice set title with a %lu length. Only 500 characters are supported", (unsigned long)title.length);
return nil;
@@ -78,7 +76,7 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
_title = title;
_delegate = delegate;
_layout = layout;
- _timeout = timeout;
+ self.timeout = timeout;
_initialPrompt = initialPrompt;
_timeoutPrompt = timeoutPrompt;
_helpPrompt = helpPrompt;
@@ -97,12 +95,30 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
#pragma mark - Getters / Setters
++ (void)setDefaultTimeout:(NSTimeInterval)defaultTimeout {
+ _defaultTimeout = defaultTimeout;
+}
+
+ (NSTimeInterval)defaultTimeout {
+ if (_defaultTimeout < TimeoutMinCap) {
+ return TimeoutMinCap;
+ } else if (_defaultTimeout > TimeoutMaxCap) {
+ return TimeoutMaxCap;
+ }
+
return _defaultTimeout;
}
-+ (void)setDefaultTimeout:(NSTimeInterval)defaultTimeout {
- _defaultTimeout = defaultTimeout;
+- (NSTimeInterval)timeout {
+ if (_timeout == TimeoutDefault) {
+ return SDLChoiceSet.defaultTimeout;
+ } else if (_timeout < TimeoutMinCap) {
+ return TimeoutMinCap;
+ } else if (_timeout > TimeoutMaxCap) {
+ return TimeoutMaxCap;
+ }
+
+ return _timeout;
}
+ (SDLChoiceSetLayout)defaultLayout {
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
index 63a8a6821..54084c213 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
@@ -186,6 +186,81 @@ describe(@"an SDLChoiceSet", ^{
});
});
+ describe(@"setting the default timeout", ^{
+ __block SDLChoiceSet *testChoiceSet = nil;
+
+ beforeEach(^{
+ testChoiceSet = [[SDLChoiceSet alloc] init];
+ });
+
+ it(@"should return the default timeout if the timeout value was not set", ^{
+ int testDefaultTimeout = 6.0;
+ SDLChoiceSet.defaultTimeout = testDefaultTimeout;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(testDefaultTimeout));
+ expect(testChoiceSet.timeout).to(equal(testDefaultTimeout));
+ });
+
+ it(@"should return the timeout value even if the default timeout was set", ^{
+ int testTimeout = 7.0;
+ int testDefaultTimeout = 9.0;
+ SDLChoiceSet.defaultTimeout = testDefaultTimeout;
+ testChoiceSet.timeout = testTimeout;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(testDefaultTimeout));
+ expect(testChoiceSet.timeout).to(equal(testTimeout));
+ });
+
+ it(@"should return 100 if a value greater than 100 has been set", ^{
+ SDLChoiceSet.defaultTimeout = 155.0;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(100.0));
+ expect(testChoiceSet.timeout).to(equal(100.0));
+ });
+
+ it(@"should return 5 if a value less than 5 has been set", ^{
+ SDLChoiceSet.defaultTimeout = -3.0;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(5.0));
+ expect(testChoiceSet.timeout).to(equal(5.0));
+ });
+ });
+
+ describe(@"setting the timeout", ^{
+ __block SDLChoiceSet *testChoiceSet = nil;
+ __block NSTimeInterval testDefaultTimeout = 7.0;
+
+ beforeEach(^{
+ testChoiceSet = [[SDLChoiceSet alloc] init];
+ SDLChoiceSet.defaultTimeout = testDefaultTimeout;
+ });
+
+ it(@"should return the default timeout if the timeout was not set", ^{
+ expect(testChoiceSet.timeout).to(equal(testDefaultTimeout));
+ });
+
+ it(@"should return the default timeout if the timeout was set to 0", ^{
+ testChoiceSet.timeout = 0.0;
+ expect(testChoiceSet.timeout).to(equal(testDefaultTimeout));
+ });
+
+ it(@"should return the timeout value if it was set", ^{
+ int testTimeout = 9.0;
+ testChoiceSet.timeout = testTimeout;
+ expect(testChoiceSet.timeout).to(equal(testTimeout));
+ });
+
+ it(@"should return 100 if a value greater than 100 has been set", ^{
+ testChoiceSet.timeout = 214.0;
+ expect(testChoiceSet.timeout).to(equal(100.0));
+ });
+
+ it(@"should return 5 if a value less than 5 has been set", ^{
+ testChoiceSet.timeout = 2.25;
+ expect(testChoiceSet.timeout).to(equal(5.0));
+ });
+ });
+
describe(@"canceling the choice set", ^{
__block BOOL canceledHandlerCalled = NO;