summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Kirk <askirk@umich.edu>2017-05-17 13:26:22 -0400
committerAustin Kirk <askirk@umich.edu>2017-05-17 13:26:22 -0400
commitee79bd8c7d7b0aef852ba6b695f63c11aecbdb2d (patch)
treea6ea37fc946016e7f9c51d65ebeaf141d94d2929
parentae8a31b9356e0c4ccf6182251ff3a364c79dcf6e (diff)
downloadsdl_android-bugfix/utest_Mime.tar.gz
Using Semaphore to lock when manipulating trusted listbugfix/utest_Mime
-rw-r--r--sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java101
1 files changed, 77 insertions, 24 deletions
diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java b/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
index 03abbc7f4..2496e9cd9 100644
--- a/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
+++ b/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
@@ -1,14 +1,5 @@
package com.smartdevicelink.transport;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.test.AndroidTestCase;
@@ -17,7 +8,17 @@ import android.util.Log;
import com.smartdevicelink.transport.RouterServiceValidator.TrustedAppStore;
import com.smartdevicelink.util.HttpRequestTask.HttpRequestTaskCallback;
-public class RSVTestCase extends AndroidTestCase {
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.concurrent.Semaphore;
+
+public class RSVTestCase extends AndroidTestCase{
private static final String TAG = "RSVTestCase";
private static final long REFRESH_TRUSTED_APP_LIST_TIME_DAY = 3600000 * 24; // A day in ms
@@ -34,13 +35,33 @@ public class RSVTestCase extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
rsvp = new RouterServiceValidator(this.mContext);
-
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
+
+ private static final Semaphore TRUSTED_LIST_LOCK = new Semaphore(1);
+
+ private void requestTListLock(){
+ try {
+ TRUSTED_LIST_LOCK.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void releaseTListLock(){
+ TRUSTED_LIST_LOCK.release();
+ }
+
+ private RouterServiceValidator.TrustedListCallback trustedListCallback = new RouterServiceValidator.TrustedListCallback(){
+ @Override
+ public void onListObtained(boolean successful) {
+ releaseTListLock();
+ }
+ };
/*
* These tests are a little strange because they don't test the logic behind the validation of each piece.
@@ -100,6 +121,8 @@ public class RSVTestCase extends AndroidTestCase {
}
public void testHighSecurity(){
+ requestTListLock();
+
RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -108,11 +131,12 @@ public class RSVTestCase extends AndroidTestCase {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, null));
-
+ assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
}
public void testMediumSecurity(){
+ requestTListLock();
+
RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_MED);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -121,11 +145,13 @@ public class RSVTestCase extends AndroidTestCase {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, null));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
}
public void testLowSecurity(){
+ requestTListLock();
+
RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_LOW);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -134,11 +160,13 @@ public class RSVTestCase extends AndroidTestCase {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_MONTH);
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, null));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
}
public void testNoSecurity(){
+ requestTListLock();
+
RouterServiceValidator rsvp = new RouterServiceValidator(this.mContext); //Use a locally scoped instance
rsvp.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
rsvp.setFlags(RouterServiceValidator.FLAG_DEBUG_INSTALLED_FROM_CHECK);
@@ -147,7 +175,7 @@ public class RSVTestCase extends AndroidTestCase {
assertEquals(RouterServiceValidator.getRefreshRate(), REFRESH_TRUSTED_APP_LIST_TIME_WEEK);
- assertFalse(RouterServiceValidator.createTrustedListRequest(mContext, true, null, null));
+ assertFalse(RouterServiceValidator.createTrustedListRequest(mContext, true, null, trustedListCallback));
//This should always return true
assertTrue(rsvp.validate());
@@ -179,16 +207,26 @@ public class RSVTestCase extends AndroidTestCase {
}
public void testInvalidateList(){
+ requestTListLock();
+
assertFalse(RouterServiceValidator.invalidateList(null));
assertTrue(RouterServiceValidator.invalidateList(mContext));
+
+ releaseTListLock();
}
public void testGetTrustedList(){
+ requestTListLock();
+
assertNull(RouterServiceValidator.getTrustedList(null));
assertNotNull(RouterServiceValidator.getTrustedList(mContext));
+
+ releaseTListLock();
}
public void testSetTrustedList(){
+ requestTListLock();
+
assertFalse(RouterServiceValidator.setTrustedList(null,null));
assertFalse(RouterServiceValidator.setTrustedList(mContext,null));
assertFalse(RouterServiceValidator.setTrustedList(null,"test"));
@@ -201,9 +239,13 @@ public class RSVTestCase extends AndroidTestCase {
builder.append(test);
}
assertTrue(RouterServiceValidator.setTrustedList(mContext,builder.toString()));
+
+ releaseTListLock();
}
public void testTrustedListSetAndGet(){
+ requestTListLock();
+
String test = "{\"response\": {\"com.livio.sdl\" : { \"versionBlacklist\":[] }, \"com.lexus.tcapp\" : { \"versionBlacklist\":[] }, \"com.toyota.tcapp\" : { \"versionBlacklist\": [] } , \"com.sdl.router\":{\"versionBlacklist\": [] },\"com.ford.fordpass\" : { \"versionBlacklist\":[] } }}";
assertTrue(RouterServiceValidator.setTrustedList(mContext,test));
String retVal = RouterServiceValidator.getTrustedList(mContext);
@@ -219,11 +261,15 @@ public class RSVTestCase extends AndroidTestCase {
retVal = RouterServiceValidator.getTrustedList(mContext);
assertNotNull(retVal);
assertTrue(builder.toString().equals(retVal));
+
+ releaseTListLock();
}
public void testInvalidationSequence(){
+ requestTListLock();
+
assertTrue(RouterServiceValidator.invalidateList(mContext));
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext,false));
+ assertTrue(RouterServiceValidator.createTrustedListRequest(mContext, false, null, trustedListCallback));
}
public void testAppStorePackages(){
@@ -264,13 +310,15 @@ public class RSVTestCase extends AndroidTestCase {
assertFalse(rsvp.verifyVersion(-3, array));
}
-
+
static boolean didFinish = false;
public void testGetAndCheckList(){
+ requestTListLock();
+
final Object REQUEST_LOCK = new Object();
didFinish = false;
HttpRequestTaskCallback cb = new HttpRequestTaskCallback(){
-
+
@Override
public void httpCallComplete(String response) {
//Might want to check if this list is ok
@@ -279,6 +327,7 @@ public class RSVTestCase extends AndroidTestCase {
didFinish = true;
REQUEST_LOCK.notify();
}
+ releaseTListLock();
}
@Override
public void httpFailure(int statusCode) {
@@ -287,10 +336,11 @@ public class RSVTestCase extends AndroidTestCase {
didFinish = true;
REQUEST_LOCK.notify();
}
+ releaseTListLock();
}
};
-
- assertTrue(RouterServiceValidator.createTrustedListRequest(mContext,true, cb));
+
+ assertTrue(RouterServiceValidator.createTrustedListRequest(mContext,true, cb, trustedListCallback));
//Now wait for call to finish
synchronized(REQUEST_LOCK){
try {
@@ -300,15 +350,17 @@ public class RSVTestCase extends AndroidTestCase {
e.printStackTrace();
}
}
-
-
+
+
}
/**
* Test to check that we can save our last request which actually houses all the previous known sdl enabled apps
*/
public void testRequestChange(){
- RouterServiceValidator.setLastRequest(mContext, null);
+ requestTListLock();
+
+ assertTrue(RouterServiceValidator.setLastRequest(mContext, null));
assertNull(RouterServiceValidator.getLastRequest(mContext));
String test = "{\"response\": {\"com.livio.sdl\" : { \"versionBlacklist\":[] }, \"com.lexus.tcapp\" : { \"versionBlacklist\":[] }, \"com.toyota.tcapp\" : { \"versionBlacklist\": [] } , \"com.sdl.router\":{\"versionBlacklist\": [] },\"com.ford.fordpass\" : { \"versionBlacklist\":[] } }}";
JSONObject object = null;
@@ -339,6 +391,7 @@ public class RSVTestCase extends AndroidTestCase {
//Clear it for next test
RouterServiceValidator.setLastRequest(mContext, null);
+ releaseTListLock();
}