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@1260
|
21 |
import java.io.ByteArrayOutputStream;
|
jaroslav@595
|
22 |
import java.io.IOException;
|
jaroslav@595
|
23 |
import java.io.InputStreamReader;
|
jaroslav@1260
|
24 |
import java.io.OutputStreamWriter;
|
jaroslav@714
|
25 |
import java.io.UnsupportedEncodingException;
|
jaroslav@595
|
26 |
import java.util.Arrays;
|
jaroslav@595
|
27 |
import org.apidesign.bck2brwsr.vmtest.Compare;
|
jaroslav@595
|
28 |
import org.apidesign.bck2brwsr.vmtest.VMTest;
|
jaroslav@595
|
29 |
import org.testng.annotations.Factory;
|
jaroslav@595
|
30 |
|
jaroslav@595
|
31 |
/**
|
jaroslav@595
|
32 |
*
|
jaroslav@595
|
33 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@595
|
34 |
*/
|
jaroslav@595
|
35 |
public class ReaderTest {
|
jaroslav@595
|
36 |
@Compare public String readUTFString() throws IOException {
|
jaroslav@595
|
37 |
byte[] arr = {
|
jaroslav@595
|
38 |
(byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91,
|
jaroslav@595
|
39 |
(byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61,
|
jaroslav@595
|
40 |
(byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59,
|
jaroslav@595
|
41 |
(byte)-120
|
jaroslav@595
|
42 |
};
|
jaroslav@595
|
43 |
ByteArrayInputStream is = new ByteArrayInputStream(arr);
|
lubomir@735
|
44 |
InputStreamReader r = new InputStreamReader(is, "UTF-8");
|
jaroslav@1260
|
45 |
return readReader(r);
|
jaroslav@1260
|
46 |
}
|
jaroslav@1260
|
47 |
|
jaroslav@1260
|
48 |
private String readReader(InputStreamReader r) throws IOException {
|
jaroslav@595
|
49 |
StringBuilder sb = new StringBuilder();
|
jaroslav@595
|
50 |
for (;;) {
|
jaroslav@595
|
51 |
int ch = r.read();
|
jaroslav@595
|
52 |
if (ch == -1) {
|
jaroslav@595
|
53 |
break;
|
jaroslav@595
|
54 |
}
|
jaroslav@595
|
55 |
sb.append((char)ch);
|
jaroslav@595
|
56 |
}
|
jaroslav@595
|
57 |
return sb.toString().toString();
|
jaroslav@595
|
58 |
}
|
jaroslav@714
|
59 |
@Compare public String stringToBytes() throws UnsupportedEncodingException {
|
jaroslav@1260
|
60 |
return Arrays.toString(YellowHorse.getBytes("UTF-8"));
|
jaroslav@1260
|
61 |
}
|
jaroslav@1260
|
62 |
private final String YellowHorse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
|
jaroslav@1260
|
63 |
|
jaroslav@1260
|
64 |
@Compare public String readAndWrite() throws Exception {
|
jaroslav@1260
|
65 |
ByteArrayOutputStream arr = new ByteArrayOutputStream();
|
jaroslav@1260
|
66 |
OutputStreamWriter w = new OutputStreamWriter(arr);
|
jaroslav@1260
|
67 |
w.write(YellowHorse);
|
jaroslav@1260
|
68 |
w.close();
|
jaroslav@1260
|
69 |
|
jaroslav@1260
|
70 |
ByteArrayInputStream is = new ByteArrayInputStream(arr.toByteArray());
|
jaroslav@1260
|
71 |
InputStreamReader r = new InputStreamReader(is, "UTF-8");
|
jaroslav@1260
|
72 |
return readReader(r);
|
jaroslav@595
|
73 |
}
|
jaroslav@595
|
74 |
|
jaroslav@595
|
75 |
@Factory public static Object[] create() {
|
jaroslav@595
|
76 |
return VMTest.create(ReaderTest.class);
|
jaroslav@595
|
77 |
}
|
jaroslav@595
|
78 |
}
|