Skip to content

Commit

Permalink
Release 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Ads Travis committed Jan 30, 2019
1 parent 037c40e commit 94c7a6a
Show file tree
Hide file tree
Showing 100 changed files with 1,230 additions and 493 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source 'https://rubygems.org'
# xcodeproj has an issue with newest Xcode, fix is not a release gem at this moment
# Use github master until fix is released in gem.
gem 'xcodeproj', '~> 1.4.2'
gem 'xcodeproj', '~> 1.6.0'
gem 'optimist'
gem 'plist', '~> 3.2'
gem 'fastlane', '~> 2.113.0'
gem 'slather', '~> 2.4.6'
6 changes: 6 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library('applifier-shared-libs@master') _

Script {
extraSteps = ['scripts/extra.groovy']
disable_registry = true
}
143 changes: 143 additions & 0 deletions UnityAdsIntegrationTests/CacheQueueTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#import <XCTest/XCTest.h>
//#import "UnityAdsTests-Bridging-Header.h"
#import "USRVWebViewApp.h"
#import "USRVCacheQueue.h"
#import "USRVSdkProperties.h"
#import "TestUtilities.h"

static long kMinFileSize = 5000;

@interface MockWebViewApp : USRVWebViewApp
@property (nonatomic, strong) XCTestExpectation *expectation;
@property (nonatomic, strong) XCTestExpectation *progressExpectation;
@property (nonatomic, strong) XCTestExpectation *resumeEndExpectation;


@end

@implementation MockWebViewApp

- (BOOL)sendEvent:(NSString *)eventId category:(NSString *)category param1:(id)param1, ... {
if (eventId && [eventId isEqualToString:@"DOWNLOAD_END"]) {
NSLog(@"DOWNLOAD_END");
if (self.expectation) {
[self.expectation fulfill];
self.expectation = nil;
}

if (self.resumeEndExpectation) {
[self.resumeEndExpectation fulfill];
self.resumeEndExpectation = nil;
}
}
if (eventId && [eventId isEqualToString:@"DOWNLOAD_PROGRESS"]) {

va_list args;
va_start(args, param1);

NSMutableArray *params = [[NSMutableArray alloc] init];

__unsafe_unretained id arg = nil;

if (param1) {
[params addObject:param1];

while ((arg = va_arg(args, id)) != nil) {
[params addObject:arg];
}

va_end(args);
}
NSLog(@"DOWNLOAD_PROGRESS %li", (long)[[params objectAtIndex:1] integerValue]);
if ([[params objectAtIndex:1] integerValue] > kMinFileSize) {
if (self.progressExpectation) {
[self.progressExpectation fulfill];
self.progressExpectation = nil;
}
}

}

return true;
}

- (BOOL)invokeCallback:(USRVInvocation *)invocation {
return true;
}
@end

@interface CacheQueueTests : XCTestCase
@end

@implementation CacheQueueTests

- (void)setUp {
[super setUp];
MockWebViewApp *webApp = [[MockWebViewApp alloc] init];
[USRVWebViewApp setCurrentApp:webApp];
[USRVCacheQueue start];
}

- (void)testDownloadFile {
XCTestExpectation *expectation = [self expectationWithDescription:@"downloadFinishExpectation"];
MockWebViewApp *mockApp = (MockWebViewApp *)[USRVWebViewApp getCurrentApp];
[mockApp setExpectation:expectation];
NSString *fileName = [NSString stringWithFormat:@"%@/%@", [USRVSdkProperties getCacheDirectory], @"test.mp4"];
[[NSFileManager defaultManager]removeItemAtPath:fileName error:nil];

[USRVCacheQueue download:[TestUtilities getTestVideoUrl] target:fileName headers:nil append:false];

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
}];

NSFileManager *fileManager = [NSFileManager defaultManager];
XCTAssertTrue([fileManager fileExistsAtPath:fileName], "File should exist after downloading");
}

- (void)testResumeDownload {
XCTestExpectation *expectation = [self expectationWithDescription:@"downloadProgressExpectation"];
MockWebViewApp *mockApp = (MockWebViewApp *)[USRVWebViewApp getCurrentApp];
[mockApp setProgressExpectation:expectation];
NSString *fileName = [NSString stringWithFormat:@"%@/%@", [USRVSdkProperties getCacheDirectory], @"resume_test.mp4"];
[[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];

[USRVCacheQueue setProgressInterval:50];
[USRVCacheQueue download:[TestUtilities getTestVideoUrl] target:fileName headers:nil append:false];

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
[mockApp setProgressExpectation:nil];
}];

[USRVCacheQueue cancelAllDownloads];
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:fileName], "File should exist");

XCTestExpectation *delayExpectation = [self expectationWithDescription:@"delayEndExpectation"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[delayExpectation fulfill];
});

[self waitForExpectationsWithTimeout:2 handler:^(NSError * _Nullable error) {
}];

NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
unsigned long long fileSize = [fileHandle seekToEndOfFile];
XCTAssertTrue(fileSize > kMinFileSize, "File size should be over 5000 %llu", fileSize);
XCTAssertTrue(fileSize < [TestUtilities getTestVideoExpectedSize], "File size should be less than kVideoSize (%d)", [TestUtilities getTestVideoExpectedSize]);

XCTestExpectation *endExpectation = [self expectationWithDescription:@"downloadEndExpectation"];
[mockApp setResumeEndExpectation:endExpectation];

NSDictionary *headers = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:[NSString stringWithFormat:@"bytes=%llu-", fileSize]] forKey:@"Range"];

