2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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.
18 package org.apidesign.bck2brwsr.tck;
20 import java.io.UnsupportedEncodingException;
21 import java.net.MalformedURLException;
23 import org.apidesign.bck2brwsr.vmtest.Compare;
24 import org.apidesign.bck2brwsr.vmtest.VMTest;
25 import org.testng.annotations.Factory;
29 * @author Jaroslav Tulach <jtulach@netbeans.org>
31 public class CompareStringsTest {
32 @Compare public String firstChar() {
33 return "" + ("Hello".toCharArray()[0]);
36 @Compare public String classCast() {
37 Object o = firstChar();
38 return String.class.cast(o);
41 @Compare public String classCastThrown() {
43 return String.class.cast(o);
46 @Compare public boolean equalToNull() {
47 return "Ahoj".equals(null);
50 @Compare public static Object compareURLs() throws MalformedURLException {
51 return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
54 @Compare public String deleteLastTwoCharacters() {
55 StringBuilder sb = new StringBuilder();
57 if (sb.toString().endsWith(".0")) {
58 final int l = sb.length();
61 return sb.toString().toString();
64 @Compare public String nameOfStringClass() throws Exception {
65 return Class.forName("java.lang.String").getName();
67 @Compare public String nameOfArrayClass() throws Exception {
68 return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
71 @Compare public String lowerHello() {
72 return "HeLlO".toLowerCase();
75 @Compare public String lowerA() {
76 return String.valueOf(Character.toLowerCase('A')).toString();
78 @Compare public String upperHello() {
79 return "hello".toUpperCase();
82 @Compare public String upperA() {
83 return String.valueOf(Character.toUpperCase('a')).toString();
86 @Compare public boolean matchRegExp() throws Exception {
87 return "58038503".matches("\\d*");
90 @Compare public boolean doesNotMatchRegExp() throws Exception {
91 return "58038503GH".matches("\\d*");
94 @Compare public boolean doesNotMatchRegExpFully() throws Exception {
95 return "Hello".matches("Hell");
98 @Compare public String emptyCharArray() {
99 char[] arr = new char[10];
100 return new String(arr);
103 @Compare public String variousCharacterTests() throws Exception {
104 StringBuilder sb = new StringBuilder();
106 sb.append(Character.isUpperCase('a'));
107 sb.append(Character.isUpperCase('A'));
108 sb.append(Character.isLowerCase('a'));
109 sb.append(Character.isLowerCase('A'));
111 sb.append(Character.isLetter('A'));
112 sb.append(Character.isLetterOrDigit('9'));
113 sb.append(Character.isLetterOrDigit('A'));
114 sb.append(Character.isLetter('0'));
116 return sb.toString().toString();
120 public String nullFieldInitialized() {
121 NullField nf = new NullField();
122 return ("" + nf.name).toString();
125 public String toUTFString() throws UnsupportedEncodingException {
127 (byte) -59, (byte) -67, (byte) 108, (byte) 117, (byte) -59, (byte) -91,
128 (byte) 111, (byte) 117, (byte) -60, (byte) -115, (byte) 107, (byte) -61,
129 (byte) -67, (byte) 32, (byte) 107, (byte) -59, (byte) -81, (byte) -59,
132 return new String(arr, "utf-8");
136 public int stringToBytesLenght() throws UnsupportedEncodingException {
137 return "Žluťoučký kůň".getBytes("utf8").length;
141 public static Object[] create() {
142 return VMTest.create(CompareStringsTest.class);
145 private static final class NullField {