-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10838dd
commit f874035
Showing
65 changed files
with
1,320 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#import "UnityAdsDelegate.h" | ||
|
||
@interface UnityAdsDelegateMock: NSObject <UnityAdsDelegate> | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "UnityAdsDelegateMock.h" | ||
|
||
@implementation UnityAdsDelegateMock | ||
|
||
// UnityAdsDelegate Methods | ||
- (void)unityAdsReady:(NSString *)placementId { | ||
|
||
} | ||
|
||
- (void)unityAdsDidError:(UnityAdsError)error withMessage:(NSString *)message { | ||
|
||
} | ||
|
||
- (void)unityAdsDidStart:(NSString *)placementId { | ||
|
||
} | ||
|
||
- (void)unityAdsDidFinish:(NSString *)placementId | ||
withFinishState:(UnityAdsFinishState)state { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "UADSProperties.h" | ||
#import "UnityAdsDelegateMock.h" | ||
|
||
@interface UADSPropertiesTests: XCTestCase | ||
@end | ||
|
||
@implementation UADSPropertiesTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
// reset UADSProperties object | ||
for (id<UnityAdsDelegate> delegate in [UADSProperties getDelegates]) { | ||
[UADSProperties removeDelegate:delegate]; | ||
} | ||
[UADSProperties setShowTimeout:UADSPROPERTIES_DEFAULT_SHOW_TIMEOUT]; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
// reset UADSProperties object | ||
for (id<UnityAdsDelegate> delegate in [UADSProperties getDelegates]) { | ||
[UADSProperties removeDelegate:delegate]; | ||
} | ||
[UADSProperties setShowTimeout:UADSPROPERTIES_DEFAULT_SHOW_TIMEOUT]; | ||
} | ||
|
||
- (void)testAddDelegate { | ||
UnityAdsDelegateMock *delegate = [[UnityAdsDelegateMock alloc] init]; | ||
XCTAssertEqual(0, [[UADSProperties getDelegates] count]); | ||
[UADSProperties addDelegate:delegate]; | ||
XCTAssertEqual(1, [[UADSProperties getDelegates] count]); | ||
XCTAssertEqual(delegate, [[UADSProperties getDelegates] firstObject]); | ||
[UADSProperties removeDelegate:delegate]; | ||
XCTAssertEqual(0, [[UADSProperties getDelegates] count]); | ||
} | ||
|
||
- (void)testAddMultipleDelegates { | ||
UnityAdsDelegateMock *delegate1 = [[UnityAdsDelegateMock alloc] init]; | ||
UnityAdsDelegateMock *delegate2 = [[UnityAdsDelegateMock alloc] init]; | ||
XCTAssertEqual(0, [[UADSProperties getDelegates] count]); | ||
[UADSProperties addDelegate:delegate1]; | ||
[UADSProperties addDelegate:delegate2]; | ||
XCTAssertEqual(2, [[UADSProperties getDelegates] count]); | ||
XCTAssertTrue([[UADSProperties getDelegates] containsObject:delegate1]); | ||
XCTAssertTrue([[UADSProperties getDelegates] containsObject:delegate2]); | ||
[UADSProperties removeDelegate:delegate1]; | ||
[UADSProperties removeDelegate:delegate2]; | ||
XCTAssertEqual(0, [[UADSProperties getDelegates] count]); | ||
} | ||
|
||
- (void)testSetShowTimeout { | ||
XCTAssertEqual(UADSPROPERTIES_DEFAULT_SHOW_TIMEOUT, [UADSProperties getShowTimeout]); | ||
[UADSProperties setShowTimeout:100]; | ||
XCTAssertEqual(100, [UADSProperties getShowTimeout]); | ||
[UADSProperties setShowTimeout:UADSPROPERTIES_DEFAULT_SHOW_TIMEOUT]; | ||
XCTAssertEqual(UADSPROPERTIES_DEFAULT_SHOW_TIMEOUT, [UADSProperties getShowTimeout]); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "UnityAds.h" | ||
#import "UADSProperties.h" | ||
#import "UnityAdsDelegateMock.h" | ||
|
||
@interface UnityServices (Mock) | ||
@end | ||
|
||
@implementation UnityServices (Mock) | ||
|
||
+(void)initialize:(NSString *)gameId | ||
delegate:(nullable id <UnityServicesDelegate>)delegate | ||
testMode:(BOOL)testMode { | ||
// do nothing | ||
} | ||
|
||
@end | ||
|
||
@interface UnityAdsTests : XCTestCase | ||
@end | ||
|
||
@implementation UnityAdsTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
// reset UADSProperties object | ||
for (id<UnityAdsDelegate> delegate in [UADSProperties getDelegates]) { | ||
[UADSProperties removeDelegate:delegate]; | ||
} | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
// reset UADSProperties object | ||
for (id<UnityAdsDelegate> delegate in [UADSProperties getDelegates]) { | ||
[UADSProperties removeDelegate:delegate]; | ||
} | ||
} | ||
|
||
|
||
-(void)testInitializeMultipleTimes { | ||
UnityAdsDelegateMock *firstDelegate = [[UnityAdsDelegateMock alloc] init]; | ||
[UnityAds initialize:@"mediator1" delegate:firstDelegate]; | ||
XCTAssertEqual([UnityAds getDelegate], firstDelegate); | ||
UnityAdsDelegateMock *secondDelegate = [[UnityAdsDelegateMock alloc] init]; | ||
[UnityAds initialize:@"mediator2" delegate:secondDelegate]; | ||
XCTAssertEqual([UnityAds getDelegate], firstDelegate); | ||
XCTAssertEqual([[UADSProperties getDelegates] count], 2); | ||
XCTAssertTrue([[UADSProperties getDelegates] containsObject:firstDelegate]); | ||
XCTAssertTrue([[UADSProperties getDelegates] containsObject:secondDelegate]); | ||
} | ||
|
||
-(void)testInitializeThenRemove { | ||
UnityAdsDelegateMock *firstDelegate = [[UnityAdsDelegateMock alloc] init]; | ||
[UnityAds initialize:@"mediator1" delegate:firstDelegate]; | ||
XCTAssertEqual([UnityAds getDelegate], firstDelegate); | ||
[UnityAds removeDelegate:firstDelegate]; | ||
XCTAssertNil([UnityAds getDelegate]); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
UnityAdsTests/Core/Auth/USRVASWebAuthenticationSessionManagerTest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "USRVASWebAuthenticationSessionManager.h" | ||
|
||
@interface USRVASWebAuthenticationSessionManagerTest: XCTestCase | ||
|
||
@property (nonatomic, strong) USRVASWebAuthenticationSessionManager *sessionManager; | ||
@end | ||
|
||
@implementation USRVASWebAuthenticationSessionManagerTest | ||
|
||
-(void)setUp { | ||
self.sessionManager = [[USRVASWebAuthenticationSessionManager alloc] init]; | ||
} | ||
|
||
- (void)testCreateSession { | ||
NSURL *url = [[NSURL alloc] initWithString:@"https://google.com"]; | ||
USRVASWebAuthenticationSession *session = [self.sessionManager createSession:url callbackUrlScheme:@"google.com"]; | ||
XCTAssertNotNil(session); | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testCreateSessionExpectation"]; | ||
[self.sessionManager getSessions:^(NSDictionary *sessions){ | ||
XCTAssertEqual([sessions allValues].count, 1); | ||
XCTAssertEqual([sessions objectForKey:[session getSessionId]], session); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError * _Nullable error) {}]; | ||
|
||
session = [self.sessionManager createSession:url callbackUrlScheme:@"google.com"]; | ||
XCTAssertNotNil(session); | ||
expectation = [self expectationWithDescription:@"testCreateSessionExpectation2"]; | ||
[self.sessionManager getSessions:^(NSDictionary *sessions){ | ||
XCTAssertEqual([sessions allValues].count, 2); | ||
XCTAssertEqual([sessions objectForKey:[session getSessionId]], session); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError * _Nullable error) {}]; | ||
} | ||
|
||
- (void)testRemoveSession { | ||
NSURL *url = [[NSURL alloc] initWithString:@"https://google.com"]; | ||
USRVASWebAuthenticationSession *session = [self.sessionManager createSession:url callbackUrlScheme:@"google.com"]; | ||
XCTAssertNotNil(session); | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testCreateSessionExpectation"]; | ||
[self.sessionManager getSessions:^(NSDictionary *sessions){ | ||
XCTAssertEqual([sessions allValues].count, 1); | ||
XCTAssertEqual([sessions objectForKey:[session getSessionId]], session); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError * _Nullable error) {}]; | ||
|
||
[self.sessionManager removeSession:[session getSessionId]]; | ||
expectation = [self expectationWithDescription:@"testCreateSessionExpectation"]; | ||
[self.sessionManager getSessions:^(NSDictionary *sessions){ | ||
XCTAssertEqual([sessions allValues].count, 0); | ||
XCTAssertNil([sessions objectForKey:[session getSessionId]]); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError * _Nullable error) {}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "USRVJsonUtilities.h" | ||
|
||
@interface USRVJsonUtilities (Mock) | ||
+(void)setMockException:(NSException *)mockException; | ||
@end | ||
|
||
@implementation USRVJsonUtilities (Mock) | ||
|
||
static NSException *_mockException; | ||
|
||
+(NSData *)_dataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError *_Nullable *)error { | ||
if (_mockException) { | ||
@throw _mockException; | ||
} else { | ||
return [NSJSONSerialization dataWithJSONObject:obj options:opt error:error]; | ||
} | ||
} | ||
|
||
+(void)setMockException:(NSException *)mockException { | ||
_mockException = mockException; | ||
} | ||
|
||
@end | ||
|
||
@interface USRVJsonUtilitiesTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation USRVJsonUtilitiesTests | ||
|
||
-(void)setUp { | ||
[super setUp]; | ||
[USRVJsonUtilities setMockException:nil]; | ||
} | ||
|
||
-(void)testNilError { | ||
// should not throw | ||
[USRVJsonUtilities dataWithJSONObject:@1 options:0 error:nil]; | ||
} | ||
|
||
-(void)testInvalidJsonError { | ||
NSError *error; | ||
[USRVJsonUtilities dataWithJSONObject:@1 options:0 error:&error]; | ||
XCTAssertNotNil(error); | ||
NSString *localizedDescription = [error localizedDescription]; | ||
XCTAssertTrue([localizedDescription isEqualToString:@"USRVJsonUtilities.dataWithJSONObject was not able to convert invalid json object to json : 1"]); | ||
} | ||
|
||
-(void)testException { | ||
[USRVJsonUtilities setMockException:[[NSException alloc] initWithName:NSMallocException reason:@"Out of memory in test" userInfo:nil]]; | ||
NSError *error; | ||
NSData *data = [USRVJsonUtilities dataWithJSONObject:@{ | ||
@"key": @"value" | ||
} options:0 error:&error]; | ||
XCTAssertNil(data); | ||
XCTAssertNotNil(error); | ||
XCTAssertTrue([@"USRVJsonUtilities.dataWithJSONObject an exception occurred during dataWithJSONObject : NSMallocException : Out of memory in test" isEqualToString:[error localizedDescription]]); | ||
} | ||
|
||
-(void)testValidTranslation { | ||
NSError *error; | ||
NSData *data = [USRVJsonUtilities dataWithJSONObject:@{ | ||
@"key": @"value" | ||
} options:0 error:&error]; | ||
XCTAssertNotNil(data); | ||
XCTAssertNil(error); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.