Skip to content

Commit

Permalink
Release 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Ads Travis committed Feb 28, 2018
1 parent 1cfae31 commit f3f5042
Show file tree
Hide file tree
Showing 46 changed files with 3,252 additions and 76 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.unity3d.ads.example"
minSdkVersion 9
targetSdkVersion 23
versionCode = 2102
versionName = "2.1.2"
versionCode = 2200
versionName = "2.2.0"
}
buildTypes {
release {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -5,12 +5,12 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="UnityAds 2.1"
android:label="UnityAds 2.2"
android:theme="@style/AppTheme" >
<activity
android:name="com.unity3d.ads.example.UnityAdsExample"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:label="UnityAds 2.1" >
android:label="UnityAds 2.2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle
Expand Up @@ -11,8 +11,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode = 2102
versionName = "2.1.2"
versionCode = 2200
versionName = "2.2.0"

setProperty("archivesBaseName", "unity-ads")

Expand Down
Expand Up @@ -37,6 +37,9 @@
WebViewCallbackTest.class,
LifecycleListenerTest.class,
VolumeChangeTest.class,
UtilitiesTest.class
UtilitiesTest.class,
WebPlayerTest.class,
PreferencesTest.class
})

public class UnitTestSuite {}
Expand Up @@ -73,13 +73,19 @@ public void run() {
com.unity3d.ads.api.VideoPlayer.class,
com.unity3d.ads.api.Placement.class,
com.unity3d.ads.api.Intent.class,
com.unity3d.ads.api.WebPlayer.class,
com.unity3d.ads.test.hybrid.HybridTest.class,
com.unity3d.ads.api.Lifecycle.class,
com.unity3d.ads.api.Preferences.class,
com.unity3d.ads.api.Purchasing.class,
com.unity3d.ads.api.SensorInfo.class,
com.unity3d.ads.test.hybrid.HybridTest.class
};

configuration.setWebAppApiClassList(apiClassList);
InitializeThread.initialize(configuration);

