diff options
author | Austin Kirk <askirk@umich.edu> | 2017-05-17 13:44:55 -0400 |
---|---|---|
committer | Austin Kirk <askirk@umich.edu> | 2017-05-17 13:44:55 -0400 |
commit | 9a05619df166705582fb744c968fdccefae8ec7a (patch) | |
tree | b7c53ff5348dc252f42afbb1cc94c24446b8386f | |
parent | 0dd722c1fb1b95190e0e4481d6d5fffb7ef6e599 (diff) | |
download | sdl_android-9a05619df166705582fb744c968fdccefae8ec7a.tar.gz |
Add Semaphore to lock/unlock when editing trusted listbugfix/utest_fixRSVTestSynch
-rw-r--r-- | sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java | 83 |
1 files changed, 69 insertions, 14 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 d28dabddc..a6dfe613a 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,6 +8,16 @@ import android.util.Log; import com.smartdevicelink.transport.RouterServiceValidator.TrustedAppStore; import com.smartdevicelink.util.HttpRequestTask.HttpRequestTaskCallback; +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"; @@ -41,6 +42,27 @@ public class RSVTestCase extends AndroidTestCase { 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 +122,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 +132,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 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 +147,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 +162,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 +177,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 +209,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")); @@ -200,9 +240,13 @@ public class RSVTestCase extends AndroidTestCase { builder.append(TEST); } assertTrue(RouterServiceValidator.setTrustedList(mContext,builder.toString())); + + releaseTListLock(); } public void testTrustedListSetAndGet(){ + requestTListLock(); + assertTrue(RouterServiceValidator.setTrustedList(mContext,TEST)); String retVal = RouterServiceValidator.getTrustedList(mContext); assertNotNull(retVal); @@ -216,11 +260,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,6 +312,8 @@ public class RSVTestCase extends AndroidTestCase { static boolean didFinish = false; public void testGetAndCheckList(){ + requestTListLock(); + final Object REQUEST_LOCK = new Object(); didFinish = false; HttpRequestTaskCallback cb = new HttpRequestTaskCallback(){ @@ -276,6 +326,7 @@ public class RSVTestCase extends AndroidTestCase { didFinish = true; REQUEST_LOCK.notify(); } + releaseTListLock(); } @Override public void httpFailure(int statusCode) { @@ -284,6 +335,7 @@ public class RSVTestCase extends AndroidTestCase { didFinish = true; REQUEST_LOCK.notify(); } + releaseTListLock(); } }; @@ -305,6 +357,8 @@ public class RSVTestCase extends AndroidTestCase { * Test to check that we can save our last request which actually houses all the previous known sdl enabled apps */ public void testRequestChange(){ + requestTListLock(); + RouterServiceValidator.setLastRequest(mContext, null); assertNull(RouterServiceValidator.getLastRequest(mContext)); @@ -336,6 +390,7 @@ public class RSVTestCase extends AndroidTestCase { //Clear it for next test RouterServiceValidator.setLastRequest(mContext, null); + releaseTListLock(); } |