FileDocCategorySizeDatePackage
MemoryFileProviderTest.javaAPI DocAndroid 5.1 API3251Thu Mar 12 22:22:12 GMT 2015android.content

MemoryFileProviderTest

public class MemoryFileProviderTest extends android.test.AndroidTestCase
Tests reading a MemoryFile-based AssestFile from a ContentProvider running in a different process.

Fields Summary
Constructors Summary
Methods Summary
public voidtestClose()

        ContentResolver resolver = getContext().getContentResolver();
        // open enough file descriptors that we will crash something if we leak FDs
        // or address space
        for (int i = 0; i < 1025; i++) {
            Uri uri = Uri.parse("content://android.content.MemoryFileProvider/huge");
            InputStream in = resolver.openInputStream(uri);
            assertNotNull("Failed to open stream number " + i, in);
            byte[] buf = new byte[MemoryFileProvider.TEST_BLOB.length];
            int count = in.read(buf);
            assertEquals(buf.length, count);
            assertTrue(Arrays.equals(MemoryFileProvider.TEST_BLOB, buf));
            in.close();
        }
    
public voidtestFile()

        ContentResolver resolver = getContext().getContentResolver();
        Uri uri = Uri.parse("content://android.content.MemoryFileProvider/file");
        byte[] buf = new byte[MemoryFileProvider.TEST_BLOB.length];
        InputStream in = resolver.openInputStream(uri);
        assertNotNull(in);
        int count = in.read(buf);
        assertEquals(buf.length, count);
        assertEquals(-1, in.read());
        in.close();
        assertTrue(Arrays.equals(MemoryFileProvider.TEST_BLOB, buf));
    
public voidtestRead()

        ContentResolver resolver = getContext().getContentResolver();
        Uri uri = Uri.parse("content://android.content.MemoryFileProvider/data/1/blob");
        byte[] buf = new byte[MemoryFileProvider.TEST_BLOB.length];
        InputStream in = resolver.openInputStream(uri);
        assertNotNull(in);
        int count = in.read(buf);
        assertEquals(buf.length, count);
        assertEquals(-1, in.read());
        in.close();
        assertTrue(Arrays.equals(MemoryFileProvider.TEST_BLOB, buf));