FileDocCategorySizeDatePackage
AssetTest.javaAPI DocAndroid 5.1 API2475Thu Mar 12 22:22:12 GMT 2015android.content

AssetTest

public class AssetTest extends android.test.AndroidTestCase

Fields Summary
private android.content.res.AssetManager
mAssets
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        mAssets = mContext.getAssets();
    
public voidtestReadToEnd()

        InputStream is = mAssets.open("text.txt");
        verifyTextAsset(is);
    
public static voidverifyTextAsset(java.io.InputStream is)

        String expectedString = "OneTwoThreeFourFiveSixSevenEightNineTen";
        byte[] buffer = new byte[10];

        int readCount;
        int curIndex = 0;
        while ((readCount = is.read(buffer, 0, buffer.length)) > 0) {
            for (int i = 0; i < readCount; i++) {
                assertEquals("At index " + curIndex
                            + " expected " + expectedString.charAt(curIndex)
                            + " but found " + ((char) buffer[i]),
                        buffer[i], expectedString.charAt(curIndex));
                curIndex++;
            }
        }

        readCount = is.read(buffer, 0, buffer.length);
        assertEquals("Reading end of buffer: expected readCount=-1 but got " + readCount,
                -1, readCount);

        readCount = is.read(buffer, buffer.length, 0);
        assertEquals("Reading end of buffer length 0: expected readCount=0 but got " + readCount,
                0, readCount);

        is.close();
    
public voidxxtestListDir()

        String[] files = mAssets.list("");
        assertEquals(1, files.length);
        assertEquals("test.txt", files[0]);