You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2007/06/08 18:35:10 UTC
svn commit: r545554 [9/13] - in
/harmony/enhanced/buildtest/branches/2.0/tests/reliability: ./ run/ src/
src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/harmony/
src/java/org/apache/harmony/test/ src/java/org/apache/harmony/test/reliab...
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/EncodingModesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/EncodingModesTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/EncodingModesTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/EncodingModesTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Oleg Oleinik
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.charset;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.util.SortedMap;
+import java.util.Random;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+
+
+/**
+ * Goal: find memory leaks invoking encodings for each available charset using different
+ * combinations of onUnmappable/onMalformed.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations. For each string, each encoding -
+ * - number of cycles with all combinations of malformed, unmappable actions flags.
+ *
+ * 2. Creates 3 strings of length 0xFFFF:
+ * string[0] = all chars are those for which isJavaIdentifierPart(ch) returns true, from 0 to 0xFFFF
+ * string[1] = all chars in range 0..0xFFFF, including malformed
+ * string[2] = all chars are those for which isJavaIdentifierPart(ch) returns true, randomly chosen
+ * 3. For each of the string:
+ * 1) receives all charsets through availableCharsets().
+ * 2) for each charset:
+ * 2.1) starts a cycle of param[0] iterations. On each iteration:
+ * a) sets replaceWith() bytes
+ * b) choses next combination of onUnmappable/onMalformed
+ * c) invokes encode(CharBuffer, ByteBuffer, false)
+ * d) repeats b-c until all 9 combinations of onUnmappable/onMalformed are chosen
+ * 2.2) runs System.gc()
+ *
+ */
+
+public class EncodingModesTest extends Test {
+
+ public int callSystemGC = 1;
+
+ public int SWITCH_ITERATIONS = 100;
+
+ public static void main(String[] args) {
+ System.exit(new EncodingModesTest().test(args));
+ }
+
+ public int test(String[] params) {
+
+ parseParams(params);
+ String[] strs_to_encode = new String[3];
+
+ strs_to_encode[0] = StringCreator.getValidString((char)0, (char)0xFFFF, StringCreator.START_TO_END);
+ strs_to_encode[1] = StringCreator.getInvalidString();
+ strs_to_encode[2] = StringCreator.getValidString((char)0, (char)0xFFFF, StringCreator.RANDOM);
+
+ CodingErrorAction[] action = {CodingErrorAction.REPLACE,
+ CodingErrorAction.IGNORE,
+ CodingErrorAction.REPORT};
+
+ for (int k = 0; k < strs_to_encode.length; ++k) {
+
+ SortedMap allCharsets = Charset.availableCharsets();
+ Object[] names = allCharsets.keySet().toArray();
+
+ for (int i = 0; i < names.length; ++i) {
+ Charset chset = (Charset) allCharsets.get(names[i]);
+ if (!chset.canEncode()) {
+ continue;
+ }
+ CharsetEncoder ce = chset.newEncoder().reset();
+ ByteBuffer bytes;
+ CharBuffer chars;
+
+ // log.add("Charset " + names[i]);
+ for (int j = 0; j < SWITCH_ITERATIONS; ++j) {
+ for (int x = 0; x < action.length; ++x) {
+ for (int y = 0; y < action.length; ++y) {
+ try {
+ chars = CharBuffer.wrap(strs_to_encode[k]
+ .subSequence(0, strs_to_encode[k].length()));
+ ce = ce.replaceWith(getReplacementBytes());
+ ce.onMalformedInput(action[x]);
+ ce.onUnmappableCharacter(action[y]);
+ ce.encode(chars, (bytes = ByteBuffer
+ .wrap(new byte[strs_to_encode[k].length() * 2])), false);
+
+ } catch (Throwable t) {
+ // log.add(t);
+ }
+ }
+ }
+ }
+ if (callSystemGC != 0) {
+ System.gc();
+ }
+ }
+ }
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ SWITCH_ITERATIONS = Integer.parseInt(params[0]);
+ }
+ }
+
+
+ public byte[] getReplacementBytes() {
+ byte[] b = new byte[1];
+ b[0] = (byte) 0;
+ return b;
+ }
+}
+
+class StringCreator {
+ public static final int START_TO_END = 2;
+ public static final int RANDOM = 3;
+
+ public static String getValidString(char start, char end, int order) {
+
+ char[] ch = new char[end - start];
+ // creates a String of (end-start) length, consisting of chars for which
+ // isJavaIdentifierPart(c) returns true. If we checked all chars between
+ // <start> and <end> but, the array is not fully complete, copy the last
+ // isJavaIdentifierPart(c) char at each position in the rest of the array.
+
+ if (order != RANDOM) {
+ int i = 0;
+
+ for (char c = start; c < end; ++c) {
+ if (Character.isJavaIdentifierPart(c)) {
+ ch[i++] = c;
+ }
+ }
+
+ if (i == 0) {
+ ch[i++] = 'A';
+ }
+
+ for (; i < ch.length; ++i) {
+ ch[i] = ch[i - 1];
+ }
+ return new String(ch);
+
+ } else if (order == RANDOM) {
+ // creates a String of (end-start) length, consisting of random chars
+
+ Random rand = new Random(10);
+ int i = 0;
+ while (i < ch.length) {
+
+ int c = rand.nextInt(end - start) + start;
+ if (Character.isJavaIdentifierPart((char)c)) {
+ ch[i++] = (char)c;
+ }
+ }
+
+ return new String(ch);
+
+ } else {
+ return "";
+ }
+ }
+
+ public static String getInvalidString() {
+
+ // creates a String of 0xFFFF length, consisting of all Unicode chars,
+ // including "private use", "hi surrogate", "low surrogate" and other
+ // invalid chars (sequences).
+
+ char[] ch = new char[65535];
+ for (int i = 0; i < ch.length; ++i){
+ ch[i] = (char) i;
+ }
+ return new String(ch);
+ }
+}
+
+
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/EncodingModesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/WrongCharsetNameTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/WrongCharsetNameTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/WrongCharsetNameTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/WrongCharsetNameTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,464 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Oleg Oleinik
+ * @version $Revision: 1.2 $
+ */
+
+package org.apache.harmony.test.reliability.api.nio.charset;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.Vector;
+
+/**
+ * Goal: find memory leaks caused by wrong management of Charset cache in case of
+ * accessing Charset via non-IANA names, like "UTF8", "UTF16".
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations to call/initialize one encoder in a cycle
+ *
+ * 2. For each of encodingName which does not cause UnsupportedEncodingException but
+ * nevertheless differ from canonical name or alias, it calls String(new byte[0], encodingName)
+ * in a cycle for param[0] iterations. It tries to force Charset cache to create new Encoder
+ * object instead of re-using already created, since, it is possible that cache works
+ * using canonical names or aliases, but, misses "unofficial" names, like "UTF8".
+ *
+ */
+
+public class WrongCharsetNameTest extends Test {
+
+ public int callSystemGC = 1;
+
+ public int NUMBER_OF_ENCODING_ITERATIONS = 100;
+
+ // These are non-IANA names of charsets which are accepted as names for
+ // creation of encoder (UnsupportedEncodingException is not thrown)
+
+ // Must contain at least "UTF8", "UTF16".
+ public String[] encodingName;
+
+ private String s = "";
+ private CharBuffer ch_buf = null;
+
+
+ public static void main(String[] args) {
+ System.exit(new WrongCharsetNameTest().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ parseParams(params);
+
+ // First, receive names of encodings which are not canonical or alias names,
+ // but are acceptable as valid encoding names.
+
+ encodingName = EncodingNames.getNames();
+
+ // log.add("Selected " + encodingName.length + " names");
+
+ for (int j = 0; j < encodingName.length; ++j){
+
+ //log.add("Iteration " + encodingName[j]);
+
+ for (int i = 0; i < NUMBER_OF_ENCODING_ITERATIONS; ++i){
+
+ // log.add("Iteration " + i + ", " + encodingName[j]);
+
+ try {
+
+ s = new String(new byte[0], encodingName[j]);
+
+ } catch (UnsupportedEncodingException uee){
+
+ log.add("Unsupported " + encodingName[j]);
+
+ }
+
+ if (callSystemGC !=0 ){
+ System.gc();
+ }
+ }
+ }
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ENCODING_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ }
+
+}
+
+
+class EncodingNames {
+
+ public static String[] getNames(){
+
+ // lets select only those chrset names from encodingNIOIONames
+ // which are valid (i.e. forName() returns Charset) but, are not
+ // canonical name or alias.
+
+ Vector v = new Vector();
+
+ // System.out.println("Total: " + encodingNIOIONames.length);
+
+ for (int i = 0; i < encodingNIOIONames.length; ++i){
+
+ try {
+
+ Charset c = Charset.forName(encodingNIOIONames[i]);
+
+ if (c.name().equals(encodingNIOIONames[i])){
+ continue;
+ }
+
+ Object[] aliases = c.aliases().toArray();
+
+ boolean isAlias = false;
+
+ for (int j = 0; j < aliases.length; ++j){
+ if (aliases[j].equals(encodingNIOIONames[i])){
+ isAlias = true;
+ break;
+ }
+ }
+
+ if (!isAlias){
+ v.add(encodingNIOIONames[i]);
+ }
+
+ } catch(IllegalCharsetNameException icne){
+ } catch (UnsupportedCharsetException uce){
+ }
+ }
+
+ return (String[]) v.toArray(new String[0]);
+
+ }
+
+
+ public static String[] encodingNIOIONames =
+ {
+ "ISO-8859-1",
+ "ISO8859_1",
+ "ISO-8859-2",
+ "ISO8859_2",
+ "ISO-8859-4",
+ "ISO8859_4",
+ "ISO-8859-5",
+ "ISO8859_5",
+ "ISO-8859-7",
+ "ISO8859_7",
+ "ISO-8859-9",
+ "ISO8859_9",
+ "ISO-8859-13",
+ "ISO8859_13",
+ "ISO-8859-15",
+ "ISO8859_15",
+ "KOI8-R",
+ "KOI8_R",
+ "US-ASCII",
+ "ASCII",
+ "UTF-8",
+ "UTF8", // for sure
+ "UTF-16",
+ "UTF16", // for sure
+ "UTF-16BE",
+ "UnicodeBigUnmarked",
+ "UTF-16LE",
+ "UnicodeLittleUnmarked",
+ "windows-1250",
+ "Cp1250",
+ "windows-1251",
+ "Cp1251",
+ "windows-1252",
+ "Cp1252",
+ "windows-1253",
+ "Cp1253",
+ "windows-1254",
+ "Cp1254",
+ "windows-1257",
+ "Cp1257",
+ "UnicodeBig",
+ "UnicodeLittle",
+ "Big5",
+ "Big5",
+ "Big5-HKSCS",
+ "Big5_HKSCS",
+ "EUC-JP",
+ "EUC_JP",
+ "EUC-KR",
+ "EUC_KR",
+ "GB18030",
+ "GB18030",
+ "GB2312",
+ "EUC_CN",
+ "GBK",
+ "GBK",
+ "IBM-Thai",
+ "Cp838",
+ "IBM00858",
+ "Cp858",
+ "IBM01140",
+ "Cp1140",
+ "IBM01141",
+ "Cp1141",
+ "IBM01142",
+ "Cp1142",
+ "IBM01143",
+ "Cp1143",
+ "IBM01144",
+ "Cp1144",
+ "IBM01145",
+ "Cp1145",
+ "IBM01146",
+ "Cp1146",
+ "IBM01147",
+ "Cp1147",
+ "IBM01148",
+ "Cp1148",
+ "IBM01149",
+ "Cp1149",
+ "IBM037",
+ "Cp037",
+ "IBM1026",
+ "Cp1026",
+ "IBM1047",
+ "Cp1047",
+ "IBM273",
+ "Cp273",
+ "IBM277",
+ "Cp277",
+ "IBM278",
+ "Cp278",
+ "IBM280",
+ "Cp280",
+ "IBM284",
+ "Cp284",
+ "IBM285",
+ "Cp285",
+ "IBM297",
+ "Cp297",
+ "IBM420",
+ "Cp420",
+ "IBM424",
+ "Cp424",
+ "IBM437",
+ "Cp437",
+ "IBM500",
+ "Cp500",
+ "IBM775",
+ "Cp775",
+ "IBM850",
+ "Cp850",
+ "IBM852",
+ "Cp852",
+ "IBM855",
+ "Cp855",
+ "IBM857",
+ "Cp857",
+ "IBM860",
+ "Cp860",
+ "IBM861",
+ "Cp861",
+ "IBM862",
+ "Cp862",
+ "IBM863",
+ "Cp863",
+ "IBM864",
+ "Cp864",
+ "IBM865",
+ "Cp865",
+ "IBM866",
+ "Cp866",
+ "IBM868",
+ "Cp868",
+ "IBM869",
+ "Cp869",
+ "IBM870",
+ "Cp870",
+ "IBM871",
+ "Cp871",
+ "IBM918",
+ "Cp918",
+ "ISO-2022-CN",
+ "ISO2022CN",
+ "ISO-2022-JP",
+ "ISO2022JP",
+ "ISO-2022-KR",
+ "ISO2022KR",
+ "ISO-8859-3",
+ "ISO8859_3",
+ "ISO-8859-6",
+ "ISO8859_6",
+ "ISO-8859-8",
+ "ISO8859_8",
+ "Shift_JIS",
+ "SJIS",
+ "TIS-620",
+ "TIS620",
+ "windows-1255",
+ "Cp1255",
+ "windows-1256",
+ "Cp1256",
+ "windows-1258",
+ "Cp1258",
+ "windows-31j",
+ "MS932",
+ "x-Big5_Solaris",
+ "Big5_Solaris",
+ "x-euc-jp-linux",
+ "EUC_JP_LINUX",
+ "x-EUC-TW",
+ "EUC_TW",
+ "x-eucJP-Open",
+ "EUC_JP_Solaris",
+ "x-IBM1006",
+ "Cp1006",
+ "x-IBM1025",
+ "Cp1025",
+ "x-IBM1046",
+ "Cp1046",
+ "x-IBM1097",
+ "Cp1097",
+ "x-IBM1098",
+ "Cp1098",
+ "x-IBM1112",
+ "Cp1112",
+ "x-IBM1122",
+ "Cp1122",
+ "x-IBM1123",
+ "Cp1123",
+ "x-IBM1124",
+ "Cp1124",
+ "x-IBM1381",
+ "Cp1381",
+ "x-IBM1383",
+ "Cp1383",
+ "x-IBM33722",
+ "Cp33722",
+ "x-IBM737",
+ "Cp737",
+ "x-IBM856",
+ "Cp856",
+ "x-IBM874",
+ "Cp874",
+ "x-IBM875",
+ "Cp875",
+ "x-IBM921",
+ "Cp921",
+ "x-IBM922",
+ "Cp922",
+ "x-IBM930",
+ "Cp930",
+ "x-IBM933",
+ "Cp933",
+ "x-IBM935",
+ "Cp935",
+ "x-IBM937",
+ "Cp937",
+ "x-IBM939",
+ "Cp939",
+ "x-IBM942",
+ "Cp942",
+ "x-IBM942C",
+ "Cp942C",
+ "x-IBM943",
+ "Cp943",
+ "x-IBM943C",
+ "Cp943C",
+ "x-IBM948",
+ "Cp948",
+ "x-IBM949",
+ "Cp949",
+ "x-IBM949C",
+ "Cp949C",
+ "x-IBM950",
+ "Cp950",
+ "x-IBM964",
+ "Cp964",
+ "x-IBM970",
+ "Cp970",
+ "x-ISCII91",
+ "ISCII91",
+ "x-ISO2022-CN-CNS",
+ "ISO2022_CN_CNS",
+ "x-ISO2022-CN-GB",
+ "ISO2022_CN_GB",
+ "x-iso-8859-11",
+ "x-iso-8859-11",
+ "x-JISAutoDetect",
+ "JISAutoDetect",
+ "x-Johab",
+ "x-Johab",
+ "x-MacArabic",
+ "MacArabic",
+ "x-MacCentralEurope",
+ "MacCentralEurope",
+ "x-MacCroatian",
+ "MacCroatian",
+ "x-MacCyrillic",
+ "MacCyrillic",
+ "x-MacDingbat",
+ "MacDingbat",
+ "x-MacGreek",
+ "MacGreek",
+ "x-MacHebrew",
+ "MacHebrew",
+ "x-MacIceland",
+ "MacIceland",
+ "x-MacRoman",
+ "MacRoman",
+ "x-MacRomania",
+ "MacRomania",
+ "x-MacSymbol",
+ "MacSymbol",
+ "x-MacThai",
+ "MacThai",
+ "x-MacTurkish",
+ "MacTurkish",
+ "x-MacUkraine",
+ "MacUkraine",
+ "x-MS950-HKSCS",
+ "MS950_HKSCS",
+ "x-mswin-936",
+ "MS936",
+ "x-PCK",
+ "PCK",
+ "x-windows-874",
+ "MS874",
+ "x-windows-949",
+ "MS949",
+ "x-windows-950",
+ "MS950"
+ };
+
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/WrongCharsetNameTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/Status.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/Status.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/Status.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/Status.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.test.reliability.api.nio.charset.auxiliary;
+
+public class Status {
+ public static final int FAIL = -10;
+ public static final int PASS = 10;
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/Status.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/StringCreator.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/StringCreator.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/StringCreator.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/StringCreator.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.test.reliability.api.nio.charset.auxiliary;
+
+
+/**
+ * @author Olessia Salmina
+ * @version $Revision: 1.1 $
+ */
+
+
+
+import java.util.Random;
+
+
+public class StringCreator {
+
+ public static final int START_TO_END = 2;
+
+ public static final int RANDOM = 3;
+
+
+ public static String getValidString(char start, char end, int order) {
+
+ char[] ch = new char[end - start];
+
+ // creates a String of (end-start) length, consisting of chars for which
+ // isJavaIdentifierPart(c) returns true. If we checked all chars between
+ // <start> and <end> but, the array is not fully complete, copy the last
+ // isJavaIdentifierPart(c) char at each position in the rest of the array.
+
+ if (order != RANDOM) {
+
+ int i = 0;
+
+ for (char c = start; c < end; ++c) {
+ if (Character.isJavaIdentifierPart(c)) {
+ ch[i++] = c;
+ }
+ }
+
+ if (i == 0) {
+ ch[i++] = 'A';
+ }
+
+ for (; i < ch.length; ++i) {
+ ch[i] = ch[i - 1];
+ }
+
+ return new String(ch);
+
+ } else if (order == RANDOM) {
+
+ // creates a String of (end-start) length, consisting of random chars
+
+ Random rand = new Random(10);
+
+ int i = 0;
+
+ while (i < ch.length) {
+
+ int c = rand.nextInt(end - start) + start;
+
+ if (Character.isJavaIdentifierPart((char)c)) {
+ ch[i++] = (char)c;
+ }
+ }
+
+ return new String(ch);
+
+ } else {
+
+ return "";
+
+ }
+ }
+
+ public static String getInvalidString() {
+
+ // creates a String of 0xFFFF length, consisting of all Unicode chars,
+ // including "private use", "hi surrogate", "low surrogate" and other
+ // invalid chars (sequences).
+
+ char[] ch = new char[65535];
+
+ for (int i = 0; i < ch.length; ++i){
+ ch[i] = (char) i;
+ }
+
+ return new String(ch);
+
+ }
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/nio/charset/auxiliary/StringCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/BreakIterator_AllLocales.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/BreakIterator_AllLocales.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/BreakIterator_AllLocales.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/BreakIterator_AllLocales.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,315 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+
+/**
+ * Goal: find resource leaks (or intermittent failures, or cache problems),
+ * connected with use of following java.text.BreakIterator methods:
+ * - BreakIterator.getAvailableLocales()
+ * - BreakIterator.getCharacterInstance()
+ * - BreakIterator.getCharacterInstance(Locale)
+ * - BreakIterator.getWordInstance()
+ * - BreakIterator.getWordInstance(Locale)
+ * - BreakIterator.getSentenceInstance()
+ * - BreakIterator.getSentenceInstance(Locale)
+ * - BreakIterator.getLineInstance()
+ * - BreakIterator.getLineInstance(Locale)
+ * - BreakIterator.setText(String)
+ * - BreakIterator.first()
+ * - BreakIterator.next()
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations in each thread.
+ *
+ * 2. a. Obtains SomeText to parse
+ * b. NUMBER_OF_ITERATIONS times in a cycle marks out characters, words,
+ * sentances and lines for tis text. This maring is made for default Locale
+ * and for all available Locales, obtainted by BreakIterator.getAvailableLocales().
+ * c. Runs System.gc()
+ */
+
+
+public class BreakIterator_AllLocales extends Test {
+
+
+ public static int callSystemGC = 1;
+
+ public static int NUMBER_OF_ITERATIONS = 100;
+
+ public static void main(String[] args) {
+ System.exit(new BreakIterator_AllLocales().test(args));
+ }
+
+
+ public int test(String[] params) {
+
+ boolean failed = false;
+
+ parseParams(params);
+
+ String SomeText = " Some text ... by BreakIterator.getWordInstance()" +
+ " some text some text some text some text some text \' t" +
+ " some text some text some text some text some text" +
+ " some text some text some text some text some text" +
+ " some text some text some text some text some text."+
+ " some text some text some text, some text some text some text some text" +
+ " some text some text: Some text some text some text some text" +
+ " some text (some text some text," +
+ " a CJK some text, a Hangul syllable, a Kana character, etc.), then the text" +
+ " some text some text some text; some text, it\'s the material between words.)";
+
+ for (int k = 0; k < NUMBER_OF_ITERATIONS; k++) {
+
+ parseCharacter(SomeText);
+ parseWord(SomeText);
+ parseSentence(SomeText);
+ parseLine(SomeText);
+
+ Locale[] allLocals = BreakIterator.getAvailableLocales();
+
+ for(int i = 0; i < allLocals.length; i++){
+
+ parseCharacter(SomeText, allLocals[i]);
+ parseWord(SomeText, allLocals[i]);
+ parseSentence(SomeText, allLocals[i]);
+ parseLine(SomeText, allLocals[i]);
+
+ }
+
+ if (callSystemGC != 0){
+ System.gc();
+ }
+ }
+
+
+ return failed == true ? fail("failed") : pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ }
+
+
+
+ public void parseCharacter(String toParse) {
+
+ //log.add("Default locale" + (Locale.getDefault()).toString());
+
+ BreakIterator CharIterator =
+ BreakIterator.getCharacterInstance();
+
+ CharIterator.setText(toParse);
+
+ int boundary = CharIterator.first();
+
+ //log.add("Character boundaries are");
+
+ while (boundary != BreakIterator.DONE) {
+ //log.add(" "+boundary);
+ boundary = CharIterator.next();
+ }
+
+ }
+
+
+ public void parseCharacter(String toParse, Locale currentLocale) {
+
+ //log.add("Used locale" + (currentLocale.toString()));
+
+ BreakIterator CharIterator =
+ BreakIterator.getCharacterInstance(currentLocale);
+
+ CharIterator.setText(toParse);
+
+ int boundary = CharIterator.first();
+
+ //log.add("Character boundaries are");
+
+ while (boundary != BreakIterator.DONE) {
+ //log.add(" "+boundary);
+ boundary = CharIterator.next();
+ }
+ }
+
+ public void parseWord(String toParse) {
+
+ //log.add("Default locale" + (Locale.getDefault()).toString());
+ BreakIterator wordIterator =
+ BreakIterator.getWordInstance();
+
+ wordIterator.setText(toParse);
+
+ int start = wordIterator.first();
+ int finish = wordIterator.next();
+
+ while (finish != BreakIterator.DONE) {
+ String word = toParse.substring(start,finish);
+ if (Character.isLetterOrDigit(word.charAt(0))) {
+ //log.add(word);
+ }
+ start = finish;
+ finish = wordIterator.next();
+ }
+
+ }
+
+
+ public void parseWord(String toParse, Locale currentLocale) {
+
+ //log.add("Used locale" + (currentLocale.toString()));
+ BreakIterator wordIterator =
+ BreakIterator.getWordInstance(currentLocale);
+
+ wordIterator.setText(toParse);
+
+ int start = wordIterator.first();
+ int finish = wordIterator.next();
+
+ while (finish != BreakIterator.DONE) {
+ String word = toParse.substring(start,finish);
+ if (Character.isLetterOrDigit(word.charAt(0))) {
+ //log.add(word);
+ }
+ start = finish;
+ finish = wordIterator.next();
+ }
+ }
+
+ public void parseSentence(String toParse) {
+ //log.add("Default locale" + (Locale.getDefault()).toString());
+
+ BreakIterator sentenceIterator =
+ BreakIterator.getSentenceInstance();
+
+ sentenceIterator.setText(toParse);
+
+ StringBuffer markers = new StringBuffer();
+ markers.setLength(toParse.length() + 1);
+ for (int k = 0; k < markers.length(); k++) {
+ markers.setCharAt(k,' ');
+ }
+
+ int boundary = sentenceIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ markers.setCharAt(boundary,'^');
+ boundary = sentenceIterator.next();
+ }
+
+ //log.add(" "+toParse);
+ //log.add(" "+markers);
+ }
+
+
+ public void parseSentence(String toParse, Locale currentLocale) {
+
+ //log.add("Used locale" + (currentLocale.toString()));
+
+ BreakIterator sentenceIterator =
+ BreakIterator.getSentenceInstance(currentLocale);
+
+ sentenceIterator.setText(toParse);
+
+ StringBuffer markers = new StringBuffer();
+ markers.setLength(toParse.length() + 1);
+ for (int k = 0; k < markers.length(); k++) {
+ markers.setCharAt(k,' ');
+ }
+
+ int boundary = sentenceIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ markers.setCharAt(boundary,'^');
+ boundary = sentenceIterator.next();
+ }
+
+ //log.add(" "+toParse);
+ //log.add(" "+markers);
+
+
+ }
+
+ public void parseLine(String toParse) {
+
+ //log.add("Default locale" + (Locale.getDefault()).toString());
+ BreakIterator lineIterator =
+ BreakIterator.getLineInstance();
+
+ lineIterator.setText(toParse);
+
+ StringBuffer markers = new StringBuffer();
+ markers.setLength(toParse.length() + 1);
+ for (int k = 0; k < markers.length(); k++) {
+ markers.setCharAt(k,' ');
+ }
+
+ int boundary = lineIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ markers.setCharAt(boundary,'^');
+ boundary = lineIterator.next();
+ }
+
+ //log.add(" "+toParse);
+ //log.add(" "+markers);
+
+ }
+
+
+ public void parseLine(String toParse, Locale currentLocale) {
+ //log.add("Used locale" + (currentLocale.toString()));
+ BreakIterator lineIterator =
+ BreakIterator.getLineInstance(currentLocale);
+
+ lineIterator.setText(toParse);
+
+ StringBuffer markers = new StringBuffer();
+ markers.setLength(toParse.length() + 1);
+ for (int k = 0; k < markers.length(); k++) {
+ markers.setCharAt(k,' ');
+ }
+
+ int boundary = lineIterator.first();
+
+ while (boundary != BreakIterator.DONE) {
+ markers.setCharAt(boundary,'^');
+ boundary = lineIterator.next();
+ }
+
+ //log.add(" "+toParse);
+ //log.add(" "+markers);
+ }
+
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/BreakIterator_AllLocales.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationElementIteratorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationElementIteratorTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationElementIteratorTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationElementIteratorTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+import javax.swing.text.Segment;
+
+/**
+ * Goal: find resource leaks or intermittent failures or java.text.CollationElementIterator cache problems.
+ * Test simple invokes all implemented methods of CollationElementIterator in some combination.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread.
+ *
+ * 2. Gets all available locales via Locale.getAvailableLocales().
+ * Creates two strings of length 50 and 20 (their chars are those
+ * for which isJavaIdentifierPart(ch) returns true, randomly chosen).
+ * Use first string to invoke all CollationElementIterator methods for all base locales
+ * (static fields of Locale class, such as Locale.CANADA).
+ * Use second string to invoke some CollationElementIterator methods for all available locales.
+ *
+ * 3. Runs System.gc()
+ *
+ */
+
+public class CollationElementIteratorTest extends Test{
+
+
+ public static int callSystemGC = 1;
+ public static int NUMBER_OF_ITERATIONS = 100;
+ public int numThreads = 10;
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new CollationElementIteratorTest().test(args));
+ }
+
+ public int test(String[] params) {
+ parseParams(params);
+
+ Thread[] t = new Thread[numThreads];
+
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new ColElemItRun(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i) {
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie) {
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i) {
+ if (statuses[i] != Status.PASS) {
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+ }
+
+}
+
+
+
+class ColElemItRun implements Runnable {
+ public int id;
+ public CollationElementIteratorTest base;
+
+ public ColElemItRun(int id, CollationElementIteratorTest base) {
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+
+ Locale[] allLocales = Locale.getAvailableLocales();
+ Thread.yield();
+ //base.log.add("Number of available locales"+allLocales.length);
+ //base.log.add("Number of base locales is "+ baseLocales.Loc.length);
+
+ for (int k = 0; k < CollationElementIteratorTest.NUMBER_OF_ITERATIONS; k++) {
+ //base.log.add("Iteration number "+k);
+ String testString1 = StringCrC.getRandomString((char)50);
+
+ for (int i = 0; i < baseLocales.Loc.length; i++){
+ Invoke_ColElemIt_Methods(baseLocales.Loc[i],testString1, 0);
+ }
+
+ String testString2 = StringCrC.getRandomString((char)20);
+ for (int i = 0; i < allLocales.length; i++) {
+ Invoke_ColElemIt_Methods(allLocales[i],testString2, 1);
+ }
+ if (CollationElementIteratorTest.callSystemGC != 0){
+ System.gc();
+ }
+ }
+ base.statuses[id] = Status.PASS;
+ }
+
+ private void Invoke_ColElemIt_Methods(Locale locale, String str, int i) {
+ //base.log.add("Locale is "+locale);
+ RuleBasedCollator ruleBasedCollator = (RuleBasedCollator) Collator
+ .getInstance(locale);
+ Thread.yield();
+
+
+ switch (i) {
+ case 0:
+ CollationElementIterator collationElementIterator = ruleBasedCollator
+ .getCollationElementIterator(str);
+ Thread.yield();
+
+
+ for (int j = 0; j < str.length(); j++) {
+ int order = collationElementIterator.next();
+ Thread.yield();
+ int prOrder = CollationElementIterator.primaryOrder(order);
+ Thread.yield();
+ int exp = collationElementIterator.getMaxExpansion(order);
+ Thread.yield();
+ int position = collationElementIterator.getOffset();
+ Thread.yield();
+ //base.log.add("Primary Order of key with position " + position
+ // + " is " + prOrder
+ // + ". Maximum length of any expansion is " + exp);
+ }
+
+ collationElementIterator.reset();
+ Thread.yield();
+
+ for (int j = 0; j < str.length(); j++) {
+ int order = collationElementIterator.next();
+ int secOrder = CollationElementIterator.secondaryOrder(order);
+ int exp = collationElementIterator.getMaxExpansion(order);
+ int position = collationElementIterator.getOffset();
+ //base.log.add("Secondary Order of key with position " + position
+ // + " is " + secOrder
+ // + ". Maximum length of any expansion is " + exp);
+ }
+
+ collationElementIterator.setOffset(0);
+ Thread.yield();
+
+ for (int j = 0; j < str.length(); j++) {
+ int order = collationElementIterator.next();
+ int tOrder = CollationElementIterator.tertiaryOrder(order);
+ int exp = collationElementIterator.getMaxExpansion(order);
+ int position = collationElementIterator.getOffset();
+ //base.log.add("Tertiary Order of key with position " + position
+ // + " is " + tOrder
+ // + ". Maximum length of any expansion is " + exp);
+ }
+
+ break;
+ case 1:
+
+ Segment CI = new Segment();
+ CollationElementIterator collationElementIterator1 = ruleBasedCollator
+ .getCollationElementIterator(CI);
+ Thread.yield();
+ collationElementIterator1.setText(str);
+
+ collationElementIterator1.next();
+ collationElementIterator1.previous();
+
+ for (int j = 0; j < str.length(); j++) {
+ int order = collationElementIterator1.next();
+ int prOrder = CollationElementIterator.primaryOrder(order);
+ int position = collationElementIterator1.getOffset();
+ //base.log.add("Primary Order of key with position " + position
+ // + " is " + prOrder);
+ }
+ break;
+
+ }
+ }
+
+}
+
+final class baseLocales {
+ static final Locale[] Loc = { Locale.CANADA, Locale.CANADA_FRENCH,
+ Locale.CHINA, Locale.CHINESE, Locale.ENGLISH, Locale.FRANCE,
+ Locale.FRENCH, Locale.GERMAN, Locale.GERMANY, Locale.ITALIAN,
+ Locale.ITALY, Locale.JAPAN, Locale.JAPANESE, Locale.KOREA,
+ Locale.KOREAN, Locale.PRC, Locale.SIMPLIFIED_CHINESE,
+ Locale.TAIWAN, Locale.TRADITIONAL_CHINESE, Locale.UK, Locale.US };
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationElementIteratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author osalmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+
+import java.text.CollationKey;
+import java.text.Collator;
+import java.text.RuleBasedCollator;
+import java.util.Locale;
+import java.util.Random;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+/**
+ * GOAL: find resource leaks (or intermittent failures, or cache problems) or
+ * incorrect methods results, connected with use of methods
+ * java.text.CollationKey.compareTo(...) and java.text.CollationKey.equals(...)
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread.
+ *
+ * 2. Gets array of strings to be compared by method compareTo(...). Some of
+ * this strings are obtainted randomly, which returns all chars, for which
+ * isJavaIdentifierPart(ch) returns true.
+ *
+ * 3. In each iteration:
+ * - Gets CollaionKey elements via Collator.getCollationKey(String source)and
+ * RuleBasedCollator.getCollationKey(String source).
+ * - Sort array of strings and
+ * compare come CollationKey elements by method Collationkey.equals.
+ * - Runs System.gc()
+ */
+
+public class CollationKeyTest extends Test {
+
+ public static int callSystemGC = 1;
+
+ public static int NUMBER_OF_ITERATIONS = 100;
+
+ public int numThreads = 10;
+
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new CollationKeyTest().test(args));
+ }
+
+ public int test(String[] params) {
+ parseParams(params);
+ Thread[] t = new Thread[numThreads];
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new CollationKeyRun(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i) {
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie) {
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i) {
+ if (statuses[i] != Status.PASS) {
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+ }
+
+}
+
+class CollationKeyRun implements Runnable {
+ public int id;
+
+ public CollationKeyTest base;
+
+ public CollationKeyRun(int id, CollationKeyTest base) {
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+ String[] WordsToCompare = new String[9];
+
+ String eWithCircumflex = new String("\u00EA");
+ String eWithAcute = new String("\u00E9");
+ String ash = new String("\u00E6");
+
+ WordsToCompare[0] = "p" + eWithAcute + "ch" + eWithAcute;
+ WordsToCompare[1] = "p" + eWithCircumflex + "ch" + ash;
+ WordsToCompare[2] = "p" + ash + "che";
+ WordsToCompare[3] = "peche";
+ WordsToCompare[4] = "Peche";
+ WordsToCompare[5] = "which";
+ WordsToCompare[6] = "which";
+ for (int k = 0; k < CollationKeyTest.NUMBER_OF_ITERATIONS; k++) {
+
+ WordsToCompare[7] = "which" + StringCr.getRandomString((char) 20);
+ WordsToCompare[8] = "which" + StringCr.getRandomString((char) 10);
+
+ Collator myCollator = Collator.getInstance();
+ // base.log.add("Default locale" +
+ // (Locale.getDefault()).toString());
+ CollationKey[] mykeys = new CollationKey[WordsToCompare.length];
+
+ for (int i = 0; i < WordsToCompare.length; i++) {
+ mykeys[i] = myCollator.getCollationKey(WordsToCompare[i]);
+ }
+
+ for (int i = 0; i < mykeys.length - 1; i++) {
+ if (mykeys[i].compareTo(mykeys[i + 1])
+ * mykeys[i + 1].compareTo(mykeys[i]) > 0) {
+ base.statuses[id] = Status.FAIL;
+ base.log.add("Thread "+ id
+ + ": CollationKey.compareTo(...) return incorrect result when used for"
+ + "Strings \""
+ + mykeys[i].getSourceString() + "\" and "
+ + "\"" + mykeys[i + 1].getSourceString() + "\"");
+ }
+ }
+
+ sort(mykeys);
+
+ for (int i = 0; i < mykeys.length; i++)
+ if (!mykeys[i].equals(mykeys[i])) {
+ base.statuses[id] = Status.FAIL;
+ base.log.add("Thread "+ id
+ + ": CollationKey.equals(...) return incorrect result when used to compare"
+ + "CollationKey element with itself. String \""
+ + mykeys[i].getSourceString() + "\", "
+ + "array number " + i);
+ return;
+ }
+
+ RuleBasedCollator RCollator = (RuleBasedCollator) RuleBasedCollator
+ .getInstance();
+ CollationKey[] Rkeys = new CollationKey[mykeys.length];
+
+ for (int i = 0; i < WordsToCompare.length; i++) {
+ Rkeys[i] = RCollator.getCollationKey(mykeys[i]
+ .getSourceString());
+ }
+
+ for (int i = 0; i < Rkeys.length; i++)
+ if (!Rkeys[i].equals(mykeys[i])) {
+ base.statuses[id] = Status.FAIL;
+ base.log.add("Thread "+ id
+ + ": CollationKey.equals(...) return incorrect result when used to compare equal "
+ + "keys, obtained differently. First string: \""
+ + Rkeys[i].getSourceString() + "\", "+"array number " + i
+ + ". Second string: \""
+ + mykeys[i].getSourceString() + "\", "+ "array namber. " + i
+ + "Iteration number " + k);
+ return;
+ }
+
+ Locale[] allLocals = Collator.getAvailableLocales();
+ CollationKey[] _keys = new CollationKey[WordsToCompare.length];
+
+ for (int j = 0; j < allLocals.length; j++) {
+ Collator _myCollator = Collator.getInstance(allLocals[j]);
+ // base.log.add("Used locale" + (allLocals[j]).toString());
+ for (int i = 0; i < WordsToCompare.length; i++) {
+ _keys[i] = _myCollator.getCollationKey(WordsToCompare[i]);
+ }
+ sort(_keys);
+
+ Random rand = new Random();
+ int FIntToComp = rand.nextInt(_keys.length);
+ int SIntToComp = rand.nextInt(_keys.length);
+ boolean ColKeyEquals = _keys[FIntToComp]
+ .equals(mykeys[SIntToComp]);
+ if (ColKeyEquals) {
+ if (_keys[FIntToComp].compareTo(mykeys[SIntToComp]) != 0) {
+ base.statuses[id] = Status.FAIL;
+ base.log.add("Thread "+ id
+ + ":CollationKey.compareTo returned not 0 for equal keys "
+ + _keys[FIntToComp].toString()
+ + " (array number " + FIntToComp
+ + ", string \""
+ + _keys[FIntToComp].getSourceString()
+ + "\") and "
+ + mykeys[SIntToComp].toString()
+ + " (array number " + SIntToComp
+ + ", string \""
+ + mykeys[SIntToComp].getSourceString()
+ + "\") is " + ColKeyEquals);
+ }
+ }
+ }
+
+ if (CollationKeyTest.callSystemGC != 0) {
+ System.gc();
+ }
+ }
+ base.statuses[id] = Status.PASS;
+ }
+
+ private void sort(CollationKey[] _keys) {
+ boolean bool = false;
+ while (bool == false) {
+ for (int i = 0; i < _keys.length - 1; i++) {
+ bool = true;
+ if (_keys[i].compareTo(_keys[i + 1]) > 0) {
+ CollationKey CK = _keys[i];
+ _keys[i] = _keys[i + 1];
+ _keys[i + 1] = CK;
+ bool = false;
+ }
+ }
+ }
+
+ for (int i = 0; i < _keys.length; i++) {
+ // base.log.add(_keys[i].getSourceString());
+ }
+ }
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest_ArrHash.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest_ArrHash.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest_ArrHash.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest_ArrHash.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,283 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author osalmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import java.text.CollationKey;
+import java.text.Collator;
+import java.util.Locale;
+import java.util.Random;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+/**
+ * GOAL: find resource leaks (or intermittent failures, or cache problems) or
+ * incorrect methods results, connected with use of methods
+ * java.text.CollationKey.hashCode() and java.text.CollationKey.toByteArray()
+ *
+ * The test does:
+ *
+ * 1. Reads parameters, which are: param[0] - number of threads to be run in
+ * parallel param[1] - number of iterations in each thread.
+ *
+ * 2. Gets array of strings to be compared by method compareTo(...). Some of
+ * this strings are obtainted randomly, which returns all chars, for which
+ * isJavaIdentifierPart(ch) returns true.
+ *
+ * 3. - Gets CollaionKey elements via Collator.getCollationKey(String source)for
+ * default Locale and for all available Locales, obtained by Collator.getAvailableLocales().
+ * - Sort array of strings and checks, that
+ * - - correspondent array, obtained by CollatioKey.toByteArray() have the same order.
+ * - - if some of these arrays are equal, correspondent CollationKeys must be equal and
+ * their hashcodes also must be equal.
+ * - Runs System.gc()
+ */
+
+public class CollationKeyTest_ArrHash extends Test {
+
+ public static int callSystemGC = 1;
+
+ public static int NUMBER_OF_ITERATIONS = 100;
+
+ public int numThreads = 10;
+
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new CollationKeyTest_ArrHash().test(args));
+ }
+
+ public int test(String[] params) {
+ parseParams(params);
+ Thread[] t = new Thread[numThreads];
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new CollationKey_ArrHashRun(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i) {
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie) {
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i) {
+ if (statuses[i] != Status.PASS) {
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+ }
+
+}
+
+class CollationKey_ArrHashRun implements Runnable {
+ public int id;
+
+ public CollationKeyTest_ArrHash base;
+
+ public CollationKey_ArrHashRun(int id, CollationKeyTest_ArrHash base) {
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+ String[] WordsToCompare = new String[9];
+
+ String eWithCircumflex = new String("\u00EA");
+ String eWithAcute = new String("\u00E9");
+ String ash = new String("\u00E6");
+
+ WordsToCompare[0] = "p" + eWithAcute + "ch" + eWithAcute;
+ WordsToCompare[1] = "p" + eWithCircumflex + "ch" + ash;
+ WordsToCompare[2] = "p" + ash + "che";
+ WordsToCompare[3] = "peche";
+ WordsToCompare[4] = "Peche";
+ WordsToCompare[5] = "which";
+ WordsToCompare[6] = "which";
+
+ Locale[] allLocals = Collator.getAvailableLocales();
+ //base.log.add("Number of available locales is" + allLocals.length);
+
+ for (int k = 0; k < CollationKeyTest_ArrHash.NUMBER_OF_ITERATIONS; k++) {
+
+ WordsToCompare[7] = "which" + StringCr.getRandomString((char) 20);
+ WordsToCompare[8] = "which" + StringCr.getRandomString((char) 10);
+
+ Collator myCollator = Collator.getInstance();
+ // base.log.add("Default locale" +
+ // (Locale.getDefault()).toString());
+ CollationKey[] mykeys = new CollationKey[WordsToCompare.length];
+
+ for (int i = 0; i < WordsToCompare.length; i++) {
+ mykeys[i] = myCollator.getCollationKey(WordsToCompare[i]);
+ }
+
+ sort(mykeys);
+ Thread.yield();
+ check_ArrHash(mykeys, Locale.getDefault());
+ Thread.yield();
+
+ CollationKey[] _keys = new CollationKey[WordsToCompare.length];
+ for (int j = 0; j < allLocals.length; j++) {
+ Collator _myCollator = Collator.getInstance(allLocals[j]);
+ // base.log.add("Used locale" + (allLocals[j]).toString());
+ for (int i = 0; i < WordsToCompare.length; i++) {
+ _keys[i] = _myCollator.getCollationKey(WordsToCompare[i]);
+ }
+ sort(_keys);
+ Thread.yield();
+ check_ArrHash(_keys, allLocals[j]);
+ Thread.yield();
+ }
+ if (base.callSystemGC != 0) {
+ System.gc();
+ }
+ }
+
+ if(base.statuses[id] != Status.FAIL) base.statuses[id] = Status.PASS;
+ }
+
+ private void check_ArrHash(CollationKey[] SomeKeys, Locale L) {
+ byte[][] SomeBytes = new byte[SomeKeys.length][];
+
+ for (int i = 0; i < SomeKeys.length; i++) {
+ SomeBytes[i] = new byte[SomeKeys[i].toByteArray().length];
+ }
+
+ for (int i = 0; i < SomeKeys.length; i++) {
+ for (int j = 0; j < SomeKeys[i].toByteArray().length; j++) {
+ SomeBytes[i][j] = SomeKeys[i].toByteArray()[j];
+ }
+ }
+
+ // for (int i = 0; i < SomeBytes.length; i++) {
+ // print(SomeBytes[i]);
+ // }
+
+ for (int k = 0; k < SomeBytes.length - 1; k++) {
+ int fkey, skey;
+ int compared = 0;
+
+ int i = 0;
+ do {
+ fkey = SomeBytes[k][i] & 0xFF;
+ skey = SomeBytes[k + 1][i] & 0xFF;
+ if (fkey < skey) {
+ compared = -1;
+ //base.log.add("Used Locale " + L + " TRUE "
+ // + SomeKeys[k].getSourceString() + " "
+ // + SomeKeys[k + 1].getSourceString());
+ }
+ if (skey < fkey) {
+ base.log.add("String \"" + SomeKeys[k].getSourceString()
+ + "\" with number " + k
+ + " is greater than string \""
+ + SomeKeys[k + 1].getSourceString()
+ + "\" with number " + (k + 1));
+ compared = 1;
+ print(SomeBytes[k]);
+ print(SomeBytes[k + 1]);
+ base.log.add("Used Locale " + L + " FALSE "
+ + SomeKeys[k].getSourceString() + " "
+ + SomeKeys[k + 1].getSourceString());
+ base.statuses[id] = Status.FAIL;
+ }
+ i++;
+ } while ((i != (SomeBytes[k].length - 1))
+ && (i != (SomeBytes[k + 1].length - 1)) && (compared == 0));
+
+ if (compared == 0) {
+ int HC = SomeKeys[k].hashCode();
+ int HC1 = SomeKeys[k + 1].hashCode();
+ if (HC != HC1) {
+ base.log.add("Method CollationKey.hashCode gives"
+ + " different results for equal keys:"
+ + SomeKeys[k].toString() + " "
+ + SomeKeys[k + 1].toString());
+ print(SomeBytes[k]);
+ print(SomeBytes[k + 1]);
+
+ base.statuses[id] = Status.FAIL;
+ }
+ if (!(SomeKeys[k].equals(SomeKeys[k + 1]))) {
+ base.log.add("Strings, obtained by CollationKey.toByteArray() are equal,"
+ + " but CollationKey.equals returned false");
+ print(SomeBytes[k]);
+ print(SomeBytes[k + 1]);
+ base.statuses[id] = Status.FAIL;
+ }
+ }
+ }
+ }
+
+ private void print(byte[] bs) {
+ String toPrint = "";
+ for (int j = 0; j < bs.length; j++) {
+ toPrint = toPrint + " " + bs[j];
+ }
+ base.log.add(toPrint);
+
+ }
+
+ private void sort(CollationKey[] _keys) {
+
+ boolean bool = false;
+ while (bool == false) {
+ bool = true;
+ for (int i = 0; i < _keys.length - 1; i++) {
+ if (_keys[i].compareTo(_keys[i + 1]) > 0) {
+ CollationKey CK = _keys[i];
+ _keys[i] = _keys[i + 1];
+ _keys[i + 1] = CK;
+ bool = false;
+ }
+ }
+ }
+
+ // for (int i = 0; i < _keys.length; i++) {
+ // base.log.add(_keys[i].getSourceString());
+ // }
+ }
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/CollationKeyTest_ArrHash.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/DecimalFormat_Locales.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/DecimalFormat_Locales.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/DecimalFormat_Locales.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/DecimalFormat_Locales.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import org.apache.harmony.test.reliability.share.Test;
+
+/**
+ * Goal: find resource leaks or intermittent failures or java.text.DecimalFormat cache problems.
+ * Methods applyPattern(...) and format(...) are mainly tested.
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of threads to be run in parallel
+ * param[1] - number of iterations in each thread.
+ *
+ * 2. Gets all available locales via Locale.getAvailableLocales().
+ * 3. Create different patterns for the number 1234.5678.
+ * 4. Apply all these patterns for each locale in each thread NUMBER_OF_ITERATION times.
+ * 5. Runs System.gc().
+ *
+ */
+
+public class DecimalFormat_Locales extends Test {
+
+ public static int callSystemGC = 1;
+
+ public static int NUMBER_OF_ITERATIONS = 100;
+
+ public int numThreads = 10;
+
+ public int[] statuses;
+
+ public static void main(String[] args) {
+ System.exit(new DecimalFormat_Locales().test(args));
+ }
+
+ public int test(String[] params) {
+ parseParams(params);
+
+ Thread[] t = new Thread[numThreads];
+
+ statuses = new int[t.length];
+
+ for (int i = 0; i < t.length; i++) {
+ t[i] = new Thread(new DecimalFormatRunner(i, this));
+ t[i].start();
+ //log.add("Thread " + i + " started");
+ }
+
+ // Correctly wait for all threads to finish
+
+ for (int i = 0; i < t.length; ++i) {
+ try {
+ t[i].join();
+ //log.add("Thread " + i + ": joined() ");
+
+ } catch (InterruptedException ie) {
+ return fail("interruptedException while join() of thread #" + i);
+ }
+ }
+
+ // For each thread check whether operations/checks PASSed in the thread
+
+ for (int i = 0; i < statuses.length; ++i) {
+ if (statuses[i] != Status.PASS) {
+ return fail("thread #" + i + " returned not PASS status");
+ }
+ //log.add("Status of thread " + i + ": is PASS");
+ }
+
+ return pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+ if (params.length >= 1) {
+ numThreads = Integer.parseInt(params[0]);
+ }
+ if (params.length >= 2) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[1]);
+ }
+ }
+}
+
+class DecimalFormatRunner implements Runnable {
+ public int id;
+ public DecimalFormat_Locales base;
+
+
+ public DecimalFormatRunner(int id, DecimalFormat_Locales base) {
+ this.id = id;
+ this.base = base;
+ }
+
+ public void run() {
+ Locale[] allLocales = Locale.getAvailableLocales();
+ String[] Patterns = new String[10];
+ Patterns[0] = "###,###.###";
+ Patterns[1] = "###.##";
+ Patterns[2] = "000000.000";
+ Patterns[3] = "$###,###.###";
+ Patterns[4] = "\u00A5###,###.###";
+ Patterns[5] = "#####%";
+ Patterns[6] = "\u00A4###,###.###";
+ Patterns[7] = "#####\u2030 ";
+ Patterns[8] = "0.###E0";
+ Patterns[9] = "'#%'0.###E0";
+
+ double value = 1234.5678;
+ for(int i = 0; i < allLocales.length; i++){
+ for(int k = 0; k < base.NUMBER_OF_ITERATIONS; k++){
+
+ NumberFormat nf = NumberFormat.getNumberInstance(allLocales[i]);
+ Thread.yield();
+ DecimalFormat df = (DecimalFormat)nf;
+ Thread.yield();
+ for(int j = 0; j < Patterns.length; j++){
+ df.applyPattern(Patterns[j]);
+ Thread.yield();
+ String output = df.format(value);
+ //base.log.add(Patterns[j] + " " + output + " " + allLocales[i]);
+ }
+
+ if (base.callSystemGC != 0){
+ System.gc();
+ }
+
+ }
+ }
+ base.statuses[id] = Status.PASS;
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/DecimalFormat_Locales.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/Status.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/Status.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/Status.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/Status.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+
+package org.apache.harmony.test.reliability.api.text;
+
+
+public class Status {
+ public static final int FAIL = -10;
+ public static final int PASS = 10;
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/Status.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCr.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCr.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCr.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCr.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+public class StringCr {
+ public static String getRandomString(char size) {
+ char[] ch = new char[size];
+ Random rand = new Random();
+ int i = 0;
+ while (i < size) {
+
+ int c = rand.nextInt(0xFFFF);
+ if (Character.isJavaIdentifierPart((char) c)) {
+ ch[i++] = (char) c;
+ }
+ }
+ return new String(ch);
+ }
+}
\ No newline at end of file
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCr.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCrC.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCrC.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCrC.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCrC.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+public class StringCrC {
+ public static String getRandomString(char size) {
+ char[] ch = new char[size];
+ Random rand = new Random();
+ int i = 0;
+ while (i < size) {
+
+ int c = rand.nextInt(0xFFFF);
+ if (Character.isJavaIdentifierPart((char) c)) {
+ ch[i++] = (char) c;
+ }
+ }
+ return new String(ch);
+ }
+}
+
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/StringCrC.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocales_Coll.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocales_Coll.java?view=auto&rev=545554
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocales_Coll.java (added)
+++ harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocales_Coll.java Fri Jun 8 09:34:52 2007
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Olessia Salmina
+ */
+
+package org.apache.harmony.test.reliability.api.text;
+
+
+import org.apache.harmony.test.reliability.share.Test;
+import java.util.*;
+import java.text.*;
+
+
+/**
+ * Goal: find resource leaks (or intermittent failures, or cache problems),
+ * connected with use of following java.text.Collator methods:
+ * - java.text.Collator.getAvailableLocales()
+ * - java.text.Collator.getInstance()
+ * - java.text.Collator.getInstance(Locale)
+ * - java.text.Collator.setStrength(int)
+ * - java.text.Collator.compare(...)
+ *
+ * The test does:
+ * 1. Reads parameters, which are:
+ * param[0] - number of iterations in each thread.
+ *
+ * 2. Obtain array of strings to be sorted by method collator.compare(...)
+ * 3. In a cycle sort this array for default Locale and for all available Locales,
+ * obtained by Collator.getAvailableLocales().
+ * Comparison occurs in all possible modes: Collator.PRIMARY, Collator.SECONDARY,
+ * Collator.TERTIARY, Collator.IDENTICAL.
+ *
+ * 4. Runs System.gc()
+*/
+
+public class getAvailableLocales_Coll extends Test {
+
+ public static int callSystemGC = 1;
+
+ public static int NUMBER_OF_ITERATIONS = 100;
+
+ public static void main(String[] args) {
+ System.exit(new getAvailableLocales_Coll().test(args));
+ }
+
+ public int test(String[] params) {
+
+ boolean failed = false;
+
+ parseParams(params);
+
+ String[] WordsToCompare = new String [7];
+
+ String eWithCircumflex = new String("\u00EA");
+ String eWithAcute = new String("\u00E9");
+ String ash = new String("\u00E6");
+
+ WordsToCompare[0] = "p" + eWithAcute + "ch" + eWithAcute;
+ WordsToCompare[1] = "p" + eWithCircumflex + "ch" + ash;
+ WordsToCompare[2] = "p" + ash + "che";
+ WordsToCompare[3] = "peche";
+ WordsToCompare[4] = "Peche";
+ WordsToCompare[5] = "which";
+ WordsToCompare[6] = "which";
+
+ for (int k = 0; k < NUMBER_OF_ITERATIONS; k++) {
+
+ compare(WordsToCompare);
+ Locale[] allLocals = Collator.getAvailableLocales();
+
+ for(int i = 0; i < allLocals.length; i++){
+ compare(WordsToCompare, allLocals[i]);
+ }
+
+ if (callSystemGC != 0){
+ System.gc();
+ }
+ }
+
+
+ return failed == true ? fail("failed") : pass("OK");
+ }
+
+
+ public void parseParams(String[] params) {
+
+ if (params.length >= 1) {
+ NUMBER_OF_ITERATIONS = Integer.parseInt(params[0]);
+ }
+
+ }
+
+ public void compare(String[] Words) {
+
+ //log.add("Default locale " + (Locale.getDefault()).toString());
+ Collator Col =
+ Collator.getInstance();
+
+ Col.setStrength(Collator.PRIMARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.SECONDARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.TERTIARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.IDENTICAL);
+ comp(Col, Words);
+
+ }
+
+
+ public void compare(String[] Words, Locale currentLocale) {
+
+ //log.add("Used locale " + (currentLocale.toString()));
+ Collator Col =
+ Collator.getInstance(currentLocale);
+
+ Col.setStrength(Collator.PRIMARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.SECONDARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.TERTIARY);
+ comp(Col, Words);
+ Col.setStrength(Collator.IDENTICAL);
+ comp(Col, Words);
+
+ }
+
+
+ public void comp(Collator collator, String[] words) {
+
+ String tmp;
+ String[] WordsToSort = new String[words.length];
+ for(int i = 0; i < WordsToSort.length; i++){
+ WordsToSort[i] = new String(words[i]);
+ }
+ for (int i = 0; i < WordsToSort.length; i++) {
+ for (int j = i + 1; j < WordsToSort.length; j++) {
+
+ if (collator.compare(WordsToSort[i], WordsToSort[j] ) > 0 ) {
+
+ tmp = WordsToSort[i];
+ WordsToSort[i] = WordsToSort[j];
+ WordsToSort[j] = tmp;
+ }
+ }
+ }
+ //for (int i = 0; i < WordsToSort.length; i++){
+ // log.add(" "+WordsToSort[i]);
+ //}
+ //log.add("------------------");
+ }
+
+}
Propchange: harmony/enhanced/buildtest/branches/2.0/tests/reliability/src/java/org/apache/harmony/test/reliability/api/text/getAvailableLocales_Coll.java
------------------------------------------------------------------------------
svn:eol-style = native