diff options
Diffstat (limited to 'tests/src')
-rw-r--r-- | tests/src/org/cyanogenmod/tests/hardware/unit/PersistentStorageTest.java | 70 |
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); } } |