diff options
author | Kenny Root <kroot@google.com> | 2011-09-13 17:51:08 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-09-13 17:51:08 -0700 |
commit | c924fbd6933f6a96588b6e78d385082155cfd236 (patch) | |
tree | 1b5669c99d9e2bbf07dfcbe3a7be38591fe3e28d /core/tests | |
parent | 3f0c821740305c352eb355ba3d72906a7a97751c (diff) | |
parent | 0aaa0d931716e9f57a1d84d795fab2df75092756 (diff) | |
download | frameworks_base-c924fbd6933f6a96588b6e78d385082155cfd236.zip frameworks_base-c924fbd6933f6a96588b6e78d385082155cfd236.tar.gz frameworks_base-c924fbd6933f6a96588b6e78d385082155cfd236.tar.bz2 |
Merge "Add verifier device identity"
Diffstat (limited to 'core/tests')
4 files changed, 243 insertions, 0 deletions
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 146466f..cadc895 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -88,6 +88,7 @@ <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.DELETE_PACKAGES" /> <uses-permission android:name="android.permission.MOVE_PACKAGE" /> + <uses-permission android:name="android.permission.PACKAGE_VERIFICATION_AGENT" /> <!--os storage test permissions --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> diff --git a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java index 8922f27..cc8c4a6 100644 --- a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java +++ b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package android.content.pm; import android.os.Parcel; diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java index 68ddcc4..9575ced 100755 --- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java +++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java @@ -42,6 +42,7 @@ import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.SmallTest; import android.util.DisplayMetrics; import android.util.Log; @@ -3121,6 +3122,14 @@ public class PackageManagerTests extends AndroidTestCase { invokeInstallPackageFail(Uri.fromFile(invalidFile), 0, retCode); } + @SmallTest + public void testGetVerifierDeviceIdentity() { + PackageManager pm = getPm(); + VerifierDeviceIdentity id = pm.getVerifierDeviceIdentity(); + + assertNotNull("Verifier device identity should not be null", id); + } + /*---------- Recommended install location tests ----*/ /* * TODO's diff --git a/core/tests/coretests/src/android/content/pm/VerifierDeviceIdentityTest.java b/core/tests/coretests/src/android/content/pm/VerifierDeviceIdentityTest.java new file mode 100644 index 0000000..e6a6a26 --- /dev/null +++ b/core/tests/coretests/src/android/content/pm/VerifierDeviceIdentityTest.java @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.pm; + +import android.os.Parcel; + +import java.util.Random; + +public class VerifierDeviceIdentityTest extends android.test.AndroidTestCase { + private static final long TEST_1 = 0x7A5F00FF5A55AAA5L; + + private static final String TEST_1_ENCODED = "HUXY-A75N-FLKV-F"; + + private static final long TEST_2 = 0x5A05FF5A05F0A555L; + + private static final long TEST_MAXVALUE = Long.MAX_VALUE; + + private static final String TEST_MAXVALUE_ENCODED = "H777-7777-7777-7"; + + private static final long TEST_MINVALUE = Long.MIN_VALUE; + + private static final String TEST_MINVALUE_ENCODED = "IAAA-AAAA-AAAA-A"; + + private static final long TEST_ZERO = 0L; + + private static final String TEST_ZERO_ENCODED = "AAAA-AAAA-AAAA-A"; + + private static final long TEST_NEGONE = -1L; + + private static final String TEST_NEGONE_ENCODED = "P777-7777-7777-7"; + + private static final String TEST_OVERFLOW_ENCODED = "QAAA-AAAA-AAAA-A"; + + public void testVerifierDeviceIdentity_Equals_Success() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + VerifierDeviceIdentity id2 = new VerifierDeviceIdentity(TEST_1); + + assertTrue("The two VerifierDeviceIdentity instances should be equal", id1.equals(id2)); + } + + public void testVerifierDeviceIdentity_Equals_Failure() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + VerifierDeviceIdentity id2 = new VerifierDeviceIdentity(TEST_2); + + assertFalse("The two VerifierDeviceIdentity instances should be unique", id1.equals(id2)); + } + + public void testVerifierDeviceIdentity_HashCode() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + + assertEquals("The VerifierDeviceIdentity should have the same hashcode as its identity", + (int) TEST_1, id1.hashCode()); + } + + public void testVerifierDeviceIdentity_ToString_Success() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + + assertEquals("The identity should encode correctly to the expected Base 32 string", + TEST_1_ENCODED, id1.toString()); + } + + public void testVerifierDeviceIdentity_ToString_Largest() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MAXVALUE); + + assertEquals("The identity should encode correctly to the expected Base 32 string", + TEST_MAXVALUE_ENCODED, id1.toString()); + } + + public void testVerifierDeviceIdentity_ToString_Zero() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_ZERO); + + assertEquals("The identity should encode correctly to the expected Base 32 string", + TEST_ZERO_ENCODED, id1.toString()); + } + + public void testVerifierDeviceIdentity_ToString_NegOne() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_NEGONE); + + assertEquals("The identity should encode correctly to the expected Base 32 string", + TEST_NEGONE_ENCODED, id1.toString()); + } + + public void testVerifierDeviceIdentity_ToString_MinValue() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE); + + assertEquals("The identity should encode correctly to the expected Base 32 string", + TEST_MINVALUE_ENCODED, id1.toString()); + } + + public void testVerifierDeviceIdentity_Parcel_ReadNegative() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE); + + Parcel parcel = Parcel.obtain(); + parcel.writeLong(TEST_MINVALUE); + parcel.setDataPosition(0); + + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.CREATOR.createFromParcel(parcel); + + assertEquals("Parcel created should match expected value", id1, id2); + } + + public void testVerifierDeviceIdentity_Parcel_Read_Pass() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + + Parcel parcel = Parcel.obtain(); + id1.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.CREATOR.createFromParcel(parcel); + + assertEquals("Original identity and parceled identity should be the same", id1, id2); + } + + private static class MockRandom extends Random { + private long mNextLong; + + public MockRandom() { + } + + public void setNextLong(long nextLong) { + mNextLong = nextLong; + } + + @Override + public long nextLong() { + return mNextLong; + } + } + + public void testVerifierDeviceIdentity_Generate_MinValue() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE); + + MockRandom random = new MockRandom(); + random.setNextLong(Long.MIN_VALUE); + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.generate(random); + + assertEquals("Identity created from Long.MIN_VALUE and one created from return from RNG" + + " should be the same", id1, id2); + } + + public void testVerifierDeviceIdentity_Generate_Random() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + + MockRandom random = new MockRandom(); + random.setNextLong(TEST_1); + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.generate(random); + + assertEquals("Identity should end up being same when coming from RNG", id1, id2); + } + + public void testVerifierDeviceIdentity_Parse_Normal() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1); + + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_1_ENCODED); + + assertEquals("Parsed device identity should have the same value as original identity", + id1, id2); + } + + public void testVerifierDeviceIdentity_Parse_MaxValue() { + VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MAXVALUE); + + VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_MAXVALUE_ENCODED); + + assertEquals("Original max value and parsed max value should be equal", id1, id2); + } + + public void testVerifierDeviceIdentity_Parse_TooShort() { + try { + VerifierDeviceIdentity id = VerifierDeviceIdentity.parse("AAAA-AAAA-AAAA-"); + fail("Parsing should fail when device identifier is too short"); + } catch (IllegalArgumentException e) { + // success + } + } + + public void testVerifierDeviceIdentity_Parse_WayTooShort() { + try { + VerifierDeviceIdentity id = VerifierDeviceIdentity.parse("----------------"); + fail("Parsing should fail when device identifier is too short"); + } catch (IllegalArgumentException e) { + // success + } + } + + public void testVerifierDeviceIdentity_Parse_TooLong() { + try { + VerifierDeviceIdentity id = VerifierDeviceIdentity.parse("AAAA-AAAA-AAAA-AA"); + fail("Parsing should fail when device identifier is too long"); + } catch (IllegalArgumentException e) { + // success + } + } + + public void testVerifierDeviceIdentity_Parse_Overflow() { + try { + VerifierDeviceIdentity id = VerifierDeviceIdentity.parse(TEST_OVERFLOW_ENCODED); + fail("Parsing should fail when the value will overflow"); + } catch (IllegalArgumentException e) { + // success + } + } +} |