Skip to content

Commit

Permalink
Merge pull request #1525 from smartdevicelink/bugfix/issue-1206-SDLRa…
Browse files Browse the repository at this point in the history
…dioControlData-convenience-init

Create XM, AM and FM Convenience inits
  • Loading branch information
joeljfischer committed Jan 27, 2020
2 parents 26fc6bf + 3a3be8b commit 871a39d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
21 changes: 21 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.h
Expand Up @@ -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
*
Expand Down
39 changes: 39 additions & 0 deletions SmartDeviceLink/SDLRadioControlData.m
Expand Up @@ -43,6 +43,45 @@ - (instancetype)initWithFrequencyInteger:(nullable NSNumber<SDLInt> *)frequencyI
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];
}
Expand Down
Expand Up @@ -155,6 +155,32 @@
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

0 comments on commit 871a39d

Please sign in to comment.