aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorScott Mertz <scott@cyngn.com>2016-01-22 14:36:19 -0800
committerAdnan Begovic <adnan@cyngn.com>2016-01-22 16:24:33 -0800
commit62579b157a591b6aa464b28a5cabbffa2c190d8b (patch)
tree26ea94d6cc7c7e1e460ea3c1880234cc76ad2890 /tests
parentfc50f7cef8f55d7589a30ea7e88c1b59f70b0b05 (diff)
downloadvendor_cmsdk-62579b157a591b6aa464b28a5cabbffa2c190d8b.zip
vendor_cmsdk-62579b157a591b6aa464b28a5cabbffa2c190d8b.tar.gz
vendor_cmsdk-62579b157a591b6aa464b28a5cabbffa2c190d8b.tar.bz2
cmsdk: add invalid input checking for persistent storage APIs
Some of this exists in the PersistentStorage implementation, but it was never formally documented in the APIs. Inherit the cmhw implementation error checking & move it into the service. Add tests to validate the new restrictions & a test that was previously failing. Change-Id: I3ecda29fdd28bbc4e6d8ccce7511c4644065ea46
Diffstat (limited to 'tests')
-rw-r--r--tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java b/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
index 7f7b215..10bc390 100644
--- a/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
+++ b/tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java
@@ -35,6 +35,58 @@ public class PersistentStorageTest extends AndroidTestCase {
}
@SmallTest
+ public void testUdidFailure() {
+ String key = "udid";
+ String value = "542bc67e510e82bd6d44e4f7015d7970";
+ assertTrue(mHardwareManager.writePersistentString(key, value));
+ }
+
+ @SmallTest
+ public void testPersistentStringInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ String testString = "IM IN UR STORAGE";
+ String testKeyTooLong = getStringOfLength(65);
+ String testStringTooLong = getStringOfLength(4097);
+
+ assertFalse(mHardwareManager.writePersistentString(null, testString));
+ assertFalse(mHardwareManager.writePersistentString("", testString));
+ assertFalse(mHardwareManager.writePersistentString(testKeyTooLong, testString));
+ assertFalse(mHardwareManager.writePersistentString(testKey, testStringTooLong));
+ assertFalse(mHardwareManager.writePersistentString(testKey, ""));
+ assertNull(mHardwareManager.readPersistentString(testKey));
+ assertNull(mHardwareManager.readPersistentString(testKeyTooLong));
+ }
+
+ @SmallTest
+ public void testPersistentIntInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ String testString = "IM IN UR STORAGE";
+ String testKeyTooLong = getStringOfLength(65);
+
+ assertFalse(mHardwareManager.writePersistentInt(null, 49152));
+ assertFalse(mHardwareManager.writePersistentInt("", 49152));
+ assertFalse(mHardwareManager.writePersistentInt(testKeyTooLong, 49152));
+ assertEquals(0, mHardwareManager.readPersistentInt(testKey));
+ assertEquals(0, mHardwareManager.readPersistentInt(testKeyTooLong));
+ }
+
+ @SmallTest
+ public void testPersistentBytesInvalidInput() {
+ String testKey = UUID.randomUUID().toString();
+ byte[] testArray = new byte[1024];
+ byte[] testArrayTooLong = new byte[4097];
+ String testKeyTooLong = getStringOfLength(65);
+
+ assertFalse(mHardwareManager.writePersistentBytes(null, testArray));
+ assertFalse(mHardwareManager.writePersistentBytes("", testArray));
+ assertFalse(mHardwareManager.writePersistentBytes(testKeyTooLong, testArray));
+ assertFalse(mHardwareManager.writePersistentBytes(testKey, testArrayTooLong));
+ assertFalse(mHardwareManager.writePersistentBytes(testKey, new byte[0]));
+ assertNull(mHardwareManager.readPersistentBytes(testKey));
+ assertNull(mHardwareManager.readPersistentBytes(testKeyTooLong));
+ }
+
+ @SmallTest
public void testPersistentString() {
assertTrue(mHardwareManager.isSupported(CMHardwareManager.FEATURE_PERSISTENT_STORAGE));
@@ -52,6 +104,12 @@ public class PersistentStorageTest extends AndroidTestCase {
// erase + read
assertTrue(mHardwareManager.deletePersistentObject(testKey));
assertNull(mHardwareManager.readPersistentString(testKey));
+
+ // erase through write null
+ assertTrue(mHardwareManager.writePersistentString(testKey, testString + " AGAIN"));
+ assertEquals(testString + " AGAIN", mHardwareManager.readPersistentString(testKey));
+ assertTrue(mHardwareManager.writePersistentString(testKey, null));
+ assertNull(mHardwareManager.readPersistentString(testKey));
}
@SmallTest
@@ -96,5 +154,17 @@ public class PersistentStorageTest extends AndroidTestCase {
// erase + read
assertTrue(mHardwareManager.deletePersistentObject(testKey));
assertNull(mHardwareManager.readPersistentBytes(testKey));
+
+ // erase through write null
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, testArray));
+ assertTrue(Arrays.equals(testArray, mHardwareManager.readPersistentBytes(testKey)));
+ assertTrue(mHardwareManager.writePersistentBytes(testKey, null));
+ assertNull(mHardwareManager.readPersistentBytes(testKey));
+ }
+
+ private String getStringOfLength(int length) {
+ char[] chars = new char[length];
+ Arrays.fill(chars, 'z');
+ return new String(chars);
}
}