if(!_resultSemaphore.tryAcquire(5, TimeUnit.MINUTES)) {
if(!_resultSemaphore.tryAcquire(10, TimeUnit.MINUTES)) {
fail("onHybridTestResult did not arrive");
}

Expand Down
Expand Up @@ -186,7 +186,7 @@ public void eventCache(CacheEvent eventId, Object... params) {

Invocation invocation = new Invocation();
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
Cache.download(REMOTE_IMG, REMOTE_IMG_FILE_ID, new JSONArray(), callback);
Cache.download(REMOTE_IMG, REMOTE_IMG_FILE_ID, new JSONArray(), false, callback);
invocation.sendInvocationCallback();

boolean success = cacheCv.block(30000);
Expand Down Expand Up @@ -372,7 +372,7 @@ public void callbackOk(Object... params) {
private static long downloadPosition;

@Test
public void testStopResumeDownload() {
public void testStopResumeDownload() throws Exception {
final long minDownloadBytes = 12345;
final ConditionVariable cacheCv = new ConditionVariable();
final ConditionVariable cacheCv2 = new ConditionVariable();
Expand Down Expand Up @@ -443,7 +443,7 @@ public void eventCache(CacheEvent eventId, Object... params) {
Invocation invocation = new Invocation();
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
CacheThread.setProgressInterval(2);
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray(), callback);
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray(), false, callback);
invocation.sendInvocationCallback();

boolean success = cacheCv.block(30000);
Expand Down Expand Up @@ -505,7 +505,7 @@ public void eventCache(CacheEvent eventId, Object... params) {

Invocation invocation2 = new Invocation();
WebViewCallback callback2 = new WebViewCallback("1234", invocation2.getId());
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray(), callback2);
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray("[[\"Range\", \"bytes=" + downloadPosition + "-\"]]"), true, callback2);
invocation2.sendInvocationCallback();

boolean success2 = cacheCv2.block(30000);
Expand Down
46 changes: 46 additions & 0 deletions lib/src/androidTest/java/com/unity3d/ads/test/unit/DeviceTest.java
Expand Up @@ -149,6 +149,11 @@ public void testScreenBrightness () throws Exception {
assertTrue("Screen brightness should be equal or more than 0", Device.getScreenBrightness() >= 0);
}

@Test
public void testGetAdbStatus () throws Exception {
assertTrue("Adb status should be true", Device.isAdbEnabled());
}

@Test
public void testGetGLVersion () throws Exception {
assertNotNull("GLES version should not be null", Device.getGLVersion());
Expand Down Expand Up @@ -184,11 +189,52 @@ public void testGetProduct () throws Exception {
assertNotNull("Product should not be null", Device.getProduct());
}

@Test
public void testGetFingerprint () throws Exception {
assertNotNull("Fingerprint should not be null", Device.getFingerprint());
}

@Test
public void testGetApkDigest () throws Exception {
assertNotNull("Host should not be null", Device.getApkDigest());
}

@Test
public void testGetCertificateFingerprint () throws Exception {
assertNotNull("Certificate fingerprint should not be null", Device.getCertificateFingerprint());
}

@Test
public void testGetSupportedAbis () throws Exception {
ArrayList<String> supportedAbis = Device.getSupportedAbis();

assertNotNull("List of supported abis should not be null", supportedAbis);
assertTrue("Number of supported abis should be larger than 0", supportedAbis.size() > 0);
}

@Test
public void testGetProcessInfo () throws Exception {
Map<String, String> data = Device.getProcessInfo();

assertNotNull("Stats should not be null", data.get("stat"));
assertNotEquals("Stats should not be empty", data.get("stat"), "");

assertNotNull("Uptime should not be null", data.get("uptime"));
assertNotEquals("Uptime should not be empty", data.get("uptime"), "");
}

@Test
public void testGetCPUCount() {
assertTrue("Number of CPUs should be greater than 0", Device.getCPUCount() > 0);
}

@Test
public void testGetUptime() {
assertTrue("Uptime should be greater than 0", Device.getUptime() > 0);
}

@Test
public void testGetElapsedRealtime() {
assertTrue("Elapsed realtime should be greater than 0", Device.getElapsedRealtime() > 0);
}
}
@@ -0,0 +1,227 @@
package com.unity3d.ads.test.unit;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.unity3d.ads.preferences.AndroidPreferences;
import com.unity3d.ads.properties.ClientProperties;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
public class PreferencesTest {
String testSettings = "unity.test.preferences";
String nonExistingSettings = "unity.test.does.not.exist";
String stringKey = "test.string";
String intKey = "test.int";
String longKey = "test.long";
String boolKey = "test.boolean";
String floatKey = "test.float";
String nonExistingKey = "non.existing.key";

@Before
public void setup() {
ClientProperties.setApplicationContext(InstrumentationRegistry.getTargetContext());

deleteKey(stringKey);
deleteKey(intKey);
deleteKey(longKey);
deleteKey(boolKey);
deleteKey(floatKey);
}

@Test
public void testPreferencesStringGetter() {
String testValue = "testString";

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, stringKey));

SharedPreferences.Editor editor = getEditor();
editor.putString(stringKey, testValue);
editor.commit();

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, stringKey));
assertEquals("Proper string value was not read from SharedPreferences", AndroidPreferences.getString(testSettings, stringKey), testValue);
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getString(testSettings, nonExistingKey));
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getString(nonExistingSettings, stringKey));
}

@Test
public void testPreferencesIntGetter() {
int testValue = 12345;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, intKey));

SharedPreferences.Editor editor = getEditor();
editor.putInt(intKey, testValue);
editor.commit();

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, intKey));
assertEquals("Proper int value was not read from SharedPreferences", AndroidPreferences.getInteger(testSettings, intKey), Integer.valueOf(testValue));
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getInteger(testSettings, nonExistingKey));
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getInteger(nonExistingSettings, intKey));
}

@Test
public void testPreferencesLongGetter() {
long testValue = 12345678;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, longKey));

SharedPreferences.Editor editor = getEditor();
editor.putLong(longKey, testValue);
editor.commit();

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, longKey));
assertEquals("Proper long value was not read from SharedPreferences", AndroidPreferences.getLong(testSettings, longKey), Long.valueOf(testValue));
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getLong(testSettings, nonExistingKey));
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getLong(nonExistingSettings, longKey));
}

@Test
public void testPreferencesBooleanGetter() {
boolean testValue = true;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, boolKey));

