Skip to content

Commit

Permalink
Release 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyhampton committed Jul 22, 2019
1 parent f874035 commit 39e78b2
Show file tree
Hide file tree
Showing 36 changed files with 956 additions and 113 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ release:

zip: release
cd build/Release-iphoneos && zip -9r builds.zip UnityAds.framework
mv build/Release-iphoneos/builds.zip .
mv build/Release-iphoneos/builds.zip ./UnityAds.framework.zip

verify-release-build:
if [[ -f "UnityAds.framework.zip" ]]; then \
echo 'UnityAds.framework.zip exists'; \
else \
echo 'UnityAds.framework.zip does not exist'; \
exit 1; \
fi;
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unity Ads 3.1 iOS Release Repository
# Unity Ads 3 iOS Release Repository

Welcome to the Unity Ads 3.1 iOS release repository.
Welcome to the Unity Ads 3 iOS release repository.

## Supported Integration Configurations

Expand Down
14 changes: 14 additions & 0 deletions UnityAds.podspec
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
58 changes: 58 additions & 0 deletions UnityAdsTests/Ads/Load/UADSLoadBridgeTests.m
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
94 changes: 94 additions & 0 deletions UnityAdsTests/Ads/Load/UADSLoadModuleTests.m
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
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
Loading

0 comments on commit 39e78b2

Please sign in to comment.