Skip to content

Commit

Permalink
unit test fixes + code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankElias77 committed Jul 11, 2023
1 parent 2ba4dd3 commit 7f54a34
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 298 deletions.
2 changes: 0 additions & 2 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj
Expand Up @@ -1766,7 +1766,6 @@
C9DFFE7F257AD07E00F7D57A /* SDLSeekIndicatorType.m in Sources */ = {isa = PBXBuildFile; fileRef = C9DFFE7D257AD07E00F7D57A /* SDLSeekIndicatorType.m */; };
DA4353DF1D271FD10099B8C4 /* CGPointUtilSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353DE1D271FD10099B8C4 /* CGPointUtilSpec.m */; };
DA4353E31D2720A30099B8C4 /* SDLPinchGestureSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E21D2720A30099B8C4 /* SDLPinchGestureSpec.m */; };
DA4353EA1D2721680099B8C4 /* SDLTouchManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E71D2721680099B8C4 /* SDLTouchManagerSpec.m */; };
DA4353EB1D2721680099B8C4 /* SDLTouchSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4353E81D2721680099B8C4 /* SDLTouchSpec.m */; };
DA96C0661D4D4F730022F520 /* SDLAppInfoSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA96C0651D4D4F730022F520 /* SDLAppInfoSpec.m */; };
DA9F7E9E1DCC05B900ACAE48 /* SDLWaypointTypeSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DA9F7E9D1DCC05B900ACAE48 /* SDLWaypointTypeSpec.m */; };
Expand Down Expand Up @@ -9179,7 +9178,6 @@
5DA150D1227367580032928D /* SDLSoftButtonTransitionOperationSpec.m in Sources */,
162E83441A9BDE8B00906325 /* SDLSystemRequestSpec.m in Sources */,
162E83001A9BDE8B00906325 /* SDLTextFieldNameSpec.m in Sources */,
DA4353EA1D2721680099B8C4 /* SDLTouchManagerSpec.m in Sources */,
1EE8C4611F38865B00FDC2CF /* SDLSetInteriorVehicleDataResponseSpec.m in Sources */,
162E82FC1A9BDE8B00906325 /* SDLSystemAction.m in Sources */,
162E82CC1A9BDE8A00906325 /* SDLAppInterfaceUnregisteredReasonSpec.m in Sources */,
Expand Down
26 changes: 9 additions & 17 deletions SmartDeviceLinkTests/DevAPISpecs/SDLAudioStreamManagerSpec.m
Expand Up @@ -43,10 +43,9 @@
});

it(@"should fail to send data", ^{
[SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
expect(mockAudioManager.dataSinceClear.length).to(equal(0));
expect(mockAudioManager.error.code).to(equal(SDLAudioStreamManagerErrorNotConnected));
}];
});
});
});
});
Expand All @@ -65,10 +64,8 @@

it(@"should fail to send data", ^{
expect(mockAudioManager.dataSinceClear.length).to(equal(0));
// [SDLExpect SDLExpectWithTimeout:1.0 expectBlock:^{
sleep(SDLExpect.timeout);
expect(mockAudioManager.error.code).to(equal(SDLAudioStreamManagerErrorNotConnected));
// }];
expect(mockAudioManager.error.code).to(equal(SDLAudioStreamManagerErrorNotConnected));
});
});
});
Expand All @@ -91,12 +88,11 @@
});

it(@"should be sending data", ^{
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
sleep(SDLExpect.timeout);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
expect(testManager.isPlaying).to(beTrue());
expect(mockAudioManager.dataSinceClear.length).to(equal(34380));
expect(mockAudioManager.finishedPlaying).to(beTrue());
// }];
});
});
});

Expand All @@ -118,10 +114,8 @@
});

it(@"should have a file in the queue", ^{
// [SDLExpect SDLExpectWithTimeout:3.0 expectBlock:^{
sleep(SDLExpect.timeout);
expect(testManager.queue).toNot(beEmpty());
// }];
expect(testManager.queue).toNot(beEmpty());
});

describe(@"after attempting to play the audio buffer", ^{
Expand All @@ -131,15 +125,13 @@
});

it(@"should be sending data", ^{
// [SDLExpect SDLExpectWithTimeout:3.0 expectBlock:^{
// sleep(SDLExpect.timeout);
[NSThread sleepForTimeInterval:1.5];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
expect(testManager.isPlaying).to(beTrue());
expect(mockAudioManager.dataSinceClear.length).to(equal(14838));

// Fails when it shouldn't, `weakself` goes to nil in `sdl_playNextWhenReady`
// Fails when it shouldn't, `weakself` goes to nil in `sdl_playNextWhenReady`
expect(mockAudioManager.finishedPlaying).to(beTrue());
// }];
});
});
});

