diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-01-27 15:00:50 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 15:00:50 -0500 |
commit | 871a39dfe7a7290617392e6dd6e4ddea1f11c648 (patch) | |
tree | 5d498b9d4b606e23d11d6a22a87e23191497c239 | |
parent | 26fc6bff0670aa87cb350951790a0441b4d95c9a (diff) | |
parent | 3a3be8bd730f89b547612c0999b61979e7dfb7f5 (diff) | |
download | sdl_ios-871a39dfe7a7290617392e6dd6e4ddea1f11c648.tar.gz |
Merge pull request #1525 from smartdevicelink/bugfix/issue-1206-SDLRadioControlData-convenience-init
Create XM, AM and FM Convenience inits
-rw-r--r-- | SmartDeviceLink/SDLRadioControlData.h | 21 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRadioControlData.m | 39 | ||||
-rw-r--r-- | SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLRadioControlDataSpec.m | 26 |
3 files changed, 86 insertions, 0 deletions
diff --git a/SmartDeviceLink/SDLRadioControlData.h b/SmartDeviceLink/SDLRadioControlData.h index c3d07eaff..182e6105e 100644 --- a/SmartDeviceLink/SDLRadioControlData.h +++ b/SmartDeviceLink/SDLRadioControlData.h @@ -41,6 +41,27 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction band:(nullable SDLRadioBand)band hdChannel:(nullable NSNumber<SDLInt> *)hdChannel radioEnable:(nullable NSNumber<SDLBool> *)radioEnable hdRadioEnable:(nullable NSNumber<SDLBool> *)hdRadioEnable; +/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters. +/// +/// @param frequencyInteger Must be between 0 and 1710 +/// @param frequencyFraction Must be between 0 and 9 +/// @param hdChannel Must be between 0 and 7 +/// @return An instance of the SDLRadioControlData class +- (instancetype)initFMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction hdChannel:(nullable NSNumber<SDLInt> *)hdChannel; + +/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters. +/// +/// @param frequencyInteger Must be between 0 and 1710 +/// @param hdChannel Must be between 0 and 7 +/// @return An instance of the SDLRadioControlData class +- (instancetype)initAMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger hdChannel:(nullable NSNumber<SDLInt> *)hdChannel; + +/// Constructs a newly allocated SDLRadioControlCapabilities object with given parameters. +/// +/// @param frequencyInteger Must be between 1 and 1710 +/// @return An instance of the SDLRadioControlData class +- (instancetype)initXMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger; + /** * The integer part of the frequency ie for 101.7 this value should be 101 * diff --git a/SmartDeviceLink/SDLRadioControlData.m b/SmartDeviceLink/SDLRadioControlData.m index 9e4f37c85..9fb82f080 100644 --- a/SmartDeviceLink/SDLRadioControlData.m +++ b/SmartDeviceLink/SDLRadioControlData.m @@ -43,6 +43,45 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (instancetype)initFMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger frequencyFraction:(nullable NSNumber<SDLInt> *)frequencyFraction hdChannel:(nullable NSNumber<SDLInt> *)hdChannel { + self = [self init]; + if(!self) { + return nil; + } + + self.band = SDLRadioBandFM; + self.frequencyInteger = frequencyInteger; + self.frequencyFraction = frequencyFraction; + self.hdChannel = hdChannel; + + return self; +} + +- (instancetype)initAMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger hdChannel:(nullable NSNumber<SDLInt> *)hdChannel { + self = [self init]; + if(!self) { + return nil; + } + + self.band = SDLRadioBandAM; + self.frequencyInteger = frequencyInteger; + self.hdChannel = hdChannel; + + return self; +} + +- (instancetype)initXMWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger { + self = [self init]; + if(!self) { + return nil; + } + + self.frequencyInteger = frequencyInteger; + self.band = SDLRadioBandXM; + + return self; +} + - (void)setFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyInteger { [self.store sdl_setObject:frequencyInteger forName:SDLRPCParameterNameFrequencyInteger]; } diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLRadioControlDataSpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLRadioControlDataSpec.m index fd74e0f38..a29ff574d 100644 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLRadioControlDataSpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLRadioControlDataSpec.m @@ -155,6 +155,32 @@ describe(@"Initialization tests", ^{ expect(testStruct.hdRadioEnable).to(equal(@YES)); }); + it(@"Should get correctly when initialized FM radio control capabilities parameters", ^ { + SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initFMWithFrequencyInteger:@101 frequencyFraction:@7 hdChannel:@2]; + + expect(testStruct.frequencyInteger).to(equal(@101)); + expect(testStruct.frequencyFraction).to(equal(@7)); + expect(testStruct.band).to(equal(SDLRadioBandFM)); + expect(testStruct.hdChannel).to(equal(@2)); + }); + + it(@"Should get correctly when initialized AM radio control capabilities parameters", ^ { + SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initAMWithFrequencyInteger:@101 hdChannel:@2]; + + expect(testStruct.frequencyInteger).to(equal(@101)); + expect(testStruct.band).to(equal(SDLRadioBandAM)); + expect(testStruct.hdChannel).to(equal(@2)); + }); + + it(@"Should get correctly when initialized XM radio control capabilities parameters", ^ { + SDLRadioControlData* testStruct = [[SDLRadioControlData alloc] initXMWithFrequencyInteger:@101]; + + expect(testStruct.frequencyInteger).to(equal(@101)); + expect(testStruct.band).to(equal(SDLRadioBandXM)); + }); + + + }); QuickSpecEnd |