You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 12:47:39 UTC
svn commit: r386058 [47/49] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/archive/make/common/ modules/archive/src/test/java/tests/
modules/archive/src/test/java/tests/api/
modules/archive/src/test/java/tests/api/java/ modules/archive/...
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_PropertiesTest.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_PropertiesTest.properties?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_PropertiesTest.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_PropertiesTest.properties Wed Mar 15 03:46:17 2006
@@ -0,0 +1,29 @@
+
+
+
+
+ \ \r \n \t \f
+
+
+! dshfjklahfjkldashgjl;as
+ #jdfagdfjagkdjfghksdajfd
+
+!!properties
+
+a=a
+b bb as,dn
+c\r\ \t\nu =:: cu
+bu= b\
+ u
+d=d\r\ne=e
+f :f\
+f\
+ f
+g g
+h\u0020h
+\ i=i
+j=\ j
+space=\ c
+
+dblbackslash=\\
+
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_ZipFile.zip
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_ZipFile.zip?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_ZipFile.zip
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_att.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_att.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_att.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_available.tst
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_available.tst?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_available.tst
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_checkInput.txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_checkInput.txt?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_checkInput.txt (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_checkInput.txt Wed Mar 15 03:46:17 2006
@@ -0,0 +1,4 @@
+ crc.reset();
+ crc.update(1);
+ //System.out.print("value of crc"+crc.getValue());
+
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compDiction.txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compDiction.txt?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compDiction.txt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compressD.txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compressD.txt?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_compressD.txt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(O).txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru%28O%29.txt?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(O).txt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(OD).txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru%28OD%29.txt?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(OD).txt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(ODI).txt
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru%28ODI%29.txt?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_constru(ODI).txt
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_htmltest.html
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_htmltest.html?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_htmltest.html (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_htmltest.html Wed Mar 15 03:46:17 2006
@@ -0,0 +1,38 @@
+<HTML>
+<TITLE>Test HTML Document</TITLE>
+<BODY>
+<H2>Test HTML Document</H2>
+This file is used by the <CODE>Test_java_net_URL.test_getContent()</CODE>.
+<p>
+It contains the string <quote>A Seemingly Non Important String</quote>. Which is
+looked for in the testcase.<P>
+<UL>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+<LI>A Line of text</LI>
+</UL>
+<p>
+A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a
paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. A bunch of text representing part of a paragraph. <p>
+
+The End.
+</BODY>
+</HTML>
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_mainClass.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_mainClass.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_mainClass.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_manifest1.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_manifest1.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_manifest1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_missingclass.ser
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_missingclass.ser?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_missingclass.ser
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch2.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch2.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_patch2.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_resource.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_resource.properties?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_resource.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_resource.properties Wed Mar 15 03:46:17 2006
@@ -0,0 +1,2 @@
+property=parent
+
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_security.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_security.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_security.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_signed.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_signed.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/hyts_signed.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF Wed Mar 15 03:46:17 2006
@@ -0,0 +1,26 @@
+Manifest-Version: 1.0
+Bundle-Name: ClientSupport
+Bundle-Description: Provides SessionService, AuthenticationService. Extends RegistryService.
+Bundle-Activator: com.ibm.ive.eccomm.client.support.ClientSupportActivator
+Import-Package: com.ibm.ive.eccomm.client.services.log,
+ com.ibm.ive.eccomm.client.services.registry,
+ com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,
+ com.ibm.ive.eccomm.service.session; specification-version=1.0.0,
+ com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,
+ org.osgi.framework; specification-version=1.0.0,
+ org.osgi.service.log; specification-version=1.0.0,
+ com.ibm.ive.eccomm.flash; specification-version=1.2.0,
+ com.ibm.ive.eccomm.client.xml,
+ com.ibm.ive.eccomm.client.http.common,
+ com.ibm.ive.eccomm.client.http.client
+Import-Service: org.osgi.service.log.LogReaderService
+ org.osgi.service.log.LogService,
+ com.ibm.ive.eccomm.service.registry.RegistryService
+Export-Package: com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,
+ com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,
+ com.ibm.ive.eccomm.common; specification-version=1.0.0,
+ com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0
+Export-Service: com.ibm.ive.eccomm.service.authentication.AuthenticationService,
+ com.ibm.ive.eccomm.service.session.SessionService
+Bundle-Vendor: IBM
+Bundle-Version: 1.2.0
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar?rev=386058&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties Wed Mar 15 03:46:17 2006
@@ -0,0 +1,2 @@
+property=resource
+
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_AvailTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_AvailTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_AvailTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_AvailTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,104 @@
+/* Copyright 2002, 2005 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 tests.support;
+
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class Support_AvailTest {
+
+ public static void main(String[] args) {
+ // This test is for:
+
+ // This program accepts from stdin a
+ // string of the form '<int1> <int2> <data>'
+ // where data is some bytes, <int1> is the length of the whole string
+ // and <int2> is the length in bytes of <data> (all bytes until the end
+ // of
+ // the input)
+
+ // If the string is formatted correctly, and the available method works
+ // the string "true" will be sent to stdout, otherwise "false"
+ String output = "true";
+ try {
+ FileInputStream myin = new FileInputStream(FileDescriptor.in);
+ StringBuffer input = new StringBuffer("");
+
+ try {
+ Thread.sleep(500);
+ } catch (Exception sleepException) {
+ }
+
+ int real = myin.available();
+ int expected;
+ int c = 0;
+ while (true) {
+ c = myin.read();
+ if (c == ' ' || c == -1)
+ break;
+ input.append((char) c);
+ }
+ expected = Integer.parseInt(input.toString());
+ // Verify correct value at start of read
+ if (real != expected)
+ output = "Failed avail test1 - " + real + "!=" + expected;
+
+ c = 0;
+ input = new StringBuffer("");
+ while (true) {
+ c = myin.read();
+ if (c == ' ' || c == -1)
+ break;
+ input.append((char) c);
+ }
+ expected = Integer.parseInt(input.toString());
+ real = myin.available();
+ // Verify value at middle of reading
+ // This test doesn't work on Windows, at present
+ // if(real != expected) output = "Failed avail test2 - " + real +
+ // "!=" + expected;
+
+ // Verify value at end of reading
+ // loop to EOF, then check if available = 0
+ // replace this:
+ for (int i = 0; i < 5; i++)
+ myin.read();
+ // with:
+ // while(myin.read() != -1);
+
+ // The current for loop reads exactly to the end
+ // of the data, but is dependent on knowing the length of the data
+ // sent to it, which isn't nice
+
+ expected = 0;
+ real = myin.available();
+ if (real != 0)
+ output = "Failed avail test3 - " + real + "!=" + expected;
+
+ } catch (IOException e) {
+ output = "IOException during available() testing";
+ }
+
+ try {
+ FileOutputStream myout = new FileOutputStream(FileDescriptor.out);
+ myout.write(output.getBytes());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_BitSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_BitSet.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_BitSet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_BitSet.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,189 @@
+/* Copyright 2004, 2005 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 tests.support;
+
+public class Support_BitSet {
+ private long[] bits;
+
+ private static final int ELM_SIZE = 64; // Size in bits of the data type
+
+ // being used in the bits array
+
+ /**
+ * Create a new BitSet with size equal to 64 bits
+ *
+ * @return The number of bits contained in this BitSet.
+ *
+ * @see #clear
+ * @see #set
+ */
+ public Support_BitSet() {
+ this(64);
+ }
+
+ /**
+ * Create a new BitSet with size equal to nbits. If nbits is not a multiple
+ * of 64, then create a BitSet with size nbits rounded to the next closest
+ * multiple of 64.
+ *
+ * @exception NegativeArraySizeException
+ * if nbits < 0.
+ * @see #clear
+ * @see #set
+ */
+ public Support_BitSet(int nbits) {
+ if (nbits >= 0)
+ bits = new long[(nbits / ELM_SIZE) + (nbits % ELM_SIZE > 0 ? 1 : 0)];
+ else
+ throw new NegativeArraySizeException();
+ }
+
+ /**
+ * Clears the bit at index pos. Grows the BitSet if pos > size.
+ *
+ * @param pos
+ * int
+ *
+ * @exception IndexOutOfBoundsException
+ * when pos < 0
+ * @see #set
+ */
+ public void clear(int pos) {
+ if (pos >= 0) {
+ if (pos < bits.length * ELM_SIZE)
+ bits[pos / ELM_SIZE] &= ~(1L << (pos % ELM_SIZE));
+ else
+ growBits(pos); // Bit is cleared for free if we have to grow
+ } else
+ throw new IndexOutOfBoundsException("Negative index specified");
+ }
+
+ /**
+ * Retrieve the bit at index pos. Grows the BitSet if pos > size.
+ *
+ * @param pos
+ * int
+ * @return A boolean value indicating whether the bit at pos has been set.
+ * Answers false if pos > size().
+ *
+ * @exception IndexOutOfBoundsException
+ * when pos < 0
+ * @see #set
+ * @see #clear
+ */
+ public boolean get(int pos) {
+ if (pos >= 0) {
+ if (pos < bits.length * ELM_SIZE)
+ return (bits[pos / ELM_SIZE] & (1L << (pos % ELM_SIZE))) != 0;
+ return false;
+ } else
+ throw new IndexOutOfBoundsException("Negative index specified");
+ }
+
+ /**
+ * Increase the size of the internal array to accomodate pos bits. The new
+ * array max index will be a multiple of 64
+ *
+ * @param pos
+ * int The index the new array needs to be able to access
+ */
+ private void growBits(int pos) {
+ pos++; // Inc to get correct bit count
+ long[] tempBits = new long[(pos / ELM_SIZE)
+ + (pos % ELM_SIZE > 0 ? 1 : 0)];
+ System.arraycopy(bits, 0, tempBits, 0, bits.length);
+ bits = tempBits;
+ }
+
+ /**
+ * Sets the bit at index pos to 1. Grows the BitSet if pos > size.
+ *
+ * @param pos
+ * int
+ *
+ * @exception IndexOutOfBoundsException
+ * when pos < 0
+ * @see #clear
+ */
+ public void set(int pos) {
+ if (pos >= 0) {
+ if (pos >= bits.length * ELM_SIZE)
+ growBits(pos);
+ bits[pos / ELM_SIZE] |= 1L << (pos % ELM_SIZE);
+ } else
+ throw new IndexOutOfBoundsException("Negative index specified");
+ }
+
+ /**
+ * Clears the bit at index pos.
+ *
+ * @return The number of bits contained in this BitSet.
+ *
+ * @see #BitSet
+ * @see #clear
+ * @see #set
+ */
+ public int size() {
+ return bits.length * ELM_SIZE;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ * @return A comma delimited list of the indices of all bits that are set.
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(bits.length / 2);
+ int bitCount = 0;
+ sb.append('{');
+ boolean comma = false;
+ for (int i = 0; i < bits.length; i++) {
+ if (bits[i] == 0) {
+ bitCount += ELM_SIZE;
+ continue;
+ }
+ for (int j = 0; j < ELM_SIZE; j++) {
+ if (((bits[i] & (1L << j)) != 0)) {
+ if (comma)
+ sb.append(", ");
+ sb.append(bitCount);
+ comma = true;
+ }
+ bitCount++;
+ }
+ }
+ sb.append('}');
+ return sb.toString();
+ }
+
+ /**
+ * Returns the number of bits up to and including the highest bit set.
+ *
+ */
+ public int length() {
+ int idx = bits.length - 1;
+ while (idx >= 0 && bits[idx] == 0)
+ --idx;
+ if (idx == -1)
+ return 0;
+ int i = ELM_SIZE - 1;
+ long val = bits[idx];
+ while ((val & (1L << i)) == 0 && i > 0)
+ i--;
+ return idx * ELM_SIZE + i + 1;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_CollectionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_CollectionTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_CollectionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_CollectionTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,104 @@
+/* Copyright 1998, 2005 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 tests.support;
+
+import java.util.Collection;
+import java.util.TreeSet;
+
+/**
+ * @tests java.util.Collection
+ */
+public class Support_CollectionTest extends junit.framework.TestCase {
+
+ Collection col; // must contain the Integers 0 to 99
+
+ public Support_CollectionTest(String p1) {
+ super(p1);
+ }
+
+ public Support_CollectionTest(String p1, Collection c) {
+ super(p1);
+ col = c;
+ }
+
+ public void runTest() {
+ new Support_UnmodifiableCollectionTest("", col).runTest();
+
+ // setup
+ Collection myCollection = new TreeSet();
+ myCollection.add(new Integer(101));
+ myCollection.add(new Integer(102));
+ myCollection.add(new Integer(103));
+
+ // add
+ assertTrue("CollectionTest - a) add did not work", col.add(new Integer(
+ 101)));
+ assertTrue("CollectionTest - b) add did not work", col
+ .contains(new Integer(101)));
+
+ // remove
+ assertTrue("CollectionTest - a) remove did not work", col
+ .remove(new Integer(101)));
+ assertTrue("CollectionTest - b) remove did not work", !col
+ .contains(new Integer(101)));
+
+ // addAll
+ assertTrue("CollectionTest - a) addAll failed", col
+ .addAll(myCollection));
+ assertTrue("CollectionTest - b) addAll failed", col
+ .containsAll(myCollection));
+
+ // containsAll
+ assertTrue("CollectionTest - a) containsAll failed", col
+ .containsAll(myCollection));
+ col.remove(new Integer(101));
+ assertTrue("CollectionTest - b) containsAll failed", !col
+ .containsAll(myCollection));
+
+ // removeAll
+ assertTrue("CollectionTest - a) removeAll failed", col
+ .removeAll(myCollection));
+ assertTrue("CollectionTest - b) removeAll failed", !col
+ .removeAll(myCollection)); // should not change the colletion
+ // the 2nd time around
+ assertTrue("CollectionTest - c) removeAll failed", !col
+ .contains(new Integer(102)));
+ assertTrue("CollectionTest - d) removeAll failed", !col
+ .contains(new Integer(103)));
+
+ // retianAll
+ col.addAll(myCollection);
+ assertTrue("CollectionTest - a) retainAll failed", col
+ .retainAll(myCollection));
+ assertTrue("CollectionTest - b) retainAll failed", !col
+ .retainAll(myCollection)); // should not change the colletion
+ // the 2nd time around
+ assertTrue("CollectionTest - c) retainAll failed", col
+ .containsAll(myCollection));
+ assertTrue("CollectionTest - d) retainAll failed", !col
+ .contains(new Integer(0)));
+ assertTrue("CollectionTest - e) retainAll failed", !col
+ .contains(new Integer(50)));
+
+ // clear
+ col.clear();
+ assertTrue("CollectionTest - a) clear failed", col.isEmpty());
+ assertTrue("CollectionTest - b) clear failed", !col
+ .contains(new Integer(101)));
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,436 @@
+/* Copyright 1998, 2005 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 tests.support;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+/**
+ * This class is responsible for providing the dynamic names and addresses for
+ * the java.net classes. There are two directories which need to be placed on an
+ * ftp server and an http server which should accompany this source. The
+ * ftp-files have to be placed on an ftp server and have to be the root of a
+ * user jcltest with password jclpass. The testres files must be available on an
+ * HTTP server and the name and location can be configured below.
+ */
+public class Support_Configuration {
+
+ public static String DomainAddress = "apache.org";
+
+ public static String WebName = "jcltest.";
+
+ public static final String HomeAddress;
+
+ public static String TestResourcesDir = "/testres231";
+
+ public static final String TestResources;
+
+ public static String HomeAddressResponse = "HTTP/1.1 200 OK";
+
+ public static String HomeAddressSoftware = "Apache/1.3.33 (Win32)";
+
+ public static String ProxyServerTestHost = "jcltest.apache.org";
+
+ public static String SocksServerTestHost = "jcltest.apache.org";
+
+ public static int SocksServerTestPort = 1080;
+
+ // Need an IP address that does not resolve to a host name
+ public static String UnresolvedIP = "192.168.99.99";
+
+ // the bytes for an address which represents an address which is not
+ // one of the addresses for any of our machines on which tests will run
+ // it is used to verify we get the expected error when we try to bind
+ // to an address that is not one of the machines local addresses
+ public static byte nonLocalAddressBytes[] = { 1, 0, 0, 0 };
+
+ public static String InetTestAddress = "localhost";
+
+ public static String InetTestIP = "127.0.0.1";
+
+ public static String InetTestAddress2 = "localhost";
+
+ public static String InetTestIP2 = "127.0.0.1";
+
+ public static byte[] InetTestCaddr = { 9, 26, -56, -111 };
+
+ public static int InetTestHashcode = 2130706433;
+
+ public static final String HomeAddress6 = "jcltest6.apache.org";
+
+ public static String IPv6GlobalAddressJcl4 = "FE80:0000:0000:0000:020D:60FF:FE0F:A776%4"; // this
+
+ public static String ProxyServerTestHostIPv6 = "jcltest6.apache.org";
+
+ public static String InetTestIP6 = "fe80::20d:60ff:fe24:7410";
+
+ public static String InetTestIP6LO = "::1";
+
+ // ip address that resolves to a host that is not present on the local
+ // network
+ // this allows us to check the timeouts for connect
+ public static String ResolvedNotExistingHost = "9.26.194.72";
+
+ /**
+ * You can compute the hash code with the following code: try { String name =
+ * "whatever.xxx.com";
+ * System.out.println(InetAddress.getByName(name).hashCode()); } catch
+ * (UnknownHostException e) {}
+ */
+
+ /**
+ * An address that resolves to more than one IP address so that the
+ * getAllByName test has something to test.
+ */
+ public static String SpecialInetTestAddress = "jcltestmultiple.apache.org";
+
+ public static int SpecialInetTestAddressNumber = 4;
+
+ /**
+ * InetAlias1 and InetAlias2 must be different host names that resolve to
+ * the same IP address.
+ */
+ public static String InetAlias1 = "alias1.apache.org";
+
+ public static String InetAlias2 = "alias2.apache.org";
+
+ public static String FTPTestAddress = "jcltest:jclpass@localhost";
+
+ public static String URLConnectionLastModifiedString = "Mon, 14 Jun 1999 21:06:22 GMT";
+
+ public static long URLConnectionLastModified = 929394382000L;
+
+ public static long URLConnectionDate = 929106872000L;
+
+ public static boolean RunCommTests = false;
+
+ public static String Port1 = "COM1";
+
+ public static String Port2 = "COM2";
+
+ static Hashtable props = null;
+ static {
+ loadProperties();
+ HomeAddress = WebName + DomainAddress;
+ TestResources = HomeAddress + TestResourcesDir;
+ }
+
+ static void loadProperties() {
+ InputStream in = null;
+ Hashtable props = new Hashtable();
+
+ String iniName = System.getProperty("test.ini.file", "JCLAuto.ini");
+ if (System.getProperty("test.comm") != null) {
+ RunCommTests = true;
+ }
+
+ try {
+ in = new FileInputStream(iniName);
+ } catch (IOException e) {
+ } catch (Exception e) {
+ System.out.println("SupportConfiguration.loadProperties()");
+ System.out.println(e);
+ e.printStackTrace();
+ }
+ if (in == null) {
+ try {
+ Class cl = Class
+ .forName("com.ibm.support.Support_Configuration");
+ in = cl.getResourceAsStream(iniName);
+ } catch (ClassNotFoundException e) {
+ }
+ }
+ try {
+ if (in != null) {
+ System.out.println("Loading: " + iniName);
+ load(in, props);
+ }
+ } catch (IOException e) {
+ }
+ if (props.size() == 0)
+ return;
+ String value;
+
+ value = (String) props.get("DomainAddress");
+ if (value != null)
+ DomainAddress = value;
+
+ value = (String) props.get("WebName");
+ if (value != null)
+ WebName = value;
+
+ value = (String) props.get("TestResourcesDir");
+ if (value != null)
+ TestResourcesDir = value;
+ value = (String) props.get("HomeAddressResponse");
+ if (value != null)
+ HomeAddressResponse = value;
+
+ value = (String) props.get("HomeAddressSoftware");
+ if (value != null)
+ HomeAddressSoftware = value;
+
+ value = (String) props.get("ProxyServerTestHost");
+ if (value != null)
+ ProxyServerTestHost = value;
+
+ value = (String) props.get("SocksServerTestHost");
+ if (value != null)
+ SocksServerTestHost = value;
+
+ value = (String) props.get("SocksServerTestPort");
+ if (value != null)
+ SocksServerTestPort = Integer.parseInt(value);
+
+ value = (String) props.get("UnresolvedIP");
+ if (value != null)
+ UnresolvedIP = value;
+
+ value = (String) props.get("InetTestAddress");
+ if (value != null)
+ InetTestAddress = value;
+
+ value = (String) props.get("InetTestIP");
+ if (value != null) {
+ InetTestIP = value;
+ byte[] addr = new byte[4];
+ int last = 0;
+ try {
+ for (int i = 0; i < 3; i++) {
+ int dot = InetTestIP.indexOf('.', last);
+ addr[i] = (byte) Integer.parseInt(InetTestIP.substring(
+ last, dot));
+ last = dot + 1;
+ }
+ addr[3] = (byte) Integer.parseInt(InetTestIP.substring(last));
+ InetTestCaddr = addr;
+ } catch (RuntimeException e) {
+ System.out.println("Error parsing InetTestIP (" + InetTestIP
+ + ")");
+ System.out.println(e);
+ }
+ }
+
+ value = (String) props.get("NonLocalAddressBytes");
+ if (value != null) {
+ String nonLocalAddressBytesString = value;
+ byte[] addr = new byte[4];
+ int last = 0;
+ try {
+ for (int i = 0; i < 3; i++) {
+ int dot = nonLocalAddressBytesString.indexOf('.', last);
+ addr[i] = (byte) Integer
+ .parseInt(nonLocalAddressBytesString.substring(
+ last, dot));
+ last = dot + 1;
+ }
+ addr[3] = (byte) Integer.parseInt(nonLocalAddressBytesString
+ .substring(last));
+ nonLocalAddressBytes = addr;
+ } catch (RuntimeException e) {
+ System.out.println("Error parsing NonLocalAddressBytes ("
+ + nonLocalAddressBytesString + ")");
+ System.out.println(e);
+ }
+ }
+
+ value = (String) props.get("InetTestAddress2");
+ if (value != null)
+ InetTestAddress2 = value;
+
+ value = (String) props.get("InetTestIP2");
+ if (value != null)
+ InetTestIP2 = value;
+
+ value = (String) props.get("InetTestHashcode");
+ if (value != null)
+ InetTestHashcode = Integer.parseInt(value);
+
+ value = (String) props.get("SpecialInetTestAddress");
+ if (value != null)
+ SpecialInetTestAddress = value;
+
+ value = (String) props.get("SpecialInetTestAddressNumber");
+ if (value != null)
+ SpecialInetTestAddressNumber = Integer.parseInt(value);
+
+ value = (String) props.get("FTPTestAddress");
+ if (value != null)
+ FTPTestAddress = value;
+
+ value = (String) props.get("URLConnectionLastModifiedString");
+ if (value != null)
+ URLConnectionLastModifiedString = value;
+
+ value = (String) props.get("URLConnectionLastModified");
+ if (value != null)
+ URLConnectionLastModified = Long.parseLong(value);
+
+ value = (String) props.get("URLConnectionDate");
+ if (value != null)
+ URLConnectionDate = Long.parseLong(value);
+
+ value = (String) props.get("Port1");
+ if (value != null)
+ Port1 = value;
+
+ value = (String) props.get("Port2");
+ if (value != null)
+ Port2 = value;
+
+ value = (String) props.get("InetTestIP6");
+ if (value != null)
+ InetTestIP6 = value;
+
+ value = (String) props.get("InetTestIP6LO");
+ if (value != null)
+ InetTestIP6LO = value;
+
+ value = (String) props.get("ProxyServerTestHostIPv6");
+ if (value != null)
+ ProxyServerTestHostIPv6 = value;
+
+ value = (String) props.get("ResolvedNotExistingHost");
+ if (value != null)
+ ResolvedNotExistingHost = value;
+
+ value = (String) props.get("InetAlias1");
+ if (value != null)
+ InetAlias1 = value;
+
+ value = (String) props.get("InetAlias2");
+ if (value != null)
+ InetAlias2 = value;
+
+ value = (String) props.get("IPv6GlobalAddressJcl4");
+ if (value != null)
+ IPv6GlobalAddressJcl4 = value;
+
+ }
+
+ static void load(InputStream in, Hashtable result) throws IOException {
+ int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, DONE = 4, IGNORE = 5;
+ int mode = NONE, unicode = 0, count = 0, nextChar;
+ StringBuffer key = new StringBuffer(), value = new StringBuffer(), buffer = key;
+ boolean firstChar = true;
+
+ while ((nextChar = in.read()) != -1) {
+ if (mode == UNICODE) {
+ int digit = Character.digit((char) nextChar, 16);
+ if (digit >= 0) {
+ unicode = (unicode << 4) + digit;
+ if (++count < 4)
+ continue;
+ }
+ mode = NONE;
+ buffer.append((char) unicode);
+ if (nextChar != '\n')
+ continue;
+ }
+ if (mode == SLASH) {
+ mode = NONE;
+ switch (nextChar) {
+ case '\r':
+ mode = CONTINUE; // Look for a following \n
+ continue;
+ case '\n':
+ mode = IGNORE; // Ignore whitespace on the next line
+ continue;
+ case 'b':
+ nextChar = '\b';
+ break;
+ case 'f':
+ nextChar = '\f';
+ break;
+ case 'n':
+ nextChar = '\n';
+ break;
+ case 'r':
+ nextChar = '\r';
+ break;
+ case 't':
+ nextChar = '\t';
+ break;
+ case 'u':
+ mode = UNICODE;
+ unicode = count = 0;
+ continue;
+ }
+ } else {
+ switch (nextChar) {
+ case '#':
+ case '!':
+ if (firstChar) {
+ while ((nextChar = in.read()) != -1)
+ if (nextChar == '\r' || nextChar == '\n')
+ break;
+ continue;
+ }
+ break;
+ case '\n':
+ if (mode == CONTINUE) { // Part of a \r\n sequence
+ mode = IGNORE; // Ignore whitespace on the next line
+ continue;
+ }
+ // fall into the next case
+ case '\r':
+ mode = NONE;
+ firstChar = true;
+ if (key.length() > 0 || buffer == value)
+ result.put(key.toString(), value.toString());
+ key.setLength(0);
+ value.setLength(0);
+ buffer = key;
+ continue;
+ case '\\':
+ mode = SLASH;
+ continue;
+ case ':':
+ case '=':
+ if (buffer == key) {
+ buffer = value;
+ continue;
+ }
+ break;
+ }
+ char c = (char) nextChar;
+ if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) {
+ if (mode == CONTINUE)
+ mode = IGNORE;
+ if (buffer.length() == 0 || mode == IGNORE)
+ continue;
+ if (buffer == key) {
+ mode = DONE;
+ continue;
+ }
+ }
+ if (mode == IGNORE || mode == CONTINUE)
+ mode = NONE;
+ }
+ firstChar = false;
+ if (mode == DONE) {
+ buffer = value;
+ mode = NONE;
+ }
+ buffer.append((char) nextChar);
+ }
+ if (key.length() > 0 || buffer == value)
+ result.put(key.toString(), value.toString());
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DecimalFormat.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DecimalFormat.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DecimalFormat.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DecimalFormat.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,283 @@
+/* Copyright 2005 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 tests.support;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.Vector;
+
+public class Support_DecimalFormat extends Support_Format {
+
+ public Support_DecimalFormat(String p1) {
+ super(p1);
+ }
+
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_DecimalFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ DecimalFormat format = (DecimalFormat) NumberFormat
+ .getCurrencyInstance(Locale.US);
+ Number number = new Double(10000000.76);
+ String text = "$10,000,000.76";
+
+ t_FormatWithField(0, format, number, text, NumberFormat.Field.CURRENCY,
+ 0, 1);
+ t_FormatWithField(1, format, number, text, NumberFormat.Field.INTEGER,
+ 1, 11);
+ t_FormatWithField(2, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 3, 4);
+ t_FormatWithField(3, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 11, 12);
+ t_FormatWithField(4, format, number, text, NumberFormat.Field.FRACTION,
+ 12, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(5, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(6, format, number, text, NumberFormat.Field.EXPONENT,
+ 0, 0);
+ t_FormatWithField(7, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(8, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(9, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(10, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test Exponential
+ format = new DecimalFormat("000000000.0#E0");
+ text = "100000007.6E-1";
+ t_FormatWithField(11, format, number, text, NumberFormat.Field.INTEGER,
+ 0, 9);
+ t_FormatWithField(12, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 9, 10);
+ t_FormatWithField(13, format, number, text,
+ NumberFormat.Field.FRACTION, 10, 11);
+ t_FormatWithField(14, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 11, 12);
+ t_FormatWithField(15, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 12, 13);
+ t_FormatWithField(16, format, number, text,
+ NumberFormat.Field.EXPONENT, 13, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(17, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(18, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(19, format, number, text,
+ NumberFormat.Field.CURRENCY, 0, 0);
+ t_FormatWithField(20, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(21, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test currency instance with TR Locale
+ number = new Double(350.76);
+ format = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale(
+ "tr", "TR"));
+ text = "351 TL";
+ t_FormatWithField(22, format, number, text, NumberFormat.Field.INTEGER,
+ 0, 3);
+ t_FormatWithField(23, format, number, text,
+ NumberFormat.Field.CURRENCY, 4, 6);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(25, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(26, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 0, 0);
+ t_FormatWithField(27, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(28, format, number, text,
+ NumberFormat.Field.EXPONENT, 0, 0);
+ t_FormatWithField(29, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(30, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(31, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(32, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ }
+
+ public void t_formatToCharacterIterator() {
+
+ Number number = new Double(350.76);
+ Number negativeNumber = new Double(-350.76);
+
+ Locale us = Locale.US;
+ Locale tr = new Locale("tr", "TR");
+
+ // test number instance
+ t_Format(1, number, NumberFormat.getNumberInstance(us),
+ getNumberVectorUS());
+
+ // test integer instance
+ // testFormat(2, number, NumberFormat.getIntegerInstance(us),
+ // getPercentVectorUS());
+
+ // test percent instance
+ t_Format(3, number, NumberFormat.getPercentInstance(us),
+ getPercentVectorUS());
+
+ // test permille pattern
+ DecimalFormat format = new DecimalFormat("###0.##\u2030");
+ t_Format(4, number, format, getPermilleVector());
+
+ // test exponential pattern with positive exponent
+ format = new DecimalFormat("00.0#E0");
+ t_Format(5, number, format, getPositiveExponentVector());
+
+ // test exponential pattern with negative exponent
+ format = new DecimalFormat("0000.0#E0");
+ t_Format(6, number, format, getNegativeExponentVector());
+
+ // test currency instance with US Locale
+ t_Format(7, number, NumberFormat.getCurrencyInstance(us),
+ getPositiveCurrencyVectorUS());
+
+ // test negative currency instance with US Locale
+ t_Format(8, negativeNumber, NumberFormat.getCurrencyInstance(us),
+ getNegativeCurrencyVectorUS());
+
+ // test currency instance with TR Locale
+ t_Format(9, number, NumberFormat.getCurrencyInstance(tr),
+ getPositiveCurrencyVectorTR());
+
+ // test negative currency instance with TR Locale
+ t_Format(10, negativeNumber, NumberFormat.getCurrencyInstance(tr),
+ getNegativeCurrencyVectorTR());
+
+ // test multiple grouping seperators
+ number = new Long(100300400);
+ t_Format(11, number, NumberFormat.getNumberInstance(us),
+ getNumberVector2US());
+
+ // test 0
+ number = new Long(0);
+ t_Format(12, number, NumberFormat.getNumberInstance(us),
+ getZeroVector());
+ }
+
+ private static Vector getNumberVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getPositiveCurrencyVectorTR() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector getNegativeCurrencyVectorTR() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector getPositiveCurrencyVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getNegativeCurrencyVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(1, 2, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(2, 5, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(6, 8, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getPercentVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERCENT));
+ return v;
+ }
+
+ private static Vector getPermilleVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE));
+ return v;
+ }
+
+ private static Vector getNegativeExponentVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN));
+ v.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector getPositiveExponentVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(3, 5, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector getNumberVector2US() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+ private static Vector getZeroVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DeleteOnExitTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DeleteOnExitTest.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DeleteOnExitTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_DeleteOnExitTest.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,26 @@
+/* Copyright 2001, 2005 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 tests.support;
+
+import java.io.File;
+
+public class Support_DeleteOnExitTest {
+
+ public static void main(java.lang.String[] args) {
+ File f1 = new File(args[0]);
+ f1.deleteOnExit();
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Exec.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,152 @@
+/* Copyright 2001, 2005 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 tests.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+public class Support_Exec extends TestCase {
+
+ public static String execJava(String[] args, String[] classpath,
+ boolean displayOutput) throws IOException, InterruptedException {
+ // this function returns the output of the process as a string
+ Object[] execArgs = execJava2(args, classpath, displayOutput);
+ Process proc = (Process) execArgs[0];
+
+ StringBuffer output = new StringBuffer();
+ InputStream in = proc.getInputStream();
+ int result;
+ byte[] bytes = new byte[1024];
+ while ((result = in.read(bytes)) != -1) {
+ output.append(new String(bytes, 0, result));
+ if (displayOutput)
+ System.out.write(bytes, 0, result);
+ }
+ in.close();
+ proc.waitFor();
+ checkStderr(execArgs);
+ proc.destroy();
+ return output.toString();
+ }
+
+ public static void checkStderr(Object[] execArgs) {
+ Process proc = (Process) execArgs[0];
+ StringBuffer errBuf = (StringBuffer) execArgs[1];
+ synchronized (errBuf) {
+ if (errBuf.length() > 0) {
+ fail(errBuf.toString());
+ }
+ }
+ }
+
+ public static Object[] execJava2(String[] args, String[] classpath,
+ boolean displayOutput) throws IOException, InterruptedException {
+ // this function returns the resulting process from the exec
+ int baseArgs = 0;
+ String[] execArgs = null;
+ String vendor = System.getProperty("java.vendor");
+ boolean onUnix = File.separatorChar == '/';
+ String classPathString = "";
+ if (classpath != null)
+ for (int i = 0; i < classpath.length; i++)
+ classPathString += File.pathSeparator + classpath[i];
+ if (vendor.indexOf("Sun") != -1) {
+ baseArgs = 3;
+ execArgs = new String[baseArgs + args.length];
+ String executable = System.getProperty("java.home");
+ if (!executable.endsWith(File.separator))
+ executable += File.separator;
+ executable += "bin" + File.separator;
+ execArgs[0] = executable + "java";
+ execArgs[1] = "-cp";
+ execArgs[2] = "\"" + System.getProperty("java.class.path")
+ + classPathString + "\"";
+ } else if (vendor.indexOf("IBM") != -1) {
+ baseArgs = 5;
+ String full = System.getProperty("java.fullversion");
+ if (full != null && full.indexOf("(JIT disabled") >= 0)
+ baseArgs++;
+ execArgs = new String[baseArgs + args.length];
+ execArgs[0] = System.getProperty("com.ibm.oti.vm.exe");
+ // stop passing -jcl:null into the VM
+ execArgs[1] = "";
+ if (onUnix) {
+ execArgs[2] = "-Xbootclasspath:"
+ + System.getProperty("com.ibm.oti.system.class.path");
+ execArgs[3] = "-cp";
+ execArgs[4] = System.getProperty("java.class.path")
+ + classPathString;
+ } else {
+ execArgs[2] = "\"-Xbootclasspath:"
+ + System.getProperty("com.ibm.oti.system.class.path")
+ + "\"";
+ execArgs[3] = "-cp";
+ execArgs[4] = "\"" + System.getProperty("java.class.path")
+ + classPathString + "\"";
+ }
+ if (baseArgs > 5)
+ execArgs[5] = "-Xint";
+ }
+ for (int i = 0; i < args.length; i++)
+ execArgs[baseArgs + i] = args[i];
+ StringBuffer command = new StringBuffer(execArgs[0]);
+ for (int i = 1; i < execArgs.length; i++)
+ command.append(" " + execArgs[i]);
+ System.out.println();
+ System.out.println("Exec: " + command.toString());
+
+ final Process proc = Runtime.getRuntime().exec(execArgs);
+ final StringBuffer errBuf = new StringBuffer();
+ Thread errThread = new Thread(new Runnable() {
+ public void run() {
+ synchronized (errBuf) {
+ synchronized (proc) {
+ proc.notifyAll();
+ }
+ InputStream err = proc.getErrorStream();
+ int result;
+ byte[] bytes = new byte[1024];
+ try {
+ while ((result = err.read(bytes)) != -1) {
+ System.err.write(bytes, 0, result);
+ errBuf.append(new String(bytes));
+ }
+ err.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintStream printer = new PrintStream(out);
+ e.printStackTrace(printer);
+ printer.close();
+ errBuf.append(new String(out.toByteArray()));
+ }
+ }
+ }
+ });
+ synchronized (proc) {
+ errThread.start();
+ // wait for errThread to start
+ proc.wait();
+ }
+ return new Object[] { proc, errBuf };
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Field.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Field.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Field.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Field.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,43 @@
+/* Copyright 2002, 2005 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 tests.support;
+
+public class Support_Field {
+
+ protected Object objectField;
+
+ protected boolean booleanField;
+
+ protected byte byteField;
+
+ protected char charField;
+
+ protected short shortField;
+
+ protected int intField;
+
+ protected long longField;
+
+ protected float floatField;
+
+ protected double doubleField;
+
+ /**
+ *
+ */
+ public Support_Field() {
+ }
+}
\ No newline at end of file
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Format.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Format.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Format.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Format.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,138 @@
+/* Copyright 2005 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 tests.support;
+
+import java.text.AttributedCharacterIterator;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.Iterator;
+import java.util.Vector;
+
+public class Support_Format extends junit.framework.TestCase {
+
+ protected String text = null;
+
+ public Support_Format(String p1) {
+ super(p1);
+ }
+
+ protected void t_FormatWithField(int count, Format format, Object object,
+ String text, Format.Field field, int begin, int end) {
+ StringBuffer buffer = new StringBuffer();
+ FieldPosition pos = new FieldPosition(field);
+ format.format(object, buffer, pos);
+
+ // System.out.println(buffer);
+ // System.out.println(pos);
+
+ if (text == null)
+ assertEquals("Test " + count + ": incorrect formatted text",
+ this.text, buffer.toString());
+ else
+ assertEquals("Test " + count + ": incorrect formatted text", text,
+ buffer.toString());
+
+ assertEquals("Test " + count + ": incorrect begin index for field "
+ + field, begin, pos.getBeginIndex());
+ assertEquals("Test " + count + ": incorrect end index for field"
+ + field, end, pos.getEndIndex());
+ }
+
+ protected void t_Format(int count, Object object, Format format,
+ Vector expectedResults) {
+ // System.out.println(format.format(object));
+ Vector results = findFields(format.formatToCharacterIterator(object));
+ assertTrue("Test " + count
+ + ": Format returned incorrect CharacterIterator for "
+ + format.format(object), compare(results, expectedResults));
+ }
+
+ /**
+ * compares two vectors regardless of the order of their elements
+ */
+ protected static boolean compare(Vector vector1, Vector vector2) {
+ return vector1.size() == vector2.size() && vector1.containsAll(vector2);
+ }
+
+ /**
+ * finds attributes with regards to char index in this
+ * AttributedCharacterIterator, and puts them in a vector
+ *
+ * @param iterator
+ * @return a vector, each entry in this vector are of type FieldContainer ,
+ * which stores start and end indexes and an attribute this range
+ * has
+ */
+ protected static Vector findFields(AttributedCharacterIterator iterator) {
+ Vector result = new Vector();
+ while (iterator.getIndex() != iterator.getEndIndex()) {
+ int start = iterator.getRunStart();
+ int end = iterator.getRunLimit();
+
+ Iterator it = iterator.getAttributes().keySet().iterator();
+ while (it.hasNext()) {
+ AttributedCharacterIterator.Attribute attribute = (AttributedCharacterIterator.Attribute) it
+ .next();
+ Object value = iterator.getAttribute(attribute);
+ result.add(new FieldContainer(start, end, attribute, value));
+ // System.out.println(start + " " + end + ": " + attribute + ",
+ // " + value );
+ // System.out.println("v.add(new FieldContainer(" + start +"," +
+ // end +"," + attribute+ "," + value+ "));");
+ }
+ iterator.setIndex(end);
+ }
+ return result;
+ }
+
+ protected static class FieldContainer {
+ int start, end;
+
+ AttributedCharacterIterator.Attribute attribute;
+
+ Object value;
+
+ // called from support_decimalformat and support_simpledateformat tests
+ public FieldContainer(int start, int end,
+ AttributedCharacterIterator.Attribute attribute) {
+ this(start, end, attribute, attribute);
+ }
+
+ // called from support_messageformat tests
+ public FieldContainer(int start, int end, Attribute attribute, int value) {
+ this(start, end, attribute, new Integer(value));
+ }
+
+ // called from support_messageformat tests
+ public FieldContainer(int start, int end, Attribute attribute,
+ Object value) {
+ this.start = start;
+ this.end = end;
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof FieldContainer))
+ return false;
+
+ FieldContainer fc = (FieldContainer) obj;
+ return (start == fc.start && end == fc.end
+ && attribute == fc.attribute && value.equals(fc.value));
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpConnector.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpConnector.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpConnector.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpConnector.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,45 @@
+/* Copyright 2002, 2005 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 tests.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * This interface contains the basic methods necessary to open and use a
+ * connection to an HTTP server.
+ *
+ */
+public interface Support_HttpConnector {
+
+ public void open(String address) throws IOException;
+
+ public void close() throws IOException;
+
+ public InputStream getInputStream() throws IOException;
+
+ public OutputStream getOutputStream() throws IOException;
+
+ public boolean isChunkedOnFlush();
+
+ public void setRequestProperty(String key, String value) throws IOException;
+
+ public String getHeaderField(int index) throws IOException;
+
+ public String getHeaderFieldKey(int index) throws IOException;
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java?rev=386058&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java Wed Mar 15 03:46:17 2006
@@ -0,0 +1,512 @@
+/* Copyright 2002, 2005 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 tests.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+public class Support_HttpServer {
+
+ private static final int timeout = 10000;
+
+ public static final String AUTHTEST = "/authTest";
+
+ public static final String CHUNKEDTEST = "/chunkedTest.html";
+
+ public static final String CONTENTTEST = "/contentTest.html";
+
+ public static final String REDIRECTTEST = "/redirectTest.html";
+
+ public static final String PORTREDIRTEST = "/portredirTest.html";
+
+ public static final String OTHERTEST = "/otherTest.html";
+
+ public static final String POSTTEST = "/postTest.html";
+
+ public static final String HEADERSTEST = "/headersTest.html";
+
+ public static final int OK = 200;
+
+ public static final int MULT_CHOICE = 300;
+
+ public static final int MOVED_PERM = 301;
+
+ public static final int FOUND = 302;
+
+ public static final int SEE_OTHER = 303;
+
+ public static final int NOT_MODIFIED = 304;
+
+ public static final int UNUSED = 306;
+
+ public static final int TEMP_REDIRECT = 307;
+
+ public static final int UNAUTHORIZED = 401;
+
+ public static final int NOT_FOUND = 404;
+
+ private int port;
+
+ private boolean proxy = false;
+
+ private boolean started = false;
+
+ private boolean portRedirectTestEnable = false;
+
+ private volatile Support_ServerSocket serversocket;
+
+ private boolean shuttingDown = false;
+
+ // synchronization
+ private Object lock = new Object();
+
+ TestCase testcase = null;
+
+ public Support_HttpServer(Support_ServerSocket serversocket, TestCase test) {
+ this.serversocket = serversocket;
+ this.testcase = test;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void startServer(final int port) {
+ if (started)
+ return;
+ started = true;
+ this.port = port;
+ Thread serverThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+
+ synchronized (lock) {
+ serversocket.setPort(port);
+ serversocket.setTimeout(timeout);
+ serversocket.open();
+ lock.notifyAll();
+ }
+
+ while (true) {
+ // wait for a connection to be made
+ Support_Socket socket = serversocket.accept();
+ Thread thread = new Thread(new ServerThread(socket));
+ thread.start();
+ }
+ } catch (InterruptedIOException e) {
+ System.out
+ .println("Wait timed out. Test HTTP Server shut down.");
+ started = false;
+ try {
+ if (serversocket != null)
+ serversocket.close();
+ } catch (IOException e2) {
+ }
+ } catch (IOException e) {
+ // release the lock so the tests will finish running
+ if (!shuttingDown) {
+ e.printStackTrace();
+ testcase
+ .fail("Test server error on HTTP Server on port "
+ + port + ": " + e);
+ }
+ synchronized (lock) {
+ lock.notifyAll();
+ }
+ } finally {
+ try {
+ if (serversocket != null)
+ serversocket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+
+ // start the server and continue
+ synchronized (lock) {
+ serverThread.start();
+
+ // wait for the port to be opened before continuing
+ // to eliminate a race condition between starting the
+ // server and the clients accessing the server
+ try {
+ lock.wait();
+ } catch (InterruptedException e) {
+ System.err.println("Unexpected interrupt 2");
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ public void stopServer() {
+ try {
+ shuttingDown = true;
+ serversocket.close();
+ } catch (IOException e) {
+ }
+ }
+
+ class ServerThread implements Runnable {
+
+ Support_Socket socket;
+
+ ServerThread(Support_Socket s) {
+ socket = s;
+ }
+
+ String readln(InputStream is) throws IOException {
+ boolean lastCr = false;
+ StringBuffer result = new StringBuffer();
+ int c = is.read();
+ if (c < 0)
+ return null;
+ while (c != '\n') {
+ if (lastCr) {
+ result.append('\r');
+ lastCr = false;
+ }
+ if (c == '\r')
+ lastCr = true;
+ else
+ result.append((char) c);
+ c = is.read();
+ if (c < 0)
+ break;
+ }
+ return result.toString();
+ }
+
+ void print(OutputStream os, String text) throws IOException {
+ os.write(text.getBytes("ISO8859_1"));
+ }
+
+ public void run() {
+ try {
+ // get the input stream
+
+ // parse the result headers until the first blank line
+ InputStream in = socket.getInputStream();
+ String line;
+ boolean authenticated = false, contentLength = false, chunked = false;
+ int length = -1;
+ String resourceName = "";
+ Vector headers = new Vector();
+ while (((line = readln(in)) != null) && (line.length() > 1)) {
+ headers.addElement(line);
+ String lline = line.toLowerCase();
+ // determine the resource requested in the first line
+ if (lline.startsWith("get") || lline.startsWith("post")) {
+ int start = line.indexOf(' ') + 1;
+ int end = line.indexOf(' ', start);
+ if (start > 0 && end > -1)
+ resourceName = line.substring(start, end);
+ }
+ if (lline.startsWith("authorization:")) {
+ authenticated = true;
+ }
+ if (lline.startsWith("content-length")) {
+ if (contentLength)
+ testcase.fail("Duplicate Content-Length: " + line);
+ contentLength = true;
+ length = Integer.parseInt(line.substring(line
+ .indexOf(' ') + 1));
+ }
+ if (line.startsWith("transfer-encoding")) {
+ if (chunked)
+ testcase.fail("Duplicate Transfer-Encoding: "
+ + line);
+ chunked = true;
+ String encoding = line.substring(line.indexOf(' ') + 1);
+ if ("chunked".equals(encoding))
+ testcase.fail("Unknown Transfer-Encoding: "
+ + encoding);
+ }
+
+ }
+ if (contentLength && chunked)
+ testcase
+ .fail("Found both Content-Length and Transfer-Encoding");
+
+ // call the test function based on the requested resource
+ if (resourceName.equals(CHUNKEDTEST))
+ chunkedTest();
+ else if (resourceName.equals(CONTENTTEST))
+ contentTest();
+ else if (resourceName.equals(AUTHTEST))
+ authenticateTest(authenticated);
+ else if (resourceName.startsWith(REDIRECTTEST))
+ redirectTest(resourceName);
+ else if (portRedirectTestEnable
+ && resourceName.equals(PORTREDIRTEST))
+ contentTest();
+ else if (resourceName.equals(OTHERTEST))
+ otherTest();
+ else if (resourceName.equals(HEADERSTEST))
+ headersTest(headers);
+ else if (resourceName.startsWith("http://")
+ && resourceName.indexOf(OTHERTEST) > -1)
+ // redirection to a proxy passes an absolute URI to the
+ // proxy server
+ otherTest();
+ else if (resourceName.equals(POSTTEST)) {
+ postTest(length, in);
+ } else
+ notFound(); // return a not found error
+
+ in.close();
+ socket.close();
+
+ } catch (IOException e) {
+ System.err.println("Error performing http server test.");
+ e.printStackTrace();
+ }
+
+ }
+
+ private void contentTest() {
+ // send 5 bytes of data, specifying a content-length
+ try {
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ print(os, "Content-Length: 5\r\n");
+ print(os, "\r\nABCDE");
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ System.err.println("Error performing content coding test.");
+ e.printStackTrace();
+ }
+
+ }
+
+ private void chunkedTest() {
+ // send 5 bytes of chunked data
+ try {
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ print(os, "Transfer-Encoding: chunked\r\n");
+ print(os, "\r\n");
+ print(os, "5\r\nFGHIJ");
+ print(os, "\r\n0\r\n\r\n");
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ System.err
+ .println("Error performing chunked transfer coding test.");
+ e.printStackTrace();
+ }
+
+ }
+
+ private void authenticateTest(boolean authenticated) {
+ // send an authentication required response
+ // the client should respond with a new request
+ // that includes authorization credentials
+ try {
+ OutputStream os = socket.getOutputStream();
+
+ // if the user has not sent along credentials, return
+ // unauthorized, which should prompt them to repeat
+ // the request with an authorization header added
+ if (!authenticated) {
+ print(os, "HTTP/1.1 " + UNAUTHORIZED + " Unauthorized\r\n");
+ print(os, "WWW-Authenticate: Basic realm=\"test\"\r\n");
+ } else {
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ }
+
+ print(os, "Content-Length: 5\r\n");
+ print(os, "\r\nKLMNO");
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ System.err.println("Error performing authentication test.");
+ e.printStackTrace();
+ }
+ }
+
+ private void redirectTest(String test) {
+ // send a redirect response
+
+ // the URL was in the format:
+ // "http://localhost:<port>/redirectTest.html/<3XX level response
+ // code>-<new URL>"
+ // "eg.
+ // http://localhost:8080/redirectTest.html/301-http://www.apache.org"
+ int responseNum = Integer.parseInt(test.substring(
+ test.indexOf('3'), test.indexOf('3') + 3));
+ String location = test.substring(test.lastIndexOf('-') + 1);
+
+ try {
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + responseNum + " Irrelevant\r\n");
+ print(os, "Location: " + location + "\r\n");
+ print(os, "Content-Length: 5\r\n");
+ print(os, "\r\nPQRST");
+ os.flush();
+ os.close();
+
+ } catch (IOException e) {
+ System.err.println("Error performing redirection test.");
+ e.printStackTrace();
+ }
+
+ }
+
+ private void otherTest() {
+ // send 5 bytes of content coded data
+ try {
+ OutputStream os = socket.getOutputStream();
+ if (!proxy) {
+ print(os, "HTTP/1.1 " + 305 + " Use Proxy\r\n");
+ // print(os, "Location: http://intl2000.ott.oti.com\r\n");
+ print(os, "Location: http://localhost:" + (port + 1)
+ + "/otherTest.html\r\n");
+ print(os, "Content-Length: 9\r\n");
+ print(os, "\r\nNOT PROXY");
+ } else {
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ print(os, "Content-Length: 5\r\n");
+ print(os, "\r\nPROXY");
+ }
+ os.flush();
+ os.close();
+
+ } catch (IOException e) {
+ System.err.println("Error performing content coding test.");
+ e.printStackTrace();
+ }
+
+ }
+
+ private void headersTest(Vector headers) {
+ int found = 0;
+ for (int i = 0; i < headers.size(); i++) {
+ String header = (String) headers.elementAt(i);
+ if (header.startsWith("header1:")) {
+ found++;
+ testcase.assertTrue("unexpected header: " + header,
+ found == 1);
+ testcase.assertTrue("invalid header: " + header,
+ "header1: value2".equals(header));
+ }
+ }
+ // send duplicate headers
+ try {
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ print(os, "Cache-Control: no-cache=\"set-cookie\"\r\n");
+ print(os, "Cache-Control: private\r\n");
+ print(os, "Cache-Control: no-transform\r\n\r\n");
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ System.err.println("Error performing headers test.");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method postTest.
+ */
+ private void postTest(int length, InputStream in) {
+ try {
+ ByteArrayOutputStream data = new ByteArrayOutputStream();
+ // read content-length specified data
+ for (int i = 0; i < length; i++)
+ data.write(in.read());
+
+ // read chunked-encoding data
+ if (length == -1) {
+ int len = in.read() - 48;
+ in.read();
+ in.read();
+ while (len > 0) {
+ data.write('C');
+ for (int i = 0; i < len; i++) {
+ data.write(in.read());
+ }
+ in.read();
+ in.read();
+ len = in.read() - 48;
+ in.read();
+ in.read();
+ }
+ in.read();
+ in.read();
+ }
+
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + OK + " OK\r\n");
+ print(os, "Content-Length: " + data.size() + "\r\n\r\n");
+ os.write(data.toByteArray());
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void notFound() {
+ try {
+ // System.out.println("File not found on test server.");
+ OutputStream os = socket.getOutputStream();
+ print(os, "HTTP/1.1 " + NOT_FOUND + " Not Found\r\n");
+ print(os, "Content-Length: 1\r\n");
+ print(os, "\r\nZ");
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ * Sets portRedirectTestEnable.
+ *
+ * @param portRedirectTestEnable
+ * The portRedirectTestEnable to set
+ */
+ public void setPortRedirectTestEnable(boolean portRedirectTestEnable) {
+ // enables an additional resource ("portredirTest.html") to be returned
+ // so that the port redirection test can distinguish
+ // between the two servers (on different ports).
+
+ this.portRedirectTestEnable = portRedirectTestEnable;
+ }
+
+ /**
+ * Sets the proxy.
+ *
+ * @param proxy
+ * The proxy to set
+ */
+ public void setProxy(boolean proxy) {
+ this.proxy = proxy;
+ }
+
+}