parent
1561df8b63
commit
171ae93690
@ -1,39 +0,0 @@
|
||||
//
|
||||
// PEPPEPSessionProviderTest.m
|
||||
// pEpObjCAdapterTests
|
||||
//
|
||||
// Created by Andreas Buff on 17.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
@interface PEPPEPSessionProviderTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation PEPPEPSessionProviderTest
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testExample {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
}
|
||||
|
||||
- (void)testPerformanceExample {
|
||||
// This is an example of a performance test case.
|
||||
[self measureBlock:^{
|
||||
// Put the code you want to measure the time of here.
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,101 @@
|
||||
//
|
||||
// PEPSessionProviderTest.m
|
||||
// pEpObjCAdapterTests
|
||||
//
|
||||
// Created by Andreas Buff on 17.01.18.
|
||||
// Copyright © 2018 p≡p. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "PEPSession.h"
|
||||
#import "PEPInternalSession.h"
|
||||
#import "PEPSessionProvider.h"
|
||||
|
||||
@interface PEPSessionProviderTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation PEPSessionProviderTest
|
||||
|
||||
- (void)testSeperatedSessionPerThread {
|
||||
// Get main session
|
||||
PEPInternalSession *sessionMain = [PEPSessionProvider session];
|
||||
__block PEPInternalSession *sessionBackground = nil;
|
||||
XCTestExpectation *exp = [self expectationWithDescription:@"background session created"];
|
||||
|
||||
// Get background session
|
||||
dispatch_queue_t backgroundQueue = dispatch_queue_create("PEPSessionProviderTest.peptest1", 0);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
sessionBackground = [PEPSessionProvider session];
|
||||
[exp fulfill];
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:^(NSError * _Nullable error) {
|
||||
if (error) { XCTFail(@"timeout: %@", error); }
|
||||
}];
|
||||
XCTAssertNotNil(sessionMain);
|
||||
XCTAssertNotNil(sessionBackground);
|
||||
|
||||
// Make sure we have seperated sessions
|
||||
XCTAssertNotEqual(sessionBackground, sessionMain,
|
||||
@"We should have seperated sessions, one per thread");
|
||||
}
|
||||
|
||||
- (void)testMainSessionDoesNotChange {
|
||||
// Get main session
|
||||
PEPInternalSession *sessionMain = [PEPSessionProvider session];
|
||||
__block PEPInternalSession *sessionBackground = nil;
|
||||
XCTestExpectation *exp = [self expectationWithDescription:@"background session created"];
|
||||
|
||||
// Get background session
|
||||
dispatch_queue_t backgroundQueue = dispatch_queue_create("PEPSessionProviderTest.peptest1", 0);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
sessionBackground = [PEPSessionProvider session];
|
||||
[exp fulfill];
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:^(NSError * _Nullable error) {
|
||||
if (error) { XCTFail(@"timeout: %@", error); }
|
||||
}];
|
||||
// Get main session again
|
||||
PEPInternalSession *sessionMain2 = [PEPSessionProvider session];
|
||||
XCTAssertNotNil(sessionMain);
|
||||
XCTAssertNotNil(sessionMain2);
|
||||
XCTAssertNotNil(sessionBackground);
|
||||
XCTAssertEqual(sessionMain, sessionMain2, @"The main session stayed the same (was kept \
|
||||
alive, was not recreated)");
|
||||
}
|
||||
|
||||
- (void)testNewMainSessionAfterCleanup {
|
||||
// Get main session
|
||||
PEPInternalSession *sessionMain = [PEPSessionProvider session];
|
||||
__block PEPInternalSession *sessionBackground = nil;
|
||||
XCTestExpectation *exp = [self expectationWithDescription:@"background session created"];
|
||||
|
||||
// Get background session
|
||||
dispatch_queue_t backgroundQueue = dispatch_queue_create("PEPSessionProviderTest.peptest1", 0);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
sessionBackground = [PEPSessionProvider session];
|
||||
[exp fulfill];
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:1.0 handler:^(NSError * _Nullable error) {
|
||||
if (error) { XCTFail(@"timeout: %@", error); }
|
||||
}];
|
||||
// Get main session again
|
||||
PEPInternalSession *sessionMain2 = [PEPSessionProvider session];
|
||||
XCTAssertNotNil(sessionMain);
|
||||
XCTAssertNotNil(sessionMain2);
|
||||
XCTAssertNotNil(sessionBackground);
|
||||
XCTAssertEqual(sessionMain, sessionMain2, @"The main session stayed the same (was kept \
|
||||
alive, was not recreated)");
|
||||
[PEPSession cleanup];
|
||||
PEPInternalSession *sessionMainAfterCleanup = [PEPSessionProvider session];
|
||||
XCTAssertNotNil(sessionMainAfterCleanup);
|
||||
XCTAssertNotEqual(sessionMainAfterCleanup, sessionMain,
|
||||
@"We got a new main session after cleanup");
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in new issue