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