summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Gluck <justin.gluck@livio.io>2019-12-11 12:13:20 -0500
committerJustin Gluck <justin.gluck@livio.io>2019-12-11 12:13:20 -0500
commitb9ef96950db113266b4afdc4fb5a055f8647d00d (patch)
treed5a5fe884fcd65663c48793a81b97f218a9780a4
parent050dab7c326e3871b4781c2b16984f11b3adf2bb (diff)
downloadsdl_ios-b9ef96950db113266b4afdc4fb5a055f8647d00d.tar.gz
Fixing unit tests making them have better names
-rw-r--r--SmartDeviceLink/SDLSecondaryTransportManager.m1
-rw-r--r--SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m97
2 files changed, 51 insertions, 47 deletions
diff --git a/SmartDeviceLink/SDLSecondaryTransportManager.m b/SmartDeviceLink/SDLSecondaryTransportManager.m
index ab179e031..df28ff4cd 100644
--- a/SmartDeviceLink/SDLSecondaryTransportManager.m
+++ b/SmartDeviceLink/SDLSecondaryTransportManager.m
@@ -282,6 +282,7 @@ static const int TCPPortUnspecified = -1;
}
- (void)didEnterStateReconnecting {
+ self.appReady = NO;
__weak typeof(self) weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(RetryConnectionDelay * NSEC_PER_SEC)), _stateMachineQueue, ^{
if ([weakSelf.stateMachine isCurrentState:SDLSecondaryTransportStateReconnecting]) {
diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m
index c70b62b2b..08cb04d15 100644
--- a/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m
+++ b/SmartDeviceLinkTests/ProxySpecs/SDLSecondaryTransportManagerSpec.m
@@ -488,7 +488,6 @@ describe(@"the secondary transport manager ", ^{
});
});
-
describe(@"In Configured state", ^{
describe(@"if secondary transport is iAP", ^{
beforeEach(^{
@@ -504,35 +503,41 @@ describe(@"the secondary transport manager ", ^{
manager.secondaryTransportType = SDLTransportSelectionIAP;
});
- it(@"should transition to Connecting state but before RAIR is sent", ^{
- // setToState cannot be used here, as the method will set the state after calling didEnterStateConfigured
- dispatch_sync(testStateMachineQueue, ^{
- [manager.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
- });
+ context(@"before the security manager is set by register app interface response", ^{
+ it(@"should transition to Connecting", ^{
+ // setToState cannot be used here, as the method will set the state after calling didEnterStateConfigured
+ dispatch_sync(testStateMachineQueue, ^{
+ [manager.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
+ });
- expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
- expect(manager.secondaryProtocol.securityManager).to(beNil());
+ expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
+ expect(manager.secondaryProtocol.securityManager).to(beNil());
+ expect(manager.isAppReady).to(equal(NO));
- OCMVerifyAll(testStreamingProtocolDelegate);
+ OCMVerifyAll(testStreamingProtocolDelegate);
+ });
});
- it(@"should transition to Connecting state after RAIR is sent", ^{
- testPrimaryProtocol.securityManager = OCMClassMock([SDLFakeSecurityManager class]);
+ context(@"after the security manager is set by register app interface response", ^{
+ it(@"should transition to Connecting state", ^{
+ testPrimaryProtocol.securityManager = OCMClassMock([SDLFakeSecurityManager class]);
- dispatch_sync(testStateMachineQueue, ^{
- [manager.stateMachine setToState:SDLSecondaryTransportStateConfigured fromOldState:nil callEnterTransition:NO];
- });
+ dispatch_sync(testStateMachineQueue, ^{
+ [manager.stateMachine setToState:SDLSecondaryTransportStateConfigured fromOldState:nil callEnterTransition:NO];
+ });
- // By the time this notification is recieved the RAIR should have been sent and the security manager should exist if available
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidBecomeReady object:nil];
+ // By the time this notification is recieved the RAIR should have been sent and the security manager should exist if available
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidBecomeReady object:nil];
- expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
- expect(manager.secondaryProtocol.securityManager).to(equal(testPrimaryProtocol.securityManager));
+ expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
+ expect(manager.secondaryProtocol.securityManager).to(equal(testPrimaryProtocol.securityManager));
+ expect(manager.isAppReady).to(equal(YES));
- OCMVerifyAll(testStreamingProtocolDelegate);
+ OCMVerifyAll(testStreamingProtocolDelegate);
+ });
});
-
});
+
describe(@"if secondary transport is TCP", ^{
beforeEach(^{
testPrimaryProtocol = [[SDLProtocol alloc] init];
@@ -546,15 +551,15 @@ describe(@"the secondary transport manager ", ^{
manager.secondaryTransportType = SDLTransportSelectionTCP;
manager.ipAddress = nil;
manager.tcpPort = TCPPortUnspecified;
+
+ dispatch_sync(testStateMachineQueue, ^{
+ [manager.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
+ });
});
describe(@"and Transport Event Update is not received", ^{
it(@"should stay in Configured state", ^{
- dispatch_sync(testStateMachineQueue, ^{
- [manager.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
- });
-
expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConfigured));
OCMVerifyAll(testStreamingProtocolDelegate);
@@ -580,35 +585,32 @@ describe(@"the secondary transport manager ", ^{
testTransportEventUpdateMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testTransportEventUpdateHeader andPayload:testTransportEventUpdatePayload.data];
});
- it(@"should transition to Connecting state but before RAIR is sent", ^{
- dispatch_sync(testStateMachineQueue, ^{
- [manager.stateMachine transitionToState:SDLSecondaryTransportStateConfigured];
- });
+ context(@"before the security manager is set by register app interface response", ^{
+ it(@"should transition to Connecting", ^{
+ [testPrimaryProtocol handleBytesFromTransport:testTransportEventUpdateMessage.data];
+ [NSThread sleepForTimeInterval:0.1];
- [testPrimaryProtocol handleBytesFromTransport:testTransportEventUpdateMessage.data];
- [NSThread sleepForTimeInterval:0.1];
-
- expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
- expect(manager.secondaryProtocol.securityManager).to(beNil());
- OCMVerifyAll(testStreamingProtocolDelegate);
+ expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
+ expect(manager.secondaryProtocol.securityManager).to(beNil());
+ OCMVerifyAll(testStreamingProtocolDelegate);
+ });
});
- it(@"should transition to Connecting state after RAIR is sent", ^{
- testPrimaryProtocol.securityManager = OCMClassMock([SDLFakeSecurityManager class]);
- [testPrimaryProtocol handleBytesFromTransport:testTransportEventUpdateMessage.data];
- [NSThread sleepForTimeInterval:0.1];
+ context(@"after the security manager is set by register app interface response", ^{
+ it(@"should transition to Connecting", ^{
+ testPrimaryProtocol.securityManager = OCMClassMock([SDLFakeSecurityManager class]);
- dispatch_sync(testStateMachineQueue, ^{
- [manager.stateMachine setToState:SDLSecondaryTransportStateConfigured fromOldState:nil callEnterTransition:NO];
- });
+ // By the time this notification is recieved the RAIR should have been sent and the security manager should exist if available
+ [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidBecomeReady object:nil];
- // By the time this notification is recieved the RAIR should have been sent and the security manager should exist if available
- [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidBecomeReady object:nil];
+ [testPrimaryProtocol handleBytesFromTransport:testTransportEventUpdateMessage.data];
+ [NSThread sleepForTimeInterval:0.1];
- expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
- expect(manager.secondaryProtocol.securityManager).to(equal(testPrimaryProtocol.securityManager));
+ expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateConnecting));
+ expect(manager.secondaryProtocol.securityManager).to(equal(testPrimaryProtocol.securityManager));
- OCMVerifyAll(testStreamingProtocolDelegate);
+ OCMVerifyAll(testStreamingProtocolDelegate);
+ });
});
});
});
@@ -735,6 +737,7 @@ describe(@"the secondary transport manager ", ^{
[NSThread sleepForTimeInterval:0.1];
expect(manager.stateMachine.currentState).to(equal(SDLSecondaryTransportStateReconnecting));
+ expect(manager.isAppReady).to(equal(NO));
OCMVerifyAll(testStreamingProtocolDelegate);
});
});
@@ -750,7 +753,6 @@ describe(@"the secondary transport manager ", ^{
manager.secondaryTransportType = SDLTransportSelectionTCP;
manager.ipAddress = @"192.168.1.1";
manager.tcpPort = 12345;
- manager.appReady = YES;
testTransportEventUpdateHeader = [SDLProtocolHeader headerForVersion:5];
testTransportEventUpdateHeader.frameType = SDLFrameTypeControl;
@@ -780,6 +782,7 @@ describe(@"the secondary transport manager ", ^{
beforeEach(^{
testTcpIpAddress = @"172.16.12.34";
testTcpPort = 12345;
+ manager.appReady = YES;
testTransportEventUpdatePayload = [[SDLControlFramePayloadTransportEventUpdate alloc] initWithTcpIpAddress:testTcpIpAddress tcpPort:testTcpPort];
testTransportEventUpdateMessage = [[SDLV2ProtocolMessage alloc] initWithHeader:testTransportEventUpdateHeader andPayload:testTransportEventUpdatePayload.data];