Expand Down
20 changes: 6 additions & 14 deletions SmartDeviceLinkTests/DevAPISpecs/SDLLifecycleManagerSpec.m
Expand Up @@ -281,10 +281,8 @@ + (void)configure:(QCKConfiguration *)configuration {
// When we connect, we should be creating an sending an RAI

[testManager.notificationDispatcher postNotificationName:SDLRPCServiceDidConnect infoObject:nil];
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
[NSThread sleepForTimeInterval:SDLExpect.timeout];
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateConnected));
// }];
});
itBehavesLike(@"unable to send an RPC", ^{ return @{ @"manager": testManager }; });

Expand Down Expand Up @@ -379,10 +377,8 @@ + (void)configure:(QCKConfiguration *)configuration {
testManager.hmiLevel = SDLHMILevelFull;
transitionToState(SDLLifecycleStateRegistered);

// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
[NSThread sleepForTimeInterval:SDLExpect.timeout];
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateReady));
// }];
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateReady));
OCMVerify([(SDLLockScreenManager *)lockScreenManagerMock start]);
OCMVerify([(SDLSystemCapabilityManager *)systemCapabilityMock start]);
OCMVerify([fileManagerMock startWithCompletionHandler:[OCMArg any]]);
Expand Down Expand Up @@ -537,10 +533,8 @@ + (void)configure:(QCKConfiguration *)configuration {
});

it(@"should enter the started state", ^{
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
[NSThread sleepForTimeInterval:SDLExpect.timeout];
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateStarted));
// }];
expect(testManager.lifecycleState).to(equal(SDLLifecycleStateStarted));
});
});

Expand Down Expand Up @@ -705,13 +699,11 @@ + (void)configure:(QCKConfiguration *)configuration {
returnError = error;
}];

// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
[NSThread sleepForTimeInterval:SDLExpect.timeout + 3];
expect(returnRequest).toNot(beNil());
expect(returnRequest).to(beAnInstanceOf([SDLShow class]));
expect(returnResponse).to(beNil());
expect(returnError).toNot(beNil());
// }];
expect(returnRequest).toNot(beNil());
expect(returnRequest).to(beAnInstanceOf([SDLShow class]));
expect(returnResponse).to(beNil());
expect(returnError).toNot(beNil());
});

it(@"can send an RPC of type Response", ^{
Expand Down
Expand Up @@ -1021,11 +1021,9 @@ @interface SDLChoiceCell()
});

it(@"should finish", ^{
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
expect(testOp.isExecuting).to(beFalse());
expect(testOp.isFinished).to(beTrue());
expect(testOp.isCancelled).to(beTrue());
// }];
expect(testOp.isExecuting).to(beFalse());
expect(testOp.isFinished).to(beTrue());
expect(testOp.isCancelled).to(beTrue());
});
});
});
Expand Down
17 changes: 12 additions & 5 deletions SmartDeviceLinkTests/DevAPISpecs/SDLRTPH264PacketizerSpec.m
Expand Up @@ -80,21 +80,28 @@ static inline UInt32 sdl_readLongInNetworkByteOrder(const UInt8 *buffer) {
beforeEach(^{
NSArray<NSData *> *nalUnits = @[iframe];
NSArray<NSData *> *results = [packetizer createPackets:nalUnits presentationTimestamp:0.0];
[NSThread sleepForTimeInterval:1.5];
header = results[0].bytes;
});

it(@"indicates version 2", ^{
expect(@((header[FrameLengthLen] >> 6) & 3)).to(equal(@2));
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
expect(@((header[FrameLengthLen] >> 6) & 3)).to(equal(@2));
});
});
it(@"indicates no padding", ^{
expect(@((header[FrameLengthLen] >> 5) & 1)).to(equal(@0));
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
expect(@((header[FrameLengthLen] >> 5) & 1)).to(equal(@0));
});
});
it(@"indicates no extension", ^{
expect(@((header[FrameLengthLen] >> 4) & 1)).to(equal(@0));
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
expect(@((header[FrameLengthLen] >> 4) & 1)).to(equal(@0));
});
});
it(@"indicates no CSRC", ^{
expect(@(header[FrameLengthLen] & 0xF)).to(equal(@0));
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
expect(@(header[FrameLengthLen] & 0xF)).to(equal(@0));
});
});
});

Expand Down
Expand Up @@ -222,7 +222,7 @@ - (void)sdl_displayCapabilityDidUpdate;
expect(testObject2.manager).to(equal(testManager));