[USRVCacheQueue download:[TestUtilities getTestVideoUrl] target:fileName headers:headers append:true];

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
}];

XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:fileName], "File should exist");
NSFileHandle *fileHandle2 = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
unsigned long long fileSize2 = [fileHandle2 seekToEndOfFile];
XCTAssertEqual(fileSize2, [TestUtilities getTestVideoExpectedSize], "File size should be kVideoSize (%d)", [TestUtilities getTestVideoExpectedSize]);
}

@end
68 changes: 68 additions & 0 deletions UnityAdsIntegrationTests/ConfigurationTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#import <XCTest/XCTest.h>
#import "USRVConfiguration.h"
#import "USRVSdkProperties.h"

@interface ConfigurationTests : XCTestCase
@end

@implementation ConfigurationTests

- (void)setUp {
[super setUp];

}

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

- (void)testMakeRequest {
NSString *configUrl = [USRVSdkProperties getConfigUrl];
USRVConfiguration *configuration = [[USRVConfiguration alloc] initWithConfigUrl:configUrl];

XCTestExpectation *expectation = [self expectationWithDescription:@"expectation"];

__block BOOL success = true;

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
[configuration makeRequest];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
if (error) {
success = false;
}
}];

XCTAssertTrue(success, "Request should have succeeded");
XCTAssertNotNil([configuration webViewUrl], @"Config url : %@ : Web view url shouldn't be nil", configUrl);
XCTAssertNil([configuration error], "Error should be nil");
}

- (void)testMakeRequestNotValidUrl {
USRVConfiguration *configuration = [[USRVConfiguration alloc] initWithConfigUrl:@"https://cdn.unityadsssss.unity3d.com/webview/master/release/config.json"];

XCTestExpectation *expectation = [self expectationWithDescription:@"expectation"];

__block BOOL success = true;

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
[configuration makeRequest];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
if (error) {
success = false;
}
}];

XCTAssertTrue(success, "Request should have succeeded");
XCTAssertNotNil([configuration error], "Error should not be null");
XCTAssertEqualObjects(@"ERROR_REQUESTING_CONFIG", [configuration error], "Error message should be equal to 'ERROR_REQUESTING_CONFIG'");
}

@end
22 changes: 22 additions & 0 deletions UnityAdsIntegrationTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
73 changes: 73 additions & 0 deletions UnityAdsIntegrationTests/InitializeTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#import <XCTest/XCTest.h>
#import "USRVConfiguration.h"
#import "USRVSdkProperties.h"
#import "USRVInitialize.h"

@interface InitializeTests : XCTestCase
@end

@implementation InitializeTests

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

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

- (void)testInitializeStateConfig {
USRVConfiguration *config = [[USRVConfiguration alloc] init];
[config setConfigUrl:[USRVSdkProperties getConfigUrl]];
USRVInitializeStateConfig *initializeState = [[USRVInitializeStateConfig alloc] initWithConfiguration:config];

__block id nextState = NULL;

XCTestExpectation *expectation = [self expectationWithDescription:@"expectation"];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
nextState = [initializeState execute];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
}];

XCTAssertTrue([nextState isKindOfClass:[USRVInitializeStateLoadCache class]], @"Next state should be 'Load Cache'");
XCTAssertNotNil([config webViewUrl], @"WebViewUrl should not be nil");
XCTAssertNotNil([config webViewHash], @"WebViewHash should not be nil");
}

- (void)testInitializeStateLoadWeb {
USRVConfiguration *config = [[USRVConfiguration alloc] init];
[config setConfigUrl:[USRVSdkProperties getConfigUrl]];

__block id nextState = NULL;

XCTestExpectation *expectation = [self expectationWithDescription:@"expectation"];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
[config makeRequest];
[expectation fulfill];
});

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
}];

USRVInitializeStateLoadWeb *loadWebState = [[USRVInitializeStateLoadWeb alloc] initWithConfiguration:config];

XCTestExpectation *expectation2 = [self expectationWithDescription:@"expectation2"];
dispatch_async(queue, ^{
nextState = [loadWebState execute];
[expectation2 fulfill];
});

[self waitForExpectationsWithTimeout:60 handler:^(NSError * _Nullable error) {
}];

XCTAssertTrue([nextState isKindOfClass:[USRVInitializeStateCreate class]], @"Next state should be 'Create'");
XCTAssertNotNil([config webViewUrl], @"WebViewUrl should not be nil");
XCTAssertNotNil([config webViewHash], @"WebViewHash should not be nil");
}

@end
9 changes: 9 additions & 0 deletions UnityAdsIntegrationTests/TestUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <Foundation/Foundation.h>

@interface TestUtilities : NSObject

+ (NSString *)getTestServerAddress;
+ (NSString *)getTestVideoUrl;
+ (int)getTestVideoExpectedSize;

@end
23 changes: 23 additions & 0 deletions UnityAdsIntegrationTests/TestUtilities.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#import "TestUtilities.h"

@implementation TestUtilities

+ (NSString *)getTestServerAddress {
NSString *testServerAddress = [NSString stringWithFormat:@"%@", @"http://unity-ads-test-server.unityads.unity3d.com"];

if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UADSTestServerAddress"] isKindOfClass:[NSString class]]) {
testServerAddress = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UADSTestServerAddress"];
}

return testServerAddress;
}

+ (NSString *)getTestVideoUrl {
return [NSString stringWithFormat:@"%@/%@", [TestUtilities getTestServerAddress], @"blue_test_trailer.mp4"];
}

+ (int)getTestVideoExpectedSize {
return 134924;
}

@end
Loading

0 comments on commit 94c7a6a

Please sign in to comment.