Skip to content

Commit

Permalink
Release 3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
UnitySteven committed Dec 8, 2020
1 parent 3d5f741 commit 59b2bde
Show file tree
Hide file tree
Showing 38 changed files with 606 additions and 264 deletions.
3 changes: 3 additions & 0 deletions Modules/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ framework module UnityAds {
header "UnityAdsInitializationDelegate.h"
header "UnityAdsInitializationError.h"
header "UnityAdsLoadDelegate.h"
header "UADSBaseOptions.h"
header "UADSLoadOptions.h"
header "UADSShowOptions.h"

header "USRVUnityPurchasing.h"
header "USRVUnityPurchasingDelegate.h"
Expand Down
4 changes: 2 additions & 2 deletions UnityAds.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = 'UnityAds'
s.version = '3.5.1'
s.version = '3.6.0'
s.license = { :type => 'Unity License', :file => 'LICENSE' }
s.author = { 'UnityAds' => 'itunes@unity3d.com' }
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.5.1/UnityAds.framework.zip' }
s.source = { :http => 'https://github.com/Unity-Technologies/unity-ads-ios/releases/download/3.6.0/UnityAds.framework.zip' }
s.ios.deployment_target = '9.0'
s.ios.vendored_frameworks = 'UnityAds.framework'
s.ios.xcconfig = { 'OTHER_LDFLAGS' => '-framework UnityAds' }
Expand Down
59 changes: 50 additions & 9 deletions UnityAdsTests/Ads/Load/UADSLoadModuleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "USRVSdkProperties.h"
#import "USRVInitializationNotificationCenter.h"
#import "USRVWebViewApp.h"
#import "UADSLoadOptions.h"

@interface UnityAdsLoadDelegateMock : NSObject<UnityAdsLoadDelegate>
@property (strong) NSMutableArray* adLoaded;
Expand Down Expand Up @@ -41,14 +42,18 @@ @interface MockLoadWebViewApp : USRVWebViewApp {
}
@property (nonatomic, strong) XCTestExpectation *loadCallExpectation;
@property (strong) UADSLoadModule* loadModule;
@property NSArray *params;

- (void)simulateLoadCall;
- (void)simulateFailedLoadCall;
- (void)simulateLoadCallTimeout;

@end

@implementation MockLoadWebViewApp

@synthesize params;

- (instancetype)initWithLoadModule:(UADSLoadModule*)loadModule {
if (self = [super init]) {
self.loadModule = loadModule;
Expand All @@ -60,7 +65,7 @@ - (BOOL)invokeMethod:(NSString *)methodName className:(NSString *)className rece

self->receiverClass = receiverClass;
self->callback = callback;
self->params = params;
self.params = params;

[_loadCallExpectation fulfill];
return YES;
Expand All @@ -83,7 +88,7 @@ - (void)simulateLoadCall {
[invocation retainArguments];
[invocation invoke];

NSDictionary* dict = self->params[0];
NSDictionary* dict = self.params[0];

[_loadModule sendAdLoaded:[dict objectForKey:@"placementId"] listenerId:[dict objectForKey:@"listenerId"]];
}
Expand Down Expand Up @@ -123,6 +128,7 @@ - (void)simulateLoadCallTimeout {
[invocation retainArguments];
[invocation invoke];
}

@end

@interface UADSLoadModule (Test)
Expand Down Expand Up @@ -157,7 +163,7 @@ -(void)testLoadAfterInitialized {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

Expand Down Expand Up @@ -185,7 +191,7 @@ -(void)testLoadAfterInitialized_WithWebViewTimeout {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

Expand All @@ -211,7 +217,7 @@ -(void)testLoadAfterInitialized_WithFailedInvocation {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

Expand Down Expand Up @@ -239,7 +245,7 @@ -(void)testLoadAfterInitialized_ListenerCleanup {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

Expand Down Expand Up @@ -268,7 +274,7 @@ -(void)testLoadAfterInitialized_WithHardcodedTimeout {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

Expand All @@ -285,6 +291,41 @@ -(void)testLoadAfterInitialized_WithHardcodedTimeout {
XCTAssertEqualObjects(@[@"test"], delegate.adFailedToLoad);
}

-(void)testLoadAfterInitialized_WithCorrectLoadOptions {
MockLoadWebViewApp* mock = [[MockLoadWebViewApp alloc] initWithLoadModule:_loadModule];
[USRVWebViewApp setCurrentApp:mock];

[USRVSdkProperties setInitialized:YES];

XCTestExpectation* expectation = [self expectationWithDescription:@"load call"];
mock.loadCallExpectation = expectation;

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];
UADSLoadOptions* loadOptions = [UADSLoadOptions new];
[loadOptions setAdMarkup:@"MyAdMarkup"];
[loadOptions setObjectId:@"MyObjectID"];

[self.loadModule load:@"test" options:loadOptions loadDelegate:delegate];

[self waitForExpectationsWithTimeout:1 handler:nil];

expectation = [self expectationWithDescription:@"event call"];
delegate.expectation = expectation;

[mock simulateLoadCall];

[self waitForExpectationsWithTimeout:1 handler:nil];

NSDictionary *options = [[[mock params] objectAtIndex:0] objectForKey:@"options"];

XCTAssertEqual(1, delegate.adLoaded.count);
XCTAssertEqualObjects(@[@"test"], delegate.adLoaded);
XCTAssertEqual(0, delegate.adFailedToLoad.count);

XCTAssertEqual(@"MyAdMarkup", [options objectForKey:@"adMarkup"]);
XCTAssertEqual(@"MyObjectID", [options objectForKey:@"objectId"]);
}

-(void)testLoadBeforeInitialized {
MockLoadWebViewApp* mock = [[MockLoadWebViewApp alloc] initWithLoadModule:_loadModule];
[USRVWebViewApp setCurrentApp:mock];
Expand All @@ -296,7 +337,7 @@ -(void)testLoadBeforeInitialized {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

[USRVSdkProperties setInitialized:YES];
[_loadModule sdkDidInitialize];
Expand Down Expand Up @@ -324,7 +365,7 @@ -(void)testLoadBeforeInitialized_InitFailed {

UnityAdsLoadDelegateMock* delegate = [[UnityAdsLoadDelegateMock alloc] init];

[self.loadModule load:@"test" loadDelegate:delegate];
[self.loadModule load:@"test" options:[UADSLoadOptions new] loadDelegate:delegate];

XCTestExpectation* expectation = [self expectationWithDescription:@"event call"];
delegate.expectation = expectation;
Expand Down
51 changes: 51 additions & 0 deletions UnityAdsTests/Ads/Options/LoadOptionsTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#import <XCTest/XCTest.h>
#import "UADSLoadOptions.h"

@interface LoadOptionsTest : XCTestCase

@property UADSLoadOptions* loadOptions;

@end

@implementation LoadOptionsTest

- (void)setUp {
self.loadOptions = [UADSLoadOptions new];
}

- (void)tearDown {
self.loadOptions = nil;
}

- (void)testAdMarkup {
[self.loadOptions setAdMarkup:@"MyAdMarkup"];

XCTAssertEqual(@"MyAdMarkup", [self.loadOptions adMarkup]);
XCTAssertEqual(@"MyAdMarkup", [self.loadOptions.dictionary objectForKey:@"adMarkup"]);

XCTAssertEqual(1, [self.loadOptions.dictionary count]);
}

- (void)testObjectId {
[self.loadOptions setObjectId:@"MyObjectId"];

XCTAssertEqual(@"MyObjectId", [self.loadOptions objectId]);
XCTAssertEqual(@"MyObjectId", [self.loadOptions.dictionary objectForKey:@"objectId"]);

XCTAssertEqual(1, [self.loadOptions.dictionary count]);
}

- (void)testObjectIdAndAdMarkup {
[self.loadOptions setObjectId:@"MyObjectId"];
[self.loadOptions setAdMarkup:@"MyAdMarkup"];

XCTAssertEqual(@"MyObjectId", [self.loadOptions objectId]);
XCTAssertEqual(@"MyObjectId", [self.loadOptions.dictionary objectForKey:@"objectId"]);

XCTAssertEqual(@"MyAdMarkup", [self.loadOptions adMarkup]);
XCTAssertEqual(@"MyAdMarkup", [self.loadOptions.dictionary objectForKey:@"adMarkup"]);

XCTAssertEqual(2, [self.loadOptions.dictionary count]);
}

@end
27 changes: 27 additions & 0 deletions UnityAdsTests/Ads/Options/ShowOptionsTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#import <XCTest/XCTest.h>
#import "UADSShowOptions.h"

@interface ShowOptionsTest : XCTestCase

@property UADSShowOptions* showOptions;

@end

@implementation ShowOptionsTest

- (void)setUp {
self.showOptions = [UADSShowOptions new];
}

- (void)tearDown {
self.showOptions = nil;
}

- (void)testObjectId {
[self.showOptions setObjectId:@"MyObjectId"];
XCTAssertEqual(@"MyObjectId", [self.showOptions objectId]);
XCTAssertEqual(@"MyObjectId", [self.showOptions.dictionary objectForKey:@"objectId"]);
XCTAssertEqual(1, [self.showOptions.dictionary count]);
}

@end
132 changes: 132 additions & 0 deletions UnityAdsTests/TokenStorageTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#import <XCTest/XCTest.h>
#import "UnityAdsTests-Bridging-Header.h"

@interface TokenStorageEventHandlerMock : NSObject<UADSTokenStorageEventProtocol>

@property int queueEmptyCount;
@property int accessTokenCount;
@property NSMutableArray* indecies;

- (void) sendQueueEmpty;
- (void) sendTokenAccessIndex:(NSNumber*)index;

@end

@implementation TokenStorageEventHandlerMock

- (void) sendQueueEmpty {
self.queueEmptyCount++;
}

- (void) sendTokenAccessIndex:(NSNumber*)index {
self.accessTokenCount++;

if (self.indecies == nil) {
self.indecies = [NSMutableArray new];
}

[self.indecies addObject:index];
}

@end

@interface TokenStorageTests : XCTestCase

@property UADSTokenStorage* tokenStorage;
@property TokenStorageEventHandlerMock* eventHandlerMock;

@end

@implementation TokenStorageTests

- (void)setUp {
[super setUp];

self.eventHandlerMock = [TokenStorageEventHandlerMock new];
self.tokenStorage = [[UADSTokenStorage alloc] initWithEventHandler:self.eventHandlerMock];
}

- (void)tearDown {
[super tearDown];
}

- (void)testCreateToken {
[self.tokenStorage createTokens:@[@"token1", @"token2", @"token3"]];

XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual([self.tokenStorage getToken], @"token2");
XCTAssertEqual([self.tokenStorage getToken], @"token3");
XCTAssertEqual([self.tokenStorage getToken], nil);
}

- (void)testDeleteToken {
[self.tokenStorage createTokens:@[@"token1", @"token2", @"token3"]];
[self.tokenStorage deleteTokens];

XCTAssertEqual([self.tokenStorage getToken], nil);
}

- (void)testAppendToken {
[self.tokenStorage createTokens:@[@"token1"]];
[self.tokenStorage appendTokens:@[@"token2", @"token3"]];

XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual([self.tokenStorage getToken], @"token2");
XCTAssertEqual([self.tokenStorage getToken], @"token3");
XCTAssertEqual([self.tokenStorage getToken], nil);
}

- (void)testAppendTokenOnEmptyStorage {
[self.tokenStorage deleteTokens];
[self.tokenStorage appendTokens:@[@"token1", @"token2"]];

XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual([self.tokenStorage getToken], @"token2");
XCTAssertEqual([self.tokenStorage getToken], nil);
}

- (void)testAppendTokenWithoutQueueShouldNotCrashApp {
[self.tokenStorage appendTokens:@[@"token2", @"token3"]];
}


- (void)testGetTokenWhenNoQueue {
XCTAssertEqual([self.tokenStorage getToken], nil);
XCTAssertEqual(self.eventHandlerMock.queueEmptyCount, 0);
XCTAssertEqual(self.eventHandlerMock.accessTokenCount, 0);
}

- (void)testGetTokenAccessToken {
[self.tokenStorage createTokens:@[@"token1"]];

XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual(self.eventHandlerMock.queueEmptyCount, 0);
XCTAssertEqual(self.eventHandlerMock.accessTokenCount, 1);

NSArray *myArray = @[@0];
XCTAssertEqualObjects(self.eventHandlerMock.indecies, myArray);
}

- (void)testGetTokenEmptyQueue {
[self.tokenStorage createTokens:@[]];

XCTAssertEqual([self.tokenStorage getToken], nil);
XCTAssertEqual(self.eventHandlerMock.queueEmptyCount, 1);
XCTAssertEqual(self.eventHandlerMock.accessTokenCount, 0);
}

- (void)testGetTokenAccessTokenInPeekMode {
[self.tokenStorage setPeekMode:YES];

[self.tokenStorage createTokens:@[@"token1", @"token2"]];

XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual([self.tokenStorage getToken], @"token1");
XCTAssertEqual(self.eventHandlerMock.queueEmptyCount, 0);
XCTAssertEqual(self.eventHandlerMock.accessTokenCount, 2);

NSArray *myArray = @[@0, @1];
XCTAssertEqualObjects(self.eventHandlerMock.indecies, myArray);
}

@end
Loading

0 comments on commit 59b2bde

Please sign in to comment.