emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 07 Feb 2013 12:58:12 +0100
branchemul
changeset 694 0d277415ed02
child 693 92b628f99997
permissions -rw-r--r--
Rebasing the Inflater support on jzlib which, unlike GNU ClassPath, has correct implementation of Huffman code. Making the implementation more easily testable by turning Inflater and ZipInputStream into pure delegates. Current implementation is going to need proper long support.
jaroslav@595
     1
/**
jaroslav@595
     2
 * Back 2 Browser Bytecode Translator
jaroslav@595
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@595
     4
 *
jaroslav@595
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@595
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@595
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@595
     8
 *
jaroslav@595
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@595
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@595
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@595
    12
 * GNU General Public License for more details.
jaroslav@595
    13
 *
jaroslav@595
    14
 * You should have received a copy of the GNU General Public License
jaroslav@595
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@595
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@595
    17
 */
jaroslav@595
    18
package org.apidesign.bck2brwsr.compact.tck;
jaroslav@595
    19
jaroslav@595
    20
import java.io.ByteArrayInputStream;
jaroslav@595
    21
import java.io.IOException;
jaroslav@595
    22
import java.io.InputStreamReader;
jaroslav@595
    23
import java.util.Arrays;
jaroslav@595
    24
import org.apidesign.bck2brwsr.vmtest.Compare;
jaroslav@595
    25
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@595
    26
import org.testng.annotations.Factory;
jaroslav@595
    27
jaroslav@595
    28
/**
jaroslav@595
    29
 *
jaroslav@595
    30
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@595
    31
 */
jaroslav@595
    32
public class ReaderTest {
jaroslav@595
    33
    @Compare public String readUTFString() throws IOException {
jaroslav@595
    34
        byte[] arr = { 
jaroslav@595
    35
            (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, 
jaroslav@595
    36
            (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, 
jaroslav@595
    37
            (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, 
jaroslav@595
    38
            (byte)-120 
jaroslav@595
    39
        };
jaroslav@595
    40
        ByteArrayInputStream is = new ByteArrayInputStream(arr);
jaroslav@595
    41
        InputStreamReader r = new InputStreamReader(is);
jaroslav@595
    42
        
jaroslav@595
    43
        StringBuilder sb = new StringBuilder();
jaroslav@595
    44
        for (;;) {
jaroslav@595
    45
            int ch = r.read();
jaroslav@595
    46
            if (ch == -1) {
jaroslav@595
    47
                break;
jaroslav@595
    48
            }
jaroslav@595
    49
            sb.append((char)ch);
jaroslav@595
    50
        }
jaroslav@595
    51
        return sb.toString().toString();
jaroslav@595
    52
    }
jaroslav@595
    53
    @Compare public String stringToBytes() {
jaroslav@595
    54
        return Arrays.toString("Žluťoučký kůň".getBytes());
jaroslav@595
    55
    }
jaroslav@595
    56
    
jaroslav@595
    57
    @Factory public static Object[] create() {
jaroslav@595
    58
        return VMTest.create(ReaderTest.class);
jaroslav@595
    59
    }
jaroslav@595
    60
}