1.1 --- a/rt/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java Wed Feb 27 17:50:47 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,162 +0,0 @@
1.4 -/**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, version 2 of the License.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program. Look for COPYING file in the top folder.
1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 - */
1.21 -package org.apidesign.bck2brwsr.tck;
1.22 -
1.23 -import java.io.UnsupportedEncodingException;
1.24 -import java.net.MalformedURLException;
1.25 -import java.net.URL;
1.26 -import org.apidesign.bck2brwsr.vmtest.Compare;
1.27 -import org.apidesign.bck2brwsr.vmtest.VMTest;
1.28 -import org.testng.annotations.Factory;
1.29 -
1.30 -/**
1.31 - *
1.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.33 - */
1.34 -public class CompareStringsTest {
1.35 - @Compare public String firstChar() {
1.36 - return "" + ("Hello".toCharArray()[0]);
1.37 - }
1.38 -
1.39 - @Compare public String classCast() {
1.40 - Object o = firstChar();
1.41 - return String.class.cast(o);
1.42 - }
1.43 -
1.44 - @Compare public String classCastThrown() {
1.45 - Object o = null;
1.46 - return String.class.cast(o);
1.47 - }
1.48 -
1.49 - @Compare public boolean equalToNull() {
1.50 - return "Ahoj".equals(null);
1.51 - }
1.52 -
1.53 - @Compare public int highByteLenght() {
1.54 - byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
1.55 - return new String(arr, 0).length();
1.56 - }
1.57 -
1.58 - @Compare public String highByte() {
1.59 - byte[] arr= { 77,97,110,105,102,101,115,116,45,86,101,114,115,105,111,110 };
1.60 - StringBuilder sb = new StringBuilder();
1.61 - sb.append("pref:");
1.62 - sb.append(new String(arr, 0));
1.63 - return sb.toString();
1.64 - }
1.65 -
1.66 - @Compare public static Object compareURLs() throws MalformedURLException {
1.67 - return new URL("http://apidesign.org:8080/wiki/").toExternalForm().toString();
1.68 - }
1.69 -
1.70 - @Compare public String deleteLastTwoCharacters() {
1.71 - StringBuilder sb = new StringBuilder();
1.72 - sb.append("453.0");
1.73 - if (sb.toString().endsWith(".0")) {
1.74 - final int l = sb.length();
1.75 - sb.delete(l - 2, l);
1.76 - }
1.77 - return sb.toString().toString();
1.78 - }
1.79 -
1.80 - @Compare public String nameOfStringClass() throws Exception {
1.81 - return Class.forName("java.lang.String").getName();
1.82 - }
1.83 - @Compare public String nameOfArrayClass() throws Exception {
1.84 - return Class.forName("org.apidesign.bck2brwsr.tck.CompareHashTest").getName();
1.85 - }
1.86 -
1.87 - @Compare public String lowerHello() {
1.88 - return "HeLlO".toLowerCase();
1.89 - }
1.90 -
1.91 - @Compare public String lowerA() {
1.92 - return String.valueOf(Character.toLowerCase('A')).toString();
1.93 - }
1.94 - @Compare public String upperHello() {
1.95 - return "hello".toUpperCase();
1.96 - }
1.97 -
1.98 - @Compare public String upperA() {
1.99 - return String.valueOf(Character.toUpperCase('a')).toString();
1.100 - }
1.101 -
1.102 - @Compare public boolean matchRegExp() throws Exception {
1.103 - return "58038503".matches("\\d*");
1.104 - }
1.105 -
1.106 - @Compare public boolean doesNotMatchRegExp() throws Exception {
1.107 - return "58038503GH".matches("\\d*");
1.108 - }
1.109 -
1.110 - @Compare public boolean doesNotMatchRegExpFully() throws Exception {
1.111 - return "Hello".matches("Hell");
1.112 - }
1.113 -
1.114 - @Compare public String emptyCharArray() {
1.115 - char[] arr = new char[10];
1.116 - return new String(arr);
1.117 - }
1.118 -
1.119 - @Compare public String variousCharacterTests() throws Exception {
1.120 - StringBuilder sb = new StringBuilder();
1.121 -
1.122 - sb.append(Character.isUpperCase('a'));
1.123 - sb.append(Character.isUpperCase('A'));
1.124 - sb.append(Character.isLowerCase('a'));
1.125 - sb.append(Character.isLowerCase('A'));
1.126 -
1.127 - sb.append(Character.isLetter('A'));
1.128 - sb.append(Character.isLetterOrDigit('9'));
1.129 - sb.append(Character.isLetterOrDigit('A'));
1.130 - sb.append(Character.isLetter('0'));
1.131 -
1.132 - return sb.toString().toString();
1.133 - }
1.134 -
1.135 - @Compare
1.136 - public String nullFieldInitialized() {
1.137 - NullField nf = new NullField();
1.138 - return ("" + nf.name).toString();
1.139 - }
1.140 - @Compare
1.141 - public String toUTFString() throws UnsupportedEncodingException {
1.142 - byte[] arr = {
1.143 - (byte) -59, (byte) -67, (byte) 108, (byte) 117, (byte) -59, (byte) -91,
1.144 - (byte) 111, (byte) 117, (byte) -60, (byte) -115, (byte) 107, (byte) -61,
1.145 - (byte) -67, (byte) 32, (byte) 107, (byte) -59, (byte) -81, (byte) -59,
1.146 - (byte) -120
1.147 - };
1.148 - return new String(arr, "utf-8");
1.149 - }
1.150 -
1.151 - @Compare
1.152 - public int stringToBytesLenght() throws UnsupportedEncodingException {
1.153 - return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length;
1.154 - }
1.155 -
1.156 - @Factory
1.157 - public static Object[] create() {
1.158 - return VMTest.create(CompareStringsTest.class);
1.159 - }
1.160 -
1.161 - private static final class NullField {
1.162 -
1.163 - String name;
1.164 - }
1.165 -}