-
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
f874035
commit 39e78b2
Showing
36 changed files
with
956 additions
and
113 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,14 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'UnityAds' | ||
s.version = '3.1.0' | ||
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' } | ||
s.author = { 'UnityAds' => '[email protected]' } | ||
s.homepage = 'https://unity3d.com/services/ads' | ||
s.summary = 'Monetize your entire player base and reach new audiences with video ads.' | ||
s.platform = :ios | ||
s.source = { :http => 'https://github.com/Unity-Technologies/unity-ads-ios/releases/download/3.1.0/UnityAds.framework.zip' } | ||
s.ios.deployment_target = '7.0' | ||
s.ios.vendored_frameworks = 'UnityAds.framework' | ||
s.ios.xcconfig = { 'OTHER_LDFLAGS' => '-framework UnityAds' } | ||
|
||
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,58 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "UnityAdsTests-Bridging-Header.h" | ||
#import "UADSLoadBridge.h" | ||
|
||
@interface MockWebViewAppForLoadBridgeTests : USRVWebViewApp | ||
@property(nonatomic, copy) void (^loadPlacementsCallback)(NSString *eventId, NSString *category, NSArray *params); | ||
@end | ||
|
||
@implementation MockWebViewAppForLoadBridgeTests | ||
|
||
-(BOOL)sendEvent:(NSString *)eventId category:(NSString *)category params:(NSArray *)params { | ||
if (eventId && [eventId isEqualToString:@"LOAD_PLACEMENTS"] && category && [category isEqualToString:@"LOAD_API"]) { | ||
_loadPlacementsCallback(eventId, category, params); | ||
} | ||
return true; | ||
} | ||
|
||
-(BOOL)invokeCallback:(USRVInvocation *)invocation { | ||
return true; | ||
} | ||
|
||
@end | ||
|
||
|
||
@interface UADSLoadBridgeTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation UADSLoadBridgeTests | ||
|
||
UADSLoadBridge *loadBridge = nil; | ||
|
||
-(void)setUp { | ||
MockWebViewAppForLoadBridgeTests *webApp = [[MockWebViewAppForLoadBridgeTests alloc] init]; | ||
[USRVWebViewApp setCurrentApp:webApp]; | ||
|
||
loadBridge = [[UADSLoadBridge alloc] init]; | ||
} | ||
|
||
-(void)tearDown { | ||
[USRVWebViewApp setCurrentApp:nil]; | ||
} | ||
|
||
-(void)testSendLoadEvent { | ||
XCTestExpectation *expectation2 = [self expectationWithDescription:@"presentAppSheetEventExpectation"]; | ||
MockWebViewAppForLoadBridgeTests *mockApp = (MockWebViewAppForLoadBridgeTests *) [USRVWebViewApp getCurrentApp]; | ||
mockApp.loadPlacementsCallback = ^(NSString *eventId, NSString *category, NSArray *params){ | ||
if (params.count == 1 && [params[0] isEqual:@{@"video1":@1, @"video2":@1}]) { | ||
[expectation2 fulfill]; | ||
} | ||
}; | ||
|
||
[loadBridge loadPlacements:@{@"video1":@1, @"video2":@1}]; | ||
|
||
[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,94 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "UADSLoadModule.h" | ||
#import "USRVSdkProperties.h" | ||
#import "UADSLoadBridge.h" | ||
#import "USRVInitializationNotificationCenter.h" | ||
|
||
@interface UADSLoadBridgeMock : NSObject <UADSLoadBridgeProtocol> | ||
@property(nonatomic, strong) NSMutableArray<NSDictionary *> *loadPlacementCallLog; | ||
@property(nonatomic, copy) void (^loadPlacementsBlock)(NSDictionary<NSString *, NSNumber *> *); | ||
|
||
-(void)loadPlacements:(NSDictionary<NSString *, NSNumber *> *)placements; | ||
@end | ||
|
||
@implementation UADSLoadBridgeMock | ||
|
||
-(instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
self.loadPlacementCallLog = [[NSMutableArray alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
-(void)loadPlacements:(NSDictionary<NSString *, NSNumber *> *)placements { | ||
[self.loadPlacementCallLog addObject:placements]; | ||
if (_loadPlacementsBlock) { | ||
_loadPlacementsBlock(placements); | ||
} | ||
} | ||
|
||
@end | ||
|
||
@interface UADSLoadModule (Test) | ||
|
||
-(instancetype)initWithBridge:(NSObject <UADSLoadBridgeProtocol> *)bridge initializationNotificationCenter:(NSObject <USRVInitializationNotificationCenterProtocol> *)initializeNotificationCenter; | ||
|
||
@end | ||
|
||
@interface UADSLoadModuleTests : XCTestCase | ||
|
||
@property(nonatomic, strong) UADSLoadBridgeMock *loadBridgeTest; | ||
@property(nonatomic, strong) USRVInitializationNotificationCenter *initializationNotificationCenterTest; | ||
@property(nonatomic, strong) UADSLoadModule *loadModule; | ||
|
||
@end | ||
|
||
@implementation UADSLoadModuleTests | ||
|
||
-(void)setUp { | ||
[super setUp]; | ||
self.loadBridgeTest = [[UADSLoadBridgeMock alloc] init]; | ||
self.initializationNotificationCenterTest = [[USRVInitializationNotificationCenter alloc] init]; | ||
self.loadModule = [[UADSLoadModule alloc] initWithBridge:self.loadBridgeTest initializationNotificationCenter:self.initializationNotificationCenterTest]; | ||
} | ||
|
||
-(void)testLoadAfterInitialized { | ||
[USRVSdkProperties setInitialized:YES]; | ||
[self.loadModule load:@"test"]; | ||
XCTAssertEqual(1, self.loadBridgeTest.loadPlacementCallLog.count); | ||
XCTAssertEqualObjects(@{@"test": @1}, self.loadBridgeTest.loadPlacementCallLog.firstObject); | ||
} | ||
|
||
-(void)testLoadWithNilPlacement { | ||
[USRVSdkProperties setInitialized:YES]; | ||
[self.loadModule load:nil]; | ||
// call log should be empty | ||
XCTAssertEqual(0, self.loadBridgeTest.loadPlacementCallLog.count); | ||
} | ||
|
||
-(void)testLoadBeforeInitialized { | ||
[USRVSdkProperties setInitialized:NO]; | ||
[self.loadModule load:@"test"]; | ||
[self.loadModule load:@"test2"]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testLoadBeforeInitialized"]; | ||
self.loadBridgeTest.loadPlacementsBlock = ^(NSDictionary *placements) { | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenterTest triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
XCTAssertEqual(1, self.loadBridgeTest.loadPlacementCallLog.count); | ||
NSDictionary *expected = @{@"test":@1, @"test2":@1}; | ||
XCTAssertEqualObjects(expected, self.loadBridgeTest.loadPlacementCallLog.firstObject); | ||
[USRVSdkProperties setInitialized:YES]; | ||
XCTestExpectation *expectation2 = [self expectationWithDescription:@"testLoadBeforeInitialized2"]; | ||
self.loadBridgeTest.loadPlacementsBlock = ^(NSDictionary<NSString *, NSNumber *> *placements) { | ||
[expectation2 fulfill]; | ||
}; | ||
[self.loadModule load:@"test3"]; | ||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
XCTAssertEqual(2, self.loadBridgeTest.loadPlacementCallLog.count); | ||
XCTAssertEqualObjects(@{@"test3":@1}, [self.loadBridgeTest.loadPlacementCallLog objectAtIndex:1]); | ||
} | ||
|
||
@end |
203 changes: 203 additions & 0 deletions
203
UnityAdsTests/Core/Configuration/USRVInitializationNotificationCenterTests.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,203 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "USRVInitializationDelegate.h" | ||
#import "USRVInitializationNotificationCenter.h" | ||
|
||
@interface USRVInitializationMock : NSObject <USRVInitializationDelegate> | ||
|
||
@property(nonatomic, copy) void (^initializeBlock)(void); | ||
@property(nonatomic, copy) void (^failBlock)(NSError *error); | ||
|
||
@end | ||
|
||
@implementation USRVInitializationMock | ||
|
||
-(void)sdkDidInitialize { | ||
if (self.initializeBlock) { | ||
self.initializeBlock(); | ||
} | ||
} | ||
|
||
-(void)sdkInitializeFailed:(NSError *)error { | ||
if (self.failBlock) { | ||
self.failBlock(error); | ||
} | ||
} | ||
|
||
@end | ||
|
||
@interface USRVInitializationDelegateWrapper : NSObject | ||
|
||
@property(nonatomic, weak) NSObject <USRVInitializationDelegate> *delegate; | ||
|
||
-(instancetype)initWithDelegate:(__weak NSObject <USRVInitializationDelegate> *)delegate; | ||
|
||
@end | ||
|
||
@interface USRVInitializationNotificationCenterTests : XCTestCase | ||
|
||
@property(nonatomic, strong) USRVInitializationNotificationCenter *initializationNotificationCenter; | ||
|
||
@end | ||
|
||
@implementation USRVInitializationNotificationCenterTests | ||
|
||
-(void)setUp { | ||
[super setUp]; | ||
self.initializationNotificationCenter = [[USRVInitializationNotificationCenter alloc] init]; | ||
} | ||
|
||
-(void)testAddDelegate { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testAddDelegate"]; | ||
mock.initializeBlock = ^() { | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
XCTestExpectation *expectation2 = [self expectationWithDescription:@"testAddDelegate2"]; | ||
mock.initializeBlock = ^(){ | ||
[expectation2 fulfill]; | ||
}; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testRemoveDelegate { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
USRVInitializationMock *mock2 = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testRemoveDelegate"]; | ||
mock.initializeBlock = ^() { | ||
XCTFail(@"mock initializeBlock should not be called"); | ||
}; | ||
mock2.initializeBlock = ^() { | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter addDelegate:mock2]; | ||
[self.initializationNotificationCenter removeDelegate:mock]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testCleanupOfWeakDelegate { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
USRVInitializationMock *mock2 = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testCleanupOfWeakDelegate"]; | ||
mock.initializeBlock = ^() { | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter addDelegate:mock2]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
XCTestExpectation *expectation2 = [self expectationWithDescription:@"testCleanupOfWeakDelegate2"]; | ||
mock.initializeBlock = ^() { | ||
XCTFail(@"mock initializeBlock should not be called"); | ||
}; | ||
mock2.initializeBlock = ^() { | ||
[expectation2 fulfill]; | ||
}; | ||
mock = nil; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testCleanupOfWeakDelegateForFailedInit { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
mock.failBlock = ^(NSError *error) { | ||
XCTFail(@"mock failBlock should not be called"); | ||
}; | ||
USRVInitializationMock *mock2 = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testCleanupOfWeakDelegateForFailedInit"]; | ||
mock2.failBlock = ^(NSError *error){ | ||
[expectation fulfill]; | ||
}; | ||
|
||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter addDelegate:mock2]; | ||
mock = nil; | ||
|
||
[self.initializationNotificationCenter triggerSdkInitializeDidFail:@"test" code:0]; | ||
|
||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
} | ||
|
||
-(void)testAddDelegateTwice { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testAddDelegateTwice"]; | ||
__block int count = 0; | ||
mock.initializeBlock = ^() { | ||
count++; | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
XCTAssertEqual(1, count); | ||
} | ||
|
||
-(void)testTriggerSdkDidInitialize { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testTriggerSdkDidInitialize"]; | ||
mock.initializeBlock = ^() { | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testTriggerSdkDidInitializeMultipleDelegates { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
USRVInitializationMock *mock2 = [[USRVInitializationMock alloc] init]; | ||
USRVInitializationMock *mock3 = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testTriggerSdkDidInitialize1"]; | ||
XCTestExpectation *expectation2 = [self expectationWithDescription:@"testTriggerSdkDidInitialize2"]; | ||
XCTestExpectation *expectation3 = [self expectationWithDescription:@"testTriggerSdkDidInitialize3"]; | ||
mock.initializeBlock = ^() { | ||
[expectation fulfill]; | ||
}; | ||
mock2.initializeBlock = ^() { | ||
[expectation2 fulfill]; | ||
}; | ||
mock3.initializeBlock = ^() { | ||
[expectation3 fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter addDelegate:mock2]; | ||
[self.initializationNotificationCenter addDelegate:mock3]; | ||
[self.initializationNotificationCenter triggerSdkDidInitialize]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testTriggerSdkInitializeDidFail { | ||
USRVInitializationMock *mock = [[USRVInitializationMock alloc] init]; | ||
XCTestExpectation *expectation = [self expectationWithDescription:@"testTriggerSdkInitializeDidFail"]; | ||
mock.failBlock = ^(NSError *error) { | ||
XCTAssertEqualObjects(@"USRVInitializationNotificationCenter", error.domain); | ||
XCTAssertEqual(@"test fail", [error.userInfo valueForKey:@"message"]); | ||
XCTAssertEqual(0, [error code]); | ||
[expectation fulfill]; | ||
}; | ||
[self.initializationNotificationCenter addDelegate:mock]; | ||
[self.initializationNotificationCenter triggerSdkInitializeDidFail:@"test fail" code:0]; | ||
[self waitForExpectationsWithTimeout:1 handler:^(NSError *error) { | ||
}]; | ||
} | ||
|
||
-(void)testDelegateWrapperMemory { | ||
USRVInitializationDelegateWrapper *initializationDelegateWrapper = [[USRVInitializationDelegateWrapper alloc] initWithDelegate:[[USRVInitializationMock alloc] init]]; | ||
XCTAssertNil(initializationDelegateWrapper.delegate); | ||
} | ||
|
||
@end |
Oops, something went wrong.