summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2019-03-05 09:55:14 -0500
committerNicoleYarroch <nicole@livio.io>2019-03-05 09:55:14 -0500
commitcbae4acc19126cb7482b8f41b991b49b09f78893 (patch)
tree0aab493f4277ff0dd35720090dc2bb7ee7a87cb6
parentbfcbbdb4b4d1e60a981ef4dd424bd81042b7edff (diff)
downloadsdl_ios-cbae4acc19126cb7482b8f41b991b49b09f78893.tar.gz
Fixed broken protocol version test cases
* Fixed broken protocol version test cases * Added `isGreaterThanOrEqualVersion:` method to `SDLVersion` * Addded protocol version check before getting the `authToken` in the `SDLProtocol` class
-rw-r--r--SmartDeviceLink/SDLProtocol.m6
-rw-r--r--SmartDeviceLink/SDLVersion.h1
-rw-r--r--SmartDeviceLink/SDLVersion.m4
-rw-r--r--SmartDeviceLinkTests/ProtocolSpecs/MessageSpecs/SDLProtocolSpec.m42
4 files changed, 40 insertions, 13 deletions
diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m
index 299b40289..19c9d8207 100644
--- a/SmartDeviceLink/SDLProtocol.m
+++ b/SmartDeviceLink/SDLProtocol.m
@@ -485,11 +485,11 @@ NS_ASSUME_NONNULL_BEGIN
if (startServiceACKPayload.hashId != SDLControlFrameInt32NotFound) {
self.hashId = startServiceACKPayload.hashId;
}
-
- // FIXME: Add check for protocol version 5.2 or greater
- self.authToken = startServiceACKPayload.authToken;
[SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion = (startServiceACKPayload.protocolVersion != nil) ? [SDLVersion versionWithString:startServiceACKPayload.protocolVersion] : [SDLVersion versionWithMajor:startServiceACK.header.version minor:0 patch:0];
+
+ self.authToken = [SDLGlobals.sharedGlobals.maxHeadUnitProtocolVersion isGreaterThanOrEqualVersion:[[SDLVersion alloc] initWithMajor:5 minor:2 patch:0]] ? startServiceACKPayload.authToken : nil;
+
// TODO: Hash id?
} break;
default:
diff --git a/SmartDeviceLink/SDLVersion.h b/SmartDeviceLink/SDLVersion.h
index f7b226206..debdd2630 100644
--- a/SmartDeviceLink/SDLVersion.h
+++ b/SmartDeviceLink/SDLVersion.h
@@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)isLessThanVersion:(SDLVersion *)otherVersion;
- (BOOL)isEqualToVersion:(SDLVersion *)otherVersion;
- (BOOL)isGreaterThanVersion:(SDLVersion *)otherVersion;
+- (BOOL)isGreaterThanOrEqualVersion:(SDLVersion *)otherVersion;
@end
diff --git a/SmartDeviceLink/SDLVersion.m b/SmartDeviceLink/SDLVersion.m
index 37df25966..0e44d187a 100644
--- a/SmartDeviceLink/SDLVersion.m
+++ b/SmartDeviceLink/SDLVersion.m
@@ -110,6 +110,10 @@ NS_ASSUME_NONNULL_BEGIN
return ([self compare:otherVersion] == NSOrderedDescending);
}
+- (BOOL)isGreaterThanOrEqualVersion:(SDLVersion *)otherVersion {
+ return ([self isGreaterThanVersion:otherVersion] || [self isEqualToVersion:otherVersion]);
+}
+
#pragma mark - NSObject overrides
- (BOOL)isEqual:(id)object {
diff --git a/SmartDeviceLinkTests/ProtocolSpecs/MessageSpecs/SDLProtocolSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/MessageSpecs/SDLProtocolSpec.m
index 656a5d6f2..7d625556a 100644
--- a/SmartDeviceLinkTests/ProtocolSpecs/MessageSpecs/SDLProtocolSpec.m
+++ b/SmartDeviceLinkTests/ProtocolSpecs/MessageSpecs/SDLProtocolSpec.m
@@ -24,6 +24,7 @@
#import "SDLV1ProtocolHeader.h"
#import "SDLV2ProtocolHeader.h"
#import "SDLVersion.h"
+
QuickSpecBegin(SDLProtocolSpec)
//Test dictionaries
@@ -439,8 +440,29 @@ describe(@"HandleProtocolSessionStarted tests", ^ {
OCMExpect([delegateMock handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:nil]]);
expect(testProtocol.authToken).to(equal(testAuthToken));
- expect([SDLGlobals sharedGlobals].protocolVersion).to(equal(@"5.2.0"));
- expect([SDLGlobals sharedGlobals].maxHeadUnitVersion).to(equal(@"5.2.0"));
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"5.2.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"5.2.0"));
+ });
+
+ it(@"Should store the protocol version, but not get the auth token, and pass the start service along to the delegate if the protocol version is greater than 5.0.0 but less than 5.2.0", ^{
+ SDLControlFramePayloadRPCStartServiceAck *testPayload = [[SDLControlFramePayloadRPCStartServiceAck alloc] initWithHashId:1545784 mtu:989786483 authToken:testAuthToken protocolVersion:@"5.1.0" secondaryTransports:nil audioServiceTransports:nil videoServiceTransports:nil];
+ NSData *testData = testPayload.data;
+
+ SDLV2ProtocolHeader* testHeader = [[SDLV2ProtocolHeader alloc] initWithVersion:5];
+ testHeader.frameType = SDLFrameTypeControl;
+ testHeader.serviceType = SDLServiceTypeRPC;
+ testHeader.frameData = SDLFrameInfoStartServiceACK;
+ testHeader.sessionID = 0x93;
+ testHeader.bytesInPayload = (UInt32)testData.length;
+
+ [testProtocol.protocolDelegateTable addObject:delegateMock];
+ [testProtocol handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:testData]];
+
+ OCMExpect([delegateMock handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:nil]]);
+
+ expect(testProtocol.authToken).to(beNil());
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"5.1.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"5.1.0"));
});
it(@"Should set the max head unit version using the header version if the protocol version is missing from the payload", ^{
@@ -460,8 +482,8 @@ describe(@"HandleProtocolSessionStarted tests", ^ {
OCMExpect([delegateMock handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:nil]]);
expect(testProtocol.authToken).to(beNil());
- expect([SDLGlobals sharedGlobals].protocolVersion).to(equal(@"5.0.0"));
- expect([SDLGlobals sharedGlobals].maxHeadUnitVersion).to(equal(@"5.0.0"));
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"5.0.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"5.0.0"));
});
});
@@ -484,8 +506,8 @@ describe(@"HandleProtocolSessionStarted tests", ^ {
// Should keep their default values
expect(testProtocol.authToken).to(beNil());
- expect([SDLGlobals sharedGlobals].protocolVersion).to(equal(@"1.0.0"));
- expect([SDLGlobals sharedGlobals].maxHeadUnitVersion).to(equal(@"0.0.0"));
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"1.0.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"0.0.0"));
});
});
});
@@ -508,8 +530,8 @@ describe(@"HandleProtocolSessionStarted tests", ^ {
OCMExpect([delegateMock handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:nil]]);
- expect([SDLGlobals sharedGlobals].protocolVersion).to(equal(@"3.1.0"));
- expect([SDLGlobals sharedGlobals].maxHeadUnitVersion).to(equal(@"3.1.0"));
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"3.1.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"3.1.0"));
});
});
@@ -531,8 +553,8 @@ describe(@"HandleProtocolSessionStarted tests", ^ {
OCMExpect([delegateMock handleProtocolStartServiceACKMessage:[SDLProtocolMessage messageWithHeader:testHeader andPayload:nil]]);
// Should keep their default values
- expect([SDLGlobals sharedGlobals].protocolVersion).to(equal(@"1.0.0"));
- expect([SDLGlobals sharedGlobals].maxHeadUnitVersion).to(equal(@"0.0.0"));
+ expect([SDLGlobals sharedGlobals].protocolVersion.stringVersion).to(equal(@"1.0.0"));
+ expect([SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion.stringVersion).to(equal(@"0.0.0"));
});
});
});