Skip to content

Commit

Permalink
Release 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyhampton committed May 16, 2019
1 parent 10838dd commit f874035
Show file tree
Hide file tree
Showing 65 changed files with 1,320 additions and 463 deletions.
1 change: 1 addition & 0 deletions Modules/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ framework module UnityAds {
umbrella header "UnityAds.h"
header "UnityAdsFinishState.h"
header "UnityAdsExtended.h"
header "UnityAdsExtendedDelegate.h"
header "UADSPurchasing.h"
header "UnityServices.h"
header "UnityAnalytics.h"
Expand Down
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 iOS Release Repository
# Unity Ads 3.1 iOS Release Repository

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

## Supported Integration Configurations

Expand Down
4 changes: 4 additions & 0 deletions UnityAdsTests/Ads/Mocks/UnityAdsDelegateMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import "UnityAdsDelegate.h"

@interface UnityAdsDelegateMock: NSObject <UnityAdsDelegate>
@end
24 changes: 24 additions & 0 deletions UnityAdsTests/Ads/Mocks/UnityAdsDelegateMock.m
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
60 changes: 60 additions & 0 deletions UnityAdsTests/Ads/Properties/UADSPropertiesTests.m
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
61 changes: 61 additions & 0 deletions UnityAdsTests/Ads/UnityAdsTests.m
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
10 changes: 5 additions & 5 deletions UnityAdsTests/Analytics/UnityAnalyticsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ -(void)testOnItemSpentNull {
}

-(void)testOnLevelFail {
[UnityAnalytics onLevelFail:8789];
[UnityAnalytics onLevelFail:@"8789"];
NSDictionary *expected = @{
@"type": @"analytics.custom.v1",
@"msg": @{
@"ts": [NSNumber numberWithLong:((long) [[NSDate date] timeIntervalSince1970]) * 1000],
@"name": @"level_fail",
@"custom_params": @{
@"level_index": [NSNumber numberWithInt:8789]
@"level_index": @"8789"
}
}
};
Expand All @@ -162,14 +162,14 @@ -(void)testOnLevelFail {
}

-(void)testOnLevelUp {
[UnityAnalytics onLevelUp:334];
[UnityAnalytics onLevelUp:@"334"];
NSDictionary *expected = @{
@"type": @"analytics.custom.v1",
@"msg": @{
@"ts": [NSNumber numberWithLong:((long) [[NSDate date] timeIntervalSince1970]) * 1000],
@"name": @"level_up",
@"custom_params": @{
@"new_level_index": [NSNumber numberWithInt:334]
@"new_level_index": @"334"
}
}
};
Expand Down Expand Up @@ -294,4 +294,4 @@ -(void)testMaximumQueuedEvents {
XCTAssertEqual(200, [eventQueue count]);
}

@end
@end
8 changes: 4 additions & 4 deletions UnityAdsTests/ClientPropertiesTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ - (void)setUp {

- (void)tearDown {
[super tearDown];
[UADSProperties removeDelegate:self];
}

- (void)testGetSupportedOrientations {
Expand All @@ -36,10 +37,9 @@ - (void)testSetCurrentViewController {

}

- (void)testSetDelegate {
[UADSProperties setDelegate:self];
XCTAssertEqualObjects(self, [UADSProperties getDelegate]);

- (void)testAddDelegate {
[UADSProperties addDelegate:self];
XCTAssertTrue([[UADSProperties getDelegates] containsObject:self]);
}

- (void)testIsAppDebuggable {
Expand Down
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
70 changes: 70 additions & 0 deletions UnityAdsTests/Core/Data/USRVJsonUtilitiesTests.m
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
10 changes: 10 additions & 0 deletions UnityAdsTests/SdkPropertiesTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ -(void)testSetShowTimeout {
XCTAssertTrue(4000 == [UADSProperties getShowTimeout], @"New show timeout should equal to 4000");
}

- (void)testIsChinaLocale {
XCTAssertTrue([USRVSdkProperties isChinaLocale:@"cn"], @"Should return true with a china iso alpha 2 code");
XCTAssertTrue([USRVSdkProperties isChinaLocale:@"chn" ], @"Should return true with a china iso alpha 3 code");
XCTAssertTrue([USRVSdkProperties isChinaLocale:@"CN"], @"Should return true with an uppercase china iso alpha 2 code");
XCTAssertTrue([USRVSdkProperties isChinaLocale:@"CHN"], @"Should return true with an uppercase china iso alpha 3 code");
XCTAssertTrue([USRVSdkProperties isChinaLocale:@"ChN"], @"Should return true with a mixture of upper and lowercase china iso alpha 2 code characters");

XCTAssertFalse([USRVSdkProperties isChinaLocale:@"us"], @"Should return false with a US iso code");
}

@end
Loading

0 comments on commit f874035

Please sign in to comment.