rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 735 emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java@419d8802bcba
child 1260 fe3567c7b522
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
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@714
    23
import java.io.UnsupportedEncodingException;
jaroslav@595
    24
import java.util.Arrays;
jaroslav@595
    25
import org.apidesign.bck2brwsr.vmtest.Compare;
jaroslav@595
    26
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@595
    27
import org.testng.annotations.Factory;
jaroslav@595
    28
jaroslav@595
    29
/**
jaroslav@595
    30
 *
jaroslav@595
    31
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@595
    32
 */
jaroslav@595
    33
public class ReaderTest {
jaroslav@595
    34
    @Compare public String readUTFString() throws IOException {
jaroslav@595
    35
        byte[] arr = { 
jaroslav@595
    36
            (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, 
jaroslav@595
    37
            (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, 
jaroslav@595
    38
            (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, 
jaroslav@595
    39
            (byte)-120 
jaroslav@595
    40
        };
jaroslav@595
    41
        ByteArrayInputStream is = new ByteArrayInputStream(arr);
lubomir@735
    42
        InputStreamReader r = new InputStreamReader(is, "UTF-8");
jaroslav@595
    43
        
jaroslav@595
    44
        StringBuilder sb = new StringBuilder();
jaroslav@595
    45
        for (;;) {
jaroslav@595
    46
            int ch = r.read();
jaroslav@595
    47
            if (ch == -1) {
jaroslav@595
    48
                break;
jaroslav@595
    49
            }
jaroslav@595
    50
            sb.append((char)ch);
jaroslav@595
    51
        }
jaroslav@595
    52
        return sb.toString().toString();
jaroslav@595
    53
    }
jaroslav@714
    54
    @Compare public String stringToBytes() throws UnsupportedEncodingException {
jaroslav@714
    55
        return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8"));
jaroslav@595
    56
    }
jaroslav@595
    57
    
jaroslav@595
    58
    @Factory public static Object[] create() {
jaroslav@595
    59
        return VMTest.create(ReaderTest.class);
jaroslav@595
    60
    }
jaroslav@595
    61
}