Search in sources :

Example 26 with BackupDataInput

use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.

the class BackupDataTest method testReadRealData.

public void testReadRealData() throws IOException {
    copyAssetToFile("backup_real.dat", "backup_read_real_test.dat");
    openForReading();
    BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
    BufferedReader truth = new BufferedReader(new InputStreamReader(mAssets.openFd("backup_real.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());
}
Also used : BackupDataInput(android.app.backup.BackupDataInput) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 27 with BackupDataInput

use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.

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());
}
Also used : BackupDataInput(android.app.backup.BackupDataInput) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 28 with BackupDataInput

use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.

the class BackupDataTest method testDelete.

public void testDelete() throws IOException {
    mFile = new File(mDirectory, "backup_delete_test.dat");
    openForWriting();
    BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
    for (int i = 0; i < KEYS.length; i++) {
        deleteEntity(bdo, KEYS[i]);
    }
    mDataFile.close();
    openForReading();
    BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
    int count = 0;
    while (bdi.readNextHeader()) {
        readAndVerifyDeletedEntity(bdi, KEYS[count]);
        count++;
    }
    assertEquals("four deletes in this stream", KEYS.length, count);
}
Also used : BackupDataInput(android.app.backup.BackupDataInput) File(java.io.File) BackupDataOutput(android.app.backup.BackupDataOutput)

Example 29 with BackupDataInput

use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.

the class BackupDataTest method testMultiple.

public void testMultiple() throws IOException {
    mFile = new File(mDirectory, "backup_multiple_test.dat");
    openForWriting();
    BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
    for (int i = 0; i < KEYS.length; i++) {
        writeEntity(bdo, KEYS[i], DATA[i].getBytes());
    }
    mDataFile.close();
    openForReading();
    BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
    int count = 0;
    while (bdi.readNextHeader()) {
        readAndVerifyEntity(bdi, KEYS[count], DATA[count].getBytes());
        count++;
    }
    assertEquals("four entities in this stream", KEYS.length, count);
}
Also used : BackupDataInput(android.app.backup.BackupDataInput) File(java.io.File) BackupDataOutput(android.app.backup.BackupDataOutput)

Example 30 with BackupDataInput

use of android.app.backup.BackupDataInput in project android_frameworks_base by ResurrectionRemix.

the class BackupDataTest method testReadRealData.

public void testReadRealData() throws IOException {
    copyAssetToFile("backup_real.dat", "backup_read_real_test.dat");
    openForReading();
    BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
    BufferedReader truth = new BufferedReader(new InputStreamReader(mAssets.openFd("backup_real.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());
}
Also used : BackupDataInput(android.app.backup.BackupDataInput) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Aggregations

BackupDataInput (android.app.backup.BackupDataInput)37 File (java.io.File)27 BackupDataOutput (android.app.backup.BackupDataOutput)20 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 FileOutputStream (java.io.FileOutputStream)7 IOException (java.io.IOException)7 ErrnoException (android.system.ErrnoException)5 StructStat (android.system.StructStat)5