Skip to content

Commit f3f5042

Browse files
author
Unity Ads Travis
committed
Release 2.2.0
1 parent 1cfae31 commit f3f5042

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3252
-76
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.unity3d.ads.example"
99
minSdkVersion 9
1010
targetSdkVersion 23
11-
versionCode = 2102
12-
versionName = "2.1.2"
11+
versionCode = 2200
12+
versionName = "2.2.0"
1313
}
1414
buildTypes {
1515
release {

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<application
66
android:allowBackup="true"
77
android:icon="@mipmap/ic_launcher"
8-
android:label="UnityAds 2.1"
8+
android:label="UnityAds 2.2"
99
android:theme="@style/AppTheme" >
1010
<activity
1111
android:name="com.unity3d.ads.example.UnityAdsExample"
1212
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
13-
android:label="UnityAds 2.1" >
13+
android:label="UnityAds 2.2" >
1414
<intent-filter>
1515
<action android:name="android.intent.action.MAIN" />
1616
<category android:name="android.intent.category.LAUNCHER" />

lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
defaultConfig {
1212
minSdkVersion 9
1313
targetSdkVersion 23
14-
versionCode = 2102
15-
versionName = "2.1.2"
14+
versionCode = 2200
15+
versionName = "2.2.0"
1616

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

lib/src/androidTest/java/com/unity3d/ads/test/UnitTestSuite.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
WebViewCallbackTest.class,
3838
LifecycleListenerTest.class,
3939
VolumeChangeTest.class,
40-
UtilitiesTest.class
40+
UtilitiesTest.class,
41+
WebPlayerTest.class,
42+
PreferencesTest.class
4143
})
44+
4245
public class UnitTestSuite {}

lib/src/androidTest/java/com/unity3d/ads/test/hybrid/HybridTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ public void run() {
7373
com.unity3d.ads.api.VideoPlayer.class,
7474
com.unity3d.ads.api.Placement.class,
7575
com.unity3d.ads.api.Intent.class,
76+
com.unity3d.ads.api.WebPlayer.class,
7677
com.unity3d.ads.test.hybrid.HybridTest.class,
78+
com.unity3d.ads.api.Lifecycle.class,
79+
com.unity3d.ads.api.Preferences.class,
80+
com.unity3d.ads.api.Purchasing.class,
81+
com.unity3d.ads.api.SensorInfo.class,
82+
com.unity3d.ads.test.hybrid.HybridTest.class
7783
};
7884

7985
configuration.setWebAppApiClassList(apiClassList);
8086
InitializeThread.initialize(configuration);
8187

82-
if(!_resultSemaphore.tryAcquire(5, TimeUnit.MINUTES)) {
88+
if(!_resultSemaphore.tryAcquire(10, TimeUnit.MINUTES)) {
8389
fail("onHybridTestResult did not arrive");
8490
}
8591

lib/src/androidTest/java/com/unity3d/ads/test/unit/CacheTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void eventCache(CacheEvent eventId, Object... params) {
186186

187187
Invocation invocation = new Invocation();
188188
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
189-
Cache.download(REMOTE_IMG, REMOTE_IMG_FILE_ID, new JSONArray(), callback);
189+
Cache.download(REMOTE_IMG, REMOTE_IMG_FILE_ID, new JSONArray(), false, callback);
190190
invocation.sendInvocationCallback();
191191

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

374374
@Test
375-
public void testStopResumeDownload() {
375+
public void testStopResumeDownload() throws Exception {
376376
final long minDownloadBytes = 12345;
377377
final ConditionVariable cacheCv = new ConditionVariable();
378378
final ConditionVariable cacheCv2 = new ConditionVariable();
@@ -443,7 +443,7 @@ public void eventCache(CacheEvent eventId, Object... params) {
443443
Invocation invocation = new Invocation();
444444
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
445445
CacheThread.setProgressInterval(2);
446-
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray(), callback);
446+
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, new JSONArray(), false, callback);
447447
invocation.sendInvocationCallback();
448448

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

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

511511
boolean success2 = cacheCv2.block(30000);

lib/src/androidTest/java/com/unity3d/ads/test/unit/DeviceTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public void testScreenBrightness () throws Exception {
149149
assertTrue("Screen brightness should be equal or more than 0", Device.getScreenBrightness() >= 0);
150150
}
151151

152+
@Test
153+
public void testGetAdbStatus () throws Exception {
154+
assertTrue("Adb status should be true", Device.isAdbEnabled());
155+
}
156+
152157
@Test
153158
public void testGetGLVersion () throws Exception {
154159
assertNotNull("GLES version should not be null", Device.getGLVersion());
@@ -184,11 +189,52 @@ public void testGetProduct () throws Exception {
184189
assertNotNull("Product should not be null", Device.getProduct());
185190
}
186191

192+
@Test
193+
public void testGetFingerprint () throws Exception {
194+
assertNotNull("Fingerprint should not be null", Device.getFingerprint());
195+
}
196+
197+
@Test
198+
public void testGetApkDigest () throws Exception {
199+
assertNotNull("Host should not be null", Device.getApkDigest());
200+
}
201+
202+
@Test
203+
public void testGetCertificateFingerprint () throws Exception {
204+
assertNotNull("Certificate fingerprint should not be null", Device.getCertificateFingerprint());
205+
}
206+
187207
@Test
188208
public void testGetSupportedAbis () throws Exception {
189209
ArrayList<String> supportedAbis = Device.getSupportedAbis();
190210

191211
assertNotNull("List of supported abis should not be null", supportedAbis);
192212
assertTrue("Number of supported abis should be larger than 0", supportedAbis.size() > 0);
193213
}
214+
215+
@Test
216+
public void testGetProcessInfo () throws Exception {
217+
Map<String, String> data = Device.getProcessInfo();
218+
219+
assertNotNull("Stats should not be null", data.get("stat"));
220+
assertNotEquals("Stats should not be empty", data.get("stat"), "");
221+
222+
assertNotNull("Uptime should not be null", data.get("uptime"));
223+
assertNotEquals("Uptime should not be empty", data.get("uptime"), "");
224+
}
225+
226+
@Test
227+
public void testGetCPUCount() {
228+
assertTrue("Number of CPUs should be greater than 0", Device.getCPUCount() > 0);
229+
}
230+
231+
@Test
232+
public void testGetUptime() {
233+
assertTrue("Uptime should be greater than 0", Device.getUptime() > 0);
234+
}
235+
236+
@Test
237+
public void testGetElapsedRealtime() {
238+
assertTrue("Elapsed realtime should be greater than 0", Device.getElapsedRealtime() > 0);
239+
}
194240
}
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package com.unity3d.ads.test.unit;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.support.test.InstrumentationRegistry;
6+
import android.support.test.runner.AndroidJUnit4;
7+
8+
import com.unity3d.ads.preferences.AndroidPreferences;
9+
import com.unity3d.ads.properties.ClientProperties;
10+
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertFalse;
17+
import static org.junit.Assert.assertNull;
18+
import static org.junit.Assert.assertTrue;
19+
20+
@RunWith(AndroidJUnit4.class)
21+
public class PreferencesTest {
22+
String testSettings = "unity.test.preferences";
23+
String nonExistingSettings = "unity.test.does.not.exist";
24+
String stringKey = "test.string";
25+
String intKey = "test.int";
26+
String longKey = "test.long";
27+
String boolKey = "test.boolean";
28+
String floatKey = "test.float";
29+
String nonExistingKey = "non.existing.key";
30+
31+
@Before
32+
public void setup() {
33+
ClientProperties.setApplicationContext(InstrumentationRegistry.getTargetContext());
34+
35+
deleteKey(stringKey);
36+
deleteKey(intKey);
37+
deleteKey(longKey);
38+
deleteKey(boolKey);
39+
deleteKey(floatKey);
40+
}
41+
42+
@Test
43+
public void testPreferencesStringGetter() {
44+
String testValue = "testString";
45+
46+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, stringKey));
47+
48+
SharedPreferences.Editor editor = getEditor();
49+
editor.putString(stringKey, testValue);
50+
editor.commit();
51+
52+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, stringKey));
53+
assertEquals("Proper string value was not read from SharedPreferences", AndroidPreferences.getString(testSettings, stringKey), testValue);
54+
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getString(testSettings, nonExistingKey));
55+
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getString(nonExistingSettings, stringKey));
56+
}
57+
58+
@Test
59+
public void testPreferencesIntGetter() {
60+
int testValue = 12345;
61+
62+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, intKey));
63+
64+
SharedPreferences.Editor editor = getEditor();
65+
editor.putInt(intKey, testValue);
66+
editor.commit();
67+
68+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, intKey));
69+
assertEquals("Proper int value was not read from SharedPreferences", AndroidPreferences.getInteger(testSettings, intKey), Integer.valueOf(testValue));
70+
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getInteger(testSettings, nonExistingKey));
71+
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getInteger(nonExistingSettings, intKey));
72+
}
73+
74+
@Test
75+
public void testPreferencesLongGetter() {
76+
long testValue = 12345678;
77+
78+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, longKey));
79+
80+
SharedPreferences.Editor editor = getEditor();
81+
editor.putLong(longKey, testValue);
82+
editor.commit();
83+
84+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, longKey));
85+
assertEquals("Proper long value was not read from SharedPreferences", AndroidPreferences.getLong(testSettings, longKey), Long.valueOf(testValue));
86+
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getLong(testSettings, nonExistingKey));
87+
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getLong(nonExistingSettings, longKey));
88+
}
89+
90+
@Test
91+
public void testPreferencesBooleanGetter() {
92+
boolean testValue = true;
93+
94+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, boolKey));
95+
96+
SharedPreferences.Editor editor = getEditor();
97+
editor.putBoolean(boolKey, testValue);
98+
editor.commit();
99+
100+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, boolKey));
101+
assertEquals("Proper boolean value was not read from SharedPreferences", AndroidPreferences.getBoolean(testSettings, boolKey), Boolean.valueOf(testValue));
102+
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getBoolean(testSettings, nonExistingKey));
103+
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getBoolean(nonExistingSettings, boolKey));
104+
}
105+
106+
@Test
107+
public void testPreferencesFloatGetter() {
108+
float testValue = 1.2345f;
109+
110+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, floatKey));
111+
112+
SharedPreferences.Editor editor = getEditor();
113+
editor.putFloat(floatKey, testValue);
114+
editor.commit();
115+
116+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, floatKey));
117+
assertEquals("Proper float value was not read from SharedPreferences", AndroidPreferences.getFloat(testSettings, floatKey), Float.valueOf(testValue));
118+
assertNull("Non-null value returned for a non-existing key", AndroidPreferences.getFloat(testSettings, nonExistingKey));
119+
assertNull("Non-null value returned for a non-existing settings", AndroidPreferences.getFloat(nonExistingSettings, floatKey));
120+
}
121+
122+
@Test
123+
public void testPreferencesStringSetter() {
124+
String testValue = "testString";
125+
126+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, stringKey));
127+
128+
AndroidPreferences.setString(testSettings, stringKey, testValue);
129+
130+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, stringKey));
131+
assertEquals("Proper string value was not read from SharedPreferences", getPrefs().getString(stringKey, ""), testValue);
132+
}
133+
134+
@Test
135+
public void testPreferencesIntSetter() {
136+
int testValue = 12345;
137+
138+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, intKey));
139+
140+
AndroidPreferences.setInteger(testSettings, intKey, testValue);
141+
142+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, intKey));
143+
assertEquals("Proper int value was not read from SharedPreferences", (Integer)getPrefs().getInt(intKey, -1), Integer.valueOf(testValue));
144+
}
145+
146+
@Test
147+
public void testPreferencesLongSetter() {
148+
long testValue = 12345678;
149+
150+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, longKey));
151+
152+
AndroidPreferences.setLong(testSettings, longKey, testValue);
153+
154+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, longKey));
155+
assertEquals("Proper long value was not read from SharedPreferences", (Long)getPrefs().getLong(longKey, -1), Long.valueOf(testValue));
156+
}
157+
158+
@Test
159+
public void testPreferencesBooleanSetter() {
160+
boolean testValue = true;
161+
162+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, boolKey));
163+
164+
AndroidPreferences.setBoolean(testSettings, boolKey, testValue);
165+
166+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, boolKey));
167+
assertEquals("Proper boolean value was not read from SharedPreferences", getPrefs().getBoolean(boolKey, false), Boolean.valueOf(testValue));
168+
}
169+
170+
@Test
171+
public void testPreferencesFloatSetter() {
172+
float testValue = 1.2345f;
173+
174+
assertFalse("Preferences contained a key before key was written", AndroidPreferences.hasKey(testSettings, floatKey));
175+
176+
AndroidPreferences.setFloat(testSettings, floatKey, new Double(testValue));
177+
178+
assertTrue("Preferences did not contain previously committed value", AndroidPreferences.hasKey(testSettings, floatKey));
179+
assertEquals("Proper float value was not read from SharedPreferences", (Float)getPrefs().getFloat(floatKey, Float.NaN), Float.valueOf(testValue));
180+
}
181+
182+
@Test
183+
public void testPreferencesTypeErrors() {
184+
SharedPreferences.Editor editor = getEditor();
185+
editor.putString(stringKey, "testString");
186+
editor.putInt(intKey, 12345);
187+
editor.commit();
188+
189+
assertNull("Type mismatch did not return null", AndroidPreferences.getString(testSettings, intKey));
190+
assertNull("Type mismatch did not return null", AndroidPreferences.getInteger(testSettings, stringKey));
191+
assertNull("Type mismatch did not return null", AndroidPreferences.getLong(testSettings, stringKey));
192+
assertNull("Type mismatch did not return null", AndroidPreferences.getBoolean(testSettings, stringKey));
193+
assertNull("Type mismatch did not return null", AndroidPreferences.getFloat(testSettings, stringKey));
194+
}
195+
196+
@Test
197+
public void testPreferencesRemoveKey() {
198+
SharedPreferences.Editor editor = getEditor();
199+
editor.putString(stringKey, "testString");
200+
editor.commit();
201+
202+
assertTrue("Preferences did not contain test string value", AndroidPreferences.hasKey(testSettings, stringKey));
203+
204+
AndroidPreferences.removeKey(testSettings, stringKey);
205+
206+
assertFalse("Preferences has a key after is was removed", AndroidPreferences.hasKey(testSettings, stringKey));
207+
}
208+
209+
private SharedPreferences getPrefs() {
210+
return InstrumentationRegistry.getTargetContext().getSharedPreferences(testSettings, Context.MODE_PRIVATE);
211+
}
212+
213+
private SharedPreferences.Editor getEditor() {
214+
return InstrumentationRegistry.getTargetContext().getSharedPreferences(testSettings, Context.MODE_PRIVATE).edit();
215+
}
216+
217+
private void deleteKey(String key) {
218+
SharedPreferences prefs = getPrefs();
219+
if(prefs != null) {
220+
if(prefs.contains(key)) {
221+
SharedPreferences.Editor editor = getEditor();
222+
editor.remove(key);
223+
editor.commit();
224+
}
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)