summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Beharry <justin.beharry@livio.io>2022-09-01 11:12:57 -0400
committerJustin Beharry <justin.beharry@livio.io>2022-09-01 11:12:57 -0400
commit899bcbfca63e755c8806b781a31df87c6fd436b9 (patch)
treea578e3cb0c5aa8f8c9b188fa11ec527f628121b4
parent2c979b8fbf9fd5ce7b40e5b85c48f72db669d052 (diff)
downloadsdl_ios-899bcbfca63e755c8806b781a31df87c6fd436b9.tar.gz
Add test for Headers and modify hash function
Removed data from hash function. Does not work on SDlProtocolHeader hash
-rw-r--r--SmartDeviceLink/private/SDLProtocolHeader.m11
-rw-r--r--SmartDeviceLink/private/SDLProtocolReceivedMessageProcessor.m1
-rw-r--r--SmartDeviceLink/private/SDLV2ProtocolHeader.m2
-rw-r--r--SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m17
-rw-r--r--SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m17
-rw-r--r--SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m17
6 files changed, 58 insertions, 7 deletions
diff --git a/SmartDeviceLink/private/SDLProtocolHeader.m b/SmartDeviceLink/private/SDLProtocolHeader.m
index 89e544d30..2eb4f16d2 100644
--- a/SmartDeviceLink/private/SDLProtocolHeader.m
+++ b/SmartDeviceLink/private/SDLProtocolHeader.m
@@ -44,13 +44,14 @@ NS_ASSUME_NONNULL_BEGIN
}
- (NSUInteger)hash {
- return NSUIntRotateCell(self.data.hash, NSUIntBitCell / 2)
- ^ NSUIntRotateCell(self.version, NSUIntBitCell / 3)
+ return NSUIntRotateCell(self.version, NSUIntBitCell / 2)
+ ^ NSUIntRotateCell(self.size, NSUIntBitCell / 3)
^ NSUIntRotateCell(self.encrypted, NSUIntBitCell / 4)
^ NSUIntRotateCell(self.frameType, NSUIntBitCell / 5)
- ^ NSUIntRotateCell(self.frameData, NSUIntBitCell / 6)
- ^ NSUIntRotateCell(self.sessionID, NSUIntBitCell / 7)
- ^ NSUIntRotateCell(self.bytesInPayload, NSUIntBitCell / 8);
+ ^ NSUIntRotateCell(self.serviceType, NSUIntBitCell / 6)
+ ^ NSUIntRotateCell(self.frameData, NSUIntBitCell / 7)
+ ^ NSUIntRotateCell(self.sessionID, NSUIntBitCell / 8)
+ ^ NSUIntRotateCell(self.bytesInPayload, NSUIntBitCell / 9);
}
+ (__kindof SDLProtocolHeader *)headerForVersion:(UInt8)version {
diff --git a/SmartDeviceLink/private/SDLProtocolReceivedMessageProcessor.m b/SmartDeviceLink/private/SDLProtocolReceivedMessageProcessor.m
index c65ffc5f9..10f27a789 100644
--- a/SmartDeviceLink/private/SDLProtocolReceivedMessageProcessor.m
+++ b/SmartDeviceLink/private/SDLProtocolReceivedMessageProcessor.m
@@ -205,7 +205,6 @@ typedef NS_ENUM(NSUInteger, ProcessorState) {
if (self.dataLength == 0) {
self.header = [SDLProtocolHeader headerForVersion:self.version];
[self.header parse:self.headerBuffer];
- //todo - Payload!
messageHasEnded = YES;
} else {
self.state = DATA_PUMP_STATE;
diff --git a/SmartDeviceLink/private/SDLV2ProtocolHeader.m b/SmartDeviceLink/private/SDLV2ProtocolHeader.m
index 7f47f445c..d91e74926 100644
--- a/SmartDeviceLink/private/SDLV2ProtocolHeader.m
+++ b/SmartDeviceLink/private/SDLV2ProtocolHeader.m
@@ -126,7 +126,7 @@ const int ProtocolV2HeaderByteSize = 12;
}
- (NSUInteger)hash {
- return [super hash] ^ NSUIntRotateCell(self.messageID, NSUIntBitCell / 9);
+ return [super hash] ^ NSUIntRotateCell(self.messageID, NSUIntBitCell / 10);
}
- (BOOL)isEqual:(SDLV2ProtocolHeader *)object {
diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m
index a578ec561..9fcff743c 100644
--- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m
+++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m
@@ -38,4 +38,21 @@ describe(@"DetermineVersion Tests", ^ {
});
});
+describe(@"Hash Tests", ^ {
+ it(@"Should return equivalent hash values", ^ {
+ SDLProtocolHeader *testHeader = [[SDLProtocolHeader alloc] init];
+ SDLProtocolHeader *equalHeader = [[SDLProtocolHeader alloc] init];
+
+ expect([testHeader hash]).to(equal([equalHeader hash]));
+ });
+
+ it(@"Should return unequivalent hash values", ^ {
+ SDLProtocolHeader *testHeader = [[SDLProtocolHeader alloc] init];
+ SDLProtocolHeader *unequalHeader = [[SDLProtocolHeader alloc] init];
+ unequalHeader.frameType = SDLFrameTypeFirst;
+
+ expect([testHeader hash]).toNot(equal([unequalHeader hash]));
+ });
+});
+
QuickSpecEnd
diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m
index a7c6c1660..d5ddb4707 100644
--- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m
+++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m
@@ -86,4 +86,21 @@ describe(@"RPCPayloadWithData Test", ^ {
});
});
+describe(@"IsEqual Tests", ^ {
+ it (@"Should be equal to copy of header", ^ {
+ // Create exact copy of test header
+ SDLV1ProtocolHeader *equalHeader = [testHeader copy];
+
+ expect([testHeader isEqual:equalHeader]).to(equal(@YES));
+ });
+
+ it (@"Should not be equal to a different header", ^ {
+ // create a slighty different version of test header
+ SDLV1ProtocolHeader *unequalHeader = [testHeader copy];
+ unequalHeader.encrypted = NO;
+
+ expect(([testHeader isEqual:unequalHeader])).to(equal(@NO));
+ });
+});
+
QuickSpecEnd
diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m
index 1ade6e426..8c1de8a56 100644
--- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m
+++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m
@@ -90,4 +90,21 @@ describe(@"RPCPayloadWithData Test", ^ {
});
});
+describe(@"IsEqual Tests", ^ {
+ it (@"Should be equal to copy of header", ^ {
+ // Create exact copy of test header
+ SDLV2ProtocolHeader *equalHeader = [testHeader copy];
+
+ expect([testHeader isEqual:equalHeader]).to(equal(@YES));
+ });
+
+ it (@"Should not be equal to a different header", ^ {
+ // Create a slighty different version of test header
+ SDLV2ProtocolHeader *unequalHeader = [testHeader copy];
+ unequalHeader.messageID = 0x6DAB424E;
+
+ expect(([testHeader isEqual:unequalHeader])).to(equal(@NO));
+ });
+});
+
QuickSpecEnd