// One replace operation
expect(testManager.transactionQueue.operationCount).toEventually(equal(1));
expect(testManager.transactionQueue.operationCount).to(equal(1));
});

// should replace earlier operations when a replace operation is entered
Expand Down
Expand Up @@ -48,6 +48,7 @@
#import "TestConnectionManager.h"
#import "TestSmartConnectionManager.h"
#import "TestStreamingMediaDelegate.h"
#import "SDLExpect.h"

// expose private methods to the test suite
@interface SDLStreamingVideoLifecycleManager (test)
Expand Down Expand Up @@ -299,35 +300,46 @@ - (instancetype)shortCopy;
});

context(@"init extended manager", ^{
id<SDLConnectionManagerType> mockConnectionManager = OCMProtocolMock(@protocol(SDLConnectionManagerType));
SDLConfiguration *configuration = [[SDLConfiguration alloc] init];
SDLStreamingVideoLifecycleTestManager *streamingLifecycleManager = [[SDLStreamingVideoLifecycleTestManager alloc] initWithConnectionManager:mockConnectionManager configuration:configuration systemCapabilityManager:nil];
// __block id<SDLConnectionManagerType> mockConnectionManager;
// __block SDLStreamingVideoLifecycleTestManager *streamingLifecycleManager;

// beforeEach(^{
// mockConnectionManager = OCMProtocolMock(@protocol(SDLConnectionManagerType));
// SDLConfiguration *configuration = [[SDLConfiguration alloc] init];
// streamingLifecycleManager = [[SDLStreamingVideoLifecycleTestManager alloc] initWithConnectionManager:mockConnectionManager configuration:configuration systemCapabilityManager:nil];
// });

context(@"test didEnterStateVideoStreamReady", ^{
it(@"expect displayLink update properly", ^{
id<SDLConnectionManagerType> mockConnectionManager = OCMProtocolMock(@protocol(SDLConnectionManagerType));
SDLConfiguration *configuration = [[SDLConfiguration alloc] init];
SDLStreamingVideoLifecycleTestManager *streamingLifecycleManager = [[SDLStreamingVideoLifecycleTestManager alloc] initWithConnectionManager:mockConnectionManager configuration:configuration systemCapabilityManager:nil];
[streamingLifecycleManager useDisplayLink];

expect(streamingLifecycleManager.displayLink).to(beNil());
[streamingLifecycleManager didEnterStateVideoStreamReady];

[NSThread sleepForTimeInterval:1.5];

// [NSThread sleepForTimeInterval:1.5];
expect([streamingLifecycleManager.displayLink isKindOfClass:[CADisplayLink class]]).to(beTrue());
});
});

context(@"test didEnterStateVideoStreamSuspended", ^{
SDLVideoStreamingCapability *videoStreamingCapabilityUpdated = OCMClassMock([SDLVideoStreamingCapability class]);
streamingLifecycleManager.videoStreamingCapabilityUpdated = videoStreamingCapabilityUpdated;
it(@"expect properties to update properly", ^{
id<SDLConnectionManagerType> mockConnectionManager = OCMProtocolMock(@protocol(SDLConnectionManagerType));
SDLConfiguration *configuration = [[SDLConfiguration alloc] init];
SDLStreamingVideoLifecycleTestManager *streamingLifecycleManager = [[SDLStreamingVideoLifecycleTestManager alloc] initWithConnectionManager:mockConnectionManager configuration:configuration systemCapabilityManager:nil];

SDLVideoStreamingCapability *videoStreamingCapabilityUpdated = OCMClassMock([SDLVideoStreamingCapability class]);
streamingLifecycleManager.videoStreamingCapabilityUpdated = videoStreamingCapabilityUpdated;

streamingLifecycleManager.shouldAutoResume = YES;

expect(streamingLifecycleManager.shouldAutoResume).to(equal(YES));
expect(streamingLifecycleManager.videoStreamingCapabilityUpdated).notTo(beNil());
expect(streamingLifecycleManager.videoStreamingCapabilityUpdated).toNot(beNil());
expect(streamingLifecycleManager.videoStreamingCapabilityUpdated).to(equal(videoStreamingCapabilityUpdated));

[streamingLifecycleManager didEnterStateVideoStreamSuspended];

[NSThread sleepForTimeInterval:1.5];

expect(streamingLifecycleManager.shouldAutoResume).to(equal(NO));
expect(streamingLifecycleManager.videoStreamingCapability).to(equal(videoStreamingCapabilityUpdated));
expect(streamingLifecycleManager.shouldAutoResume).to(equal(NO));
Expand Down
27 changes: 10 additions & 17 deletions SmartDeviceLinkTests/DevAPISpecs/SDLUploadFileOperationSpec.m
Expand Up @@ -365,15 +365,13 @@ + (NSUInteger)testMaxBulkDataSizeForFile:(SDLFile *)file mtuSize:(NSUInteger)mtu
[testConnectionManager respondToRequestWithResponse:successResponse requestNumber:i error:nil];
}

// [SDLExpect SDLExpectWithTimeout:(SDLExpect.timeout + 3) expectBlock:^{
[NSThread sleepForTimeInterval:1.0];
expect(successResult).to(beTrue());
expect(bytesAvailableResult).to(equal(spaceLeft));
expect(errorResult).to(beNil());
expect(successResult).to(beTrue());
expect(bytesAvailableResult).to(equal(spaceLeft));
expect(errorResult).to(beNil());

expect(testOperation.finished).to(beTrue());
expect(testOperation.executing).to(beFalse());
// }];
expect(testOperation.finished).to(beTrue());
expect(testOperation.executing).to(beFalse());
});
});

Expand Down Expand Up @@ -440,12 +438,10 @@ + (NSUInteger)testMaxBulkDataSizeForFile:(SDLFile *)file mtuSize:(NSUInteger)mtu
[testConnectionManager respondToRequestWithResponse:response requestNumber:i error:error];
}

// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
sleep(SDLExpect.timeout + 3);
expect(errorResult.localizedDescription).to(match(responseErrorDescription));
expect(errorResult.localizedFailureReason).to(match(responseErrorReason));
expect(successResult).to(beFalse());
// }];
expect(errorResult.localizedDescription).to(match(responseErrorDescription));
expect(errorResult.localizedFailureReason).to(match(responseErrorReason));
expect(successResult).to(beFalse());
});
});

Expand All @@ -461,13 +457,10 @@ + (NSUInteger)testMaxBulkDataSizeForFile:(SDLFile *)file mtuSize:(NSUInteger)mtu

[testConnectionManager respondToRequestWithResponse:response requestNumber:i error:[NSError sdl_lifecycle_unknownRemoteErrorWithDescription:responseErrorDescription andReason:responseErrorReason]];
}
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{

[NSThread sleepForTimeInterval:1.0];
expect(errorResult.localizedDescription).to(match(responseErrorDescription));
expect(errorResult.localizedFailureReason).to(match(responseErrorReason));
expect(successResult).to(beFalse());
// }];
expect(errorResult.localizedFailureReason).to(match(responseErrorReason));
expect(successResult).to(beFalse());
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions SmartDeviceLinkTests/DevAPISpecs/SDLVoiceCommandManagerSpec.m
Expand Up @@ -167,10 +167,10 @@ + (BOOL)sdl_arePendingVoiceCommandsUnique:(NSArray<SDLVoiceCommand *> *)voiceCom
});

it(@"should update the second operation", ^{
[NSThread sleepForTimeInterval:1.0];
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
[NSThread sleepForTimeInterval:3.0];
[SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
expect(((SDLVoiceCommandUpdateOperation *)testManager.transactionQueue.operations.firstObject).oldVoiceCommands.firstObject).to(equal(testVoiceCommand2));
// }];
}];
});
});
});
Expand Down
Expand Up @@ -112,13 +112,10 @@
});

it(@"should run the handler", ^{
// [NSThread sleepForTimeInterval:SDLExpect.timeout];
// [SDLExpect SDLExpectWithTimeout:SDLExpect.timeout expectBlock:^{
sleep(SDLExpect.timeout);
expect(@(handlerCalled)).to(beTrue());
expect(testDispatcher.rpcRequestDictionary).to(haveCount(@0));
expect(testDispatcher.rpcResponseHandlerMap).to(haveCount(@0));
// }];
expect(@(handlerCalled)).to(beTrue());
expect(testDispatcher.rpcRequestDictionary).to(haveCount(@0));
expect(testDispatcher.rpcResponseHandlerMap).to(haveCount(@0));
});
});
});
Expand Down
Expand Up @@ -387,9 +387,9 @@
[SDLGlobals sharedGlobals].maxHeadUnitProtocolVersion = [SDLVersion versionWithMajor:5 minor:0 patch:0];
BOOL sent = [testProtocol sendRPC:deleteRequest error:&error];

// expect(numTimesCalled).to(equal(3));
// expect(sent).to(beTrue());
// expect(error).to(beNil());
expect(numTimesCalled).to(equal(3));
expect(sent).to(beTrue());
expect(error).to(beNil());
});
});
});
Expand Down

0 comments on commit 7f54a34

Please sign in to comment.