use of android.app.backup.BackupDataInput in project android_frameworks_base by crdroidandroid.
the class BackupDataTest method testReadMockData.
public void testReadMockData() throws IOException {
copyAssetToFile("backup_mock.dat", "backup_read_mock_test.dat");
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
BufferedReader truth = new BufferedReader(new InputStreamReader(mAssets.openFd("backup_mock.gld").createInputStream()));
while (bdi.readNextHeader()) {
String[] expected = truth.readLine().split(":");
byte[] expectedBytes = null;
if (expected.length > 1) {
expectedBytes = Base64.decode(expected[1], Base64.DEFAULT);
}
String key = bdi.getKey();
int dataSize = bdi.getDataSize();
assertEquals("wrong key", expected[0], key);
assertEquals("wrong length for key " + key, (expectedBytes == null ? -1 : expectedBytes.length), dataSize);
if (dataSize != -1) {
byte[] buffer = new byte[dataSize];
bdi.readEntityData(buffer, 0, dataSize);
assertEquals("wrong data for key " + key, expected[1], Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));
}
}
assertNull("there are unused entries in the golden file", truth.readLine());
}
use of android.app.backup.BackupDataInput in project android_frameworks_base by crdroidandroid.
the class BackupDataTest method testMixed.
public void testMixed() throws IOException {
mFile = new File(mDirectory, "backup_mixed_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
int i = 0;
deleteEntity(bdo, KEYS[i]);
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
deleteEntity(bdo, KEYS[i]);
i++;
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int out = 0;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertFalse("four items in this stream", bdi.readNextHeader());
}
Aggregations