diff options
| author | Joey Grover <joeygrover@gmail.com> | 2017-02-20 16:42:53 -0500 |
|---|---|---|
| committer | Joey Grover <joeygrover@gmail.com> | 2017-02-20 16:42:53 -0500 |
| commit | ee31efeee6fdb94d288ae6940e33b49c7885c499 (patch) | |
| tree | e267499c3bf6ca31bc25772624d5877c8b45c715 | |
| parent | 128bc7ab1d3c479c7e716555d01f4bfaa7e3abff (diff) | |
| download | sdl_android-bugfix/issue_393.tar.gz | |
Adding unit testsbugfix/issue_393
| -rw-r--r-- | sdl_android_tests/src/com/smartdevicelink/test/utl/AndroidToolsTests.java | 32 | ||||
| -rw-r--r-- | sdl_android_tests/src/com/smartdevicelink/transport/LocalRouterServiceTests.java | 142 |
2 files changed, 174 insertions, 0 deletions
diff --git a/sdl_android_tests/src/com/smartdevicelink/test/utl/AndroidToolsTests.java b/sdl_android_tests/src/com/smartdevicelink/test/utl/AndroidToolsTests.java new file mode 100644 index 000000000..e15c95098 --- /dev/null +++ b/sdl_android_tests/src/com/smartdevicelink/test/utl/AndroidToolsTests.java @@ -0,0 +1,32 @@ +package com.smartdevicelink.test.utl; + +import junit.framework.Assert; +import android.content.ComponentName; +import android.test.AndroidTestCase; + +import com.smartdevicelink.util.AndroidTools; + +public class AndroidToolsTests extends AndroidTestCase{ + + + public void testIsServiceExportedNormal(){ + + try{ + AndroidTools.isServiceExported(mContext, new ComponentName(mContext, "test")); + }catch(Exception e){ + Assert.fail("Exception during normal test: " + e.getMessage()); + } + + } + public void testIsServiceExportedNull(){ + + try{ + AndroidTools.isServiceExported(mContext, null); + Assert.fail("Proccessed null data"); + }catch(Exception e){ + + } + + } + +} diff --git a/sdl_android_tests/src/com/smartdevicelink/transport/LocalRouterServiceTests.java b/sdl_android_tests/src/com/smartdevicelink/transport/LocalRouterServiceTests.java new file mode 100644 index 000000000..c918ffa12 --- /dev/null +++ b/sdl_android_tests/src/com/smartdevicelink/transport/LocalRouterServiceTests.java @@ -0,0 +1,142 @@ +package com.smartdevicelink.transport; + +import android.content.ComponentName; +import android.content.Intent; +import android.os.Parcel; +import android.test.AndroidTestCase; + +public class LocalRouterServiceTests extends AndroidTestCase { + + private static final int TEST_WITH_CONSTRUCTOR = 0; + private static final int TEST_WITH_CREATOR = 1; + + + + public void testLocalRouterServiceParcel(){ + Parcel p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + p.writeParcelable(new Intent(), 0); + p.writeParcelable(new ComponentName(mContext, "test"), 0); + p.setDataPosition(0); + + SdlRouterService.LocalRouterService local = new SdlRouterService.LocalRouterService(p); + + assertNotNull(local); + assertEquals(local.version,4); + p.recycle(); + + } + + public void testLocalRouterServiceParcelCreator(){ + Parcel p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + p.writeParcelable(new Intent(), 0); + p.writeParcelable(new ComponentName(mContext, "test"), 0); + p.setDataPosition(0); + + SdlRouterService.LocalRouterService local = SdlRouterService.LocalRouterService.CREATOR.createFromParcel(p); + + assertNotNull(local); + assertEquals(local.version,4); + p.recycle(); + + } + + public SdlRouterService.LocalRouterService getLocalRouterService(int testWith, Parcel p){ + if(testWith == TEST_WITH_CONSTRUCTOR){ + return new SdlRouterService.LocalRouterService(p); + }else{ + return SdlRouterService.LocalRouterService.CREATOR.createFromParcel(p); + } + } + + public void corruptParcel(int testWith){ + Parcel p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + p.writeParcelable(new ComponentName(mContext, "test"), 0); + p.writeParcelable(new Intent(), 0); + p.setDataPosition(0); + + SdlRouterService.LocalRouterService local = getLocalRouterService(testWith, p); + + assertNotNull(local); + assertNull(local.launchIntent); + assertNull(local.name); + + p.recycle(); + //--------------------------------------------------------------------------- + + p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + p.writeParcelable(null,0); + p.writeParcelable(null,0); + p.setDataPosition(0); + + local = getLocalRouterService(testWith, p); + + assertNotNull(local); + assertNull(local.launchIntent); + assertNull(local.name); + + p.recycle(); + //--------------------------------------------------------------------------- + + p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + p.setDataPosition(0); + + local = getLocalRouterService(testWith, p); + + assertNotNull(local); + assertNull(local.launchIntent); + assertNull(local.name); + + p.recycle(); + + //--------------------------------------------------------------------------- + local = null; + p = null; + + p = Parcel.obtain(); + p.writeInt(4); + p.writeLong(System.currentTimeMillis()); + int space = p.dataSize(); + p.writeParcelable(new Intent(), 0); + p.writeParcelable(new ComponentName(mContext, "test"), 0); + p.setDataPosition(0); + + byte[] raw = p.marshall(); + for(;space<raw.length;space++){ + raw[space] = 0x00; + } + p.recycle(); + p = Parcel.obtain(); + p.unmarshall(raw, 0, raw.length); + p.setDataPosition(0); + + + local = getLocalRouterService(testWith, p); + + assertNotNull(local); + assertNull(local.launchIntent); + assertNull(local.name); + + p.recycle(); + + } + + public void testLocalRouterServiceCorruptParcel(){ + corruptParcel(TEST_WITH_CONSTRUCTOR); + } + + public void testLocalRouterServiceCorruptParcelCreator(){ + corruptParcel(TEST_WITH_CREATOR); + } + + +} |