SharedPreferences.Editor editor = getEditor();
editor.putBoolean(boolKey, testValue);
editor.commit();

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, boolKey));
assertEquals("Proper boolean value was not read from SharedPreferences", AndroidPreferences.getBoolean(testSettings, boolKey), Boolean.valueOf(testValue));
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getBoolean(testSettings, nonExistingKey));
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getBoolean(nonExistingSettings, boolKey));
}

@Test
public void testPreferencesFloatGetter() {
float testValue = 1.2345f;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, floatKey));

SharedPreferences.Editor editor = getEditor();
editor.putFloat(floatKey, testValue);
editor.commit();

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, floatKey));
assertEquals("Proper float value was not read from SharedPreferences", AndroidPreferences.getFloat(testSettings, floatKey), Float.valueOf(testValue));
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getFloat(testSettings, nonExistingKey));
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getFloat(nonExistingSettings, floatKey));
}

@Test
public void testPreferencesStringSetter() {
String testValue = "testString";

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, stringKey));

AndroidPreferences.setString(testSettings, stringKey, testValue);

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, stringKey));
assertEquals("Proper string value was not read from SharedPreferences", getPrefs().getString(stringKey, ""), testValue);
}

@Test
public void testPreferencesIntSetter() {
int testValue = 12345;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, intKey));

AndroidPreferences.setInteger(testSettings, intKey, testValue);

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, intKey));
assertEquals("Proper int value was not read from SharedPreferences", (Integer)getPrefs().getInt(intKey, -1), Integer.valueOf(testValue));
}

@Test
public void testPreferencesLongSetter() {
long testValue = 12345678;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, longKey));

AndroidPreferences.setLong(testSettings, longKey, testValue);

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, longKey));
assertEquals("Proper long value was not read from SharedPreferences", (Long)getPrefs().getLong(longKey, -1), Long.valueOf(testValue));
}

@Test
public void testPreferencesBooleanSetter() {
boolean testValue = true;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, boolKey));

AndroidPreferences.setBoolean(testSettings, boolKey, testValue);

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, boolKey));
assertEquals("Proper boolean value was not read from SharedPreferences", getPrefs().getBoolean(boolKey, false), Boolean.valueOf(testValue));
}

@Test
public void testPreferencesFloatSetter() {
float testValue = 1.2345f;

assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, floatKey));

AndroidPreferences.setFloat(testSettings, floatKey, new Double(testValue));

assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, floatKey));
assertEquals("Proper float value was not read from SharedPreferences", (Float)getPrefs().getFloat(floatKey, Float.NaN), Float.valueOf(testValue));
}

@Test
public void testPreferencesTypeErrors() {
SharedPreferences.Editor editor = getEditor();
editor.putString(stringKey, "testString");
editor.putInt(intKey, 12345);
editor.commit();

assertNull("Type mismatch did not return null", AndroidPreferences.getString(testSettings, intKey));
assertNull("Type mismatch did not return null", AndroidPreferences.getInteger(testSettings, stringKey));
assertNull("Type mismatch did not return null", AndroidPreferences.getLong(testSettings, stringKey));
assertNull("Type mismatch did not return null", AndroidPreferences.getBoolean(testSettings, stringKey));
assertNull("Type mismatch did not return null", AndroidPreferences.getFloat(testSettings, stringKey));
}

@Test
public void testPreferencesRemoveKey() {
SharedPreferences.Editor editor = getEditor();
editor.putString(stringKey, "testString");
editor.commit();

assertTrue("Preferences did not contain test string value", AndroidPreferences.hasKey(testSettings, stringKey));

AndroidPreferences.removeKey(testSettings, stringKey);

assertFalse("Preferences has a key after is was removed", AndroidPreferences.hasKey(testSettings, stringKey));
}

private SharedPreferences getPrefs() {
return InstrumentationRegistry.getTargetContext().getSharedPreferences(testSettings, Context.MODE_PRIVATE);
}

private SharedPreferences.Editor getEditor() {
return InstrumentationRegistry.getTargetContext().getSharedPreferences(testSettings, Context.MODE_PRIVATE).edit();
}

private void deleteKey(String key) {
SharedPreferences prefs = getPrefs();
if(prefs != null) {
if(prefs.contains(key)) {
SharedPreferences.Editor editor = getEditor();
editor.remove(key);
editor.commit();
}
}
}
}

0 comments on commit f3f5042

Please sign in to comment.