Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e0efd15 authored by Jesse Wilson's avatar Jesse Wilson Committed by Android (Google) Code Review
Browse files

Merge "Fix MemoryFile's output stream to advance."

parents 4ad06c32 112d3396
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ public class MemoryFile
        @Override
        public void write(byte buffer[], int offset, int count) throws IOException {
            writeBytes(buffer, offset, mOffset, count);
            mOffset += count;
        }

        @Override
+20 −3
Original line number Diff line number Diff line
@@ -20,13 +20,11 @@ import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MemoryFileTest extends AndroidTestCase {
@@ -101,6 +99,25 @@ public class MemoryFileTest extends AndroidTestCase {
        file.close();
    }

    // http://code.google.com/p/android/issues/detail?id=11415
    public void testOutputStreamAdvances() throws IOException {
        MemoryFile file = new MemoryFile("MemoryFileTest", 10);

        OutputStream os = file.getOutputStream();
        os.write(new byte[] { 1, 2, 3, 4, 5 });
        os.write(new byte[] { -1, -1, 6, 7, 8, -1 }, 2, 3);
        os.write(9);
        try {
            os.write(new byte[] { -1, -1 });
            fail();
        } catch (IndexOutOfBoundsException expected) {
        }

        byte[] copy = new byte[file.length()];
        file.readBytes(copy, 0, 0, file.length());
        assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]", Arrays.toString(copy));
    }

    // Tests for the IndexOutOfBoundsException cases in read().

    private void readIndexOutOfBoundsException(int offset, int count, String msg)