summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2013-04-03 20:27:42 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-03 20:27:43 +0000
commit75827d4a3155c190f455329a67c84ac8fbb9bda0 (patch)
treea22326aa9356d0942f1653037fc60cd5e7b9a585 /core/tests
parente0b39fc18c10224c4e66f70aa472d8497b1b4621 (diff)
parent6c918cec31f396bb19597d107856122173c90594 (diff)
downloadframeworks_base-75827d4a3155c190f455329a67c84ac8fbb9bda0.zip
frameworks_base-75827d4a3155c190f455329a67c84ac8fbb9bda0.tar.gz
frameworks_base-75827d4a3155c190f455329a67c84ac8fbb9bda0.tar.bz2
Merge "Add direct API to get ManifestDigest" into jb-mr2-dev
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/coretests/src/android/content/pm/ManifestDigestTest.java67
1 files changed, 27 insertions, 40 deletions
diff --git a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
index cc8c4a6..37495e1 100644
--- a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
+++ b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
@@ -18,64 +18,51 @@ package android.content.pm;
import android.os.Parcel;
import android.test.AndroidTestCase;
-import android.util.Base64;
-import java.util.jar.Attributes;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.MessageDigest;
public class ManifestDigestTest extends AndroidTestCase {
- private static final byte[] DIGEST_1 = {
+ private static final byte[] MESSAGE_1 = {
(byte) 0x00, (byte) 0xAA, (byte) 0x55, (byte) 0xFF
};
- private static final String DIGEST_1_STR = Base64.encodeToString(DIGEST_1, Base64.DEFAULT);
-
- private static final byte[] DIGEST_2 = {
- (byte) 0x0A, (byte) 0xA5, (byte) 0xF0, (byte) 0x5A
- };
-
- private static final String DIGEST_2_STR = Base64.encodeToString(DIGEST_2, Base64.DEFAULT);
-
- private static final Attributes.Name SHA1_DIGEST = new Attributes.Name("SHA1-Digest");
-
- private static final Attributes.Name MD5_DIGEST = new Attributes.Name("MD5-Digest");
-
- public void testManifestDigest_FromAttributes_Null() {
+ public void testManifestDigest_FromInputStream_Null() {
assertNull("Attributes were null, so ManifestDigest.fromAttributes should return null",
- ManifestDigest.fromAttributes(null));
+ ManifestDigest.fromInputStream(null));
}
- public void testManifestDigest_FromAttributes_NoAttributes() {
- Attributes a = new Attributes();
+ public void testManifestDigest_FromInputStream_ThrowsIoException() {
+ InputStream is = new InputStream() {
+ @Override
+ public int read() throws IOException {
+ throw new IOException();
+ }
+ };
- assertNull("There were no attributes to extract, so ManifestDigest should be null",
- ManifestDigest.fromAttributes(a));
+ assertNull("InputStream threw exception, so ManifestDigest should be null",
+ ManifestDigest.fromInputStream(is));
}
- public void testManifestDigest_FromAttributes_SHA1PreferredOverMD5() {
- Attributes a = new Attributes();
- a.put(SHA1_DIGEST, DIGEST_1_STR);
-
- a.put(MD5_DIGEST, DIGEST_2_STR);
-
- ManifestDigest fromAttributes = ManifestDigest.fromAttributes(a);
-
- assertNotNull("A valid ManifestDigest should be returned", fromAttributes);
+ public void testManifestDigest_Equals() throws Exception {
+ InputStream is = new ByteArrayInputStream(MESSAGE_1);
- ManifestDigest created = new ManifestDigest(DIGEST_1);
+ ManifestDigest expected =
+ new ManifestDigest(MessageDigest.getInstance("SHA-256").digest(MESSAGE_1));
- assertEquals("SHA-1 should be preferred over MD5: " + created.toString() + " vs. "
- + fromAttributes.toString(), created, fromAttributes);
+ ManifestDigest actual = ManifestDigest.fromInputStream(is);
+ assertEquals(expected, actual);
- assertEquals("Hash codes should be the same: " + created.toString() + " vs. "
- + fromAttributes.toString(), created.hashCode(), fromAttributes
- .hashCode());
+ ManifestDigest unexpected = new ManifestDigest(new byte[0]);
+ assertFalse(unexpected.equals(actual));
}
- public void testManifestDigest_Parcel() {
- Attributes a = new Attributes();
- a.put(SHA1_DIGEST, DIGEST_1_STR);
+ public void testManifestDigest_Parcel() throws Exception {
+ InputStream is = new ByteArrayInputStream(MESSAGE_1);
- ManifestDigest digest = ManifestDigest.fromAttributes(a);
+ ManifestDigest digest = ManifestDigest.fromInputStream(is);
Parcel p = Parcel.obtain();
digest.writeToParcel(p, 0);