diff options
Diffstat (limited to 'SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs')
3 files changed, 72 insertions, 0 deletions
diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m index a578ec561..9dac0203f 100644 --- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m +++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLProtocolHeaderSpec.m @@ -15,6 +15,18 @@ QuickSpecBegin(SDLProtocolHeaderSpec) +__block SDLProtocolHeader *testHeader; + +beforeSuite(^ { + testHeader = [[SDLProtocolHeader alloc] init]; + testHeader.encrypted = YES; + testHeader.frameType = SDLFrameTypeControl; + testHeader.serviceType = SDLServiceTypeRPC; + testHeader.frameData = SDLFrameInfoStartService; + testHeader.sessionID = 0x53; + testHeader.bytesInPayload = 0x1234; +}); + describe(@"HeaderForVersion Tests", ^ { it(@"Should return the correct header", ^ { expect([SDLProtocolHeader headerForVersion:1]).to(beAKindOf(SDLV1ProtocolHeader.class)); @@ -38,4 +50,30 @@ describe(@"DetermineVersion Tests", ^ { }); }); +describe(@"hashing tests", ^ { + it(@"should return equivalent hash values", ^ { + SDLProtocolHeader *equalHeader = [[SDLProtocolHeader alloc] init]; + equalHeader.encrypted = YES; + equalHeader.frameType = SDLFrameTypeControl; + equalHeader.serviceType = SDLServiceTypeRPC; + equalHeader.frameData = SDLFrameInfoStartService; + equalHeader.sessionID = 0x53; + equalHeader.bytesInPayload = 0x1234; + + expect([testHeader hash]).to(equal([equalHeader hash])); + }); + + it(@"should return unequivalent hash values", ^ { + SDLProtocolHeader *unequalHeader = [[SDLProtocolHeader alloc] init]; + unequalHeader.encrypted = NO; + unequalHeader.frameType = SDLFrameTypeFirst; + unequalHeader.serviceType = SDLServiceTypeVideo; + unequalHeader.frameData = SDLFrameInfoStartService; + unequalHeader.sessionID = 0x54; + unequalHeader.bytesInPayload = 0x1234; + + expect([testHeader hash]).toNot(equal([unequalHeader hash])); + }); +}); + QuickSpecEnd diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m index a7c6c1660..f2218f7db 100644 --- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m +++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV1ProtocolHeaderSpec.m @@ -86,4 +86,21 @@ describe(@"RPCPayloadWithData Test", ^ { }); }); +describe(@"equality tests", ^ { + it (@"should be equal to copy of header", ^ { + // Create exact copy of test header + SDLV1ProtocolHeader *equalHeader = [testHeader copy]; + + expect([testHeader isEqual:equalHeader]).to(beTrue()); + }); + + 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(beFalse()); + }); +}); + QuickSpecEnd diff --git a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m index 1ade6e426..ec06d2b4d 100644 --- a/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m +++ b/SmartDeviceLinkTests/ProtocolSpecs/HeaderSpecs/SDLV2ProtocolHeaderSpec.m @@ -90,4 +90,21 @@ describe(@"RPCPayloadWithData Test", ^ { }); }); +describe(@"equality tests", ^ { + it (@"should be equal to copy of header", ^ { + // Create exact copy of test header + SDLV2ProtocolHeader *equalHeader = [testHeader copy]; + + expect([testHeader isEqual:equalHeader]).to(beTrue()); + }); + + 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(beFalse()); + }); +}); + QuickSpecEnd |