Search in sources :

Example 21 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_unreadI.

/**
     * java.io.PushbackReader#unread(int)
     */
public void test_unreadI() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying);
    // Why does this work?!?
    tobj.unread(23);
    tobj.skip(2);
    tobj.unread(23);
    assertEquals("Wrong value read!", 23, tobj.read());
    tobj.unread(13);
    try {
        tobj.unread(13);
        fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
    } catch (IOException e) {
    // expected
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 22 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_read.

/**
     * java.io.PushbackReader#read()
     */
public void test_read() throws IOException {
    PushbackReader tobj;
    tobj = new PushbackReader(underlying);
    assertEquals("Wrong value read!", 66, tobj.read());
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read();
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 23 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_read$CII.

/**
     * java.io.PushbackReader#read(char[], int, int)
     */
public void test_read$CII() throws IOException {
    PushbackReader tobj;
    char[] buf = ("01234567890123456789").toCharArray();
    tobj = new PushbackReader(underlying);
    tobj.read(buf, 6, 5);
    assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
    assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf, 6, 5);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // Test for method int java.io.PushbackReader.read(char [], int, int)
    try {
        char[] c = new char[5];
        pbr.read(c, 0, 5);
        assertTrue("Failed to read chars", new String(c).equals(pbString.substring(0, 5)));
        assertEquals(0, pbr.read(c, 0, 0));
        assertEquals(c.length, pbr.read(c, 0, c.length));
        assertEquals(0, pbr.read(c, c.length, 0));
    } catch (IOException e) {
        fail("IOException during read test : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 24 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_read_$CII_Exception.

/**
     * java.io.PushbackReader#read(char[], int, int)
     */
public void test_read_$CII_Exception() throws IOException {
    pbr = new PushbackReader(new StringReader(pbString), 10);
    char[] nullCharArray = null;
    char[] charArray = new char[10];
    try {
        pbr.read(nullCharArray, 0, 1);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    // expected
    }
    try {
        pbr.read(charArray, 0, -1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, -1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, charArray.length + 1, 0);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, charArray.length, 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, 1, charArray.length);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    try {
        pbr.read(charArray, 0, charArray.length + 1);
        fail("should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    // expected
    }
    pbr.close();
    try {
        pbr.read(charArray, 0, 1);
        fail("should throw IOException");
    } catch (IOException e) {
    // expected
    }
}
Also used : StringReader(java.io.StringReader) IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Example 25 with PushbackReader

use of java.io.PushbackReader in project j2objc by google.

the class OldPushbackReaderTest method test_unread$C.

/**
     * java.io.PushbackReader#unread(char[])
     */
public void test_unread$C() throws IOException {
    PushbackReader tobj;
    String str2 = "0123456789";
    char[] buf2 = str2.toCharArray();
    char[] readBuf = new char[10];
    tobj = new PushbackReader(underlying, 10);
    tobj.unread(buf2);
    try {
        tobj.unread(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    tobj.read(readBuf);
    assertEquals("Incorrect bytes read", str2, new String(readBuf));
    underlying.throwExceptionOnNextUse = true;
    try {
        tobj.read(buf2);
        fail("IOException not thrown.");
    } catch (IOException e) {
    // expected
    }
    // Test for method void java.io.PushbackReader.unread(char [])
    try {
        char[] c = new char[5];
        pbr.read(c, 0, 5);
        pbr.unread(c);
        pbr.read(c, 0, 5);
        assertTrue("Failed to unread chars", new String(c).equals(pbString.substring(0, 5)));
    } catch (IOException e) {
        fail("IOException during read test : " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) PushbackReader(java.io.PushbackReader)

Aggregations

PushbackReader (java.io.PushbackReader)37 IOException (java.io.IOException)22 StringReader (java.io.StringReader)12 CompileException (com.googlecode.prolog_cafe.exceptions.CompileException)3 JavaObjectTerm (com.googlecode.prolog_cafe.lang.JavaObjectTerm)3 SymbolTerm (com.googlecode.prolog_cafe.lang.SymbolTerm)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 StructureTerm (com.googlecode.prolog_cafe.lang.StructureTerm)2 FileNotFoundException (java.io.FileNotFoundException)2 LineNumberReader (java.io.LineNumberReader)2 Lexer (net.sourceforge.processdash.data.compiler.lexer.Lexer)2 Parser (net.sourceforge.processdash.data.compiler.parser.Parser)2 SyntaxException (com.googlecode.prolog_cafe.exceptions.SyntaxException)1 TermException (com.googlecode.prolog_cafe.exceptions.TermException)1 BufferingPrologControl (com.googlecode.prolog_cafe.lang.BufferingPrologControl)1 ListTerm (com.googlecode.prolog_cafe.lang.ListTerm)1 Term (com.googlecode.prolog_cafe.lang.Term)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1