summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commitfdb2704414a9ed92394ada0d1395e4db86889465 (patch)
tree9b591a4a50054274a197f02b3ccb51313681879f /support
downloadlibcore-fdb2704414a9ed92394ada0d1395e4db86889465.zip
libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.gz
libcore-fdb2704414a9ed92394ada0d1395e4db86889465.tar.bz2
Initial Contribution
Diffstat (limited to 'support')
-rw-r--r--support/MODULE_LICENSE_APACHE20
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/CertificateStub.java109
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/IdentityScopeStub.java125
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/IdentityStub.java84
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/KeyStoreTestSupport.java177
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MDGoldenData.java201
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyAlgorithmParameterGeneratorSpi.java55
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyBasicPermission.java29
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyGuard.java38
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator1.java146
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator2.java68
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator3.java51
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGeneratorSpi.java60
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStore.java238
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStoreSpi.java164
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyLoadStoreParams.java42
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest1.java79
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest2.java73
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyPermission.java52
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MyPermissionCollection.java53
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java114
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/MySignature2.java85
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/PrivateKeyStub.java77
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/PublicKeyStub.java73
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/RandomImpl.java57
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/SecurityChecker.java58
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/SignerStub.java64
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/SpiEngUtils.java69
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/TestCertUtils.java831
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/TestKeyPair.java602
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/TestUtils.java80
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCRL.java60
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java107
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathBuilderSpi.java47
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathValidatorSpi.java56
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreParameters.java43
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java64
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java103
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java138
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/cert/TestUtils.java532
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/spec/MyEncodedKeySpec.java49
-rw-r--r--support/src/test/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java46
-rw-r--r--support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java587
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java82
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java145
-rw-r--r--support/src/test/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java71
-rw-r--r--support/src/test/java/tests/resources/Created_by_1_4.jarbin0 -> 2919 bytes
-rw-r--r--support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gzbin0 -> 42 bytes
-rw-r--r--support/src/test/java/tests/resources/Harmony.GIFbin0 -> 5220 bytes
-rw-r--r--support/src/test/java/tests/resources/Inserted_Entry_Manifest.jarbin0 -> 1977 bytes
-rw-r--r--support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jarbin0 -> 1970 bytes
-rw-r--r--support/src/test/java/tests/resources/Integrate.jarbin0 -> 1963 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_11.jarbin0 -> 1219 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_12.jarbin0 -> 1250 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_13.jarbin0 -> 1698 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_14.jarbin0 -> 414 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_21.jarbin0 -> 1417 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_22-new.jarbin0 -> 1428 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_22.jarbin0 -> 1430 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_23.jarbin0 -> 2073 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_31.jarbin0 -> 1217 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_32.jarbin0 -> 1421 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_33.jarbin0 -> 1701 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_41.jarbin0 -> 1217 bytes
-rw-r--r--support/src/test/java/tests/resources/JarIndex/hyts_42.jarbin0 -> 1239 bytes
-rw-r--r--support/src/test/java/tests/resources/Modified_Class.jarbin0 -> 1949 bytes
-rw-r--r--support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jarbin0 -> 1963 bytes
-rw-r--r--support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jarbin0 -> 1970 bytes
-rw-r--r--support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jarbin0 -> 1949 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_all_attributes.jarbin0 -> 742 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_c.jarbin0 -> 745 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_no_attributes.jarbin0 -> 704 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_no_entry.jarbin0 -> 693 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_pq.jarbin0 -> 841 bytes
-rw-r--r--support/src/test/java/tests/resources/Package/hyts_some_attributes.jarbin0 -> 732 bytes
-rw-r--r--support/src/test/java/tests/resources/TestCodeSigners.jarbin0 -> 3381 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_Bar.serbin0 -> 414 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_Foo.serbin0 -> 467 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_PropertiesTest.properties29
-rw-r--r--support/src/test/java/tests/resources/hyts_ZipFile.zipbin0 -> 1136 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_att.jarbin0 -> 625 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_available.tstbin0 -> 17 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_checkInput.txt4
-rw-r--r--support/src/test/java/tests/resources/hyts_compDiction.txtbin0 -> 501 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_compressD.txtbin0 -> 500 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_constru_O.txtbin0 -> 25 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_constru_OD.txtbin0 -> 13 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_constru_ODI.txtbin0 -> 18 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_htmltest.html38
-rw-r--r--support/src/test/java/tests/resources/hyts_mainClass.serbin0 -> 440 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_manifest1.jarbin0 -> 400 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_missingclass.serbin0 -> 493 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_patch.jarbin0 -> 972 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_patch2.jarbin0 -> 667 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_resource.properties2
-rw-r--r--support/src/test/java/tests/resources/hyts_security.jarbin0 -> 1765 bytes
-rw-r--r--support/src/test/java/tests/resources/hyts_signed.jarbin0 -> 2375 bytes
-rw-r--r--support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF26
-rw-r--r--support/src/test/java/tests/resources/morestuff/hyts_patch.jarbin0 -> 972 bytes
-rw-r--r--support/src/test/java/tests/resources/morestuff/hyts_patch2.jarbin0 -> 667 bytes
-rw-r--r--support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties2
-rw-r--r--support/src/test/java/tests/support/Support_BitSet.java202
-rw-r--r--support/src/test/java/tests/support/Support_CollectionTest.java107
-rw-r--r--support/src/test/java/tests/support/Support_Configuration.java484
-rw-r--r--support/src/test/java/tests/support/Support_DecimalFormat.java286
-rw-r--r--support/src/test/java/tests/support/Support_Exec.java202
-rw-r--r--support/src/test/java/tests/support/Support_Field.java45
-rw-r--r--support/src/test/java/tests/support/Support_Format.java143
-rw-r--r--support/src/test/java/tests/support/Support_GetLocal.java101
-rw-r--r--support/src/test/java/tests/support/Support_ListTest.java220
-rw-r--r--support/src/test/java/tests/support/Support_MapTest2.java66
-rw-r--r--support/src/test/java/tests/support/Support_MessageFormat.java119
-rw-r--r--support/src/test/java/tests/support/Support_NetworkInterface.java47
-rw-r--r--support/src/test/java/tests/support/Support_PlatformFile.java36
-rw-r--r--support/src/test/java/tests/support/Support_PortManager.java105
-rw-r--r--support/src/test/java/tests/support/Support_ProviderTrust.java93
-rw-r--r--support/src/test/java/tests/support/Support_Proxy_I1.java28
-rw-r--r--support/src/test/java/tests/support/Support_Proxy_I2.java27
-rw-r--r--support/src/test/java/tests/support/Support_Proxy_ParentException.java22
-rw-r--r--support/src/test/java/tests/support/Support_Proxy_SubException.java23
-rw-r--r--support/src/test/java/tests/support/Support_SetTest.java48
-rw-r--r--support/src/test/java/tests/support/Support_SimpleDateFormat.java263
-rw-r--r--support/src/test/java/tests/support/Support_StringReader.java247
-rw-r--r--support/src/test/java/tests/support/Support_StringWriter.java178
-rw-r--r--support/src/test/java/tests/support/Support_TestProvider.java125
-rw-r--r--support/src/test/java/tests/support/Support_TestResource.java30
-rw-r--r--support/src/test/java/tests/support/Support_TestResource_en.java30
-rw-r--r--support/src/test/java/tests/support/Support_TestResource_en_US.java30
-rw-r--r--support/src/test/java/tests/support/Support_TestResource_fr.java30
-rw-r--r--support/src/test/java/tests/support/Support_TestResource_fr_FR.java30
-rw-r--r--support/src/test/java/tests/support/Support_TestResource_fr_FR_VAR.java31
-rw-r--r--support/src/test/java/tests/support/Support_TimeZone.java83
-rw-r--r--support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java111
-rw-r--r--support/src/test/java/tests/support/Support_UnmodifiableMapTest.java161
-rw-r--r--support/src/test/java/tests/support/resource/Support_Resources.java177
-rw-r--r--support/src/test/java/tests/util/CallVerificationStack.java353
-rw-r--r--support/src/test/java/tests/util/SerializationTester.java246
-rw-r--r--support/src/test/resources/hyts_Foo.c1
138 files changed, 10715 insertions, 0 deletions
diff --git a/support/MODULE_LICENSE_APACHE2 b/support/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/support/MODULE_LICENSE_APACHE2
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/CertificateStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/CertificateStub.java
new file mode 100644
index 0000000..18bc3e7
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/CertificateStub.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Certificate;
+import java.security.KeyException;
+import java.security.Principal;
+import java.security.PublicKey;
+
+/**
+ * Stub for interface Certificate, necessary for testing
+ */
+@SuppressWarnings("deprecation")
+public class CertificateStub implements Certificate {
+
+ String format;
+ Principal guarantor;
+ Principal principal;
+ PublicKey key;
+
+ public CertificateStub(String format, Principal guarantor, Principal principal, PublicKey key){
+ this.format = format;
+ this.guarantor = guarantor;
+ this.principal = principal;
+ this.key = key;
+ }
+
+ /**
+ * Stub - does nothing
+ * @see java.security.Certificate#decode(java.io.InputStream)
+ */
+ public void decode(InputStream stream) throws KeyException,
+ IOException {
+
+
+ }
+
+ /**
+ * Stub - does nothing
+ * @see java.security.Certificate#encode(java.io.OutputStream)
+ */
+ public void encode(OutputStream stream) throws KeyException,
+ IOException {
+
+
+ }
+
+ /**
+ * @see java.security.Certificate#getFormat()
+ */
+ public String getFormat() {
+
+ return format;
+ }
+
+ /**
+ * @see java.security.Certificate#getGuarantor()
+ */
+ public Principal getGuarantor() {
+
+ return guarantor;
+ }
+
+ /**
+ * @see java.security.Certificate#getPrincipal()
+ */
+ public Principal getPrincipal() {
+ return principal;
+ }
+
+ /**
+ * @see java.security.Certificate#getPublicKey()
+ */
+ public PublicKey getPublicKey() {
+ return key;
+ }
+
+ /**
+ * Stub - returns <code>null</code>
+ * @see java.security.Certificate#toString(boolean)
+ */
+ public String toString(boolean detailed) {
+ return null;
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/IdentityScopeStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/IdentityScopeStub.java
new file mode 100644
index 0000000..65f64ac
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/IdentityScopeStub.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.Identity;
+import java.security.IdentityScope;
+import java.security.KeyManagementException;
+import java.security.PublicKey;
+import java.util.Enumeration;
+
+/**
+ * This is stub implementation of IdentityScope for testing purposes
+ */
+@SuppressWarnings("deprecation")
+public class IdentityScopeStub extends IdentityScope {
+
+
+ /**
+ * Stub constructor
+ */
+ public IdentityScopeStub() {
+ super();
+ }
+
+ /**
+ * Stub constructor
+ * @param name
+ */
+ public IdentityScopeStub(String name) {
+ super(name);
+ }
+
+ /**
+ * Stub constructor
+ * @param name
+ * @param scope
+ * @throws KeyManagementException
+ */
+ public IdentityScopeStub(String name, IdentityScope scope)
+ throws KeyManagementException {
+ super(name, scope);
+ }
+
+ /**
+ * Stub - returns 0
+ * @see java.security.IdentityScope#size()
+ */
+ public int size() {
+
+ return 0;
+ }
+
+ /**
+ * Stub - returns <code>this</code>
+ * @see java.security.IdentityScope#getIdentity(java.lang.String)
+ */
+ public Identity getIdentity(String name) {
+
+ return this;
+ }
+
+ /**
+ * Stub - returns <code>this</code>
+ * @see java.security.IdentityScope#getIdentity(java.security.PublicKey)
+ */
+ public Identity getIdentity(PublicKey key) {
+ return this;
+ }
+
+ /**
+ * Stub - does nothing
+ * @see java.security.IdentityScope#addIdentity(java.security.Identity)
+ */
+ public void addIdentity(Identity identity) throws KeyManagementException {
+
+
+ }
+
+ /**
+ * Stub - does nothing
+ * @see java.security.IdentityScope#removeIdentity(java.security.Identity)
+ */
+ public void removeIdentity(Identity identity) throws KeyManagementException {
+
+
+ }
+
+ /**
+ * Stub - returns <code>null</code>
+ * @see java.security.IdentityScope#identities()
+ */
+ public Enumeration identities() {
+ return null;
+ }
+
+ /**
+ * Sets the system's identity scope
+ * @param scope
+ */
+ public static void mySetSystemScope(IdentityScope scope) {
+
+ IdentityScope.setSystemScope(scope);
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/IdentityStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/IdentityStub.java
new file mode 100644
index 0000000..884fbf4
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/IdentityStub.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.Identity;
+import java.security.IdentityScope;
+import java.security.KeyManagementException;
+import java.security.PublicKey;
+
+/**
+ * Stub for abstract class Identity
+ *
+ */
+@SuppressWarnings("deprecation")
+public class IdentityStub extends Identity {
+
+ /**
+ * Default constructor
+ */
+ @SuppressWarnings("deprecation")
+ public IdentityStub() {
+ super();
+ }
+
+ /**
+ * TODO Put ctor description here
+ *
+ * @param name
+ */
+ @SuppressWarnings("deprecation")
+ public IdentityStub(String name) {
+ super(name);
+ }
+
+ /**
+ * TODO Put ctor description here
+ *
+ * @param name
+ * @param scope
+ * @throws KeyManagementException
+ */
+ @SuppressWarnings("deprecation")
+ public IdentityStub(String name, IdentityScope scope)
+ throws KeyManagementException {
+ super(name, scope);
+ }
+
+ /**
+ * Auxiliary constructor
+ * @param name
+ * @param key
+ * @throws KeyManagementException
+ */
+ @SuppressWarnings("deprecation")
+ public IdentityStub(String name, PublicKey key) throws KeyManagementException{
+ this(name);
+ setPublicKey(key);
+ }
+
+ @SuppressWarnings("deprecation")
+ public boolean identityEquals(Identity identity) {
+ return super.identityEquals(identity);
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/KeyStoreTestSupport.java b/support/src/test/java/org/apache/harmony/security/tests/support/KeyStoreTestSupport.java
new file mode 100644
index 0000000..4469c8b
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/KeyStoreTestSupport.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.security.InvalidKeyException;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+
+import javax.crypto.SecretKey;
+
+/**
+ * Support class for KeyStore tests
+ *
+ */
+
+public class KeyStoreTestSupport {
+
+ public static final String srvKeyStore = "KeyStore";
+
+ public static String[] validValues = { "bks", "BKS", "bKS", "Bks", "bKs",
+ "BkS" };
+
+ public static String defaultType = "bks";
+
+ public static boolean JKSSupported = false;
+
+ public static String defaultProviderName = null;
+
+ public static Provider defaultProvider = null;
+
+ static {
+ defaultProvider = SpiEngUtils.isSupport(defaultType, srvKeyStore);
+ JKSSupported = (defaultProvider != null);
+ defaultProviderName = (JKSSupported ? defaultProvider.getName() : null);
+ }
+
+ /**
+ * Additional class to create SecretKey object
+ */
+ public static class SKey implements SecretKey {
+ private String type;
+
+ private byte[] encoded;
+
+ public SKey(String type, byte[] encoded) {
+ this.type = type;
+ this.encoded = encoded;
+ }
+
+ public String getAlgorithm() {
+ return type;
+ }
+
+ public byte[] getEncoded() {
+ return encoded;
+ }
+
+ public String getFormat() {
+ return "test";
+ }
+ }
+
+ /**
+ * Additional class to create PrivateKey object
+ */
+ public static class MyPrivateKey implements PrivateKey {
+ private String algorithm;
+
+ private String format;
+
+ private byte[] encoded;
+
+ public MyPrivateKey(String algorithm, String format, byte[] encoded) {
+ this.algorithm = algorithm;
+ this.format = format;
+ this.encoded = encoded;
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public byte[] getEncoded() {
+ return encoded;
+ }
+ }
+
+ /**
+ * Additional class to create Certificate and Key objects
+ */
+ public static class MCertificate extends Certificate {
+ private final byte[] encoding;
+
+ private final String type;
+
+ public MCertificate(String type, byte[] encoding) {
+ super(type);
+ this.encoding = encoding;
+ this.type = type;
+ }
+
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return encoding.clone();
+ }
+
+ public void verify(PublicKey key) throws CertificateException,
+ NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+ }
+
+ public void verify(PublicKey key, String sigProvider)
+ throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException,
+ SignatureException {
+ }
+
+ public String toString() {
+ return "[MCertificate, type: " + getType() + "]";
+ }
+
+ public PublicKey getPublicKey() {
+ return new PublicKey() {
+ public String getAlgorithm() {
+ return type;
+ }
+
+ public byte[] getEncoded() {
+ return encoding;
+ }
+
+ public String getFormat() {
+ return "test";
+ }
+ };
+ }
+ }
+
+ /**
+ * Additional class to create ProtectionParameter object
+ */
+ public static class ProtPar implements KeyStore.ProtectionParameter {
+ }
+
+ /**
+ * Additional class to create KeyStore.Entry object
+ */
+ public static class AnotherEntry implements KeyStore.Entry {
+ }
+}
+
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MDGoldenData.java b/support/src/test/java/org/apache/harmony/security/tests/support/MDGoldenData.java
new file mode 100644
index 0000000..ae13f59
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MDGoldenData.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.util.HashMap;
+
+/**
+ * Golden data for Message Digest related tests.<br>
+ * Encapsulates the following data:<br>
+ * - reference message<br>
+ * - reference message digests calculated using
+ * BEA JRockit j2sdk1.4.2_04 (http://www.bea.com)
+ * for various MD algorithms:
+ * SHA-1, SHA-256, SHA-384, SHA-512, MD-5.
+ * Standard algorithm names are defined in
+ * "JavaTM Cryptography Architecture API Specification & Reference"
+ *
+ */
+public class MDGoldenData {
+ // The length of test message
+ private static final int MY_MESSAGE_LEN = 1024;
+ // Test message for digest computations
+ private static final byte[] myMessage = new byte[MY_MESSAGE_LEN];
+ // Reference digests for various algorithms calculated
+ // for <code>myMessage</code>
+ private static final HashMap<String, byte[]> goldenData = new HashMap<String, byte[]>();
+
+ static {
+ // fill myMessage
+ for (int i=0; i<myMessage.length; i++) {
+ myMessage[i] = (byte)i;
+ }
+ // fill goldenData
+ // digest updated with myMessage bytes
+ goldenData.put("SHA-1", new byte[] {
+ (byte)0x5b, (byte)0x00, (byte)0x66, (byte)0x9c,
+ (byte)0x48, (byte)0x0d, (byte)0x5c, (byte)0xff,
+ (byte)0xbd, (byte)0xfa, (byte)0x8b, (byte)0xdb,
+ (byte)0xa9, (byte)0x95, (byte)0x61, (byte)0x16,
+ (byte)0x0f, (byte)0x2d, (byte)0x1b, (byte)0x77
+ });
+ // digest without updates at all;
+ // use MD algorithm name + "_NU" if not updated MD value is needed
+ goldenData.put("SHA-1_NU", new byte[] {
+ (byte)0xda, (byte)0x39, (byte)0xa3, (byte)0xee,
+ (byte)0x5e, (byte)0x6b, (byte)0x4b, (byte)0x0d,
+ (byte)0x32, (byte)0x55, (byte)0xbf, (byte)0xef,
+ (byte)0x95, (byte)0x60, (byte)0x18, (byte)0x90,
+ (byte)0xaf, (byte)0xd8, (byte)0x07, (byte)0x09
+ });
+
+ goldenData.put("SHA", goldenData.get("SHA-1"));
+ goldenData.put("SHA_NU", goldenData.get("SHA-1_NU"));
+
+ goldenData.put("SHA1", goldenData.get("SHA-1"));
+ goldenData.put("SHA1_NU", goldenData.get("SHA-1_NU"));
+
+ goldenData.put("SHA-256", new byte[] {
+ (byte)0x78, (byte)0x5b, (byte)0x07, (byte)0x51,
+ (byte)0xfc, (byte)0x2c, (byte)0x53, (byte)0xdc,
+ (byte)0x14, (byte)0xa4, (byte)0xce, (byte)0x3d,
+ (byte)0x80, (byte)0x0e, (byte)0x69, (byte)0xef,
+ (byte)0x9c, (byte)0xe1, (byte)0x00, (byte)0x9e,
+ (byte)0xb3, (byte)0x27, (byte)0xcc, (byte)0xf4,
+ (byte)0x58, (byte)0xaf, (byte)0xe0, (byte)0x9c,
+ (byte)0x24, (byte)0x2c, (byte)0x26, (byte)0xc9
+ });
+ goldenData.put("SHA-256_NU", new byte[] {
+ (byte)0xe3, (byte)0xb0, (byte)0xc4, (byte)0x42,
+ (byte)0x98, (byte)0xfc, (byte)0x1c, (byte)0x14,
+ (byte)0x9a, (byte)0xfb, (byte)0xf4, (byte)0xc8,
+ (byte)0x99, (byte)0x6f, (byte)0xb9, (byte)0x24,
+ (byte)0x27, (byte)0xae, (byte)0x41, (byte)0xe4,
+ (byte)0x64, (byte)0x9b, (byte)0x93, (byte)0x4c,
+ (byte)0xa4, (byte)0x95, (byte)0x99, (byte)0x1b,
+ (byte)0x78, (byte)0x52, (byte)0xb8, (byte)0x55
+ });
+ goldenData.put("SHA-384", new byte[] {
+ (byte)0x55, (byte)0xfd, (byte)0x17, (byte)0xee,
+ (byte)0xb1, (byte)0x61, (byte)0x1f, (byte)0x91,
+ (byte)0x93, (byte)0xf6, (byte)0xac, (byte)0x60,
+ (byte)0x02, (byte)0x38, (byte)0xce, (byte)0x63,
+ (byte)0xaa, (byte)0x29, (byte)0x8c, (byte)0x2e,
+ (byte)0x33, (byte)0x2f, (byte)0x04, (byte)0x2b,
+ (byte)0x80, (byte)0xc8, (byte)0xf6, (byte)0x91,
+ (byte)0xf8, (byte)0x00, (byte)0xe4, (byte)0xc7,
+ (byte)0x50, (byte)0x5a, (byte)0xf2, (byte)0x0c,
+ (byte)0x1a, (byte)0x86, (byte)0xa3, (byte)0x1f,
+ (byte)0x08, (byte)0x50, (byte)0x45, (byte)0x87,
+ (byte)0x39, (byte)0x5f, (byte)0x08, (byte)0x1f
+ });
+ goldenData.put("SHA-384_NU", new byte[] {
+ (byte)0x38, (byte)0xb0, (byte)0x60, (byte)0xa7,
+ (byte)0x51, (byte)0xac, (byte)0x96, (byte)0x38,
+ (byte)0x4c, (byte)0xd9, (byte)0x32, (byte)0x7e,
+ (byte)0xb1, (byte)0xb1, (byte)0xe3, (byte)0x6a,
+ (byte)0x21, (byte)0xfd, (byte)0xb7, (byte)0x11,
+ (byte)0x14, (byte)0xbe, (byte)0x07, (byte)0x43,
+ (byte)0x4c, (byte)0x0c, (byte)0xc7, (byte)0xbf,
+ (byte)0x63, (byte)0xf6, (byte)0xe1, (byte)0xda,
+ (byte)0x27, (byte)0x4e, (byte)0xde, (byte)0xbf,
+ (byte)0xe7, (byte)0x6f, (byte)0x65, (byte)0xfb,
+ (byte)0xd5, (byte)0x1a, (byte)0xd2, (byte)0xf1,
+ (byte)0x48, (byte)0x98, (byte)0xb9, (byte)0x5b
+ });
+ goldenData.put("SHA-512", new byte[] {
+ (byte)0x37, (byte)0xf6, (byte)0x52, (byte)0xbe,
+ (byte)0x86, (byte)0x7f, (byte)0x28, (byte)0xed,
+ (byte)0x03, (byte)0x32, (byte)0x69, (byte)0xcb,
+ (byte)0xba, (byte)0x20, (byte)0x1a, (byte)0xf2,
+ (byte)0x11, (byte)0x2c, (byte)0x2b, (byte)0x3f,
+ (byte)0xd3, (byte)0x34, (byte)0xa8, (byte)0x9f,
+ (byte)0xd2, (byte)0xf7, (byte)0x57, (byte)0x93,
+ (byte)0x8d, (byte)0xde, (byte)0xe8, (byte)0x15,
+ (byte)0x78, (byte)0x7c, (byte)0xc6, (byte)0x1d,
+ (byte)0x6e, (byte)0x24, (byte)0xa8, (byte)0xa3,
+ (byte)0x33, (byte)0x40, (byte)0xd0, (byte)0xf7,
+ (byte)0xe8, (byte)0x6f, (byte)0xfc, (byte)0x05,
+ (byte)0x88, (byte)0x16, (byte)0xb8, (byte)0x85,
+ (byte)0x30, (byte)0x76, (byte)0x6b, (byte)0xa6,
+ (byte)0xe2, (byte)0x31, (byte)0x62, (byte)0x0a,
+ (byte)0x13, (byte)0x0b, (byte)0x56, (byte)0x6c
+ });
+ goldenData.put("SHA-512_NU", new byte[] {
+ (byte)0xcf, (byte)0x83, (byte)0xe1, (byte)0x35,
+ (byte)0x7e, (byte)0xef, (byte)0xb8, (byte)0xbd,
+ (byte)0xf1, (byte)0x54, (byte)0x28, (byte)0x50,
+ (byte)0xd6, (byte)0x6d, (byte)0x80, (byte)0x07,
+ (byte)0xd6, (byte)0x20, (byte)0xe4, (byte)0x05,
+ (byte)0x0b, (byte)0x57, (byte)0x15, (byte)0xdc,
+ (byte)0x83, (byte)0xf4, (byte)0xa9, (byte)0x21,
+ (byte)0xd3, (byte)0x6c, (byte)0xe9, (byte)0xce,
+ (byte)0x47, (byte)0xd0, (byte)0xd1, (byte)0x3c,
+ (byte)0x5d, (byte)0x85, (byte)0xf2, (byte)0xb0,
+ (byte)0xff, (byte)0x83, (byte)0x18, (byte)0xd2,
+ (byte)0x87, (byte)0x7e, (byte)0xec, (byte)0x2f,
+ (byte)0x63, (byte)0xb9, (byte)0x31, (byte)0xbd,
+ (byte)0x47, (byte)0x41, (byte)0x7a, (byte)0x81,
+ (byte)0xa5, (byte)0x38, (byte)0x32, (byte)0x7a,
+ (byte)0xf9, (byte)0x27, (byte)0xda, (byte)0x3e
+ });
+ goldenData.put("MD5", new byte[] {
+ (byte)0xb2, (byte)0xea, (byte)0x9f, (byte)0x7f,
+ (byte)0xce, (byte)0xa8, (byte)0x31, (byte)0xa4,
+ (byte)0xa6, (byte)0x3b, (byte)0x21, (byte)0x3f,
+ (byte)0x41, (byte)0xa8, (byte)0x85, (byte)0x5b
+ });
+ goldenData.put("MD5_NU", new byte[] {
+ (byte)0xd4, (byte)0x1d, (byte)0x8c, (byte)0xd9,
+ (byte)0x8f, (byte)0x00, (byte)0xb2, (byte)0x04,
+ (byte)0xe9, (byte)0x80, (byte)0x09, (byte)0x98,
+ (byte)0xec, (byte)0xf8, (byte)0x42, (byte)0x7e
+ });
+ }
+
+ // No need to instantiate
+ private MDGoldenData() {
+ }
+
+ /**
+ * Returns reference message
+ *
+ * @return reference message
+ */
+ public static byte[] getMessage() {
+ return myMessage.clone();
+ }
+
+ /**
+ * Returns digest golden data
+ *
+ * @param key
+ * MD algorithm name or MD algorithm name + "_NU" if
+ * not updated MD value requested
+ * @return
+ * reference digest for specified MD algorithm name
+ */
+ public static byte[] getDigest(String key) {
+ return ((byte[])goldenData.get(key)).clone();
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyAlgorithmParameterGeneratorSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyAlgorithmParameterGeneratorSpi.java
new file mode 100644
index 0000000..ecc6899
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyAlgorithmParameterGeneratorSpi.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.AlgorithmParameterGeneratorSpi;
+import java.security.AlgorithmParameters;
+import java.security.SecureRandom;
+import java.security.spec.AlgorithmParameterSpec;
+
+/**
+ * Additional class for verification AlgorithmParameterGeneratorSpi and
+ * AlgorithmParameterGenerator classes
+ *
+ */
+
+public class MyAlgorithmParameterGeneratorSpi
+ extends AlgorithmParameterGeneratorSpi {
+
+ public void engineInit(int keysize, SecureRandom random) {
+ if (keysize < 0) {
+ throw new IllegalArgumentException("keysize < 0");
+ }
+ }
+
+ public void engineInit(AlgorithmParameterSpec genParamSpec,
+ SecureRandom random) {
+ if (random == null) {
+ throw new IllegalArgumentException("random is null");
+ }
+ }
+
+ public AlgorithmParameters engineGenerateParameters() {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyBasicPermission.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyBasicPermission.java
new file mode 100644
index 0000000..d0e409a
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyBasicPermission.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.security.BasicPermission;
+
+public class MyBasicPermission extends BasicPermission {
+
+ private static final long serialVersionUID = -4220730623258019258L;
+
+ public MyBasicPermission(String name) {
+ super(name);
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyGuard.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyGuard.java
new file mode 100644
index 0000000..073c928
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyGuard.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.io.Serializable;
+import java.security.Guard;
+
+public class MyGuard implements Guard, Serializable {
+
+ private static final long serialVersionUID = 5767944725614823373L;
+
+ final boolean enabled;
+
+ public MyGuard(boolean state) {
+ enabled = state;
+ }
+
+ public void checkGuard(Object object) {
+ if (!enabled) {
+ throw new SecurityException();
+ }
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator1.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator1.java
new file mode 100644
index 0000000..ce7cacd
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator1.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidParameterException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.spec.AlgorithmParameterSpec;
+
+/**
+ * Additional class extends KeyPairGenerator
+ *
+ */
+
+public class MyKeyPairGenerator1 extends KeyPairGenerator {
+ public int keySize;
+
+ public SecureRandom secureRandom;
+
+ public AlgorithmParameterSpec paramSpec;
+
+ public MyKeyPairGenerator1() {
+ super("MyKeyPairGenerator1");
+ }
+
+ public MyKeyPairGenerator1(String pp) {
+ super(pp);
+ }
+
+ public String getAlgorithm() {
+ return "MyKeyPairGenerator1";
+ }
+
+ public static final String getResAlgorithm() {
+ return "MyKeyPairGenerator1";
+ }
+
+ public void initialize(int keysize, SecureRandom random) {
+ if ((keysize < 0) || ((keysize % 100) != 0)) {
+ throw new InvalidParameterException("Incorrect keysize parameter");
+ }
+ if (random == null) {
+ throw new InvalidParameterException("Incorrect random");
+ }
+ keySize = keysize;
+ secureRandom = random;
+ }
+
+ public KeyPair generateKeyPair() {
+ try {
+ return new KeyPair(new PubKey(), new PrivKey());
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public void initialize(AlgorithmParameterSpec param, SecureRandom random)
+ throws InvalidAlgorithmParameterException {
+ if (random == null) {
+ throw new InvalidParameterException("Incorrect random");
+ }
+ if (param == null) {
+ throw new InvalidAlgorithmParameterException("Incorrect param");
+ }
+ paramSpec = param;
+ secureRandom = random;
+ }
+
+ public class PubKey implements PublicKey {
+ private String algorithm;
+
+ private String format;
+
+ private byte[] encoded;
+
+ public PubKey() {
+ this.algorithm = "MyKeyPairGenerator1";
+ this.format = "test1";
+ this.encoded = new byte[10];
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public byte[] getEncoded() {
+ return encoded;
+ }
+ }
+
+ public class PrivKey implements PrivateKey {
+ private String algorithm;
+
+ private String format;
+
+ private byte[] encoded;
+
+ public PrivKey() {
+ this.algorithm = "MyKeyPairGenerator1";
+ this.format = "test1";
+ this.encoded = new byte[10];
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public byte[] getEncoded() {
+ return encoded;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator2.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator2.java
new file mode 100644
index 0000000..9191e45
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator2.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.InvalidParameterException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.SecureRandom;
+
+/**
+ * Additional class extends KeyPairGenerator
+ *
+ */
+
+public class MyKeyPairGenerator2 extends KeyPairGenerator {
+ int keySize;
+
+ SecureRandom secureRandom;
+
+ public MyKeyPairGenerator2() {
+ super("MyKeyPairGenerator2");
+ }
+
+ public String getAlgorithm() {
+ return "MyKeyPairGenerator2";
+ }
+
+ public static final String getResAlgorithm() {
+ return "MyKeyPairGenerator2";
+ }
+
+ public MyKeyPairGenerator2(String pp) {
+ super(pp);
+ }
+
+ public void initialize(int keysize, SecureRandom random) {
+ if (keysize < 64) {
+ throw new InvalidParameterException("Incorrect keysize parameter");
+ }
+ keySize = keysize;
+ secureRandom = random;
+ }
+
+ public KeyPair generateKeyPair() {
+ return null;
+ }
+}
+
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator3.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator3.java
new file mode 100644
index 0000000..affbbd7
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGenerator3.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+/**
+ * Additional class extends KeyPairGenerator
+ *
+ */
+
+public class MyKeyPairGenerator3 extends KeyPairGenerator {
+ public MyKeyPairGenerator3() {
+ super("KPGen_3");
+ }
+
+ public MyKeyPairGenerator3(String s) {
+ super(s);
+ }
+
+ public KeyPair generateKeyPair() {
+ PublicKey pubK = (new MyKeyPairGenerator1()).new PubKey();
+ PrivateKey priK = (new MyKeyPairGenerator1()).new PrivKey();
+ return new KeyPair(pubK, priK);
+ }
+
+}
+
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGeneratorSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGeneratorSpi.java
new file mode 100644
index 0000000..e26eb8c
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyPairGeneratorSpi.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidParameterException;
+import java.security.KeyPair;
+import java.security.KeyPairGeneratorSpi;
+import java.security.SecureRandom;
+import java.security.spec.AlgorithmParameterSpec;
+
+/**
+ * Additional class for verification of KeyPairGeneratorSpi and KeyPairGenerator
+ *
+ */
+
+public class MyKeyPairGeneratorSpi extends KeyPairGeneratorSpi {
+
+ public void initialize(int keysize, SecureRandom random) {
+ if (keysize < 100) {
+ throw new InvalidParameterException(
+ "Invalid keysize: less than 100");
+ }
+ if (random == null) {
+ throw new IllegalArgumentException("Invalid random");
+ }
+ }
+
+ public KeyPair generateKeyPair() {
+ return null;
+ }
+
+ public void initialize(AlgorithmParameterSpec params, SecureRandom random)
+ throws InvalidAlgorithmParameterException {
+ if (random == null) {
+ throw new UnsupportedOperationException(
+ "Not supported for null random");
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStore.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStore.java
new file mode 100644
index 0000000..61c4a2f
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStore.java
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * Additional class for KeyStoreSpi and KeyStore verification
+ *
+ */
+
+public class MyKeyStore extends KeyStoreSpi {
+ private Hashtable<String, Object> Keys = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> Cert = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> Chain = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> Dates = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> KeysSL = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> CertSL = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> ChainSL = new Hashtable<String, Object>();
+
+ private Hashtable<String, Object> DatesSL = new Hashtable<String, Object>();
+
+ public Key engineGetKey(String alias, char[] password)
+ throws NoSuchAlgorithmException, UnrecoverableKeyException {
+ if (Keys.containsKey(alias)) {
+ return (Key) Keys.get(alias);
+ }
+ return null;
+ }
+
+ public Certificate[] engineGetCertificateChain(String alias) {
+ if (Chain.containsKey(alias)) {
+ return (Certificate[]) Chain.get(alias);
+ }
+ return null;
+ }
+
+ public Certificate engineGetCertificate(String alias) {
+ if (Cert.containsKey(alias)) {
+ return (Certificate) Cert.get(alias);
+ }
+ return null;
+ }
+
+ public Date engineGetCreationDate(String alias) {
+ if (Dates.containsKey(alias)) {
+ return (Date) Dates.get(alias);
+ }
+ return null;
+ }
+
+ public void engineSetKeyEntry(String alias, Key key, char[] password,
+ Certificate[] chain) throws KeyStoreException {
+ if (Cert.containsKey(alias)) {
+ Cert.remove(alias);
+ }
+ Keys.put(alias, key);
+ if (chain != null) {
+ Chain.put(alias, chain);
+ }
+ Dates.put(alias, new Date());
+ }
+
+ public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain)
+ throws KeyStoreException {
+ if (key == null) {
+ throw new KeyStoreException("Not Supported for null key");
+ }
+ if (Cert.containsKey(alias)) {
+ Cert.remove(alias);
+ }
+ if (Chain.containsKey(alias)) {
+ Chain.remove(alias);
+ }
+ KeyStoreTestSupport.MyPrivateKey keyK = new KeyStoreTestSupport.MyPrivateKey(
+ alias, alias, key);
+ Keys.put(alias, keyK);
+ if (chain != null) {
+ Chain.put(alias, chain);
+ }
+ Dates.put(alias, new Date());
+
+ }
+
+ public void engineSetCertificateEntry(String alias, Certificate cert)
+ throws KeyStoreException {
+ Cert.put(alias, cert);
+ Dates.put(alias, new Date());
+ }
+
+ public void engineDeleteEntry(String alias) throws KeyStoreException {
+ if (Keys.containsKey(alias)) {
+ Keys.remove(alias);
+ Chain.remove(alias);
+ return;
+ }
+ if (Cert.containsKey(alias)) {
+ Cert.remove(alias);
+ }
+ }
+
+ public Enumeration<String> engineAliases() {
+ return null;
+ }
+
+ public boolean engineContainsAlias(String alias) {
+ if (Keys.containsKey(alias)) {
+ return true;
+ }
+ if (Cert.containsKey(alias)) {
+ return true;
+ }
+ return false;
+ }
+
+ public int engineSize() {
+ return (Keys.size() + Cert.size());
+ }
+
+ public boolean engineIsKeyEntry(String alias) {
+ if (Keys.containsKey(alias)) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean engineIsCertificateEntry(String alias) {
+ if (Cert.containsKey(alias)) {
+ return true;
+ }
+ return false;
+ }
+
+ public String engineGetCertificateAlias(Certificate cert) {
+ return "";
+ }
+
+ public void engineStore(OutputStream stream, char[] password)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ if (!(stream instanceof ByteArrayOutputStream)) {
+ throw new IOException("Incorrect stream");
+ }
+ String alias;
+ Enumeration e = Keys.keys();
+ while (e.hasMoreElements()) {
+ alias = (String) e.nextElement();
+ KeysSL.put(alias, Keys.get(alias));
+ DatesSL.put(alias, Dates.get(alias));
+ if (Chain.containsKey(alias)) {
+ ChainSL.put(alias, Chain.get(alias));
+ }
+ }
+ e = Cert.keys();
+ while (e.hasMoreElements()) {
+ alias = (String) e.nextElement();
+ CertSL.put(alias, Cert.get(alias));
+ DatesSL.put(alias, Dates.get(alias));
+ }
+ }
+
+ public void engineLoad(InputStream stream, char[] password)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ Keys.clear();
+ Cert.clear();
+ Chain.clear();
+ Dates.clear();
+ String alias;
+ Enumeration e = KeysSL.keys();
+ while (e.hasMoreElements()) {
+ alias = (String) e.nextElement();
+ Keys.put(alias, KeysSL.get(alias));
+ Dates.put(alias, DatesSL.get(alias));
+ if (ChainSL.containsKey(alias)) {
+ Chain.put(alias, ChainSL.get(alias));
+ }
+ }
+ e = CertSL.keys();
+ while (e.hasMoreElements()) {
+ alias = (String) e.nextElement();
+ Cert.put(alias, CertSL.get(alias));
+ Dates.put(alias, DatesSL.get(alias));
+ }
+ }
+
+ public void engineStore(KeyStore.LoadStoreParameter param)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ if (param == null) {
+ throw new IOException("param is null");
+ }
+ }
+
+ public void engineLoad(KeyStore.LoadStoreParameter param)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ if (!(param instanceof MyLoadStoreParams)) {
+ throw new IllegalArgumentException("param is not MyLoadStoreParams: " + param);
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStoreSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStoreSpi.java
new file mode 100644
index 0000000..18acec8
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyKeyStoreSpi.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+ * @version $Revision$
+ */
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Key;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.util.Date;
+import java.util.Enumeration;
+
+/**
+ * Additional class for KeyStoreSpi and KeyStore verification
+ *
+ */
+
+public class MyKeyStoreSpi extends KeyStoreSpi {
+
+ public Key engineGetKey(String alias, char[] password)
+ throws NoSuchAlgorithmException, UnrecoverableKeyException {
+ return null;
+ }
+
+ public Certificate[] engineGetCertificateChain(String alias) {
+ return null;
+ }
+
+ public Certificate engineGetCertificate(String alias) {
+ if (alias.equals("test_engineEntryInstanceOf_Alias1")) {
+ return new MyCertificate("TestType");
+ }
+ return null;
+ }
+
+ public Date engineGetCreationDate(String alias) {
+ return new Date(0);
+ }
+
+ public void engineSetKeyEntry(String alias, Key key, char[] password,
+ Certificate[] chain) throws KeyStoreException {
+ throw new KeyStoreException(
+ "engineSetKeyEntry is not supported in myKeyStoreSpi");
+ }
+
+ public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain)
+ throws KeyStoreException {
+ throw new KeyStoreException(
+ "engineSetKeyEntry is not supported in myKeyStoreSpi");
+ }
+
+ public void engineSetCertificateEntry(String alias, Certificate cert)
+ throws KeyStoreException {
+ throw new KeyStoreException(
+ "engineSetCertificateEntry is not supported in myKeyStoreSpi");
+ }
+
+ public void engineDeleteEntry(String alias) throws KeyStoreException {
+ throw new KeyStoreException(
+ "engineDeleteEntry is not supported in myKeyStoreSpi");
+ }
+
+ public Enumeration<String> engineAliases() {
+ return null;
+ }
+
+ public boolean engineContainsAlias(String alias) {
+ return false;
+ }
+
+ public int engineSize() {
+ return 0;
+ }
+
+ public boolean engineIsKeyEntry(String alias) {
+ if (alias.equals("test_engineEntryInstanceOf_Alias1")) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public boolean engineIsCertificateEntry(String alias) {
+ if (alias.equals("test_engineEntryInstanceOf_Alias2")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public String engineGetCertificateAlias(Certificate cert) {
+ return "";
+ }
+
+ public void engineStore(OutputStream stream, char[] password)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ if (!(stream instanceof ByteArrayOutputStream)) {
+ throw new IOException("Incorrect stream");
+ }
+ if (((ByteArrayOutputStream) stream).size() == 0) {
+ throw new IOException("Incorrect stream size ");
+
+ }
+
+ }
+
+ public void engineLoad(InputStream stream, char[] password)
+ throws IOException, NoSuchAlgorithmException, CertificateException {
+ }
+
+ class MyCertificate extends Certificate {
+ public MyCertificate(String type) {
+ super(type);
+ }
+
+ public byte[] getEncoded() {
+ return null;
+ }
+
+ public PublicKey getPublicKey() {
+ return null;
+ }
+
+ public String toString() {
+ return null;
+ }
+
+ public void verify(PublicKey key) {
+
+ }
+
+ public void verify(PublicKey key, String sigProvider) {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyLoadStoreParams.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyLoadStoreParams.java
new file mode 100644
index 0000000..492e99e
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyLoadStoreParams.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.KeyStore;
+
+/**
+ * Additional class extends KeyStore.LoadStoreParameter
+ */
+public class MyLoadStoreParams implements
+ KeyStore.LoadStoreParameter {
+
+ KeyStore.ProtectionParameter protPar;
+
+ public MyLoadStoreParams(KeyStore.ProtectionParameter p) {
+ this.protPar = p;
+ }
+
+ public KeyStore.ProtectionParameter getProtectionParameter() {
+ return protPar;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest1.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest1.java
new file mode 100644
index 0000000..2744227
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest1.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.MessageDigest;
+
+/**
+ * Tests implementation of MessageDigest
+ *
+ */
+public class MyMessageDigest1 extends MessageDigest {
+
+ public boolean runEngineReset = false;
+ public boolean runEngineDigest = false;
+ public boolean runEngineUpdate1 = false;
+ public boolean runEngineUpdate2 = false;
+
+ public MyMessageDigest1() {
+ super(null);
+ }
+
+ /**
+ *
+ * @param algorithm
+ */
+ public MyMessageDigest1(String algorithm) {
+ super(algorithm);
+ }
+
+ /**
+ *
+ */
+ public void engineReset() {
+ runEngineReset = true;
+ }
+
+ /**
+ *
+ */
+ public byte[] engineDigest() {
+ runEngineDigest = true;
+ return new byte[0];
+ }
+
+ /**
+ *
+ */
+ public void engineUpdate(byte arg0) {
+ runEngineUpdate1 = true;
+ }
+
+ /**
+ *
+ */
+ public void engineUpdate(byte[] arg0, int arg1, int arg2) {
+ runEngineUpdate2 = true;
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest2.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest2.java
new file mode 100644
index 0000000..f3b3153
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyMessageDigest2.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.MessageDigestSpi;
+
+/**
+ * Tests implementation of MessageDigest
+ *
+ */
+public class MyMessageDigest2 extends MessageDigestSpi {
+
+ public static boolean runEngineReset = false;
+ public static boolean runEngineDigest = false;
+ public static boolean runEngineUpdate1 = false;
+ public static boolean runEngineUpdate2 = false;
+
+ /**
+ *
+ */
+ public void engineReset() {
+ runEngineReset = true;
+ }
+
+ /**
+ *
+ */
+ public byte[] engineDigest() {
+ runEngineDigest = true;
+ return new byte[0];
+ }
+
+ /**
+ *
+ */
+ public void engineUpdate(byte arg0) {
+ runEngineUpdate1 = true;
+ }
+
+ /**
+ *
+ */
+ public void engineUpdate(byte[] arg0, int arg1, int arg2) {
+ runEngineUpdate2 = true;
+ }
+
+ /**
+ * The implementation is not cloneable
+ */
+ public Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyPermission.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyPermission.java
new file mode 100644
index 0000000..b52bea9
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyPermission.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.security.Permission;
+
+public final class MyPermission extends Permission {
+
+ private static final long serialVersionUID = 4208595188308189251L;
+
+ public MyPermission(String name) {
+ super(name);
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MyPermission) {
+ String name = ((MyPermission) obj).getName();
+ if (name == null) {
+ return getName() == null;
+ }
+ return name.equals(getName());
+ }
+ return false;
+ }
+
+ public String getActions() {
+ return null;
+ }
+
+ public int hashCode() {
+ return 0;
+ }
+
+ public boolean implies(Permission permission) {
+ return false;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MyPermissionCollection.java b/support/src/test/java/org/apache/harmony/security/tests/support/MyPermissionCollection.java
new file mode 100644
index 0000000..360b4f6
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MyPermissionCollection.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.tests.support;
+
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+public class MyPermissionCollection extends PermissionCollection {
+
+ private static final long serialVersionUID = -8462474212761656528L;
+
+ public MyPermissionCollection(boolean readOnly) {
+ if (readOnly) {
+ setReadOnly();
+ }
+ }
+
+ public void add(Permission permission) {}
+
+ public Enumeration<Permission> elements() {
+
+ return new Enumeration<Permission>() {
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ public Permission nextElement() {
+ throw new NoSuchElementException();
+ }
+ };
+ }
+
+ public boolean implies(Permission permission) {
+ return false;
+ }
+ }
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java
new file mode 100644
index 0000000..48c3d31
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature1.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.InvalidKeyException;
+import java.security.InvalidParameterException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.Signature;
+import java.security.SignatureException;
+
+/**
+ * Tests implementation of Signature
+ *
+ */
+public class MySignature1 extends Signature {
+
+ public boolean runEngineInitVerify = false;
+ public boolean runEngineInitSign = false;
+ public boolean runEngineUpdate1 = false;
+ public boolean runEngineUpdate2 = false;
+ public boolean runEngineSign = false;
+ public boolean runEngineVerify = false;
+ public boolean runEngineSetParameter = false;
+ public boolean runEngineGetParameter = false;
+
+ public static int SIGN = Signature.SIGN;
+ public static int VERIFY = Signature.VERIFY;
+ public static int UNINITIALIZED = Signature.UNINITIALIZED;
+ private final int BUFFER_LENGTH = 10;
+ /**
+ *
+ *
+ */
+ public MySignature1() {
+ super(null);
+ }
+
+ /**
+ *
+ * @param algorithm
+ */
+ public MySignature1(String algorithm) {
+ super(algorithm);
+ }
+
+ protected void engineInitVerify(PublicKey publicKey)
+ throws InvalidKeyException {
+ runEngineInitVerify = true;
+ }
+
+ protected void engineInitSign(PrivateKey privateKey)
+ throws InvalidKeyException {
+ runEngineInitSign = true;
+ }
+
+ protected void engineUpdate(byte b) throws SignatureException {
+ runEngineUpdate1 = true;
+ }
+
+ protected void engineUpdate(byte[] b, int off, int len)
+ throws SignatureException {
+ runEngineUpdate2 = true;
+ }
+
+ protected byte[] engineSign() throws SignatureException {
+ runEngineSign = true;
+ byte [] out = new byte [BUFFER_LENGTH];
+ return out;
+ }
+
+ protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
+ runEngineVerify = true;
+ return false;
+ }
+
+ protected void engineSetParameter(String param, Object value)
+ throws InvalidParameterException {
+ runEngineSetParameter = true;
+ }
+
+ protected Object engineGetParameter(String param)
+ throws InvalidParameterException {
+ runEngineGetParameter = true;
+ return null;
+ }
+
+ public int getState() {
+ return state;
+ }
+
+ public int getBufferLength() {
+ return BUFFER_LENGTH;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/MySignature2.java b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature2.java
new file mode 100644
index 0000000..838dcae
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/MySignature2.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.InvalidKeyException;
+import java.security.InvalidParameterException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.SignatureSpi;
+
+/**
+ * Tests implementation of Signature
+ *
+ */
+public class MySignature2 extends SignatureSpi {
+
+ public static boolean runEngineInitVerify = false;
+ public static boolean runEngineInitSign = false;
+ public static boolean runEngineUpdate1 = false;
+ public static boolean runEngineUpdate2 = false;
+ public static boolean runEngineSign = false;
+ public static boolean runEngineVerify = false;
+ public static boolean runEngineSetParameter = false;
+ public static boolean runEngineGetParameter = false;
+
+ protected void engineInitVerify(PublicKey publicKey)
+ throws InvalidKeyException {
+ runEngineInitVerify = true;
+ }
+
+ protected void engineInitSign(PrivateKey privateKey)
+ throws InvalidKeyException {
+ runEngineInitSign = true;
+ }
+
+ protected void engineUpdate(byte b) throws SignatureException {
+ runEngineUpdate1 = true;
+ }
+
+ protected void engineUpdate(byte[] b, int off, int len)
+ throws SignatureException {
+ runEngineUpdate2 = true;
+ }
+
+ protected byte[] engineSign() throws SignatureException {
+ runEngineSign = true;
+ return null;
+ }
+
+ protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
+ runEngineVerify = true;
+ return false;
+ }
+
+ protected void engineSetParameter(String param, Object value)
+ throws InvalidParameterException {
+ runEngineSetParameter = true;
+ }
+
+ protected Object engineGetParameter(String param)
+ throws InvalidParameterException {
+ runEngineGetParameter = true;
+ return null;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/PrivateKeyStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/PrivateKeyStub.java
new file mode 100644
index 0000000..9741f6d
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/PrivateKeyStub.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.PrivateKey;
+
+/**
+ * Stub for interface PrivateKey tests
+ */
+
+public class PrivateKeyStub implements PrivateKey {
+
+ private static final long serialVersionUID = 111111111L;
+
+ String algorithm = null;
+ String format = null;
+ byte [] encoded = null;
+
+
+ /**
+ * Constructor
+ *
+ * @param algorithm
+ * @param format
+ * @param encoded
+ */
+ public PrivateKeyStub(String algorithm, String format, byte[] encoded) {
+ this.algorithm = algorithm;
+ this.format = format;
+ this.encoded = encoded;
+ }
+
+ /**
+ * Returns algorithm
+ * @see java.security.Key#getAlgorithm()
+ */
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * Returns format
+ * @see java.security.Key#getFormat()
+ */
+ public String getFormat() {
+ return format;
+ }
+
+ /**
+ * Returns encoded form
+ * @see java.security.Key#getEncoded()
+ */
+ public byte[] getEncoded() {
+ return encoded;
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/PublicKeyStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/PublicKeyStub.java
new file mode 100644
index 0000000..8c23e19
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/PublicKeyStub.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+
+import java.security.PublicKey;
+
+
+/**
+ * Stub implements interface PublicKey
+ *
+ */
+
+public class PublicKeyStub implements PublicKey {
+
+ private static final long serialVersionUID = 333333333L;
+
+ String algorithm = null;
+ String format = null;
+ byte [] encoded = null;
+
+ /**
+ * constructor
+ */
+ public PublicKeyStub(String algorithm, String format, byte[] encoded) {
+ this.algorithm = algorithm;
+ this.format = format;
+ this.encoded = encoded;
+ }
+
+ /**
+ * returns algorithm
+ */
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * returns format
+ * @see java.security.Key#getFormat()
+ */
+ public String getFormat() {
+ return format;
+ }
+
+ /**
+ * returns encoded
+ * @see java.security.Key#getEncoded()
+ */
+ public byte[] getEncoded() {
+ return encoded;
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/RandomImpl.java b/support/src/test/java/org/apache/harmony/security/tests/support/RandomImpl.java
new file mode 100644
index 0000000..d6dc9ec
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/RandomImpl.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.SecureRandomSpi;
+
+/**
+ * Test implementation of SecureRandom
+ *
+ */
+public class RandomImpl extends SecureRandomSpi {
+
+ public static boolean runEngineGenerateSeed = false;
+ public static boolean runEngineNextBytes = false;
+ public static boolean runEngineSetSeed = false;
+
+ protected void engineSetSeed(byte[] seed) {
+ runEngineSetSeed = true;
+ }
+
+ protected void engineNextBytes(byte[] bytes) {
+ runEngineNextBytes = true;
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] = (byte)(i + 0xF1);
+ }
+ }
+
+ protected byte[] engineGenerateSeed(int numBytes) {
+ runEngineGenerateSeed = true;
+ byte[] b = new byte[numBytes];
+ for (int i = 0; i < b.length; i++) {
+ b[i] = (byte)i;
+ }
+ return b;
+ }
+
+}
+
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/SecurityChecker.java b/support/src/test/java/org/apache/harmony/security/tests/support/SecurityChecker.java
new file mode 100644
index 0000000..73f1021
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/SecurityChecker.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.Permission;
+
+/**
+ * Custom security manager
+ */
+
+public class SecurityChecker extends SecurityManager {
+
+ public boolean enableAccess;
+
+ public Permission checkTarget;
+
+ public boolean checkAsserted;
+
+ public SecurityChecker(Permission target, boolean enable) {
+ checkAsserted = false;
+ checkTarget = target;
+ enableAccess = enable;
+ }
+
+ public void checkPermission(Permission p) {
+ if (checkTarget.equals(p)) {
+ checkAsserted = true;
+ if (!enableAccess) {
+ throw new SecurityException();
+ }
+ }
+ }
+
+ public SecurityChecker reset() {
+ checkAsserted = false;
+ return this;
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/SignerStub.java b/support/src/test/java/org/apache/harmony/security/tests/support/SignerStub.java
new file mode 100644
index 0000000..3b3edcf
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/SignerStub.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Aleksei Y. Semenov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.IdentityScope;
+import java.security.KeyManagementException;
+import java.security.Signer;
+
+/**
+ * Stub for abstract class Signer, necessary for testing purposes
+ *
+ */
+@SuppressWarnings("deprecation")
+public class SignerStub extends Signer {
+
+ /**
+ * Default constructor
+ */
+ public SignerStub() {
+ super();
+ }
+
+ /**
+ * Constructor, sets given name
+ *
+ * @param name
+ */
+ public SignerStub(String name) {
+ super(name);
+ }
+
+ /**
+ * Constructor, sets given name and scope
+ *
+ * @param name
+ * @param scope
+ * @throws KeyManagementException
+ */
+ public SignerStub(String name, IdentityScope scope)
+ throws KeyManagementException {
+ super(name, scope);
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/SpiEngUtils.java b/support/src/test/java/org/apache/harmony/security/tests/support/SpiEngUtils.java
new file mode 100644
index 0000000..9e5fd70
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/SpiEngUtils.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.Security;
+import java.security.Provider;
+
+/**
+ * Additional class for verification spi-engine classes
+ *
+ */
+
+public class SpiEngUtils {
+
+ public static final String[] invalidValues = {
+ "",
+ "BadAlgorithm",
+ "Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message Long message" };
+
+ /**
+ * Verification: is algorithm supported or not
+ *
+ * @param algorithm
+ * @param service
+ * @return
+ */
+ public static Provider isSupport(String algorithm, String service) {
+ try {
+ Provider[] provs = Security.getProviders(service.concat(".")
+ .concat(algorithm));
+ if (provs == null) {
+ return null;
+ }
+ return (provs.length == 0 ? null : provs[0]);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public class MyProvider extends Provider {
+
+ public MyProvider(String name, String info, String key, String clName) {
+ super(name, 1.0, info);
+ put(key, clName);
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/TestCertUtils.java b/support/src/test/java/org/apache/harmony/security/tests/support/TestCertUtils.java
new file mode 100644
index 0000000..0054d5f
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/TestCertUtils.java
@@ -0,0 +1,831 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.io.StreamCorruptedException;
+import java.math.BigInteger;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.Security;
+import java.security.SignatureException;
+
+import java.security.cert.*;
+import java.util.*;
+
+import javax.security.auth.x500.X500Principal;
+
+/**
+ * The class contains various utility methods used during the java.security
+ * classes testing.
+ *
+ */
+
+public final class TestCertUtils {
+
+ private TestCertUtils() {
+ throw new Error("statics only");
+ }
+
+ /**
+ * Returns new instance of test certificate each time the method is called.
+ *
+ * @return test certificate
+ */
+ public static Certificate getCert() {
+ return new TestCertificate();
+ }
+
+ /**
+ * Returns an array of 3 test certificates. IMP: The array returned is not
+ * real chain of certificates, it's just an array of 3 certs. The method
+ * returns new array each time it's called. The number of 3 was chosen
+ * arbitrarily and is subject to change.
+ *
+ * @return an array of 3 certificates
+ */
+ public static Certificate[] getCertChain() {
+ Certificate[] chain = { new TestCertificate(), new TestCertificate(),
+ new TestCertificate() };
+ return chain;
+ }
+
+ /**
+ * Returns a test CertPath, which uses getCertChain() to obtain a list of
+ * certificates to store.
+ *
+ * @return test cert path
+ */
+ public static CertPath getCertPath() {
+ return new TestCertPath();
+ }
+
+ /**
+ * Generates and returns an instance of TestCertPath.<br>
+ * TestCertificate-s included in the CertPath will be uniq (will have
+ * different numbers passed to their ctor-s).<br>
+ * The second arguments shows which number will have the first Certificate
+ * in the CertPath. The second certificate will have (startID+1) number
+ * and so on.
+ *
+ * @param howMany - shows how many TestCerts must contain the CertPath generated
+ * @param startID - specifies the starting ID which the first certificate will have
+ * @return TestCertPath
+ */
+ public static CertPath genCertPath(int howMany, int startID) {
+ Certificate[] certs = new Certificate[howMany];
+ for (int i = 0; i < howMany; i++) {
+ certs[i] = new TestCertificate(Integer.toString(startID + i));
+ }
+ return new TestCertPath(certs);
+ }
+
+ private static Provider provider = null;
+
+ private static final String providerName = "TstPrvdr";
+
+ /**
+ * A Principal used to form rootCA's certificate
+ */
+ public static final X500Principal rootPrincipal = new X500Principal(
+ UniGen.rootName);
+
+ /**
+ * Some fake rootCA's certificate.
+ */
+ public static final X509Certificate rootCA = new TestX509Certificate(
+ rootPrincipal, rootPrincipal);
+
+ public static void install_test_x509_factory() {
+ if (provider == null) {
+ provider = new TestProvider(providerName, 0.01,
+ "Test provider for serialization testing");
+ Security.insertProviderAt(provider, 1);
+ }
+ }
+
+ public static void uninstall_test_x509_factory() {
+ if (provider != null) {
+ Security.removeProvider(providerName);
+ provider = null;
+ }
+ }
+
+ /**
+ * The class represents test certificate path.
+ *
+ */
+
+ public static final class TestCertPath extends CertPath implements
+ Serializable {
+
+ private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+ private static final String serializedData = "Just a dummy string to be serialized instead of real data";
+
+ private Certificate[] certs;
+
+ /**
+ * Default ctor for TestCertPath. Uses {@link TestCertUtils#getCertChain()}
+ * to obtain list of certificates.<br>
+ * All TestCertPath-s constructed via this ctor will be equals() to each
+ * other.
+ */
+ public TestCertPath() {
+ super("testCertPath");
+ certs = getCertChain();
+ }
+
+ /**
+ * Constructs TestCertPath and keeps the given array of certificates.<br>
+ * The TestCertPaths constructed via this ctor may be different (if they
+ * have different set of certificates)<br>
+ * @see TestCertUtils#genCertPath(int, int)
+ * @param certs
+ */
+ public TestCertPath(Certificate[] certs) {
+ super("testCertPath");
+ this.certs = certs;
+ }
+
+ /**
+ * @see java.security.cert.CertPath#getCertificates()
+ */
+ public List<Certificate> getCertificates() {
+ return Arrays.asList(certs);
+ }
+
+ /**
+ * @see java.security.cert.CertPath#getEncoded()
+ */
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return encoded.clone();
+ }
+
+ /**
+ * @see java.security.cert.CertPath#getEncoded(java.lang.String)
+ */
+ public byte[] getEncoded(String encoding)
+ throws CertificateEncodingException {
+ return encoded.clone();
+ }
+
+ /**
+ * @see java.security.cert.CertPath#getEncodings()
+ */
+ public Iterator<String> getEncodings() {
+ Vector<String> v = new Vector<String>();
+ v.add("myTestEncoding");
+ return v.iterator();
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer(200);
+ buf.append("TestCertPath. certs count=");
+ if( certs == null ) {
+ buf.append("0\n");
+ }
+ else {
+ buf.append(certs.length).append("\n");
+ for( int i=0; i<certs.length; i++) {
+ buf.append("\t").append(i).append(" ");
+ buf.append(certs[i]).append("\n");
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Writes<br>
+ * (String) serializedData<br>
+ * (int) number of certificates in this CertPath<br>
+ * <array of certificates>
+ *
+ * @param out
+ * @throws IOException
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.writeUTF(serializedData);
+ if (certs == null) {
+ out.writeInt(0);
+ } else {
+ out.writeInt(certs.length);
+ for (int i = 0; i < certs.length; i++) {
+ out.writeObject(certs[i]);
+ }
+ }
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException,
+ ClassNotFoundException {
+ String s = in.readUTF();
+ if (!serializedData.equals(s)) {
+ throw new StreamCorruptedException("expect [" + serializedData
+ + "] got [" + s + "]");
+ }
+ int count = in.readInt();
+ certs = new Certificate[count];
+ for (int i = 0; i < count; i++) {
+ certs[i] = (Certificate) in.readObject();
+ }
+ }
+
+ protected Object writeReplace() {
+ return this;
+ }
+
+ protected Object readResolve() {
+ return this;
+ }
+ }
+
+ /**
+ * The class represents empty PublicKey.
+ *
+ */
+
+ public static final class TestPublicKey implements PublicKey {
+ private static final String algo = "testPublicKeyAlgorithm";
+
+ private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+ private static final String format = "testPublicKeyFormat";
+
+ public String getAlgorithm() {
+ return algo;
+ }
+
+ public byte[] getEncoded() {
+ return encoded.clone();
+ }
+
+ public String getFormat() {
+ return format;
+ }
+ }
+
+ /**
+ * The class represents test certificate.
+ *
+ */
+
+ public static class TestCertificate extends Certificate implements
+ Serializable {
+
+ private static final byte[] encoded = new byte[] { 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF };
+
+ public static final String TYPE = "Test";
+
+ //
+ // A String that makes different TestCertificates to be different.
+ //
+ private String diff = null;
+
+ /**
+ * Default ctor. All the TestCertificate-s created with this ctor are equals() to each other.
+ * Use TestCertificate(String) if you need non equal TestCertificate-s.
+ */
+ public TestCertificate() {
+ super(TYPE);
+ }
+
+ /**
+ * A special purpose ctor. Pass different String-s to have different TestCertificates.
+ * TestCertificate-s with the same String passed to this ctor are considered equal.
+ */
+ public TestCertificate(String diff) {
+ super(TYPE);
+ this.diff = diff;
+ }
+
+ /**
+ * A ctor that allows to specify both the TYPE of certificate and the
+ * diff. Leave the <code>diff</code> null when no difference needed.
+ *
+ * @param diff
+ * @param type
+ */
+ public TestCertificate(String diff, String type) {
+ super(type);
+ this.diff = diff;
+ }
+
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return encoded.clone();
+ }
+
+ public void verify(PublicKey key) throws CertificateException,
+ NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+ // do nothing
+ }
+
+ public void verify(PublicKey key, String sigProvider)
+ throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException,
+ SignatureException {
+ // do nothing
+
+ }
+
+ public String toString() {
+ return "Test certificate - for unit testing only";
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == null || !(obj instanceof TestCertificate)) {
+ return false;
+ }
+ TestCertificate that = (TestCertificate) obj;
+ if (this == that) {
+ return true;
+ }
+ if (this.diff == null) {
+ return that.diff == null;
+ }
+ return this.diff.equals(that.diff);
+ }
+
+ public PublicKey getPublicKey() {
+ return new TestPublicKey();
+ }
+
+ /**
+ * Writes:<br>
+ * boolean - true if this certificate has a diff string,
+ * false otherwise, followed by <br>
+ * writeUTF() of string (if presented)
+ *
+ * @param out
+ * @throws IOException
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ if (diff == null) {
+ out.writeBoolean(false);
+ } else {
+ out.writeBoolean(false);
+ out.writeUTF(diff);
+ }
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException,
+ ClassNotFoundException {
+ boolean hasDiffString = in.readBoolean();
+ if (hasDiffString) {
+ diff = in.readUTF();
+ }
+ }
+
+ protected Object writeReplace() {
+ return this;
+ }
+
+ protected Object readResolve() {
+ return this;
+ }
+ }
+
+ public static class TestInvalidX509Certificate extends TestX509Certificate {
+ public TestInvalidX509Certificate(X500Principal subj,
+ X500Principal issuer) {
+ super(subj, issuer);
+ }
+ }
+
+ /**
+ *
+ * TestX509CErtificate.<br>
+ * Does nothing interesting, but<br>
+ * a) is not abstract, so it can be instantiated<br>
+ * b) returns Encoded form<br>
+ *
+ */
+ public static class TestX509Certificate extends X509Certificate {
+ private X500Principal subject;
+
+ private X500Principal issuer;
+
+ public TestX509Certificate(X500Principal subj, X500Principal issuer) {
+ this.subject = subj;
+ this.issuer = issuer;
+ }
+
+ public X500Principal getIssuerX500Principal() {
+ return issuer;
+ }
+
+ public X500Principal getSubjectX500Principal() {
+ return subject;
+ }
+
+ /**
+ * The encoded for of this X509Certificate is a byte array where
+ * first are bytes of encoded form of Subject (as X500Principal),
+ * followed by one zero byte
+ * and followed by the encoded form of Issuer (as X500Principal)
+ *
+ */
+ public byte[] getEncoded() throws CertificateEncodingException {
+ byte[] asubj = subject.getEncoded();
+ byte[] aissuer = issuer.getEncoded();
+ byte[] data = new byte[asubj.length + aissuer.length + 1];
+
+ System.arraycopy(asubj, 0, data, 0, asubj.length);
+ //data[asubj.length] = 0;
+ System
+ .arraycopy(aissuer, 0, data, asubj.length + 1,
+ aissuer.length);
+ return data;
+ }
+
+ public void checkValidity() throws CertificateExpiredException,
+ CertificateNotYetValidException {
+ }
+
+ public void checkValidity(Date date)
+ throws CertificateExpiredException,
+ CertificateNotYetValidException {
+ }
+
+ public int getBasicConstraints() {
+ return 0;
+ }
+
+ public Principal getIssuerDN() {
+ return null;
+ }
+
+ public boolean[] getIssuerUniqueID() {
+ return null;
+ }
+
+ public boolean[] getKeyUsage() {
+ return null;
+ }
+
+ public Date getNotAfter() {
+ return null;
+ }
+
+ public Date getNotBefore() {
+ return null;
+ }
+
+ public BigInteger getSerialNumber() {
+ return null;
+ }
+
+ public String getSigAlgName() {
+ return null;
+ }
+
+ public String getSigAlgOID() {
+ return null;
+ }
+
+ public byte[] getSigAlgParams() {
+ return null;
+ }
+
+ public byte[] getSignature() {
+ return null;
+ }
+
+ public Principal getSubjectDN() {
+ return null;
+ }
+
+ public boolean[] getSubjectUniqueID() {
+ return null;
+ }
+
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+ return null;
+ }
+
+ public int getVersion() {
+ return 0;
+ }
+
+ public Set getCriticalExtensionOIDs() {
+ return null;
+ }
+
+ public byte[] getExtensionValue(String oid) {
+ return null;
+ }
+
+ public Set getNonCriticalExtensionOIDs() {
+ return null;
+ }
+
+ public boolean hasUnsupportedCriticalExtension() {
+ return false;
+ }
+
+ public PublicKey getPublicKey() {
+ return null;
+ }
+
+ public String toString() {
+ return null;
+ }
+
+ public void verify(PublicKey key, String sigProvider)
+ throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException,
+ SignatureException {
+
+ }
+
+ public void verify(PublicKey key) throws CertificateException,
+ NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+
+ }
+ }
+
+ /**
+ * TestProvider. Does nothing, but pretends to
+ * implement X.509 CertificateFactory.
+ */
+ public static class TestProvider extends Provider {
+
+ private Provider.Service serv;
+
+ public TestProvider(String name, double version, String info) {
+ super(name, version, info);
+ serv = new Provider.Service(this, "CertificateFactory", "X.509",
+ TestFactorySpi.class.getName(), new ArrayList<String>(), null);
+ }
+
+ public synchronized Set<Provider.Service> getServices() {
+ HashSet<Provider.Service> s = new HashSet<Service>();
+ s.add(serv);
+ return s;
+ }
+ }
+
+ /**
+ * Some kind of Certificate Factory, used during unit testing.
+ *
+ *
+ */
+ public static class TestFactorySpi extends CertificateFactorySpi {
+
+ /**
+ * Tries to create an instance of TestX509Certificate, basing
+ * on the presumption that its {@link TestX509Certificate#getEncoded()
+ * encoded} form is stored.<br>
+ * @throws CertificateException is the presumption is not met or if
+ * any IO problem occurs.
+ */
+ public Certificate engineGenerateCertificate(InputStream is)
+ throws CertificateException {
+ byte[] data = new byte[0];
+ byte[] chunk = new byte[1024];
+ int len;
+ try {
+ while ((len = is.read(chunk)) > 0) {
+ byte[] tmp = new byte[data.length + len];
+ System.arraycopy(data, 0, tmp, 0, data.length);
+ System.arraycopy(chunk, 0, tmp, data.length, len);
+ data = tmp;
+ }
+ } catch (IOException ex) {
+ throw new CertificateException("IO problem", ex);
+ }
+ int pos = Arrays.binarySearch(data, (byte) 0);
+ if (pos < 0) {
+ throw new CertificateException("invalid format");
+ }
+ byte[] subjNameData = new byte[pos];
+ System.arraycopy(data, 0, subjNameData, 0, subjNameData.length);
+ byte[] issNameData = new byte[data.length - pos - 1];
+ System.arraycopy(data, pos + 1, issNameData, 0, issNameData.length);
+ X500Principal subjName = new X500Principal(subjNameData);
+ X500Principal issName = new X500Principal(issNameData);
+ return new TestX509Certificate(subjName, issName);
+ }
+
+ /**
+ * Not supported yet.
+ * @throws UnsupportedOperationException
+ */
+ public Collection engineGenerateCertificates(InputStream inStream)
+ throws CertificateException {
+ throw new UnsupportedOperationException("not yet.");
+ }
+
+ /**
+ * Not supported yet.
+ * @throws UnsupportedOperationException
+ */
+ public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
+ throw new UnsupportedOperationException("not yet.");
+ }
+
+ /**
+ * Not supported yet.
+ * @throws UnsupportedOperationException
+ */
+ public Collection engineGenerateCRLs(InputStream inStream)
+ throws CRLException {
+ throw new UnsupportedOperationException("not yet.");
+ }
+
+ /**
+ * Returns an instance of TestCertPath.<br>
+ * @throws CertificateException if
+ * a) any of Certificates passed is not an instance of X509Certificate
+ * b) any of Certificates passed is an instance of TestInvalidX509Certificate
+ */
+ public CertPath engineGenerateCertPath(List certs)
+ throws CertificateException {
+ ArrayList<Certificate> validCerts = new ArrayList<Certificate>();
+ for (Iterator i = certs.iterator(); i.hasNext();) {
+ Certificate c = (Certificate) i.next();
+ if (!(c instanceof X509Certificate)) {
+ throw new CertificateException("Not X509: " + c);
+ }
+ if (c instanceof TestInvalidX509Certificate) {
+ throw new CertificateException("Invalid (test) X509: " + c);
+ }
+ validCerts.add(c);
+ }
+ Certificate[] acerts = new Certificate[validCerts.size()];
+ validCerts.toArray(acerts);
+ return new TestCertPath(acerts);
+ }
+ }
+
+ /**
+ * Utility class used to generate some amount of uniq names.
+ */
+ public static class UniGen {
+ public static final String rootName = "CN=Alex Astapchuk, OU=SSG, O=Intel ZAO, C=RU";
+
+ private static final String datasNames[] = { "CN", "OU", "O", "C" };
+
+ private static final String datas[][] = {
+ // Names database
+ { "Alex Astapchuk", null, null, null },
+ { "John Doe", null, null, null },
+ // 'organisation unit'-s
+ { null, "SSG", null, null }, { null, "SSG/DRL", null, null },
+ // organizations
+ { null, null, "Intel ZAO", null },
+ { null, null, "Intel Inc", null },
+ // countries
+ { null, null, null, "RU" }, { null, null, null, "US" },
+ { null, null, null, "GB" }, { null, null, null, "JA" },
+ { null, null, null, "KO" }, { null, null, null, "TW" }, };
+
+ //
+ // Returns a string from <code>data</code> from a given column and
+ // position. The positions are looked for first non-null entry. If there
+ // are no non empty items left, then it scans column starting from the
+ // beginning.
+ //
+ // @param col
+ // @param startRow
+ // @return
+ //
+ private static String getData(int col, int startRow) {
+ startRow = startRow % datas.length;
+ for (int i = startRow; i < datas.length; i++) {
+ if (datas[i][col] != null) {
+ return datas[i][col];
+ }
+ }
+ // no non-null entries left, check from the beginning
+ for (int i = 0; i < datas.length; i++) {
+ if (datas[i][col] != null) {
+ return datas[i][col];
+ }
+ }
+ // can't be
+ throw new Error();
+ }
+
+ //
+ // Increments a num.<br>
+ // <code>num</code> is interpreted as a number with a base of
+ // <code>base</code> and each digit of this number is stored as a
+ // separate num's element.
+ //
+ // @param num
+ // @param base
+ // @return <b>true</b> if overflow happened
+ //
+ private static boolean inc(int[] num, int base) {
+ for (int i = 0; i < num.length; i++) {
+ if ((++num[i]) >= base) {
+ num[i] = 0;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Generates some amount of uniq names, none of which is equals to
+ * {@link #rootName}.
+ * @param howMany
+ * @return
+ */
+ public static String[] genNames(int howMany) {
+ int counts[] = new int[datasNames.length];
+ ArrayList<String> al = new ArrayList<String>();
+
+ // not really the thrifty algorithm...
+ for (int i = 0; i < howMany;) {
+
+ // System.out.print("#"+i+": ");
+ // for( int j=0; j<counts.length; j++) {
+ // System.out.print(""+counts[j]+"|");
+ // }
+ // System.out.println();
+
+ StringBuffer buf = new StringBuffer();
+ int j = 0;
+ for (; j < datasNames.length - 1; j++) {
+ String name = datasNames[j];
+ String val = getData(j, counts[j]);
+ buf.append(name).append('=').append(val).append(",");
+ }
+ String name = datasNames[j];
+ String val = getData(j, counts[j]);
+ buf.append(name).append('=').append(val);
+
+ name = buf.toString();
+
+ if (!(rootName.equals(name) || al.contains(name))) {
+ ++i;
+ al.add(name);
+ // System.out.println("generated: "+name);
+ } else {
+ // System.out.println("rejected: "+name);
+ }
+
+ if (inc(counts, datas.length)) {
+ // if this happened, then just add some data into 'datas'
+ throw new Error(
+ "cant generate so many uniq names. sorry. add some more data.");
+ }
+ }
+ return (String[]) al.toArray(new String[al.size()]);
+ }
+
+ /**
+ * Generates some amount of uniq X500Principals, none of which is equals
+ * has a string equals to {@link #rootName}.
+ * @param howMany
+ * @return
+ */
+ public static X500Principal[] genX500s(int howMany) {
+ String names[] = genNames(howMany);
+ X500Principal[] ps = new X500Principal[howMany];
+ for (int i = 0; i < howMany; i++) {
+ ps[i] = new X500Principal(names[i]);
+ }
+ return ps;
+ }
+
+ }
+
+}
+
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/TestKeyPair.java b/support/src/test/java/org/apache/harmony/security/tests/support/TestKeyPair.java
new file mode 100644
index 0000000..ca84dc6
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/TestKeyPair.java
@@ -0,0 +1,602 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.HashMap;
+
+/**
+ * Generates key pairs based on their encodings for some algorithms.
+ * Encodings generated using
+ * BEA JRockit j2sdk1.4.2_04 (http://www.bea.com)
+ */
+public class TestKeyPair {
+ private static final HashMap<String, byte []> privateKeyEncoding = new HashMap<String, byte[]>();
+ private static final HashMap<String, byte []> publicKeyEncoding = new HashMap<String, byte[]>();
+ private final String algorithmName;
+ private final KeyFactory kf;
+ static {
+ privateKeyEncoding.put("RSA", new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x02, (byte)0x77,
+ (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30,
+ (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a,
+ (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7,
+ (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01,
+ (byte)0x05, (byte)0x00, (byte)0x04, (byte)0x82,
+ (byte)0x02, (byte)0x61, (byte)0x30, (byte)0x82,
+ (byte)0x02, (byte)0x5d, (byte)0x02, (byte)0x01,
+ (byte)0x00, (byte)0x02, (byte)0x81, (byte)0x81,
+ (byte)0x00, (byte)0xb2, (byte)0x4a, (byte)0x9b,
+ (byte)0x5b, (byte)0xba, (byte)0x01, (byte)0xc0,
+ (byte)0xcd, (byte)0x65, (byte)0x09, (byte)0x63,
+ (byte)0x70, (byte)0x0b, (byte)0x5a, (byte)0x1b,
+ (byte)0x92, (byte)0x08, (byte)0xf8, (byte)0x55,
+ (byte)0x5e, (byte)0x7c, (byte)0x1b, (byte)0x50,
+ (byte)0x17, (byte)0xec, (byte)0x44, (byte)0x4c,
+ (byte)0x58, (byte)0x42, (byte)0x2b, (byte)0x41,
+ (byte)0x09, (byte)0x59, (byte)0xf2, (byte)0xe1,
+ (byte)0x5d, (byte)0x43, (byte)0x71, (byte)0x4d,
+ (byte)0x92, (byte)0x03, (byte)0x1d, (byte)0xb6,
+ (byte)0x6c, (byte)0x7f, (byte)0x5d, (byte)0x48,
+ (byte)0xcd, (byte)0x17, (byte)0xec, (byte)0xd7,
+ (byte)0x4c, (byte)0x39, (byte)0xb1, (byte)0x7b,
+ (byte)0xe2, (byte)0xbf, (byte)0x96, (byte)0x77,
+ (byte)0xbe, (byte)0xd0, (byte)0xa0, (byte)0xf0,
+ (byte)0x2d, (byte)0x6b, (byte)0x24, (byte)0xaa,
+ (byte)0x14, (byte)0xba, (byte)0x82, (byte)0x79,
+ (byte)0x10, (byte)0x9b, (byte)0x16, (byte)0x68,
+ (byte)0x47, (byte)0x81, (byte)0x54, (byte)0xa2,
+ (byte)0xfa, (byte)0x91, (byte)0x9e, (byte)0x0a,
+ (byte)0x2a, (byte)0x53, (byte)0xa6, (byte)0xe7,
+ (byte)0x9e, (byte)0x7d, (byte)0x29, (byte)0x33,
+ (byte)0xd8, (byte)0x05, (byte)0xfc, (byte)0x02,
+ (byte)0x3f, (byte)0xbd, (byte)0xc7, (byte)0x6e,
+ (byte)0xed, (byte)0xaa, (byte)0x30, (byte)0x6c,
+ (byte)0x5f, (byte)0x52, (byte)0xed, (byte)0x35,
+ (byte)0x65, (byte)0x4b, (byte)0x0e, (byte)0xc8,
+ (byte)0xa7, (byte)0x12, (byte)0x10, (byte)0x56,
+ (byte)0x37, (byte)0xaf, (byte)0x11, (byte)0xfa,
+ (byte)0x21, (byte)0x0e, (byte)0x99, (byte)0xff,
+ (byte)0xfa, (byte)0x8c, (byte)0x65, (byte)0x8e,
+ (byte)0x6d, (byte)0x02, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x81,
+ (byte)0x80, (byte)0x78, (byte)0x41, (byte)0x72,
+ (byte)0x40, (byte)0x90, (byte)0x59, (byte)0x96,
+ (byte)0x5d, (byte)0xf3, (byte)0x84, (byte)0x3d,
+ (byte)0x99, (byte)0xd9, (byte)0x4e, (byte)0x51,
+ (byte)0xc2, (byte)0x52, (byte)0x62, (byte)0x8d,
+ (byte)0xd2, (byte)0x49, (byte)0x0b, (byte)0x73,
+ (byte)0x1e, (byte)0x6f, (byte)0xb2, (byte)0x31,
+ (byte)0x7c, (byte)0x66, (byte)0x45, (byte)0x1e,
+ (byte)0x7c, (byte)0xdc, (byte)0x3a, (byte)0xc2,
+ (byte)0x5f, (byte)0x51, (byte)0x9a, (byte)0x1e,
+ (byte)0xa4, (byte)0x19, (byte)0x8d, (byte)0xf4,
+ (byte)0xf9, (byte)0x81, (byte)0x7e, (byte)0xbe,
+ (byte)0x17, (byte)0xf7, (byte)0xc7, (byte)0x3c,
+ (byte)0x00, (byte)0xa1, (byte)0xf9, (byte)0x60,
+ (byte)0x82, (byte)0x34, (byte)0x8f, (byte)0x9c,
+ (byte)0xfd, (byte)0x0b, (byte)0x63, (byte)0x42,
+ (byte)0x1b, (byte)0x7f, (byte)0x45, (byte)0xf1,
+ (byte)0x31, (byte)0xc3, (byte)0x63, (byte)0x47,
+ (byte)0x5c, (byte)0xc1, (byte)0xb2, (byte)0x5f,
+ (byte)0x57, (byte)0xee, (byte)0x02, (byte)0x9f,
+ (byte)0x5e, (byte)0x08, (byte)0x48, (byte)0xba,
+ (byte)0x74, (byte)0xba, (byte)0x81, (byte)0xb7,
+ (byte)0x30, (byte)0xac, (byte)0x4c, (byte)0x01,
+ (byte)0x35, (byte)0xce, (byte)0x46, (byte)0x47,
+ (byte)0x8c, (byte)0xe4, (byte)0x62, (byte)0x36,
+ (byte)0x1a, (byte)0x65, (byte)0x0e, (byte)0x33,
+ (byte)0x56, (byte)0xf9, (byte)0xb7, (byte)0xa0,
+ (byte)0xc4, (byte)0xb6, (byte)0x82, (byte)0x55,
+ (byte)0x7d, (byte)0x36, (byte)0x55, (byte)0xc0,
+ (byte)0x52, (byte)0x5e, (byte)0x35, (byte)0x54,
+ (byte)0xbd, (byte)0x97, (byte)0x01, (byte)0x00,
+ (byte)0xbf, (byte)0x10, (byte)0xdc, (byte)0x1b,
+ (byte)0x51, (byte)0x02, (byte)0x41, (byte)0x00,
+ (byte)0xe7, (byte)0x68, (byte)0x03, (byte)0x3e,
+ (byte)0x21, (byte)0x64, (byte)0x68, (byte)0x24,
+ (byte)0x7b, (byte)0xd0, (byte)0x31, (byte)0xa0,
+ (byte)0xa2, (byte)0xd9, (byte)0x87, (byte)0x6d,
+ (byte)0x79, (byte)0x81, (byte)0x8f, (byte)0x8f,
+ (byte)0x2d, (byte)0x7a, (byte)0x95, (byte)0x2e,
+ (byte)0x55, (byte)0x9f, (byte)0xd7, (byte)0x86,
+ (byte)0x29, (byte)0x93, (byte)0xbd, (byte)0x04,
+ (byte)0x7e, (byte)0x4f, (byte)0xdb, (byte)0x56,
+ (byte)0xf1, (byte)0x75, (byte)0xd0, (byte)0x4b,
+ (byte)0x00, (byte)0x3a, (byte)0xe0, (byte)0x26,
+ (byte)0xf6, (byte)0xab, (byte)0x9e, (byte)0x0b,
+ (byte)0x2a, (byte)0xf4, (byte)0xa8, (byte)0xd7,
+ (byte)0xff, (byte)0xbe, (byte)0x01, (byte)0xeb,
+ (byte)0x9b, (byte)0x81, (byte)0xc7, (byte)0x5f,
+ (byte)0x02, (byte)0x73, (byte)0xe1, (byte)0x2b,
+ (byte)0x02, (byte)0x41, (byte)0x00, (byte)0xc5,
+ (byte)0x3d, (byte)0x78, (byte)0xab, (byte)0xe6,
+ (byte)0xab, (byte)0x3e, (byte)0x29, (byte)0xfd,
+ (byte)0x98, (byte)0xd0, (byte)0xa4, (byte)0x3e,
+ (byte)0x58, (byte)0xee, (byte)0x48, (byte)0x45,
+ (byte)0xa3, (byte)0x66, (byte)0xac, (byte)0xe9,
+ (byte)0x4d, (byte)0xbd, (byte)0x60, (byte)0xea,
+ (byte)0x24, (byte)0xff, (byte)0xed, (byte)0x0c,
+ (byte)0x67, (byte)0xc5, (byte)0xfd, (byte)0x36,
+ (byte)0x28, (byte)0xea, (byte)0x74, (byte)0x88,
+ (byte)0xd1, (byte)0xd1, (byte)0xad, (byte)0x58,
+ (byte)0xd7, (byte)0xf0, (byte)0x67, (byte)0x20,
+ (byte)0xc1, (byte)0xe3, (byte)0xb3, (byte)0xdb,
+ (byte)0x52, (byte)0xad, (byte)0xf3, (byte)0xc4,
+ (byte)0x21, (byte)0xd8, (byte)0x8c, (byte)0x4c,
+ (byte)0x41, (byte)0x27, (byte)0xdb, (byte)0xd0,
+ (byte)0x35, (byte)0x92, (byte)0xc7, (byte)0x02,
+ (byte)0x41, (byte)0x00, (byte)0xe0, (byte)0x99,
+ (byte)0x42, (byte)0xb4, (byte)0x76, (byte)0x02,
+ (byte)0x97, (byte)0x55, (byte)0xf9, (byte)0xda,
+ (byte)0x3b, (byte)0xa0, (byte)0xd7, (byte)0x0e,
+ (byte)0xdc, (byte)0xf4, (byte)0x33, (byte)0x7f,
+ (byte)0xbd, (byte)0xcf, (byte)0xd0, (byte)0xeb,
+ (byte)0x6e, (byte)0x89, (byte)0xf7, (byte)0x4f,
+ (byte)0x5a, (byte)0x07, (byte)0x7c, (byte)0xa9,
+ (byte)0x49, (byte)0x47, (byte)0x68, (byte)0x35,
+ (byte)0xa8, (byte)0x05, (byte)0x3d, (byte)0xfd,
+ (byte)0x04, (byte)0x7b, (byte)0x17, (byte)0x31,
+ (byte)0x0d, (byte)0xc8, (byte)0xa3, (byte)0x98,
+ (byte)0x34, (byte)0xa0, (byte)0x50, (byte)0x44,
+ (byte)0x00, (byte)0xf1, (byte)0x0c, (byte)0xe6,
+ (byte)0xe5, (byte)0xc4, (byte)0x41, (byte)0x3d,
+ (byte)0xf8, (byte)0x3d, (byte)0x4e, (byte)0x0b,
+ (byte)0x1c, (byte)0xdb, (byte)0x02, (byte)0x41,
+ (byte)0x00, (byte)0x82, (byte)0x9b, (byte)0x8a,
+ (byte)0xfd, (byte)0xa1, (byte)0x98, (byte)0x41,
+ (byte)0x68, (byte)0xc2, (byte)0xd1, (byte)0xdf,
+ (byte)0x4e, (byte)0xf3, (byte)0x2e, (byte)0x26,
+ (byte)0x53, (byte)0x5b, (byte)0x31, (byte)0xb1,
+ (byte)0x7a, (byte)0xcc, (byte)0x5e, (byte)0xbb,
+ (byte)0x09, (byte)0xa2, (byte)0xe2, (byte)0x6f,
+ (byte)0x4a, (byte)0x04, (byte)0x0d, (byte)0xef,
+ (byte)0x90, (byte)0x15, (byte)0xbe, (byte)0x10,
+ (byte)0x4a, (byte)0xac, (byte)0x92, (byte)0xeb,
+ (byte)0xda, (byte)0x72, (byte)0xdb, (byte)0x43,
+ (byte)0x08, (byte)0xb7, (byte)0x2b, (byte)0x4c,
+ (byte)0xe1, (byte)0xbb, (byte)0x58, (byte)0xcb,
+ (byte)0x71, (byte)0x80, (byte)0xad, (byte)0xbc,
+ (byte)0xdc, (byte)0x62, (byte)0x5e, (byte)0x3e,
+ (byte)0xcb, (byte)0x92, (byte)0xda, (byte)0xf6,
+ (byte)0xdf, (byte)0x02, (byte)0x40, (byte)0x4d,
+ (byte)0x81, (byte)0x90, (byte)0xc5, (byte)0x77,
+ (byte)0x30, (byte)0xb7, (byte)0x29, (byte)0x00,
+ (byte)0xa8, (byte)0xf1, (byte)0xb4, (byte)0xae,
+ (byte)0x52, (byte)0x63, (byte)0x00, (byte)0xb2,
+ (byte)0x2d, (byte)0x3e, (byte)0x7d, (byte)0xd6,
+ (byte)0x4d, (byte)0xf9, (byte)0x8a, (byte)0xc1,
+ (byte)0xb1, (byte)0x98, (byte)0x89, (byte)0x52,
+ (byte)0x40, (byte)0x14, (byte)0x1b, (byte)0x0e,
+ (byte)0x61, (byte)0x8f, (byte)0xf4, (byte)0xbe,
+ (byte)0x59, (byte)0x79, (byte)0x79, (byte)0x95,
+ (byte)0x19, (byte)0x5c, (byte)0x51, (byte)0x08,
+ (byte)0x66, (byte)0xc1, (byte)0x42, (byte)0x30,
+ (byte)0xb3, (byte)0x7a, (byte)0x86, (byte)0x9f,
+ (byte)0x3e, (byte)0xf5, (byte)0x19, (byte)0xa3,
+ (byte)0xae, (byte)0x64, (byte)0x69, (byte)0x14,
+ (byte)0x07, (byte)0x50, (byte)0x97
+ });
+ publicKeyEncoding.put("RSA", new byte[] {
+ (byte)0x30, (byte)0x81, (byte)0x9f, (byte)0x30,
+ (byte)0x0d, (byte)0x06, (byte)0x09, (byte)0x2a,
+ (byte)0x86, (byte)0x48, (byte)0x86, (byte)0xf7,
+ (byte)0x0d, (byte)0x01, (byte)0x01, (byte)0x01,
+ (byte)0x05, (byte)0x00, (byte)0x03, (byte)0x81,
+ (byte)0x8d, (byte)0x00, (byte)0x30, (byte)0x81,
+ (byte)0x89, (byte)0x02, (byte)0x81, (byte)0x81,
+ (byte)0x00, (byte)0xb2, (byte)0x4a, (byte)0x9b,
+ (byte)0x5b, (byte)0xba, (byte)0x01, (byte)0xc0,
+ (byte)0xcd, (byte)0x65, (byte)0x09, (byte)0x63,
+ (byte)0x70, (byte)0x0b, (byte)0x5a, (byte)0x1b,
+ (byte)0x92, (byte)0x08, (byte)0xf8, (byte)0x55,
+ (byte)0x5e, (byte)0x7c, (byte)0x1b, (byte)0x50,
+ (byte)0x17, (byte)0xec, (byte)0x44, (byte)0x4c,
+ (byte)0x58, (byte)0x42, (byte)0x2b, (byte)0x41,
+ (byte)0x09, (byte)0x59, (byte)0xf2, (byte)0xe1,
+ (byte)0x5d, (byte)0x43, (byte)0x71, (byte)0x4d,
+ (byte)0x92, (byte)0x03, (byte)0x1d, (byte)0xb6,
+ (byte)0x6c, (byte)0x7f, (byte)0x5d, (byte)0x48,
+ (byte)0xcd, (byte)0x17, (byte)0xec, (byte)0xd7,
+ (byte)0x4c, (byte)0x39, (byte)0xb1, (byte)0x7b,
+ (byte)0xe2, (byte)0xbf, (byte)0x96, (byte)0x77,
+ (byte)0xbe, (byte)0xd0, (byte)0xa0, (byte)0xf0,
+ (byte)0x2d, (byte)0x6b, (byte)0x24, (byte)0xaa,
+ (byte)0x14, (byte)0xba, (byte)0x82, (byte)0x79,
+ (byte)0x10, (byte)0x9b, (byte)0x16, (byte)0x68,
+ (byte)0x47, (byte)0x81, (byte)0x54, (byte)0xa2,
+ (byte)0xfa, (byte)0x91, (byte)0x9e, (byte)0x0a,
+ (byte)0x2a, (byte)0x53, (byte)0xa6, (byte)0xe7,
+ (byte)0x9e, (byte)0x7d, (byte)0x29, (byte)0x33,
+ (byte)0xd8, (byte)0x05, (byte)0xfc, (byte)0x02,
+ (byte)0x3f, (byte)0xbd, (byte)0xc7, (byte)0x6e,
+ (byte)0xed, (byte)0xaa, (byte)0x30, (byte)0x6c,
+ (byte)0x5f, (byte)0x52, (byte)0xed, (byte)0x35,
+ (byte)0x65, (byte)0x4b, (byte)0x0e, (byte)0xc8,
+ (byte)0xa7, (byte)0x12, (byte)0x10, (byte)0x56,
+ (byte)0x37, (byte)0xaf, (byte)0x11, (byte)0xfa,
+ (byte)0x21, (byte)0x0e, (byte)0x99, (byte)0xff,
+ (byte)0xfa, (byte)0x8c, (byte)0x65, (byte)0x8e,
+ (byte)0x6d, (byte)0x02, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x01
+ });
+ privateKeyEncoding.put("DSA", new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x4a,
+ (byte)0x02, (byte)0x01, (byte)0x00, (byte)0x30,
+ (byte)0x82, (byte)0x01, (byte)0x2b, (byte)0x06,
+ (byte)0x07, (byte)0x2a, (byte)0x86, (byte)0x48,
+ (byte)0xce, (byte)0x38, (byte)0x04, (byte)0x01,
+ (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x1e,
+ (byte)0x02, (byte)0x81, (byte)0x81, (byte)0x00,
+ (byte)0xca, (byte)0x84, (byte)0x1d, (byte)0xa3,
+ (byte)0xab, (byte)0xb9, (byte)0x98, (byte)0xf4,
+ (byte)0x61, (byte)0x8b, (byte)0x66, (byte)0xdb,
+ (byte)0x4e, (byte)0x3a, (byte)0xb2, (byte)0x11,
+ (byte)0x4e, (byte)0xa9, (byte)0xda, (byte)0x35,
+ (byte)0x91, (byte)0xc9, (byte)0x4e, (byte)0xc3,
+ (byte)0x16, (byte)0xa7, (byte)0xed, (byte)0xb8,
+ (byte)0x8f, (byte)0xd7, (byte)0xea, (byte)0xea,
+ (byte)0xdb, (byte)0x77, (byte)0xe1, (byte)0x77,
+ (byte)0x7a, (byte)0xc9, (byte)0xf3, (byte)0x37,
+ (byte)0x33, (byte)0x01, (byte)0x72, (byte)0xbc,
+ (byte)0xd0, (byte)0x89, (byte)0x9b, (byte)0x18,
+ (byte)0xfd, (byte)0x84, (byte)0xd6, (byte)0xe9,
+ (byte)0xbf, (byte)0x13, (byte)0x35, (byte)0x5e,
+ (byte)0x40, (byte)0xf6, (byte)0x9d, (byte)0xd9,
+ (byte)0x1a, (byte)0xba, (byte)0xa9, (byte)0xc3,
+ (byte)0x8c, (byte)0xe3, (byte)0x95, (byte)0xc8,
+ (byte)0xdf, (byte)0x2e, (byte)0x41, (byte)0xa1,
+ (byte)0xbf, (byte)0xde, (byte)0x5d, (byte)0xad,
+ (byte)0x21, (byte)0xcc, (byte)0x0d, (byte)0x42,
+ (byte)0x56, (byte)0xa0, (byte)0x32, (byte)0xc0,
+ (byte)0x90, (byte)0x73, (byte)0x3e, (byte)0xa4,
+ (byte)0x0e, (byte)0x58, (byte)0xe4, (byte)0x64,
+ (byte)0x00, (byte)0xa3, (byte)0x27, (byte)0x49,
+ (byte)0x56, (byte)0xb2, (byte)0x43, (byte)0xbc,
+ (byte)0x72, (byte)0xa8, (byte)0xd2, (byte)0x26,
+ (byte)0x89, (byte)0x35, (byte)0x37, (byte)0x29,
+ (byte)0x8d, (byte)0x21, (byte)0xb5, (byte)0x8e,
+ (byte)0x59, (byte)0xfa, (byte)0x9e, (byte)0xdf,
+ (byte)0x37, (byte)0x0d, (byte)0x9e, (byte)0xab,
+ (byte)0xfd, (byte)0xbf, (byte)0x1a, (byte)0x9e,
+ (byte)0xf3, (byte)0xe8, (byte)0x3a, (byte)0xfb,
+ (byte)0x02, (byte)0x15, (byte)0x00, (byte)0xa2,
+ (byte)0x4e, (byte)0x5d, (byte)0xe3, (byte)0x10,
+ (byte)0x5d, (byte)0xa9, (byte)0x3a, (byte)0x6a,
+ (byte)0x4d, (byte)0x07, (byte)0x3b, (byte)0xab,
+ (byte)0xca, (byte)0x7d, (byte)0x09, (byte)0xd6,
+ (byte)0x06, (byte)0x79, (byte)0x49, (byte)0x02,
+ (byte)0x81, (byte)0x80, (byte)0x5a, (byte)0x91,
+ (byte)0x83, (byte)0x1c, (byte)0x04, (byte)0x33,
+ (byte)0xca, (byte)0x25, (byte)0xb0, (byte)0x68,
+ (byte)0xb3, (byte)0xb3, (byte)0xab, (byte)0x55,
+ (byte)0x29, (byte)0x33, (byte)0x4d, (byte)0xa9,
+ (byte)0x33, (byte)0x39, (byte)0xef, (byte)0x71,
+ (byte)0xca, (byte)0x95, (byte)0xf3, (byte)0xd8,
+ (byte)0x27, (byte)0x56, (byte)0x5f, (byte)0x42,
+ (byte)0xda, (byte)0x36, (byte)0x83, (byte)0xc5,
+ (byte)0xf1, (byte)0x53, (byte)0x62, (byte)0xa5,
+ (byte)0xdc, (byte)0xe6, (byte)0x4e, (byte)0x69,
+ (byte)0x45, (byte)0x71, (byte)0x1a, (byte)0x4a,
+ (byte)0xc3, (byte)0xf4, (byte)0x7f, (byte)0x0a,
+ (byte)0xd1, (byte)0x78, (byte)0xed, (byte)0xbe,
+ (byte)0x6e, (byte)0xa6, (byte)0x36, (byte)0x34,
+ (byte)0x4e, (byte)0xc3, (byte)0x1b, (byte)0x17,
+ (byte)0xaa, (byte)0xa4, (byte)0x76, (byte)0x44,
+ (byte)0x46, (byte)0xaf, (byte)0x26, (byte)0x16,
+ (byte)0x14, (byte)0xfb, (byte)0x9f, (byte)0x5d,
+ (byte)0x08, (byte)0xaf, (byte)0x92, (byte)0xdb,
+ (byte)0xba, (byte)0xd0, (byte)0xcb, (byte)0x8b,
+ (byte)0x1e, (byte)0xc3, (byte)0x8b, (byte)0x36,
+ (byte)0x3b, (byte)0x4c, (byte)0x02, (byte)0xc3,
+ (byte)0x66, (byte)0x28, (byte)0x69, (byte)0xd0,
+ (byte)0x74, (byte)0x4f, (byte)0x1c, (byte)0x4f,
+ (byte)0x97, (byte)0x75, (byte)0x7f, (byte)0x9e,
+ (byte)0x89, (byte)0x80, (byte)0xcf, (byte)0xb2,
+ (byte)0x17, (byte)0xd6, (byte)0x66, (byte)0x91,
+ (byte)0x12, (byte)0x3a, (byte)0xb0, (byte)0x3c,
+ (byte)0x3c, (byte)0xc2, (byte)0x31, (byte)0xd1,
+ (byte)0x31, (byte)0x2a, (byte)0x35, (byte)0xbe,
+ (byte)0x9d, (byte)0x54, (byte)0x71, (byte)0x03,
+ (byte)0xcb, (byte)0xcc, (byte)0x04, (byte)0x16,
+ (byte)0x02, (byte)0x14, (byte)0x52, (byte)0xfb,
+ (byte)0xf9, (byte)0x12, (byte)0x40, (byte)0x05,
+ (byte)0x59, (byte)0x8f, (byte)0xde, (byte)0x9d,
+ (byte)0xac, (byte)0xa1, (byte)0xe2, (byte)0xed,
+ (byte)0x56, (byte)0x62, (byte)0x5f, (byte)0x56,
+ (byte)0x67, (byte)0x74
+ });
+ publicKeyEncoding.put("DSA", new byte[] {
+ (byte)0x30, (byte)0x82, (byte)0x01, (byte)0xb7,
+ (byte)0x30, (byte)0x82, (byte)0x01, (byte)0x2b,
+ (byte)0x06, (byte)0x07, (byte)0x2a, (byte)0x86,
+ (byte)0x48, (byte)0xce, (byte)0x38, (byte)0x04,
+ (byte)0x01, (byte)0x30, (byte)0x82, (byte)0x01,
+ (byte)0x1e, (byte)0x02, (byte)0x81, (byte)0x81,
+ (byte)0x00, (byte)0xca, (byte)0x84, (byte)0x1d,
+ (byte)0xa3, (byte)0xab, (byte)0xb9, (byte)0x98,
+ (byte)0xf4, (byte)0x61, (byte)0x8b, (byte)0x66,
+ (byte)0xdb, (byte)0x4e, (byte)0x3a, (byte)0xb2,
+ (byte)0x11, (byte)0x4e, (byte)0xa9, (byte)0xda,
+ (byte)0x35, (byte)0x91, (byte)0xc9, (byte)0x4e,
+ (byte)0xc3, (byte)0x16, (byte)0xa7, (byte)0xed,
+ (byte)0xb8, (byte)0x8f, (byte)0xd7, (byte)0xea,
+ (byte)0xea, (byte)0xdb, (byte)0x77, (byte)0xe1,
+ (byte)0x77, (byte)0x7a, (byte)0xc9, (byte)0xf3,
+ (byte)0x37, (byte)0x33, (byte)0x01, (byte)0x72,
+ (byte)0xbc, (byte)0xd0, (byte)0x89, (byte)0x9b,
+ (byte)0x18, (byte)0xfd, (byte)0x84, (byte)0xd6,
+ (byte)0xe9, (byte)0xbf, (byte)0x13, (byte)0x35,
+ (byte)0x5e, (byte)0x40, (byte)0xf6, (byte)0x9d,
+ (byte)0xd9, (byte)0x1a, (byte)0xba, (byte)0xa9,
+ (byte)0xc3, (byte)0x8c, (byte)0xe3, (byte)0x95,
+ (byte)0xc8, (byte)0xdf, (byte)0x2e, (byte)0x41,
+ (byte)0xa1, (byte)0xbf, (byte)0xde, (byte)0x5d,
+ (byte)0xad, (byte)0x21, (byte)0xcc, (byte)0x0d,
+ (byte)0x42, (byte)0x56, (byte)0xa0, (byte)0x32,
+ (byte)0xc0, (byte)0x90, (byte)0x73, (byte)0x3e,
+ (byte)0xa4, (byte)0x0e, (byte)0x58, (byte)0xe4,
+ (byte)0x64, (byte)0x00, (byte)0xa3, (byte)0x27,
+ (byte)0x49, (byte)0x56, (byte)0xb2, (byte)0x43,
+ (byte)0xbc, (byte)0x72, (byte)0xa8, (byte)0xd2,
+ (byte)0x26, (byte)0x89, (byte)0x35, (byte)0x37,
+ (byte)0x29, (byte)0x8d, (byte)0x21, (byte)0xb5,
+ (byte)0x8e, (byte)0x59, (byte)0xfa, (byte)0x9e,
+ (byte)0xdf, (byte)0x37, (byte)0x0d, (byte)0x9e,
+ (byte)0xab, (byte)0xfd, (byte)0xbf, (byte)0x1a,
+ (byte)0x9e, (byte)0xf3, (byte)0xe8, (byte)0x3a,
+ (byte)0xfb, (byte)0x02, (byte)0x15, (byte)0x00,
+ (byte)0xa2, (byte)0x4e, (byte)0x5d, (byte)0xe3,
+ (byte)0x10, (byte)0x5d, (byte)0xa9, (byte)0x3a,
+ (byte)0x6a, (byte)0x4d, (byte)0x07, (byte)0x3b,
+ (byte)0xab, (byte)0xca, (byte)0x7d, (byte)0x09,
+ (byte)0xd6, (byte)0x06, (byte)0x79, (byte)0x49,
+ (byte)0x02, (byte)0x81, (byte)0x80, (byte)0x5a,
+ (byte)0x91, (byte)0x83, (byte)0x1c, (byte)0x04,
+ (byte)0x33, (byte)0xca, (byte)0x25, (byte)0xb0,
+ (byte)0x68, (byte)0xb3, (byte)0xb3, (byte)0xab,
+ (byte)0x55, (byte)0x29, (byte)0x33, (byte)0x4d,
+ (byte)0xa9, (byte)0x33, (byte)0x39, (byte)0xef,
+ (byte)0x71, (byte)0xca, (byte)0x95, (byte)0xf3,
+ (byte)0xd8, (byte)0x27, (byte)0x56, (byte)0x5f,
+ (byte)0x42, (byte)0xda, (byte)0x36, (byte)0x83,
+ (byte)0xc5, (byte)0xf1, (byte)0x53, (byte)0x62,
+ (byte)0xa5, (byte)0xdc, (byte)0xe6, (byte)0x4e,
+ (byte)0x69, (byte)0x45, (byte)0x71, (byte)0x1a,
+ (byte)0x4a, (byte)0xc3, (byte)0xf4, (byte)0x7f,
+ (byte)0x0a, (byte)0xd1, (byte)0x78, (byte)0xed,
+ (byte)0xbe, (byte)0x6e, (byte)0xa6, (byte)0x36,
+ (byte)0x34, (byte)0x4e, (byte)0xc3, (byte)0x1b,
+ (byte)0x17, (byte)0xaa, (byte)0xa4, (byte)0x76,
+ (byte)0x44, (byte)0x46, (byte)0xaf, (byte)0x26,
+ (byte)0x16, (byte)0x14, (byte)0xfb, (byte)0x9f,
+ (byte)0x5d, (byte)0x08, (byte)0xaf, (byte)0x92,
+ (byte)0xdb, (byte)0xba, (byte)0xd0, (byte)0xcb,
+ (byte)0x8b, (byte)0x1e, (byte)0xc3, (byte)0x8b,
+ (byte)0x36, (byte)0x3b, (byte)0x4c, (byte)0x02,
+ (byte)0xc3, (byte)0x66, (byte)0x28, (byte)0x69,
+ (byte)0xd0, (byte)0x74, (byte)0x4f, (byte)0x1c,
+ (byte)0x4f, (byte)0x97, (byte)0x75, (byte)0x7f,
+ (byte)0x9e, (byte)0x89, (byte)0x80, (byte)0xcf,
+ (byte)0xb2, (byte)0x17, (byte)0xd6, (byte)0x66,
+ (byte)0x91, (byte)0x12, (byte)0x3a, (byte)0xb0,
+ (byte)0x3c, (byte)0x3c, (byte)0xc2, (byte)0x31,
+ (byte)0xd1, (byte)0x31, (byte)0x2a, (byte)0x35,
+ (byte)0xbe, (byte)0x9d, (byte)0x54, (byte)0x71,
+ (byte)0x03, (byte)0xcb, (byte)0xcc, (byte)0x03,
+ (byte)0x81, (byte)0x85, (byte)0x00, (byte)0x02,
+ (byte)0x81, (byte)0x81, (byte)0x00, (byte)0x95,
+ (byte)0xcc, (byte)0x11, (byte)0xd4, (byte)0x53,
+ (byte)0x3d, (byte)0x9c, (byte)0x5c, (byte)0x73,
+ (byte)0xf4, (byte)0x70, (byte)0xf0, (byte)0xe1,
+ (byte)0xac, (byte)0xe3, (byte)0x2c, (byte)0x32,
+ (byte)0x16, (byte)0x1d, (byte)0x34, (byte)0x1a,
+ (byte)0x38, (byte)0x63, (byte)0x69, (byte)0x1a,
+ (byte)0x72, (byte)0x39, (byte)0x4e, (byte)0x41,
+ (byte)0x50, (byte)0xfa, (byte)0xdc, (byte)0x78,
+ (byte)0xa4, (byte)0xb8, (byte)0x17, (byte)0x5a,
+ (byte)0xe4, (byte)0xf9, (byte)0xa2, (byte)0x52,
+ (byte)0x41, (byte)0x85, (byte)0xab, (byte)0x3f,
+ (byte)0xf4, (byte)0x73, (byte)0x2e, (byte)0xae,
+ (byte)0xa9, (byte)0x21, (byte)0x8b, (byte)0x5e,
+ (byte)0x95, (byte)0x15, (byte)0xa2, (byte)0x86,
+ (byte)0x63, (byte)0x0d, (byte)0xba, (byte)0x01,
+ (byte)0xcb, (byte)0xe3, (byte)0x68, (byte)0xc6,
+ (byte)0xaf, (byte)0x56, (byte)0x51, (byte)0x7b,
+ (byte)0xa8, (byte)0x85, (byte)0x3f, (byte)0x01,
+ (byte)0x80, (byte)0x8b, (byte)0x1f, (byte)0xb4,
+ (byte)0x4c, (byte)0x93, (byte)0x6b, (byte)0x42,
+ (byte)0xa6, (byte)0xbd, (byte)0x67, (byte)0x2a,
+ (byte)0x95, (byte)0x05, (byte)0xff, (byte)0x03,
+ (byte)0x2e, (byte)0x6f, (byte)0xd4, (byte)0xd3,
+ (byte)0xf0, (byte)0x17, (byte)0xde, (byte)0xcb,
+ (byte)0x7d, (byte)0xd9, (byte)0x42, (byte)0x4d,
+ (byte)0x97, (byte)0x2c, (byte)0x53, (byte)0xe6,
+ (byte)0x39, (byte)0x61, (byte)0xd2, (byte)0x69,
+ (byte)0xd1, (byte)0x1c, (byte)0x9a, (byte)0x8b,
+ (byte)0x5b, (byte)0x9c, (byte)0xfa, (byte)0xfa,
+ (byte)0x50, (byte)0x50, (byte)0xbb, (byte)0xe4,
+ (byte)0x2e, (byte)0x83, (byte)0x06, (byte)0x08,
+ (byte)0x96, (byte)0x2a, (byte)0x68
+ });
+ privateKeyEncoding.put("DH", new byte[] {
+ (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffffe1, (byte) 0x2,
+ (byte) 0x1, (byte) 0x0, (byte) 0x30, (byte) 0xffffff81,
+ (byte) 0xffffff97, (byte) 0x6, (byte) 0x9, (byte) 0x2a,
+ (byte) 0xffffff86, (byte) 0x48, (byte) 0xffffff86,
+ (byte) 0xfffffff7, (byte) 0xd, (byte) 0x1, (byte) 0x3,
+ (byte) 0x1, (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffff89,
+ (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xfffffff0,
+ (byte) 0xffffffaa, (byte) 0x22, (byte) 0x5a, (byte) 0x29,
+ (byte) 0xffffffb2, (byte) 0x3f, (byte) 0xffffffc9, (byte) 0xb,
+ (byte) 0xffffff87, (byte) 0x5d, (byte) 0xffffff91, (byte) 0x51,
+ (byte) 0x1, (byte) 0xffffffa4, (byte) 0xffffffb9, (byte) 0x4e,
+ (byte) 0x1e, (byte) 0xffffff85, (byte) 0xfffffffc,
+ (byte) 0xffffffa6, (byte) 0x5a, (byte) 0xffffff96,
+ (byte) 0xffffffb1, (byte) 0xffffffcb, (byte) 0xffffff81,
+ (byte) 0xffffffa3, (byte) 0x6e, (byte) 0xffffff90,
+ (byte) 0xffffffbd, (byte) 0xffffffa2, (byte) 0xe,
+ (byte) 0xffffffb4, (byte) 0xffffffba, (byte) 0x2c, (byte) 0x45,
+ (byte) 0x9, (byte) 0x1c, (byte) 0xffffff98, (byte) 0x39,
+ (byte) 0x26, (byte) 0x24, (byte) 0x40, (byte) 0xffffff80,
+ (byte) 0xffffffce, (byte) 0x15, (byte) 0xffffff8b,
+ (byte) 0xffffffe1, (byte) 0x67, (byte) 0x48, (byte) 0xfffffff3,
+ (byte) 0x70, (byte) 0xffffff98, (byte) 0xffffffca,
+ (byte) 0xffffffa7, (byte) 0x71, (byte) 0x33, (byte) 0xffffffb6,
+ (byte) 0x4, (byte) 0x13, (byte) 0xffffffe5, (byte) 0x61,
+ (byte) 0x3c, (byte) 0x1f, (byte) 0x2, (byte) 0x40, (byte) 0x1e,
+ (byte) 0xffffffd8, (byte) 0x6f, (byte) 0xffffffce, (byte) 0x23,
+ (byte) 0x71, (byte) 0x6a, (byte) 0x2a, (byte) 0xffffffa3,
+ (byte) 0x4d, (byte) 0x62, (byte) 0xffffffe9, (byte) 0x5f,
+ (byte) 0x17, (byte) 0xffffffa8, (byte) 0xffffffe8,
+ (byte) 0xffffffaa, (byte) 0xffffff8a, (byte) 0xffffff95,
+ (byte) 0x26, (byte) 0x7c, (byte) 0x38, (byte) 0xffffffa9,
+ (byte) 0x2b, (byte) 0x48, (byte) 0x5a, (byte) 0x16,
+ (byte) 0x19, (byte) 0xfffffffa, (byte) 0xffffff83,
+ (byte) 0xffffffb8, (byte) 0x76, (byte) 0xffffffaf,
+ (byte) 0xffffffb8, (byte) 0x62, (byte) 0x72, (byte) 0x45,
+ (byte) 0xffffff9f, (byte) 0xffffff95, (byte) 0x1e, (byte) 0x62,
+ (byte) 0x36, (byte) 0xffffff97, (byte) 0xffffffbf,
+ (byte) 0xffffffab, (byte) 0x20, (byte) 0xffffffb0, (byte) 0x61,
+ (byte) 0xffffffc5, (byte) 0x21, (byte) 0xffffff9e,
+ (byte) 0xffffffe4, (byte) 0xffffffde, (byte) 0xffffff91,
+ (byte) 0x1c, (byte) 0x6a, (byte) 0x7, (byte) 0x48, (byte) 0x77,
+ (byte) 0x70, (byte) 0x1d, (byte) 0xffffffff, (byte) 0x58,
+ (byte) 0x23, (byte) 0x2, (byte) 0x2, (byte) 0x1,
+ (byte) 0xffffffff, (byte) 0x4, (byte) 0x42, (byte) 0x2,
+ (byte) 0x40, (byte) 0x69, (byte) 0xffffff86, (byte) 0x48,
+ (byte) 0x57, (byte) 0xffffffbf, (byte) 0xffffffde, (byte) 0x8,
+ (byte) 0xffffffc6, (byte) 0x24, (byte) 0x6d, (byte) 0xf,
+ (byte) 0x20, (byte) 0xffffff94, (byte) 0x4a, (byte) 0x22,
+ (byte) 0x6e, (byte) 0x24, (byte) 0x60, (byte) 0xffffffd9,
+ (byte) 0xffffffa9, (byte) 0xffffffbd, (byte) 0x1e, (byte) 0x64,
+ (byte) 0xffffff89, (byte) 0xffffff83, (byte) 0x3c,
+ (byte) 0xffffffe7, (byte) 0x70, (byte) 0x24, (byte) 0xffffffe1,
+ (byte) 0xffffff8f, (byte) 0x3c, (byte) 0x4d, (byte) 0x39,
+ (byte) 0x5f, (byte) 0xffffff9e, (byte) 0xffffff93, (byte) 0x13,
+ (byte) 0xffffff86, (byte) 0xffffffe9, (byte) 0xffffff80,
+ (byte) 0xf, (byte) 0xffffffc4, (byte) 0x41, (byte) 0xffffff8b,
+ (byte) 0xfffffff4, (byte) 0xffffff8b, (byte) 0x65,
+ (byte) 0xffffffa4, (byte) 0x1b, (byte) 0xd, (byte) 0x4,
+ (byte) 0x48, (byte) 0x40, (byte) 0xffffffd6, (byte) 0xffffffa2,
+ (byte) 0x0, (byte) 0xffffff85, (byte) 0xffffffe9,
+ (byte) 0xffffffc4, (byte) 0x77, (byte) 0xffffffb2, (byte) 0x25,
+ (byte) 0xffffffd8
+ });
+ publicKeyEncoding.put("DH", new byte[] {
+ (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffffe0, (byte) 0x30,
+ (byte) 0xffffff81, (byte) 0xffffff97, (byte) 0x6, (byte) 0x9,
+ (byte) 0x2a, (byte) 0xffffff86, (byte) 0x48, (byte) 0xffffff86,
+ (byte) 0xfffffff7, (byte) 0xd, (byte) 0x1, (byte) 0x3,
+ (byte) 0x1, (byte) 0x30, (byte) 0xffffff81, (byte) 0xffffff89,
+ (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xfffffff0,
+ (byte) 0xffffffaa, (byte) 0x22, (byte) 0x5a, (byte) 0x29,
+ (byte) 0xffffffb2, (byte) 0x3f, (byte) 0xffffffc9, (byte) 0xb,
+ (byte) 0xffffff87, (byte) 0x5d, (byte) 0xffffff91, (byte) 0x51,
+ (byte) 0x1, (byte) 0xffffffa4, (byte) 0xffffffb9, (byte) 0x4e,
+ (byte) 0x1e, (byte) 0xffffff85, (byte) 0xfffffffc,
+ (byte) 0xffffffa6, (byte) 0x5a, (byte) 0xffffff96,
+ (byte) 0xffffffb1, (byte) 0xffffffcb, (byte) 0xffffff81,
+ (byte) 0xffffffa3, (byte) 0x6e, (byte) 0xffffff90,
+ (byte) 0xffffffbd, (byte) 0xffffffa2, (byte) 0xe,
+ (byte) 0xffffffb4, (byte) 0xffffffba, (byte) 0x2c, (byte) 0x45,
+ (byte) 0x9, (byte) 0x1c, (byte) 0xffffff98, (byte) 0x39,
+ (byte) 0x26, (byte) 0x24, (byte) 0x40, (byte) 0xffffff80,
+ (byte) 0xffffffce, (byte) 0x15, (byte) 0xffffff8b,
+ (byte) 0xffffffe1, (byte) 0x67, (byte) 0x48, (byte) 0xfffffff3,
+ (byte) 0x70, (byte) 0xffffff98, (byte) 0xffffffca,
+ (byte) 0xffffffa7, (byte) 0x71, (byte) 0x33, (byte) 0xffffffb6,
+ (byte) 0x4, (byte) 0x13, (byte) 0xffffffe5, (byte) 0x61,
+ (byte) 0x3c, (byte) 0x1f, (byte) 0x2, (byte) 0x40, (byte) 0x1e,
+ (byte) 0xffffffd8, (byte) 0x6f, (byte) 0xffffffce, (byte) 0x23,
+ (byte) 0x71, (byte) 0x6a, (byte) 0x2a, (byte) 0xffffffa3,
+ (byte) 0x4d, (byte) 0x62, (byte) 0xffffffe9, (byte) 0x5f,
+ (byte) 0x17, (byte) 0xffffffa8, (byte) 0xffffffe8,
+ (byte) 0xffffffaa, (byte) 0xffffff8a, (byte) 0xffffff95,
+ (byte) 0x26, (byte) 0x7c, (byte) 0x38, (byte) 0xffffffa9,
+ (byte) 0x2b, (byte) 0x48, (byte) 0x5a, (byte) 0x16,
+ (byte) 0x19, (byte) 0xfffffffa, (byte) 0xffffff83,
+ (byte) 0xffffffb8, (byte) 0x76, (byte) 0xffffffaf,
+ (byte) 0xffffffb8, (byte) 0x62, (byte) 0x72, (byte) 0x45,
+ (byte) 0xffffff9f, (byte) 0xffffff95, (byte) 0x1e, (byte) 0x62,
+ (byte) 0x36, (byte) 0xffffff97, (byte) 0xffffffbf,
+ (byte) 0xffffffab, (byte) 0x20, (byte) 0xffffffb0, (byte) 0x61,
+ (byte) 0xffffffc5, (byte) 0x21, (byte) 0xffffff9e,
+ (byte) 0xffffffe4, (byte) 0xffffffde, (byte) 0xffffff91,
+ (byte) 0x1c, (byte) 0x6a, (byte) 0x7, (byte) 0x48, (byte) 0x77,
+ (byte) 0x70, (byte) 0x1d, (byte) 0xffffffff, (byte) 0x58,
+ (byte) 0x23, (byte) 0x2, (byte) 0x2, (byte) 0x1,
+ (byte) 0xffffffff, (byte) 0x3, (byte) 0x44, (byte) 0x0,
+ (byte) 0x2, (byte) 0x41, (byte) 0x0, (byte) 0xffffff9d,
+ (byte) 0xffffffc4, (byte) 0xffffffcd, (byte) 0x10,
+ (byte) 0xffffffdf, (byte) 0x66, (byte) 0xffffff92,
+ (byte) 0xffffffe1, (byte) 0x33, (byte) 0xffffffb1,
+ (byte) 0xffffffc9, (byte) 0xffffff9f, (byte) 0xffffffb7,
+ (byte) 0xffffffdd, (byte) 0xffffff84, (byte) 0x4b,
+ (byte) 0xffffffe5, (byte) 0xffffff86, (byte) 0xfffffff0,
+ (byte) 0x53, (byte) 0x2a, (byte) 0xffffffd5, (byte) 0xffffffc6,
+ (byte) 0x15, (byte) 0xffffff94, (byte) 0xffffffae, (byte) 0x13,
+ (byte) 0x7b, (byte) 0xffffff9d, (byte) 0x37, (byte) 0xffffff8b,
+ (byte) 0xffffffc6, (byte) 0xffffffc6, (byte) 0x78,
+ (byte) 0xffffff9c, (byte) 0x60, (byte) 0xffffff8a, (byte) 0x6f,
+ (byte) 0x35, (byte) 0x39, (byte) 0xffffffe0, (byte) 0x78,
+ (byte) 0x33, (byte) 0x60, (byte) 0xffffff89, (byte) 0x30,
+ (byte) 0x61, (byte) 0xffffff84, (byte) 0xffffff8a,
+ (byte) 0xffffffbc, (byte) 0xffffff80, (byte) 0x6c, (byte) 0x1c,
+ (byte) 0x55, (byte) 0xffffff96, (byte) 0x50, (byte) 0xffffffb1,
+ (byte) 0xffffff96, (byte) 0x5, (byte) 0x21, (byte) 0x65,
+ (byte) 0x55, (byte) 0xffffffbb, (byte) 0xffffffa4
+ });
+ }
+
+ public TestKeyPair(String algorithmName) throws
+ NoSuchAlgorithmException {
+ this.algorithmName = algorithmName;
+ if (!privateKeyEncoding.containsKey(this.algorithmName)) {
+ throw new NoSuchAlgorithmException("Encoded form not available for " +
+ this.algorithmName);
+ }
+ kf = KeyFactory.getInstance(this.algorithmName);
+ }
+
+ public PublicKey getPublic() throws
+ InvalidKeySpecException {
+ return kf.generatePublic(
+ new X509EncodedKeySpec(
+ (byte[])publicKeyEncoding.get(algorithmName)));
+ }
+
+ public PrivateKey getPrivate() throws
+ InvalidKeySpecException {
+ return kf.generatePrivate(
+ new PKCS8EncodedKeySpec(
+ (byte[])privateKeyEncoding.get(algorithmName)));
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/TestUtils.java b/support/src/test/java/org/apache/harmony/security/tests/support/TestUtils.java
new file mode 100644
index 0000000..011c9f7
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/TestUtils.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.util.Properties;
+
+/**
+ * Test utility class
+ */
+public class TestUtils {
+
+ /**
+ * No need to instantiate
+ */
+ private TestUtils() {
+ }
+
+ /**
+ * Prints byte array <code>data</code> as hex to the
+ * <code>System.out</code> in the customizable form.
+ *
+ * @param perLine how many numbers put on single line
+ * @param prefix custom output number prefix
+ * @param delimiter custom output number delimiter
+ * @param data data to be printed
+ */
+ public static void printAsHex(int perLine,
+ String prefix,
+ String delimiter,
+ byte[] data) {
+ for (int i=0; i<data.length; i++) {
+ String tail = Integer.toHexString(0x000000ff & data[i]);
+ if (tail.length() == 1) {
+ tail = "0" + tail;
+ }
+ System.out.print(prefix + "0x" + tail + delimiter);
+
+ if (((i+1)%perLine) == 0) {
+ System.out.println("");
+ }
+ }
+ System.out.println("");
+ }
+
+ /**
+ * Sets system property
+ *
+ * @param key - the name of the system property.
+ * @param value - the value to be set
+ */
+ public static void setSystemProperty(String key, String value) {
+ Properties properties = System.getProperties();
+ if (value == null) {
+ properties.remove(key);
+ } else {
+ properties.setProperty(key, value);
+ }
+ System.setProperties(properties);
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCRL.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCRL.java
new file mode 100644
index 0000000..b95caf7
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCRL.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.cert.CRL;
+import java.security.cert.Certificate;
+
+/**
+ * Stub class for <code>java.security.cert.CRL</code> tests
+ *
+ */
+public class MyCRL extends CRL {
+
+ /**
+ * Constructor
+ *
+ * @param type
+ */
+ public MyCRL(String type) {
+ super(type);
+ }
+
+ /**
+ * @return <code>String</code> representation
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return "MyCRL: [" + getType() + "]";
+ }
+
+ /**
+ * @param cert <code>Certificate</code> to be checked
+ * @return always <code>false</code>
+ * @see java.security.cert.CRL#isRevoked(java.security.cert.Certificate)
+ */
+ public boolean isRevoked(Certificate cert) {
+ return false;
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
new file mode 100644
index 0000000..ccdb216
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPath.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.cert.CertPath;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+
+/**
+ * Stub class for <code>java.security.cert.CertPath</code> tests
+ *
+ */
+public class MyCertPath extends CertPath {
+ /**
+ * my certificates list
+ */
+ private final Vector<Certificate> certificates;
+ /**
+ * List of encodings supported
+ */
+ private final Vector<String> encodingNames;
+ /**
+ * my cert path the only encoding
+ */
+ private final byte[] encoding;
+
+ /**
+ * Constructs new instance of <code>MyCertPath</code>
+ *
+ * @param type
+ * @param encoding
+ */
+ public MyCertPath(byte[] encoding) {
+ super("MyEncoding");
+ this.encoding = encoding;
+ certificates = new Vector<Certificate>();
+ certificates.add(new MyCertificate("MyEncoding", encoding));
+ encodingNames = new Vector<String>();
+ encodingNames.add("MyEncoding");
+ }
+
+ /**
+ * @return certificates list
+ * @see java.security.cert.CertPath#getCertificates()
+ */
+ public List<Certificate> getCertificates() {
+ return Collections.unmodifiableList(certificates);
+ }
+
+ /**
+ * @return default encoded form of this cert path
+ * @see java.security.cert.CertPath#getEncoded()
+ */
+ public byte[] getEncoded() throws CertificateEncodingException {
+ return encoding.clone();
+ }
+
+ /**
+ * @return encoded form of this cert path as specified by
+ * <code>encoding</code> parameter
+ * @throws CertificateEncodingException if <code>encoding</code>
+ * not equals "MyEncoding"
+ * @see java.security.cert.CertPath#getEncoded(java.lang.String)
+ */
+ public byte[] getEncoded(String encoding)
+ throws CertificateEncodingException {
+ if (getType().equals(encoding)) {
+ return this.encoding.clone();
+ }
+ throw new CertificateEncodingException("Encoding not supported: " +
+ encoding);
+ }
+
+ /**
+ * @return iterator through encodings supported
+ * @see java.security.cert.CertPath#getEncodings()
+ */
+ public Iterator<String> getEncodings() {
+ return Collections.unmodifiableCollection(encodingNames).iterator();
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathBuilderSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathBuilderSpi.java
new file mode 100644
index 0000000..4fa51fa
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathBuilderSpi.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.cert.CertPathBuilderException;
+import java.security.cert.CertPathBuilderResult;
+import java.security.cert.CertPathBuilderSpi;
+import java.security.cert.CertPathParameters;
+
+/**
+ * Additional class for verification CertPathBuilderSpi
+ * and CertPathBuilder
+
+ */
+
+public class MyCertPathBuilderSpi extends CertPathBuilderSpi {
+ private int swi = 0;
+ public CertPathBuilderResult engineBuild(CertPathParameters params)
+ throws CertPathBuilderException, InvalidAlgorithmParameterException {
+ swi++;
+ if ((params == null) && ((swi %2 ) != 0)) {
+ throw new CertPathBuilderException("Null parameter");
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathValidatorSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathValidatorSpi.java
new file mode 100644
index 0000000..fb76927
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertPathValidatorSpi.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.cert.CertPath;
+import java.security.cert.CertPathParameters;
+import java.security.cert.CertPathValidatorException;
+import java.security.cert.CertPathValidatorResult;
+import java.security.cert.CertPathValidatorSpi;
+
+/**
+ * Additional class for verification of CertPathValidatorSpi
+ * and CertPathValidator
+ *
+ */
+
+public class MyCertPathValidatorSpi extends CertPathValidatorSpi {
+ private int sw = 0;
+ public CertPathValidatorResult engineValidate(CertPath certPath,
+ CertPathParameters params) throws CertPathValidatorException,
+ InvalidAlgorithmParameterException {
+ ++sw;
+ if (certPath == null) {
+ if ((sw % 2) == 0) {
+ throw new CertPathValidatorException("certPath null");
+ }
+ }
+ if (params == null) {
+ if ((sw % 3) == 0) {
+ throw new InvalidAlgorithmParameterException("params null");
+ }
+ }
+ return null;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreParameters.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreParameters.java
new file mode 100644
index 0000000..6518c6f
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreParameters.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.cert.CertStoreParameters;
+
+/**
+ * Class for verification of CertStore and CertStoreSpi
+ *
+ */
+
+public class MyCertStoreParameters implements CertStoreParameters {
+ public MyCertStoreParameters() {
+ super();
+ }
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java
new file mode 100644
index 0000000..fd6505c
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertStoreSpi.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.cert.CRLSelector;
+import java.security.cert.CertSelector;
+import java.security.cert.CertStoreException;
+import java.security.cert.CertStoreParameters;
+import java.security.cert.CertStoreSpi;
+import java.util.Collection;
+
+/**
+ * Additional class for verification CertStoreSpi
+ * and CertStore
+ *
+ */
+
+public class MyCertStoreSpi extends CertStoreSpi {
+
+ public MyCertStoreSpi(CertStoreParameters params)
+ throws InvalidAlgorithmParameterException {
+ super(params);
+ if (!(params instanceof MyCertStoreParameters)) {
+ throw new InvalidAlgorithmParameterException("Invalid params");
+ }
+ }
+
+ public Collection engineGetCertificates(CertSelector selector)
+ throws CertStoreException {
+ if (selector == null) {
+ throw new CertStoreException("Parameter is null");
+ }
+ return null;
+ }
+
+ public Collection engineGetCRLs(CRLSelector selector)
+ throws CertStoreException {
+ if (selector == null) {
+ throw new CertStoreException("Parameter is null");
+ }
+ return null;
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
new file mode 100644
index 0000000..f06ed1d
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificate.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+
+/**
+ * Stub class for <code>java.security.cert.Certificate</code> tests
+ */
+public class MyCertificate extends Certificate {
+
+ // MyCertificate encoding
+ private final byte[] encoding;
+
+ /**
+ * Constructs new object of class <code>MyCertificate</code>
+ *
+ * @param type
+ * @param encoding
+ */
+ public MyCertificate(String type, byte[] encoding) {
+ super(type);
+ // don't copy to allow null parameter in test
+ this.encoding = encoding;
+ }
+
+ /**
+ * Returns <code>MyCertificate</code> encoding
+ */
+ public byte[] getEncoded() throws CertificateEncodingException {
+ // do copy to force NPE in test
+ return encoding.clone();
+ }
+
+ /**
+ * Does nothing
+ */
+ public void verify(PublicKey key) throws CertificateException,
+ NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+ }
+
+ /**
+ * Does nothing
+ */
+ public void verify(PublicKey key, String sigProvider)
+ throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException, SignatureException {
+ }
+
+ /**
+ * Returns formatted <code>String</code>
+ * describing <code>MyCertificate</code> object
+ */
+ public String toString() {
+ return "[My test Certificate, type: " + getType() + "]";
+ }
+
+ /**
+ * Returns public key (stub) from <code>MyCertificate</code> object
+ */
+ public PublicKey getPublicKey() {
+ return new PublicKey() {
+ public String getAlgorithm() {
+ return "TEST";
+ }
+ public byte[] getEncoded() {
+ return new byte[] {(byte)1, (byte)2, (byte)3};
+ }
+ public String getFormat() {
+ return "TEST_FORMAT";
+ }
+ };
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java
new file mode 100644
index 0000000..8a94a6c
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/MyCertificateFactorySpi.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.io.DataInputStream;
+import java.io.InputStream;
+import java.security.cert.CRL;
+import java.security.cert.CRLException;
+import java.security.cert.CertPath;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactorySpi;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Additional class for verification CertificateFactorySpi and
+ * CertificateFactory classes
+ *
+ */
+
+public class MyCertificateFactorySpi extends CertificateFactorySpi {
+ // Variants of execution:
+ // mode: false - list of encodings is empty
+ // mode: true - list of encodings consists of 2 elements
+ // some exceptions are thrown when
+ private static boolean mode;
+
+ private Set<String> list;
+
+ public MyCertificateFactorySpi() {
+ super();
+ mode = true;
+ list = new HashSet<String>();
+ list.add("aa");
+ list.add("bb");
+ }
+
+ public static void putMode(boolean newMode) {
+ mode = newMode;
+ }
+
+ public Certificate engineGenerateCertificate(InputStream inStream)
+ throws CertificateException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CertificateException("Incorrect inputstream");
+ }
+ return null;
+ }
+
+ public Collection engineGenerateCertificates(InputStream inStream)
+ throws CertificateException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CertificateException("Incorrect inputstream");
+ }
+ return null;
+ }
+
+ public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CRLException("Incorrect inputstream");
+ }
+ return null;
+ }
+
+ public Collection engineGenerateCRLs(InputStream inStream)
+ throws CRLException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CRLException("Incorrect inputstream");
+ }
+ return null;
+ }
+
+ public CertPath engineGenerateCertPath(InputStream inStream)
+ throws CertificateException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CertificateException("Incorrect inputstream");
+ }
+ Iterator it = engineGetCertPathEncodings();
+ if (!it.hasNext()) {
+ throw new CertificateException("There are no CertPath encodings");
+ }
+ return engineGenerateCertPath(inStream, (String) it.next());
+ }
+
+ public CertPath engineGenerateCertPath(InputStream inStream, String encoding)
+ throws CertificateException {
+ if (!(inStream instanceof DataInputStream)) {
+ throw new CertificateException("Incorrect inputstream");
+ }
+ if (encoding.length() == 0) {
+ if (mode) {
+ throw new IllegalArgumentException("Encoding is empty");
+ }
+ }
+ return null;
+ }
+
+ public CertPath engineGenerateCertPath(List certificates)
+ throws CertificateException {
+ if (certificates == null) {
+ if (mode) {
+ throw new NullPointerException("certificates is null");
+ }
+ }
+ return null;
+ }
+
+ public Iterator<String> engineGetCertPathEncodings() {
+ if (!mode) {
+ list.clear();
+ }
+ return list.iterator();
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/cert/TestUtils.java b/support/src/test/java/org/apache/harmony/security/tests/support/cert/TestUtils.java
new file mode 100644
index 0000000..a9e565b
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/cert/TestUtils.java
@@ -0,0 +1,532 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.cert;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertPathValidatorException;
+import java.security.cert.CertStore;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.CollectionCertStoreParameters;
+import java.security.cert.PKIXCertPathChecker;
+import java.security.cert.PolicyNode;
+import java.security.cert.TrustAnchor;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import tests.support.resource.Support_Resources;
+
+/**
+ * java.security.cert test utilities
+ *
+ */
+public class TestUtils {
+ // Certificate type used during testing
+ private static final String certType = "X.509";
+ // Key store type used during testing
+ private static final String keyStoreType = "BKS";
+ // The file name prefix to load keystore from
+ private static final String keyStoreFileName = "test." + keyStoreType
+ + ".ks";
+ //
+ // The file name suffixes to load keystore from
+ // *.ks1 - keystore containing untrusted certificates only
+ // *.ks2 - keystore containing trusted certificates only
+ // *.ks3 - keystore containing both trusted and untrusted certificates
+ //
+ public static final int UNTRUSTED = 1;
+ public static final int TRUSTED = 2;
+ public static final int TRUSTED_AND_UNTRUSTED = 3;
+ //
+ // Common passwords for all test keystores
+ //
+ private final static char[] storepass =
+ new char[] {'s','t','o','r','e','p','w','d'};
+
+ /**
+ * Creates <code>TrustAnchor</code> instance
+ * constructed using self signed test certificate
+ *
+ * @return <code>TrustAnchor</code> instance
+ * @throws CertificateException
+ * @throws FileNotFoundException
+ */
+ public static TrustAnchor getTrustAnchor() {
+ CertificateFactory cf = null;
+ try {
+ cf = CertificateFactory.getInstance(certType);
+ } catch (CertificateException e) {
+ // requested cert type is not available in the
+ // default provider package or any of the other provider packages
+ // that were searched
+ throw new RuntimeException(e);
+ }
+ BufferedInputStream bis = null;
+ try {
+ bis = new BufferedInputStream(new ByteArrayInputStream(
+ getEncodedX509Certificate()));
+ X509Certificate c1 = (X509Certificate)cf.generateCertificate(bis);
+
+ return new TrustAnchor(c1, null);
+ } catch (Exception e) {
+ // all failures are fatal
+ throw new RuntimeException(e);
+ } finally {
+ if (bis != null) {
+ try {
+ bis.close() ;
+ } catch (IOException ign) {}
+ }
+ }
+ }
+
+ /**
+ * Creates <code>Set</code> of <code>TrustAnchor</code>s
+ * containing single element (self signed test certificate).
+ * @return Returns <code>Set</code> of <code>TrustAnchor</code>s
+ */
+ public static Set getTrustAnchorSet() {
+ TrustAnchor ta = getTrustAnchor();
+ if (ta == null) {
+ return null;
+ }
+ HashSet<TrustAnchor> set = new HashSet<TrustAnchor>();
+ if (!set.add(ta)) {
+ throw new RuntimeException("Could not create trust anchor set");
+ }
+ return set;
+ }
+
+ /**
+ * Creates test <code>KeyStore</code> instance
+ *
+ * @param initialize
+ * Do not initialize returned <code>KeyStore</code> if false
+ *
+ * @param testKeyStoreType
+ * this parameter ignored if <code>initialize</code> is false;
+ * The following types supported:<br>
+ * 1 - <code>KeyStore</code> with untrusted certificates only<br>
+ * 2 - <code>KeyStore</code> with trusted certificates only<br>
+ * 3 - <code>KeyStore</code> with both trusted and untrusted certificates
+ *
+ * @return Returns test <code>KeyStore</code> instance
+ */
+ public static KeyStore getKeyStore(boolean initialize,
+ int testKeyStoreType) {
+ BufferedInputStream bis = null;
+ try {
+ KeyStore ks = KeyStore.getInstance(keyStoreType);
+ if (initialize) {
+ String fileName = keyStoreFileName + testKeyStoreType;
+ ks.load(Support_Resources.getResourceStream(fileName),
+ storepass);
+ }
+ return ks;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (initialize && bis != null) {
+ try {
+ bis.close();
+ } catch (IOException ign) {}
+ }
+ }
+ }
+
+ /**
+ * Creates <code>List</code> of <code>CollectionCertStores</code>
+ *
+ * @return The list created
+ *
+ * @throws InvalidAlgorithmParameterException
+ * @throws NoSuchAlgorithmException
+ */
+ public static List getCollectionCertStoresList()
+ throws InvalidAlgorithmParameterException,
+ NoSuchAlgorithmException {
+ CertStore cs = CertStore.getInstance("Collection",
+ new CollectionCertStoreParameters());
+ ArrayList<CertStore> l = new ArrayList<CertStore>();
+ if (!l.add(cs)) {
+ throw new RuntimeException("Could not create cert stores list");
+ }
+ return l;
+ }
+
+ /**
+ * Creates stub implementation of the <code>PKIXCertPathChecker</code>
+ *
+ * @return Stub implementation of the <code>PKIXCertPathChecker</code>
+ */
+ public static PKIXCertPathChecker getTestCertPathChecker() {
+ // stub implementation for testing purposes only
+ return new PKIXCertPathChecker() {
+ private boolean forward = false;
+
+ public void check(Certificate arg0, Collection arg1)
+ throws CertPathValidatorException {
+ }
+
+ public Set getSupportedExtensions() {
+ return null;
+ }
+
+ public void init(boolean arg0) throws CertPathValidatorException {
+ forward = arg0;
+ }
+
+ public boolean isForwardCheckingSupported() {
+ // just to check this checker state
+ return forward;
+ }
+ };
+ }
+
+ /**
+ * Creates policy tree stub containing two <code>PolicyNode</code>s
+ * for testing purposes
+ *
+ * @return root <code>PolicyNode</code> of the policy tree
+ */
+ public static PolicyNode getPolicyTree() {
+ return new PolicyNode() {
+ final PolicyNode parent = this;
+ public int getDepth() {
+ // parent
+ return 0;
+ }
+
+ public boolean isCritical() {
+ return false;
+ }
+
+ public String getValidPolicy() {
+ return null;
+ }
+
+ public PolicyNode getParent() {
+ return null;
+ }
+
+ public Iterator getChildren() {
+ PolicyNode child = new PolicyNode() {
+ public int getDepth() {
+ // child
+ return 1;
+ }
+
+ public boolean isCritical() {
+ return false;
+ }
+
+ public String getValidPolicy() {
+ return null;
+ }
+
+ public PolicyNode getParent() {
+ return parent;
+ }
+
+ public Iterator getChildren() {
+ return null;
+ }
+
+ public Set getExpectedPolicies() {
+ return null;
+ }
+
+ public Set getPolicyQualifiers() {
+ return null;
+ }
+ };
+ HashSet<PolicyNode> s = new HashSet<PolicyNode>();
+ s.add(child);
+ return s.iterator();
+ }
+
+ public Set getExpectedPolicies() {
+ return null;
+ }
+
+ public Set getPolicyQualifiers() {
+ return null;
+ }
+ };
+ }
+ // X.509 encoded certificate
+ private static final String ENCODED_X509_CERTIFICATE = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIDHTCCAtsCBEFT72swCwYHKoZIzjgEAwUAMHQxCzAJBgNVBAYTAlJVMQwwCgYDVQQIEwNOU08x\n"
+ + "FDASBgNVBAcTC05vdm9zaWJpcnNrMQ4wDAYDVQQKEwVJbnRlbDEVMBMGA1UECxMMRFJMIFNlY3Vy\n"
+ + "aXR5MRowGAYDVQQDExFWbGFkaW1pciBNb2xvdGtvdjAeFw0wNDA5MjQwOTU2NTlaFw0wNjA1MTcw\n"
+ + "OTU2NTlaMHQxCzAJBgNVBAYTAlJVMQwwCgYDVQQIEwNOU08xFDASBgNVBAcTC05vdm9zaWJpcnNr\n"
+ + "MQ4wDAYDVQQKEwVJbnRlbDEVMBMGA1UECxMMRFJMIFNlY3VyaXR5MRowGAYDVQQDExFWbGFkaW1p\n"
+ + "ciBNb2xvdGtvdjCCAbgwggEsBgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3Ujzv\n"
+ + "RADDHj+AtlEmaUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7\n"
+ + "qdf+t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgBxwIVAJdgUI8V\n"
+ + "IwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7+jrqgvlXTAs9B4JnUVlXjrrU\n"
+ + "WU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqLVHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEk\n"
+ + "O8yk8b6oUZCJqIPf4VrlnwaSi2ZegHtVJWQBTDv+z0kqA4GFAAKBgQDiNmj9jgWu1ILYqYWcUhNN\n"
+ + "8CjjRitf80yWP/s/565wZz3anb2w72jum63mdShDko9eOOOd1hiVuiBnNhSL7D6JfIYBJvNXr1av\n"
+ + "Gw583BBv12OBgg0eAW/GRWBn2Ak2JjsoBc5x2c1HAEufakep7T6RoC+n3lqbKPKyHWVdfqQ9KTAL\n"
+ + "BgcqhkjOOAQDBQADLwAwLAIUaRS3C9dXcMbrOAhmidFBr7oMvH0CFEC3LUwfLJX5gY8P6uxpkPx3\n"
+ + "JDSM\n" + "-----END CERTIFICATE-----\n";
+
+ public static byte[] getEncodedX509Certificate() {
+ return ENCODED_X509_CERTIFICATE.getBytes();
+ }
+
+ /**
+ * Returns X.509 certificate encoding corresponding to version v1.
+ *
+ * Certificate encoding was created by hands according to X.509 Certificate
+ * ASN.1 notation. The certificate encoding has the following encoded
+ * field values:<br>
+ * - version: 1<br>
+ * - serialNumber: 5<br>
+ * - issuer: CN=Z<br>
+ * - notBefore: 13 Dec 1999 14:15:16<br>
+ * - notAfter: 01 Jan 2000 00:00:00<br>
+ * - subject: CN=Y<br>
+ *
+ * @return X.509 certificate encoding corresponding to version v1.
+ */
+ public static byte[] getX509Certificate_v1() {
+ return new byte[] {
+ // Certificate: SEQUENCE
+ 0x30, 0x6B,
+
+ //
+ // TBSCertificate: SEQUENCE {
+ //
+ 0x30, 0x5C,
+
+ // version: [0] EXPLICIT Version DEFAULT v1
+ (byte) 0xA0, 0x03, 0x02, 0x01, 0x00,
+
+ // serialNumber: CertificateSerialNumber
+ 0x02, 0x01, 0x05,
+
+ // signature: AlgorithmIdentifier
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+
+ //issuer: Name
+ 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+ 0x13, 0x01, 0x5A, // CN=Z
+
+ //validity: Validity
+ 0x30, 0x1E, // SEQUENCE
+ // notBefore: UTCTime
+ 0x17, 0x0D, 0x39, 0x39, 0x31, 0x32, 0x31, 0x33, 0x31, 0x34, 0x31,
+ 0x35, 0x31, 0x36, 0x5A, // 13 Dec 1999 14:15:16
+ // notAfter: UTCTime
+ 0x17, 0x0D, 0x30, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x5A, // 01 Jan 2000 00:00:00
+
+ //subject: Name
+ 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+ 0x13, 0x01, 0x59, // CN=Y
+ //SubjectPublicKeyInfo ::= SEQUENCE {
+ // algorithm AlgorithmIdentifier,
+ // subjectPublicKey BIT STRING }
+ 0x30, 0x0D, // SEQUENCE
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+ 0x03, 0x02, 0x00, 0x01, // subjectPublicKey
+
+ // issuerUniqueID - missed
+ // subjectUniqueID - missed
+ // extensions - missed
+
+ // } end TBSCertificate
+
+ //
+ // signatureAlgorithm: AlgorithmIdentifier
+ //
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+
+ //
+ // signature: BIT STRING
+ //
+ 0x03, 0x02, 0x00, 0x01 };
+ }
+
+ /**
+ * Returns X.509 certificate encoding corresponding to version v3.
+ *
+ * Certificate encoding was created by hands according to X.509 Certificate
+ * ASN.1 notation. The certificate encoding has the following encoded
+ * field values:<br>
+ * - version: 3<br>
+ * - serialNumber: 5<br>
+ * - issuer: CN=Z<br>
+ * - notBefore: 13 Dec 1999 14:15:16<br>
+ * - notAfter: 01 Jan 2000 00:00:00<br>
+ * - subject: CN=Y<br>
+ * - extensions:
+ * 1) AuthorityKeyIdentifier(OID=2.5.29.35): no values in it(empty sequence)
+ *
+ * @return X.509 certificate encoding corresponding to version v3.
+ */
+ public static byte[] getX509Certificate_v3() {
+ return new byte[] {
+ // Certificate: SEQUENCE
+ 0x30, 0x7D,
+
+ //
+ // TBSCertificate: SEQUENCE {
+ //
+ 0x30, 0x6E,
+
+ // version: [0] EXPLICIT Version DEFAULT v1
+ (byte) 0xA0, 0x03, 0x02, 0x01, 0x02,
+
+ // serialNumber: CertificateSerialNumber
+ 0x02, 0x01, 0x05,
+
+ // signature: AlgorithmIdentifier
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+
+ //issuer: Name
+ 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+ 0x13, 0x01, 0x5A, // CN=Z
+
+ //validity: Validity
+ 0x30, 0x1E, // SEQUENCE
+ // notBefore: UTCTime
+ 0x17, 0x0D, 0x39, 0x39, 0x31, 0x32, 0x31, 0x33, 0x31, 0x34, 0x31,
+ 0x35, 0x31, 0x36, 0x5A, // 13 Dec 1999 14:15:16
+ // notAfter: UTCTime
+ 0x17, 0x0D, 0x30, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x5A, // 01 Jan 2000 00:00:00
+
+ //subject: Name
+ 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
+ 0x13, 0x01, 0x59, // CN=Y
+ //SubjectPublicKeyInfo ::= SEQUENCE {
+ // algorithm AlgorithmIdentifier,
+ // subjectPublicKey BIT STRING }
+ 0x30, 0x0D, // SEQUENCE
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+ 0x03, 0x02, 0x00, 0x01, // subjectPublicKey
+
+ // issuerUniqueID - missed
+ // subjectUniqueID - missed
+ // extensions : [3] EXPLICIT Extensions OPTIONAL
+ (byte) 0xA3, 0x10,
+ // Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
+ 0x30, 0x0E,
+ // Extension ::= SEQUENCE {
+ // extnID OBJECT IDENTIFIER,
+ // critical BOOLEAN DEFAULT FALSE,
+ // extnValue OCTET STRING }
+
+ // 1) AuthorityKeyIdentifier extension (see HARMONY-3384)
+ 0x30, 0x0C,
+ 0x06, 0x03, 0x55, 0x1D, 0x23, // OID = 2.5.29.35
+ 0x01, 0x01, 0x00, // critical = FALSE
+ 0x04, 0x02, 0x30, 0x00, // extnValue: MUST be empty sequence
+ // missed: keyIdentifier
+ // missed: authorityCertIssuer
+ // missed" authorityCertSerialNumber
+
+ // } end TBSCertificate
+
+ //
+ // signatureAlgorithm: AlgorithmIdentifier
+ //
+ 0x30, 0x07, // SEQUENCE
+ 0x06, 0x02, 0x03, 0x05,//OID
+ 0x01, 0x01, 0x07, //ANY
+
+ //
+ // signature: BIT STRING
+ //
+ 0x03, 0x02, 0x00, 0x01 };
+ }
+
+ /**
+ * Returns X.509 CRL encoding corresponding to version v1.
+ *
+ * CRL encoding was created by hands according to X.509 CRL ASN.1
+ * notation. The CRL encoding has the following encoded field values:<br>
+ * - version: 1<br>
+ * - issuer: CN=Z<br>
+ * - thisUpdate: 01 Jan 2001 01:02:03<br>
+ *
+ * @return X.509 CRL encoding corresponding to version v1.
+ */
+ public static byte[] getX509CRL_v1() {
+ return new byte[] {
+ //CertificateList: SEQUENCE
+ 0x30, 0x35,
+
+ // TBSCertList: SEQUENCE
+ 0x30, 0x27,
+ // Version: INTEGER OPTIONAL
+ // 0x02, 0x01, 0x01, - missed here cause it is v1
+ // signature: AlgorithmIdentifier
+ 0x30, 0x06, // SEQUENCE
+ 0x06, 0x01, 0x01, // OID
+ 0x01, 0x01, 0x11, // ANY
+ // issuer: Name
+ 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
+ 0x03, 0x13, 0x01, 0x5A, // CN=Z
+ // thisUpdate: ChoiceOfTime
+ // GeneralizedTime: 01 Jan 2001 01:02:03
+ 0x18, 0x0F, 0x32, 0x30, 0x30, 0x31, 0x30, 0x31, 0x30, 0x31,
+ 0x30, 0x31, 0x30, 0x32, 0x30, 0x33, 0x5A,
+
+ // nextUpdate - missed
+ // revokedCertificates - missed
+ // crlExtensions - missed
+
+ // signatureAlgorithm: AlgorithmIdentifier
+ 0x30, 0x06, // SEQUENCE
+ 0x06, 0x01, 0x01, //OID
+ 0x01, 0x01, 0x11, //ANY
+ // signature: BIT STRING
+ 0x03, 0x02, 0x00, 0x01 };
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/spec/MyEncodedKeySpec.java b/support/src/test/java/org/apache/harmony/security/tests/support/spec/MyEncodedKeySpec.java
new file mode 100644
index 0000000..2a38474
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/spec/MyEncodedKeySpec.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support.spec;
+
+import java.security.spec.EncodedKeySpec;
+
+/**
+ * Support class for abstract base class testing
+ */
+
+public class MyEncodedKeySpec extends EncodedKeySpec {
+
+ /**
+ * Constructor
+ * @param encodedKey
+ */
+ public MyEncodedKeySpec(byte[] encodedKey) {
+ super(encodedKey);
+ }
+
+ /**
+ * Returns format - "My"
+ * @see java.security.spec.EncodedKeySpec#getFormat()
+ */
+ public String getFormat() {
+ return "My";
+ }
+
+}
diff --git a/support/src/test/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java b/support/src/test/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java
new file mode 100644
index 0000000..5ac2905
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/security/tests/support/tmpCallbackHandler.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.support;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+/**
+ * Additional class for creating CallBackHandler object
+ *
+ */
+
+public class tmpCallbackHandler implements CallbackHandler {
+ public void handle(Callback[] callback) throws IOException,
+ UnsupportedCallbackException {
+ if (callback == null) {
+ throw new UnsupportedCallbackException(null, "callback is null");
+ }
+ if (callback.length == 0) {
+ throw new UnsupportedCallbackException(null, "callback is empty");
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
new file mode 100644
index 0000000..c783c6d
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
@@ -0,0 +1,587 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 Alexey V. Varlamov
+* @version $Revision$
+*/
+
+package org.apache.harmony.testframework.serialization;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Framework for serialization testing. Subclasses only need to override
+ * getData() method and, optionally, assertDeserialized() method. The first one
+ * returns array of objects to be de/serialized in tests, and the second
+ * compares reference and deserialized objects (needed only if tested objects do
+ * not provide specific method equals()). <br>
+ * There are two modes of test run: <b>reference generation mode </b> and
+ * <b>testing mode </b>. The actual mode is selected via
+ * <b>&quot;test.mode&quot; </b> system property. The <b>testing mode </b> is
+ * the default mode. <br>
+ * To turn on the <b>reference generation mode </b>, the test.mode property
+ * should be set to value &quot;serial.reference&quot;. In this mode, no testing
+ * is performed but golden files are produced, which contain reference
+ * serialized objects. This mode should be run on a pure
+ * Implementation classes, which are targeted for compartibility. <br>
+ * The location of golden files (in both modes) is controlled via
+ * <b>&quot;RESOURCE_DIR&quot; </b> system property.
+ *
+ */
+public abstract class SerializationTest extends TestCase {
+
+ /**
+ * Property name for the testing mode.
+ */
+ public static final String MODE_KEY = "test.mode";
+
+
+ /**
+ * Testing mode.
+ */
+ public static String mode = System.getProperty(MODE_KEY);
+
+ /**
+ * Reference files generation mode switch.
+ */
+ public static final String SERIAL_REFERENCE_MODE = "serial.reference";
+
+ /**
+ * Key to a system property defining root location of golden files.
+ */
+ public static final String GOLDEN_PATH = "RESOURCE_DIR";
+
+ private static final String outputPath = System.getProperty(GOLDEN_PATH,
+ "src/test/resources/serialization");
+
+ /**
+ * Parameterized c-tor inherited from superclass.
+ */
+ public SerializationTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Default c-tor inherited from superclass.
+ */
+ public SerializationTest() {
+ super();
+ }
+
+ /**
+ * Depending on testing mode, produces golden files or performs testing.
+ */
+ @Override
+ public void runBare() throws Throwable {
+
+ if (mode != null && mode.equals(SERIAL_REFERENCE_MODE)) {
+ produceGoldenFiles();
+ } else {
+ super.runBare();
+ }
+ }
+
+ /**
+ * This is the main working method of this framework. Subclasses must
+ * override it to provide actual objects for testing.
+ *
+ * @return array of objects to be de/serialized in tests.
+ */
+ protected abstract Object[] getData();
+
+ /**
+ * Tests that data objects can be serialized and deserialized without
+ * exceptions, and that deserialization really produces deeply cloned
+ * objects.
+ */
+ public void testSelf() throws Throwable {
+
+ if (this instanceof SerializableAssert) {
+ verifySelf(getData(), (SerializableAssert) this);
+ } else {
+ verifySelf(getData());
+
+ }
+ }
+
+ /**
+ * Tests that data objects can be deserialized from golden files, to verify
+ * compartibility with Reference Implementation.
+ */
+ public void testGolden() throws Throwable {
+
+ verifyGolden(this, getData());
+ }
+
+ /**
+ * Returns golden file for an object being tested.
+ *
+ * @param index array index of tested data (as returned by
+ * {@link #getData() getData()})
+ * @return corresponding golden file
+ */
+ protected File getDataFile(int index) {
+ String name = this.getClass().getName();
+ int dot = name.lastIndexOf(".");
+ String path = name.substring(0, dot).replace('.', File.separatorChar);
+ if (outputPath != null && outputPath.length() != 0) {
+ path = outputPath + File.separator + path;
+ }
+
+ return new File(path, name.substring(dot + 1) + "." + index + ".dat");
+ }
+
+ /**
+ * Working method for files generation mode. Serializes test objects
+ * returned by {@link #getData() getData()}to golden files, each object to
+ * a separate file.
+ *
+ * @throws IOException
+ */
+ protected void produceGoldenFiles() throws IOException {
+
+ String goldenPath = outputPath + File.separatorChar
+ + getClass().getName().replace('.', File.separatorChar)
+ + ".golden.";
+
+ Object[] data = getData();
+ for (int i = 0; i < data.length; i++) {
+
+ File goldenFile = new File(goldenPath + i + ".ser");
+ goldenFile.getParentFile().mkdirs();
+ goldenFile.createNewFile();
+
+ putObjectToStream(data[i], new FileOutputStream(goldenFile));
+ }
+ }
+
+ /**
+ * Serializes specified object to an output stream.
+ */
+ public static void putObjectToStream(Object obj, OutputStream os)
+ throws IOException {
+ ObjectOutputStream oos = new ObjectOutputStream(os);
+ oos.writeObject(obj);
+ oos.flush();
+ oos.close();
+ }
+
+ /**
+ * Deserializes single object from an input stream.
+ */
+ public static Serializable getObjectFromStream(InputStream is) throws IOException,
+ ClassNotFoundException {
+ ObjectInputStream ois = new ObjectInputStream(is);
+ Object result = ois.readObject();
+ ois.close();
+ return (Serializable)result;
+ }
+
+ /**
+ * Interface to compare (de)serialized objects
+ *
+ * Should be implemented if a class under test does not provide specific
+ * equals() method and it's instances should to be compared manually.
+ */
+ public interface SerializableAssert {
+
+ /**
+ * Compares deserialized and reference objects.
+ *
+ * @param initial -
+ * initial object used for creating serialized form
+ * @param deserialized -
+ * deserialized object
+ */
+ void assertDeserialized(Serializable initial, Serializable deserialized);
+ }
+
+ // default comparator for a class that has equals(Object) method
+ private final static SerializableAssert DEFAULT_COMPARATOR = new SerializableAssert() {
+ public void assertDeserialized(Serializable initial,
+ Serializable deserialized) {
+
+ Assert.assertEquals(initial, deserialized);
+ }
+ };
+
+ /**
+ * Comparator for verifying that deserialized object is the same as initial.
+ */
+ public final static SerializableAssert SAME_COMPARATOR = new SerializableAssert() {
+ public void assertDeserialized(Serializable initial,
+ Serializable deserialized) {
+
+ Assert.assertSame(initial, deserialized);
+ }
+ };
+
+ /**
+ * Comparator for java.lang.Throwable objects
+ */
+ public final static SerializableAssert THROWABLE_COMPARATOR = new SerializableAssert() {
+ public void assertDeserialized(Serializable initial, Serializable deserialized) {
+
+ Throwable initThr = (Throwable) initial;
+ Throwable dserThr = (Throwable) deserialized;
+
+ // verify class
+ Assert.assertEquals(initThr.getClass(), dserThr.getClass());
+
+ // verify message
+ Assert.assertEquals(initThr.getMessage(), dserThr.getMessage());
+
+ // verify cause
+ if (initThr.getCause() == null) {
+ Assert.assertNull(dserThr.getCause());
+ } else {
+ Assert.assertNotNull(dserThr.getCause());
+
+ THROWABLE_COMPARATOR.assertDeserialized(initThr.getCause(),
+ dserThr.getCause());
+ }
+ }
+ };
+
+ /**
+ * Comparator for java.security.PermissionCollection objects
+ */
+ public final static SerializableAssert PERMISSION_COLLECTION_COMPARATOR = new SerializableAssert() {
+ public void assertDeserialized(Serializable initial, Serializable deserialized) {
+
+ PermissionCollection initPC = (PermissionCollection) initial;
+ PermissionCollection dserPC = (PermissionCollection) deserialized;
+
+ // verify class
+ Assert.assertEquals(initPC.getClass(), dserPC.getClass());
+
+ // verify 'readOnly' field
+ Assert.assertEquals(initPC.isReadOnly(), dserPC.isReadOnly());
+
+ // verify collection of permissions
+ Collection<Permission> refCollection = new HashSet<Permission>(
+ Collections.list(initPC.elements()));
+ Collection<Permission> tstCollection = new HashSet<Permission>(
+ Collections.list(dserPC.elements()));
+
+ Assert.assertEquals(refCollection, tstCollection);
+ }
+ };
+
+ /**
+ * Returns <code>comparator</code> for provided serializable
+ * <code>object</code>.
+ *
+ * The <code>comparator</code> is searched in the following order: <br>-
+ * if <code>test</code> implements SerializableAssert interface then it is
+ * selected as </code>comparator</code>.<br>- if passed <code>object</code>
+ * has class in its classes hierarchy that overrides <code>equals(Object)</code>
+ * method then <code>DEFAULT_COMPARATOR</code> is selected.<br> - the
+ * method tries to select one of known comparators basing on <code>object's</code>
+ * class,for example, if passed <code>object</code> is instance of
+ * java.lang.Throwable then <code>THROWABLE_COMPARATOR</code> is used.<br>-
+ * otherwise RuntimeException is thrown
+ *
+ * @param test -
+ * test case
+ * @param object -
+ * object to be compared
+ * @return object's comparator
+ */
+ public static SerializableAssert defineComparator(TestCase test,
+ Object object) throws Exception {
+
+ if (test instanceof SerializableAssert) {
+ return (SerializableAssert) test;
+ }
+
+ Method m = object.getClass().getMethod("equals",
+ new Class[] { Object.class });
+
+ if (m.getDeclaringClass() != Object.class) {
+ // one of classes overrides Object.equals(Object) method
+ // use default comparator
+ return DEFAULT_COMPARATOR;
+ }
+
+ // TODO use generics to detect comparator
+ // instead of 'instanceof' for the first element
+ if (object instanceof java.lang.Throwable) {
+ return THROWABLE_COMPARATOR;
+ } else if (object instanceof java.security.PermissionCollection) {
+ return PERMISSION_COLLECTION_COMPARATOR;
+ }
+
+ throw new RuntimeException("Failed to detect comparator");
+ }
+
+ /**
+ * Verifies that object deserialized from golden file correctly.
+ *
+ * The method invokes <br>
+ * verifyGolden(test, object, defineComparator(test, object));
+ *
+ * @param test -
+ * test case
+ * @param object -
+ * to be compared
+ */
+ public static void verifyGolden(TestCase test, Object object)
+ throws Exception {
+
+ verifyGolden(test, object, defineComparator(test, object));
+ }
+
+ /**
+ * Verifies that object deserialized from golden file correctly.
+ *
+ * The method loads "<code>testName</code>.golden.ser" resource file
+ * from "<module root>/src/test/resources/serialization/<code>testPackage</code>"
+ * folder, reads an object from the loaded file and compares it with
+ * <code>object</code> using specified <code>comparator</code>.
+ *
+ * @param test-
+ * test case
+ * @param object-
+ * to be compared
+ * @param comparator -
+ * for comparing (de)serialized objects
+ */
+ public static void verifyGolden(TestCase test, Object object,
+ SerializableAssert comparator) throws Exception {
+
+ Assert.assertNotNull("Null comparator", comparator);
+
+ Serializable deserialized = getObject(test, ".golden.ser");
+
+ comparator.assertDeserialized((Serializable) object, deserialized);
+ }
+
+ /**
+ * Verifies that objects from array deserialized from golden files
+ * correctly.
+ *
+ * The method invokes <br>
+ * verifyGolden(test, objects, defineComparator(test, object[0]));
+ *
+ * @param test -
+ * test case
+ * @param objects -
+ * array of objects to be compared
+ */
+ public static void verifyGolden(TestCase test, Object[] objects)
+ throws Exception {
+
+ Assert.assertFalse("Empty array", objects.length == 0);
+ verifyGolden(test, objects, defineComparator(test, objects[0]));
+ }
+
+ /**
+ * Verifies that objects from array deserialized from golden files
+ * correctly.
+ *
+ * The method loads "<code>testName</code>.golden.<code>N</code>.ser"
+ * resource files from "<module root>/src/test/resources/serialization/<code>testPackage</code>"
+ * folder, from each loaded file it reads an object from and compares it
+ * with corresponding object in provided array (i.e. <code>objects[N]</code>)
+ * using specified <code>comparator</code>. (<code>N</code> is index
+ * in object's array.)
+ *
+ * @param test-
+ * test case
+ * @param objects -
+ * array of objects to be compared
+ * @param comparator -
+ * for comparing (de)serialized objects
+ */
+ public static void verifyGolden(TestCase test, Object[] objects,
+ SerializableAssert comparator) throws Exception {
+
+ Assert.assertFalse("Empty array", objects.length == 0);
+ for (int i = 0; i < objects.length; i++) {
+ Serializable deserialized = getObject(test, ".golden." + i + ".ser");
+ comparator.assertDeserialized((Serializable) objects[i],
+ deserialized);
+ }
+ }
+
+ /**
+ * Verifies that object can be smoothly serialized/deserialized.
+ *
+ * The method invokes <br>
+ * verifySelf(object, defineComparator(null, object));
+ *
+ * @param object -
+ * to be serialized/deserialized
+ */
+ public static void verifySelf(Object object)
+ throws Exception {
+
+ verifySelf(object, defineComparator(null, object));
+ }
+
+ /**
+ * Verifies that object can be smoothly serialized/deserialized.
+ *
+ * The method serialize/deserialize <code>object</code> and compare it
+ * with initial <code>object</code>.
+ *
+ * @param object -
+ * object to be serialized/deserialized
+ * @param comparator -
+ * for comparing serialized/deserialized object with initial
+ * object
+ */
+ public static void verifySelf(Object object, SerializableAssert comparator)
+ throws Exception {
+
+ Serializable initial = (Serializable) object;
+
+ comparator.assertDeserialized(initial, copySerializable(initial));
+ }
+
+ /**
+ * Verifies that that objects from array can be smoothly
+ * serialized/deserialized.
+ *
+ * The method invokes <br>
+ * verifySelf(objects, defineComparator(null, object[0]));
+ *
+ * @param objects -
+ * array of objects to be serialized/deserialized
+ */
+ public static void verifySelf(Object[] objects)
+ throws Exception {
+
+ Assert.assertFalse("Empty array", objects.length == 0);
+ verifySelf(objects, defineComparator(null, objects[0]));
+ }
+
+ /**
+ * Verifies that that objects from array can be smoothly
+ * serialized/deserialized.
+ *
+ * The method serialize/deserialize each object in <code>objects</code>
+ * array and compare it with initial object.
+ *
+ * @param objects -
+ * array of objects to be serialized/deserialized
+ * @param comparator -
+ * for comparing serialized/deserialized object with initial
+ * object
+ */
+ public static void verifySelf(Object[] objects, SerializableAssert comparator)
+ throws Exception {
+
+ Assert.assertFalse("Empty array", objects.length == 0);
+ for(Object entry: objects){
+ verifySelf(entry, comparator);
+ }
+ }
+
+ private static Serializable getObject(TestCase test, String toAppend)
+ throws Exception {
+
+ StringBuilder path = new StringBuilder("serialization");
+
+ path.append(File.separatorChar);
+ path.append(test.getClass().getName().replace('.', File.separatorChar));
+ path.append(toAppend);
+
+ InputStream in = ClassLoader.getSystemClassLoader()
+ .getResourceAsStream(path.toString());
+
+ Assert.assertNotNull("Failed to load serialization resource file: "
+ + path, in);
+
+ return getObjectFromStream(in);
+ }
+
+ /**
+ * Creates golden file.
+ *
+ * The folder for created file is: <code>root + test's package name</code>.
+ * The file name is: <code>test's name + "golden.ser"</code>
+ *
+ * @param root -
+ * root directory for serialization resource files
+ * @param test -
+ * test case
+ * @param object -
+ * object to be serialized
+ * @throws IOException -
+ * if I/O error
+ */
+ public static void createGoldenFile(String root, TestCase test,
+ Object object) throws IOException {
+
+ String goldenPath = test.getClass().getName().replace('.',
+ File.separatorChar)
+ + ".golden.ser";
+
+ if (root != null) {
+ goldenPath = root + File.separatorChar + goldenPath;
+ }
+
+
+ File goldenFile = new File(goldenPath);
+ goldenFile.getParentFile().mkdirs();
+ goldenFile.createNewFile();
+
+ putObjectToStream(object, new FileOutputStream(goldenFile));
+
+ // don't forget to remove it from test case after using
+ Assert.fail("Generating golden file.\nGolden file name:"
+ + goldenFile.getAbsolutePath());
+ }
+
+ /**
+ * Copies an object by serializing/deserializing it.
+ *
+ * @param initial -
+ * an object to be copied
+ * @return copy of provided object
+ */
+ public static Serializable copySerializable(Serializable initial)
+ throws IOException, ClassNotFoundException {
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ putObjectToStream(initial, out);
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+ return getObjectFromStream(in);
+ }
+}
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
new file mode 100644
index 0000000..0c16029
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/xnet/tests/support/MyKeyManagerFactorySpi.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xnet.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactorySpi;
+import javax.net.ssl.ManagerFactoryParameters;
+
+/**
+ * Class for verification KeyManagerFactorySpi and KeyManagerFactory
+ * functionality
+ *
+ */
+
+public class MyKeyManagerFactorySpi extends KeyManagerFactorySpi {
+
+ protected void engineInit(KeyStore ks, char[] password)
+ throws KeyStoreException, NoSuchAlgorithmException,
+ UnrecoverableKeyException {
+ if (password == null) {
+ throw new KeyStoreException("Incorrect password");
+ }
+ if (ks == null) {
+ throw new UnrecoverableKeyException("Incorrect keystore");
+ }
+ }
+
+ protected void engineInit(ManagerFactoryParameters spec)
+ throws InvalidAlgorithmParameterException {
+ if (spec == null) {
+ throw new InvalidAlgorithmParameterException("Incorrect parameter");
+ }
+ if (spec instanceof Parameters) {
+ try {
+ engineInit(((Parameters)spec).getKeyStore(),
+ ((Parameters)spec).getPassword());
+ } catch (Exception e) {
+ throw new InvalidAlgorithmParameterException(e.toString());
+ }
+ } else {
+ throw new InvalidAlgorithmParameterException("Invalid parameter");
+ }
+ }
+
+ protected KeyManager[] engineGetKeyManagers() {
+ return null;
+ }
+ public static class Parameters implements ManagerFactoryParameters {
+ private KeyStore keyStore;
+ private char[] passWD;
+ public Parameters (KeyStore ks, char[] pass) {
+ this.keyStore = ks;
+ this.passWD = pass;
+ }
+ public KeyStore getKeyStore() {
+ return keyStore;
+ }
+ public char[] getPassword() {
+ return passWD;
+ }
+ }}
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
new file mode 100644
index 0000000..fcf1d92
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/xnet/tests/support/MySSLContextSpi.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xnet.tests.support;
+
+import java.nio.ByteBuffer;
+import java.security.KeyManagementException;
+import java.security.SecureRandom;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContextSpi;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLEngineResult;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
+/**
+ * Additional class for verification of SSLContextSpi and SSLContext
+ * functionality
+ *
+ */
+
+public class MySSLContextSpi extends SSLContextSpi {
+ private boolean init = false;
+ protected void engineInit(KeyManager[] km, TrustManager[] tm,
+ SecureRandom sr) throws KeyManagementException {
+ if (sr == null) {
+ throw new KeyManagementException(
+ "secureRandom is null");
+ }
+ init = true;
+ }
+
+ protected SSLSocketFactory engineGetSocketFactory() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ };
+ return null;
+ }
+
+ protected SSLServerSocketFactory engineGetServerSocketFactory() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ protected SSLSessionContext engineGetServerSessionContext() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ protected SSLSessionContext engineGetClientSessionContext() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return null;
+ }
+
+ /*
+ * FIXME: add these methods
+ */
+ protected SSLEngine engineCreateSSLEngine(String host, int port) {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return new tmpSSLEngine(host, port);
+ }
+
+ protected SSLEngine engineCreateSSLEngine() {
+ if (!init) {
+ throw new RuntimeException("Not initialiazed");
+ }
+ return new tmpSSLEngine();
+ }
+
+ public class tmpSSLEngine extends SSLEngine {
+ String tmpHost;
+ int tmpPort;
+ public tmpSSLEngine() {
+ tmpHost = null;
+ tmpPort = 0;
+ }
+ public tmpSSLEngine(String host, int port) {
+ tmpHost = host;
+ tmpPort = port;
+ }
+ public String getPeerHost() {
+ return tmpHost;
+ }
+ public int getPeerPort() {
+ return tmpPort;
+ }
+ public void beginHandshake() throws SSLException { }
+ public void closeInbound() throws SSLException { }
+ public void closeOutbound() {}
+ public Runnable getDelegatedTask() { return null; }
+ public String[] getEnabledCipherSuites() { return null; }
+ public String[] getEnabledProtocols() {return null; }
+ public boolean getEnableSessionCreation() { return true; }
+ public SSLEngineResult.HandshakeStatus getHandshakeStatus() { return null; };
+ public boolean getNeedClientAuth() { return true; }
+ public SSLSession getSession() { return null; }
+ public String[] getSupportedCipherSuites() { return null; }
+ public String[] getSupportedProtocols() { return null; }
+ public boolean getUseClientMode() { return true; }
+ public boolean getWantClientAuth() { return true; }
+ public boolean isInboundDone() { return true; }
+ public boolean isOutboundDone() { return true; }
+ public void setEnabledCipherSuites(String[] suites) { }
+ public void setEnabledProtocols(String[] protocols) { }
+ public void setEnableSessionCreation(boolean flag) { }
+ public void setNeedClientAuth(boolean need) { }
+ public void setUseClientMode(boolean mode) { }
+ public void setWantClientAuth(boolean want) { }
+ public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts,
+ int offset, int length) throws SSLException {
+ return null;
+ }
+ public SSLEngineResult wrap(ByteBuffer[] srcs, int offset,
+ int length, ByteBuffer dst) throws SSLException {
+ return null;
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java b/support/src/test/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
new file mode 100644
index 0000000..6a6c1ba
--- /dev/null
+++ b/support/src/test/java/org/apache/harmony/xnet/tests/support/MyTrustManagerFactorySpi.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xnet.tests.support;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactorySpi;
+
+/**
+ * Class for vertifying TrustManagerFactorySpi and TrustManagerFactory
+ * functionality
+ *
+ */
+
+public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
+ protected void engineInit(KeyStore ks) throws KeyStoreException {
+ if (ks == null) {
+ throw new KeyStoreException("Not supported operation for null KeyStore");
+ }
+ }
+
+ protected void engineInit(ManagerFactoryParameters spec)
+ throws InvalidAlgorithmParameterException {
+ if (spec == null) {
+ throw new InvalidAlgorithmParameterException("Null parameter");
+ }
+ if (spec instanceof Parameters) {
+ try {
+ engineInit(((Parameters)spec).getKeyStore());
+ } catch (KeyStoreException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ throw new InvalidAlgorithmParameterException("Invalid parameter");
+ }
+ }
+
+ protected TrustManager[] engineGetTrustManagers() {
+ return null;
+ }
+
+
+ public static class Parameters implements ManagerFactoryParameters {
+ private KeyStore keyStore;
+ public Parameters (KeyStore ks) {
+ this.keyStore = ks;
+ }
+ public KeyStore getKeyStore() {
+ return keyStore;
+ }
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/tests/resources/Created_by_1_4.jar b/support/src/test/java/tests/resources/Created_by_1_4.jar
new file mode 100644
index 0000000..7a924a2
--- /dev/null
+++ b/support/src/test/java/tests/resources/Created_by_1_4.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz b/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz
new file mode 100644
index 0000000..e0f5a00
--- /dev/null
+++ b/support/src/test/java/tests/resources/GZIPInputStream/hyts_gInput.txt.gz
Binary files differ
diff --git a/support/src/test/java/tests/resources/Harmony.GIF b/support/src/test/java/tests/resources/Harmony.GIF
new file mode 100644
index 0000000..be2dc56
--- /dev/null
+++ b/support/src/test/java/tests/resources/Harmony.GIF
Binary files differ
diff --git a/support/src/test/java/tests/resources/Inserted_Entry_Manifest.jar b/support/src/test/java/tests/resources/Inserted_Entry_Manifest.jar
new file mode 100644
index 0000000..154d8d6
--- /dev/null
+++ b/support/src/test/java/tests/resources/Inserted_Entry_Manifest.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar b/support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar
new file mode 100644
index 0000000..a94ae49
--- /dev/null
+++ b/support/src/test/java/tests/resources/Inserted_Entry_Manifest_with_DigestCode.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Integrate.jar b/support/src/test/java/tests/resources/Integrate.jar
new file mode 100644
index 0000000..16e9c55
--- /dev/null
+++ b/support/src/test/java/tests/resources/Integrate.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_11.jar b/support/src/test/java/tests/resources/JarIndex/hyts_11.jar
new file mode 100644
index 0000000..19cf5f2
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_11.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_12.jar b/support/src/test/java/tests/resources/JarIndex/hyts_12.jar
new file mode 100644
index 0000000..236659b
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_12.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_13.jar b/support/src/test/java/tests/resources/JarIndex/hyts_13.jar
new file mode 100644
index 0000000..9ea6806
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_13.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_14.jar b/support/src/test/java/tests/resources/JarIndex/hyts_14.jar
new file mode 100644
index 0000000..d8bc44b
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_14.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_21.jar b/support/src/test/java/tests/resources/JarIndex/hyts_21.jar
new file mode 100644
index 0000000..c25d4bf
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_21.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_22-new.jar b/support/src/test/java/tests/resources/JarIndex/hyts_22-new.jar
new file mode 100644
index 0000000..542c22a
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_22-new.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_22.jar b/support/src/test/java/tests/resources/JarIndex/hyts_22.jar
new file mode 100644
index 0000000..84c7af0
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_22.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_23.jar b/support/src/test/java/tests/resources/JarIndex/hyts_23.jar
new file mode 100644
index 0000000..a932052
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_23.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_31.jar b/support/src/test/java/tests/resources/JarIndex/hyts_31.jar
new file mode 100644
index 0000000..ab696964
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_31.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_32.jar b/support/src/test/java/tests/resources/JarIndex/hyts_32.jar
new file mode 100644
index 0000000..12de6bb
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_32.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_33.jar b/support/src/test/java/tests/resources/JarIndex/hyts_33.jar
new file mode 100644
index 0000000..086e494
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_33.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_41.jar b/support/src/test/java/tests/resources/JarIndex/hyts_41.jar
new file mode 100644
index 0000000..fb71bf8
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_41.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/JarIndex/hyts_42.jar b/support/src/test/java/tests/resources/JarIndex/hyts_42.jar
new file mode 100644
index 0000000..06a35cd
--- /dev/null
+++ b/support/src/test/java/tests/resources/JarIndex/hyts_42.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Modified_Class.jar b/support/src/test/java/tests/resources/Modified_Class.jar
new file mode 100644
index 0000000..d8113c7
--- /dev/null
+++ b/support/src/test/java/tests/resources/Modified_Class.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jar b/support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jar
new file mode 100644
index 0000000..bd1dbb1
--- /dev/null
+++ b/support/src/test/java/tests/resources/Modified_Manifest_EntryAttributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jar b/support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jar
new file mode 100644
index 0000000..5bc60e6
--- /dev/null
+++ b/support/src/test/java/tests/resources/Modified_Manifest_MainAttributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jar b/support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jar
new file mode 100644
index 0000000..7b76694
--- /dev/null
+++ b/support/src/test/java/tests/resources/Modified_SF_EntryAttributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_all_attributes.jar b/support/src/test/java/tests/resources/Package/hyts_all_attributes.jar
new file mode 100644
index 0000000..bde3f4d
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_all_attributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_c.jar b/support/src/test/java/tests/resources/Package/hyts_c.jar
new file mode 100644
index 0000000..111f73c
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_c.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_no_attributes.jar b/support/src/test/java/tests/resources/Package/hyts_no_attributes.jar
new file mode 100644
index 0000000..1879acb
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_no_attributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_no_entry.jar b/support/src/test/java/tests/resources/Package/hyts_no_entry.jar
new file mode 100644
index 0000000..66090a5
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_no_entry.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_pq.jar b/support/src/test/java/tests/resources/Package/hyts_pq.jar
new file mode 100644
index 0000000..5919f6c
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_pq.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/Package/hyts_some_attributes.jar b/support/src/test/java/tests/resources/Package/hyts_some_attributes.jar
new file mode 100644
index 0000000..95c87a8
--- /dev/null
+++ b/support/src/test/java/tests/resources/Package/hyts_some_attributes.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/TestCodeSigners.jar b/support/src/test/java/tests/resources/TestCodeSigners.jar
new file mode 100644
index 0000000..a4c42aa
--- /dev/null
+++ b/support/src/test/java/tests/resources/TestCodeSigners.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_Bar.ser b/support/src/test/java/tests/resources/hyts_Bar.ser
new file mode 100644
index 0000000..2802528
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_Bar.ser
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_Foo.ser b/support/src/test/java/tests/resources/hyts_Foo.ser
new file mode 100644
index 0000000..9f511ac
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_Foo.ser
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_PropertiesTest.properties b/support/src/test/java/tests/resources/hyts_PropertiesTest.properties
new file mode 100644
index 0000000..6c1b950
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_PropertiesTest.properties
@@ -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
diff --git a/support/src/test/java/tests/resources/hyts_ZipFile.zip b/support/src/test/java/tests/resources/hyts_ZipFile.zip
new file mode 100644
index 0000000..f9cd6ed
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_ZipFile.zip
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_att.jar b/support/src/test/java/tests/resources/hyts_att.jar
new file mode 100644
index 0000000..7f4530c
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_att.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_available.tst b/support/src/test/java/tests/resources/hyts_available.tst
new file mode 100644
index 0000000..d67b2f4
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_available.tst
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_checkInput.txt b/support/src/test/java/tests/resources/hyts_checkInput.txt
new file mode 100644
index 0000000..6d49d33
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_checkInput.txt
@@ -0,0 +1,4 @@
+ crc.reset();
+ crc.update(1);
+ //System.out.print("value of crc"+crc.getValue());
+ \ No newline at end of file
diff --git a/support/src/test/java/tests/resources/hyts_compDiction.txt b/support/src/test/java/tests/resources/hyts_compDiction.txt
new file mode 100644
index 0000000..f0478c8
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_compDiction.txt
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_compressD.txt b/support/src/test/java/tests/resources/hyts_compressD.txt
new file mode 100644
index 0000000..36c89f2
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_compressD.txt
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_constru_O.txt b/support/src/test/java/tests/resources/hyts_constru_O.txt
new file mode 100644
index 0000000..b6bd7b4
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_constru_O.txt
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_constru_OD.txt b/support/src/test/java/tests/resources/hyts_constru_OD.txt
new file mode 100644
index 0000000..035d12e
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_constru_OD.txt
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_constru_ODI.txt b/support/src/test/java/tests/resources/hyts_constru_ODI.txt
new file mode 100644
index 0000000..1e5d284
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_constru_ODI.txt
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_htmltest.html b/support/src/test/java/tests/resources/hyts_htmltest.html
new file mode 100644
index 0000000..9464371
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_htmltest.html
@@ -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
diff --git a/support/src/test/java/tests/resources/hyts_mainClass.ser b/support/src/test/java/tests/resources/hyts_mainClass.ser
new file mode 100644
index 0000000..0421ba9
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_mainClass.ser
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_manifest1.jar b/support/src/test/java/tests/resources/hyts_manifest1.jar
new file mode 100644
index 0000000..fb292b2
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_manifest1.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_missingclass.ser b/support/src/test/java/tests/resources/hyts_missingclass.ser
new file mode 100644
index 0000000..0a71403
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_missingclass.ser
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_patch.jar b/support/src/test/java/tests/resources/hyts_patch.jar
new file mode 100644
index 0000000..f3c51d0
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_patch.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_patch2.jar b/support/src/test/java/tests/resources/hyts_patch2.jar
new file mode 100644
index 0000000..c26f9e7
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_patch2.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_resource.properties b/support/src/test/java/tests/resources/hyts_resource.properties
new file mode 100644
index 0000000..a172a3e
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_resource.properties
@@ -0,0 +1,2 @@
+property=parent
+ \ No newline at end of file
diff --git a/support/src/test/java/tests/resources/hyts_security.jar b/support/src/test/java/tests/resources/hyts_security.jar
new file mode 100644
index 0000000..abef675
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_security.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/hyts_signed.jar b/support/src/test/java/tests/resources/hyts_signed.jar
new file mode 100644
index 0000000..8ea8489
--- /dev/null
+++ b/support/src/test/java/tests/resources/hyts_signed.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF b/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF
new file mode 100644
index 0000000..2402bca
--- /dev/null
+++ b/support/src/test/java/tests/resources/manifest/hyts_MANIFEST.MF
@@ -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
diff --git a/support/src/test/java/tests/resources/morestuff/hyts_patch.jar b/support/src/test/java/tests/resources/morestuff/hyts_patch.jar
new file mode 100644
index 0000000..f3c51d0
--- /dev/null
+++ b/support/src/test/java/tests/resources/morestuff/hyts_patch.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar b/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar
new file mode 100644
index 0000000..c26f9e7
--- /dev/null
+++ b/support/src/test/java/tests/resources/morestuff/hyts_patch2.jar
Binary files differ
diff --git a/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties b/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties
new file mode 100644
index 0000000..bf06f97
--- /dev/null
+++ b/support/src/test/java/tests/resources/subfolder/tests/resources/hyts_resource.properties
@@ -0,0 +1,2 @@
+property=resource
+ \ No newline at end of file
diff --git a/support/src/test/java/tests/support/Support_BitSet.java b/support/src/test/java/tests/support/Support_BitSet.java
new file mode 100644
index 0000000..2adbb9f
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_BitSet.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+ }
+ 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.
+ */
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(bits.length / 2);
+ int bitCount = 0;
+ sb.append('{');
+ boolean comma = false;
+ for (long element : bits) {
+ if (element == 0) {
+ bitCount += ELM_SIZE;
+ continue;
+ }
+ for (int j = 0; j < ELM_SIZE; j++) {
+ if (((element & (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;
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_CollectionTest.java b/support/src/test/java/tests/support/Support_CollectionTest.java
new file mode 100644
index 0000000..791222d
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_CollectionTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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<Integer> col; // must contain the Integers 0 to 99
+
+ public Support_CollectionTest(String p1) {
+ super(p1);
+ }
+
+ public Support_CollectionTest(String p1, Collection<Integer> c) {
+ super(p1);
+ col = c;
+ }
+
+ @Override
+ public void runTest() {
+ new Support_UnmodifiableCollectionTest("", col).runTest();
+
+ // setup
+ Collection<Integer> myCollection = new TreeSet<Integer>();
+ 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)));
+
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_Configuration.java b/support/src/test/java/tests/support/Support_Configuration.java
new file mode 100644
index 0000000..03d98a7
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Configuration.java
@@ -0,0 +1,484 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 = "Jetty(6.0.x)";
+
+ 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";
+
+ // BEGIN android-added
+ public static byte[] InetTestAddr = {127, 0, 0, 1};
+ // END android-added
+
+ 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) {}
+ */
+
+ // BEGIN android-changed
+ /**
+ * An address that resolves to more than one IP address so that the
+ * getAllByName test has something to test.
+ */
+ public static String SpecialInetTestAddress = "www.google.com";
+ // changed from jcltestmultiple.apache.org to www.google.com since
+ // the old address vaished from the net. www.google.com has also more
+ // than one addresses returned for this host name as needed by a test
+ // END android-changed
+
+ 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<String, String> props = null;
+ static {
+ loadProperties();
+ HomeAddress = WebName + DomainAddress;
+ TestResources = HomeAddress + TestResourcesDir;
+ }
+
+ static void loadProperties() {
+ InputStream in = null;
+ Hashtable<String, String> props = new Hashtable<String, String>();
+
+ 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) {
+ load(in, props);
+ }
+ } catch (IOException e) {
+ }
+ if (props.size() == 0) {
+ return;
+ }
+ String value;
+
+ value = props.get("DomainAddress");
+ if (value != null) {
+ DomainAddress = value;
+ }
+
+ value = props.get("WebName");
+ if (value != null) {
+ WebName = value;
+ }
+
+ value = props.get("TestResourcesDir");
+ if (value != null) {
+ TestResourcesDir = value;
+ }
+ value = props.get("HomeAddressResponse");
+ if (value != null) {
+ HomeAddressResponse = value;
+ }
+
+ value = props.get("HomeAddressSoftware");
+ if (value != null) {
+ HomeAddressSoftware = value;
+ }
+
+ value = props.get("ProxyServerTestHost");
+ if (value != null) {
+ ProxyServerTestHost = value;
+ }
+
+ value = props.get("SocksServerTestHost");
+ if (value != null) {
+ SocksServerTestHost = value;
+ }
+
+ value = props.get("SocksServerTestPort");
+ if (value != null) {
+ SocksServerTestPort = Integer.parseInt(value);
+ }
+
+ value = props.get("UnresolvedIP");
+ if (value != null) {
+ UnresolvedIP = value;
+ }
+
+ value = props.get("InetTestAddress");
+ if (value != null) {
+ InetTestAddress = value;
+ }
+
+ value = 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 = 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 = props.get("InetTestAddress2");
+ if (value != null) {
+ InetTestAddress2 = value;
+ }
+
+ value = props.get("InetTestIP2");
+ if (value != null) {
+ InetTestIP2 = value;
+ }
+
+ value = props.get("InetTestHashcode");
+ if (value != null) {
+ InetTestHashcode = Integer.parseInt(value);
+ }
+
+ value = props.get("SpecialInetTestAddress");
+ if (value != null) {
+ SpecialInetTestAddress = value;
+ }
+
+ value = props.get("SpecialInetTestAddressNumber");
+ if (value != null) {
+ SpecialInetTestAddressNumber = Integer.parseInt(value);
+ }
+
+ value = props.get("FTPTestAddress");
+ if (value != null) {
+ FTPTestAddress = value;
+ }
+
+ value = props.get("URLConnectionLastModifiedString");
+ if (value != null) {
+ URLConnectionLastModifiedString = value;
+ }
+
+ value = props.get("URLConnectionLastModified");
+ if (value != null) {
+ URLConnectionLastModified = Long.parseLong(value);
+ }
+
+ value = props.get("URLConnectionDate");
+ if (value != null) {
+ URLConnectionDate = Long.parseLong(value);
+ }
+
+ value = props.get("Port1");
+ if (value != null) {
+ Port1 = value;
+ }
+
+ value = props.get("Port2");
+ if (value != null) {
+ Port2 = value;
+ }
+
+ value = props.get("InetTestIP6");
+ if (value != null) {
+ InetTestIP6 = value;
+ }
+
+ value = props.get("InetTestIP6LO");
+ if (value != null) {
+ InetTestIP6LO = value;
+ }
+
+ value = props.get("ProxyServerTestHostIPv6");
+ if (value != null) {
+ ProxyServerTestHostIPv6 = value;
+ }
+
+ value = props.get("ResolvedNotExistingHost");
+ if (value != null) {
+ ResolvedNotExistingHost = value;
+ }
+
+ value = props.get("InetAlias1");
+ if (value != null) {
+ InetAlias1 = value;
+ }
+
+ value = props.get("InetAlias2");
+ if (value != null) {
+ InetAlias2 = value;
+ }
+
+ value = props.get("IPv6GlobalAddressJcl4");
+ if (value != null) {
+ IPv6GlobalAddressJcl4 = value;
+ }
+
+ }
+
+ static void load(InputStream in, Hashtable<String, String> 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());
+ }
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_DecimalFormat.java b/support/src/test/java/tests/support/Support_DecimalFormat.java
new file mode 100644
index 0000000..6fd9f0a
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_DecimalFormat.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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);
+ }
+
+ @Override
+ 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<FieldContainer> getNumberVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getPositiveCurrencyVectorTR() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNegativeCurrencyVectorTR() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getPositiveCurrencyVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getNegativeCurrencyVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getPercentVectorUS() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getPermilleVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE));
+ return v;
+ }
+
+ private static Vector<FieldContainer> getNegativeExponentVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getPositiveExponentVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getNumberVector2US() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ 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<FieldContainer> getZeroVector() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_Exec.java b/support/src/test/java/tests/support/Support_Exec.java
new file mode 100644
index 0000000..8ca01e8
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Exec.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import junit.framework.TestCase;
+
+public class Support_Exec extends TestCase {
+
+ /**
+ * This function returns the output of the process as a string
+ */
+ public static String execJava(String[] args, String[] classpath,
+ boolean displayOutput) throws IOException, InterruptedException {
+ Object[] arr =
+ execJavaCommon(args, classpath, null, displayOutput, true);
+
+ return getProcessOutput(arr, displayOutput);
+ }
+
+ /**
+ * This function returns the output of the process as a string
+ */
+ public static String execJava(String[] args, String[] classpath, String[] envp,
+ boolean displayOutput) throws IOException, InterruptedException {
+ Object[] arr =
+ execJavaCommon(args, classpath, envp, displayOutput, false);
+
+ return getProcessOutput(arr, displayOutput);
+ }
+
+ private static String getProcessOutput(Object[] arr, boolean displayOutput)
+ throws IOException, InterruptedException {
+ Process proc = (Process) arr[0];
+ StringBuilder output = new StringBuilder();
+ 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(arr);
+ proc.destroy();
+
+ return output.toString();
+ }
+
+ public static void checkStderr(Object[] execArgs) {
+ StringBuilder errBuf = (StringBuilder) execArgs[1];
+
+ synchronized (errBuf) {
+ if (errBuf.length() > 0) {
+ fail(errBuf.toString());
+ }
+ }
+ }
+
+ public static Object[] execJava2(String[] args, String[] classpath,
+ boolean displayOutput) throws IOException, InterruptedException {
+ return execJavaCommon(args, classpath, null, displayOutput, true);
+ }
+
+ private static Object[] execJavaCommon(String[] args, String[] classpath,
+ String[] envp, boolean displayOutput, boolean appendToSystemClassPath)
+ throws IOException, InterruptedException {
+ // this function returns the resulting process from the exec
+ ArrayList<String> execArgs = null;
+ StringBuilder classPathString = new StringBuilder();
+ StringBuilder command;
+ String executable;
+ String testVMArgs;
+ StringTokenizer st;
+
+ execArgs = new ArrayList<String>(3 + args.length);
+
+ // construct the name of executable file
+ executable = System.getProperty("java.home");
+ if (!executable.endsWith(File.separator)) {
+ executable += File.separator;
+ }
+ executable += "bin" + File.separator;
+ execArgs.add(executable + "java");
+
+ // add classpath string
+ if (classpath != null) {
+ for (String element : classpath) {
+ classPathString.append(File.pathSeparator);
+ classPathString.append(element);
+ }
+ }
+ if (appendToSystemClassPath) {
+ execArgs.add("-cp");
+ execArgs.add(System.getProperty("java.class.path") +
+ classPathString);
+ } else {
+ if (classpath != null) {
+ execArgs.add("-cp");
+ execArgs.add(classPathString.toString());
+ }
+ }
+
+ // parse hy.test.vmargs if was given
+ testVMArgs = System.getProperty("hy.test.vmargs");
+ if (testVMArgs != null) {
+ st = new StringTokenizer(testVMArgs, " ");
+
+ while (st.hasMoreTokens()) {
+ execArgs.add(st.nextToken());
+ }
+ }
+
+ // add custom args given as parameter
+ for (String arg : args) {
+ execArgs.add(arg);
+ }
+
+ // construct command line string and print it to stdout
+ //if (displayOutput) {
+ command = new StringBuilder(execArgs.get(0));
+ for (int i = 1; i < execArgs.size(); i++) {
+ command.append(" ");
+ command.append(execArgs.get(i));
+ }
+ System.out.println();
+ System.out.println("Exec: " + command.toString());
+ //}
+
+ // execute java process
+ final Process proc = Runtime.getRuntime().exec(
+ execArgs.toArray(new String[execArgs.size()]), envp);
+ final StringBuilder errBuf = new StringBuilder();
+ Thread errThread = new Thread(new Runnable() {
+ public void run() {
+ synchronized (errBuf) {
+ InputStream err;
+ int result;
+ byte[] bytes = new byte[1024];
+
+ synchronized (proc) {
+ proc.notifyAll();
+ }
+
+ err = proc.getErrorStream();
+ try {
+ while ((result = err.read(bytes)) != -1) {
+ System.err.write(bytes, 0, result);
+ errBuf.append(new String(bytes));
+ }
+ err.close();
+ } catch (IOException e) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintStream printer = new PrintStream(out);
+
+ e.printStackTrace();
+ 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 };
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_Field.java b/support/src/test/java/tests/support/Support_Field.java
new file mode 100644
index 0000000..07863fe
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Field.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
diff --git a/support/src/test/java/tests/support/Support_Format.java b/support/src/test/java/tests/support/Support_Format.java
new file mode 100644
index 0000000..2e50959
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Format.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+import junit.framework.TestCase;
+
+public class Support_Format extends TestCase {
+
+ protected String text;
+
+ 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<FieldContainer> expectedResults) {
+ // System.out.println(format.format(object));
+ Vector<FieldContainer> 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<FieldContainer> vector1, Vector<FieldContainer> 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<FieldContainer> findFields(AttributedCharacterIterator iterator) {
+ Vector<FieldContainer> result = new Vector<FieldContainer>();
+ while (iterator.getIndex() != iterator.getEndIndex()) {
+ int start = iterator.getRunStart();
+ int end = iterator.getRunLimit();
+
+ Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
+ while (it.hasNext()) {
+ AttributedCharacterIterator.Attribute 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;
+ }
+
+ @Override
+ 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));
+ }
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_GetLocal.java b/support/src/test/java/tests/support/Support_GetLocal.java
new file mode 100644
index 0000000..2d7acf7
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_GetLocal.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Hashtable;
+
+import tests.support.resource.Support_Resources;
+
+public class Support_GetLocal {
+
+ static Hashtable<String, File> cache = new Hashtable<String, File>(20);
+
+ public static File getLocalFile(String url) throws IOException,
+ MalformedURLException {
+ url = Support_Resources.RESOURCE_PACKAGE + url;
+ File temp = cache.get(url);
+ if (temp == null) {
+ InputStream in = Support_GetLocal.class.getResourceAsStream(url);
+ temp = File.createTempFile("hyts_local", ".tmp", null);
+ temp.deleteOnExit();
+ FileOutputStream out = new FileOutputStream(temp);
+ int result;
+ byte[] buf = new byte[4096];
+ while ((result = in.read(buf)) != -1) {
+ out.write(buf, 0, result);
+ }
+ in.close();
+ out.close();
+ cache.put(url, temp);
+ }
+ return temp;
+ }
+
+ public static File getExternalLocalFile(String url) throws IOException,
+ MalformedURLException {
+ File temp = cache.get(url);
+ if (temp == null) {
+ InputStream in = new URL(url).openStream();
+ temp = File.createTempFile("hyts_local", ".tmp", null);
+ temp.deleteOnExit();
+ FileOutputStream out = new FileOutputStream(temp);
+ int result;
+ byte[] buf = new byte[4096];
+ while ((result = in.read(buf)) != -1) {
+ out.write(buf, 0, result);
+ }
+ in.close();
+ out.close();
+ cache.put(url, temp);
+ }
+ return temp;
+ }
+
+ static ByteArrayInputStream getStream(String url) throws IOException,
+ MalformedURLException {
+ InputStream in = new URL(url).openStream();
+ ByteArrayOutputStream out = new ByteArrayOutputStream(256);
+ int result;
+ byte[] buf = new byte[256];
+ while ((result = in.read(buf)) != -1) {
+ out.write(buf, 0, result);
+ }
+ return new ByteArrayInputStream(out.toByteArray());
+ }
+
+ public static File createTempFile(String suffix) throws IOException {
+ return File.createTempFile("hyts_", suffix, null);
+ }
+
+ public static JarURLConnection getJarURLConnection() throws IOException {
+ JarURLConnection con1 = null;
+ File file = getLocalFile("hyts_att.jar");
+ URL fUrl1 = new URL("jar:file:" + file.getPath() + "!/");
+ con1 = (JarURLConnection) fUrl1.openConnection();
+ return con1;
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/tests/support/Support_ListTest.java b/support/src/test/java/tests/support/Support_ListTest.java
new file mode 100644
index 0000000..6e9160b
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_ListTest.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+public class Support_ListTest extends junit.framework.TestCase {
+
+ List<Integer> list; // must contain the Integers 0 to 99 in order
+
+ public Support_ListTest(String p1) {
+ super(p1);
+ }
+
+ public Support_ListTest(String p1, List<Integer> l) {
+ super(p1);
+ list = l;
+ }
+
+ @Override
+ public void runTest() {
+ int hashCode = 1;
+ for (int counter = 0; counter < 100; counter++) {
+ Object elem;
+ elem = list.get(counter);
+ hashCode = 31 * hashCode + elem.hashCode();
+ assertTrue("ListTest - get failed", elem
+ .equals(new Integer(counter)));
+ }
+ assertTrue("ListTest - hashCode failed", hashCode == list.hashCode());
+
+ list.add(50, new Integer(1000));
+ assertTrue("ListTest - a) add with index failed--did not insert", list
+ .get(50).equals(new Integer(1000)));
+ assertTrue(
+ "ListTest - b) add with index failed--did not move following elements",
+ list.get(51).equals(new Integer(50)));
+ assertTrue(
+ "ListTest - c) add with index failed--affected previous elements",
+ list.get(49).equals(new Integer(49)));
+
+ list.set(50, new Integer(2000));
+ assertTrue("ListTest - a) set failed--did not set", list.get(50)
+ .equals(new Integer(2000)));
+ assertTrue("ListTest - b) set failed--affected following elements",
+ list.get(51).equals(new Integer(50)));
+ assertTrue("ListTest - c) set failed--affected previous elements", list
+ .get(49).equals(new Integer(49)));
+
+ list.remove(50);
+ assertTrue("ListTest - a) remove with index failed--did not remove",
+ list.get(50).equals(new Integer(50)));
+ assertTrue(
+ "ListTest - b) remove with index failed--did not move following elements",
+ list.get(51).equals(new Integer(51)));
+ assertTrue(
+ "ListTest - c) remove with index failed--affected previous elements",
+ list.get(49).equals(new Integer(49)));
+
+ List<Integer> myList = new LinkedList<Integer>();
+ myList.add(new Integer(500));
+ myList.add(new Integer(501));
+ myList.add(new Integer(502));
+
+ list.addAll(50, myList);
+ assertTrue("ListTest - a) addAll with index failed--did not insert",
+ list.get(50).equals(new Integer(500)));
+ assertTrue("ListTest - b) addAll with index failed--did not insert",
+ list.get(51).equals(new Integer(501)));
+ assertTrue("ListTest - c) addAll with index failed--did not insert",
+ list.get(52).equals(new Integer(502)));
+ assertTrue(
+ "ListTest - d) addAll with index failed--did not move following elements",
+ list.get(53).equals(new Integer(50)));
+ assertTrue(
+ "ListTest - e) addAll with index failed--affected previous elements",
+ list.get(49).equals(new Integer(49)));
+
+ List<Integer> mySubList = list.subList(50, 53);
+ assertEquals(3, mySubList.size());
+ assertTrue(
+ "ListTest - a) sublist Failed--does not contain correct elements",
+ mySubList.get(0).equals(new Integer(500)));
+ assertTrue(
+ "ListTest - b) sublist Failed--does not contain correct elements",
+ mySubList.get(1).equals(new Integer(501)));
+ assertTrue(
+ "ListTest - c) sublist Failed--does not contain correct elements",
+ mySubList.get(2).equals(new Integer(502)));
+
+ t_listIterator(mySubList);
+
+ mySubList.clear();
+ assertEquals("ListTest - Clearing the sublist did not remove the appropriate elements from the original list",
+ 100, list.size());
+
+ t_listIterator(list);
+ ListIterator<Integer> li = list.listIterator();
+ for (int counter = 0; li.hasNext(); counter++) {
+ Object elem;
+ elem = li.next();
+ assertTrue("ListTest - listIterator failed", elem
+ .equals(new Integer(counter)));
+ }
+
+ new Support_CollectionTest("", list).runTest();
+
+ }
+
+ public void t_listIterator(List<Integer> list) {
+ ListIterator<Integer> li = list.listIterator(1);
+ assertTrue("listIterator(1)", li.next() == list.get(1));
+
+ int orgSize = list.size();
+ li = list.listIterator();
+ for (int i = 0; i <= orgSize; i++) {
+ if (i == 0) {
+ assertTrue("list iterator hasPrevious(): " + i, !li
+ .hasPrevious());
+ } else {
+ assertTrue("list iterator hasPrevious(): " + i, li
+ .hasPrevious());
+ }
+ if (i == list.size()) {
+ assertTrue("list iterator hasNext(): " + i, !li.hasNext());
+ } else {
+ assertTrue("list iterator hasNext(): " + i, li.hasNext());
+ }
+ assertTrue("list iterator nextIndex(): " + i, li.nextIndex() == i);
+ assertTrue("list iterator previousIndex(): " + i, li
+ .previousIndex() == i - 1);
+ boolean exception = false;
+ try {
+ assertTrue("list iterator next(): " + i, li.next() == list
+ .get(i));
+ } catch (NoSuchElementException e) {
+ exception = true;
+ }
+ if (i == list.size()) {
+ assertTrue("list iterator next() exception: " + i, exception);
+ } else {
+ assertTrue("list iterator next() exception: " + i, !exception);
+ }
+ }
+
+ for (int i = orgSize - 1; i >= 0; i--) {
+ assertTrue("list iterator previous(): " + i, li.previous() == list
+ .get(i));
+ assertTrue("list iterator nextIndex()2: " + i, li.nextIndex() == i);
+ assertTrue("list iterator previousIndex()2: " + i, li
+ .previousIndex() == i - 1);
+ if (i == 0) {
+ assertTrue("list iterator hasPrevious()2: " + i, !li
+ .hasPrevious());
+ } else {
+ assertTrue("list iterator hasPrevious()2: " + i, li
+ .hasPrevious());
+ }
+ assertTrue("list iterator hasNext()2: " + i, li.hasNext());
+ }
+ boolean exception = false;
+ try {
+ li.previous();
+ } catch (NoSuchElementException e) {
+ exception = true;
+ }
+ assertTrue("list iterator previous() exception", exception);
+
+ Integer add1 = new Integer(600);
+ Integer add2 = new Integer(601);
+ li.add(add1);
+ assertTrue("list iterator add(), size()", list.size() == (orgSize + 1));
+ assertEquals("list iterator add(), nextIndex()", 1, li.nextIndex());
+ assertEquals("list iterator add(), previousIndex()",
+ 0, li.previousIndex());
+ Object next = li.next();
+ assertTrue("list iterator add(), next(): " + next, next == list.get(1));
+ li.add(add2);
+ Object previous = li.previous();
+ assertTrue("list iterator add(), previous(): " + previous,
+ previous == add2);
+ assertEquals("list iterator add(), nextIndex()2", 2, li.nextIndex());
+ assertEquals("list iterator add(), previousIndex()2",
+ 1, li.previousIndex());
+
+ li.remove();
+ assertTrue("list iterator remove(), size()",
+ list.size() == (orgSize + 1));
+ assertEquals("list iterator remove(), nextIndex()", 2, li.nextIndex());
+ assertEquals("list iterator remove(), previousIndex()", 1, li
+ .previousIndex());
+ assertTrue("list iterator previous()2", li.previous() == list.get(1));
+ assertTrue("list iterator previous()3", li.previous() == list.get(0));
+ assertTrue("list iterator next()2", li.next() == list.get(0));
+ li.remove();
+ assertTrue("list iterator hasPrevious()3", !li.hasPrevious());
+ assertTrue("list iterator hasNext()3", li.hasNext());
+ assertTrue("list iterator size()", list.size() == orgSize);
+ assertEquals("list iterator nextIndex()3", 0, li.nextIndex());
+ assertEquals("list iterator previousIndex()3", -1, li.previousIndex());
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_MapTest2.java b/support/src/test/java/tests/support/Support_MapTest2.java
new file mode 100644
index 0000000..217b198
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_MapTest2.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Map;
+import junit.framework.TestCase;
+
+public class Support_MapTest2 extends TestCase {
+
+ Map<String, String> map;
+
+ public Support_MapTest2(Map<String, String> m) {
+ super();
+ map = m;
+ if (!map.isEmpty()) {
+ fail("Map must be empty");
+ }
+ }
+
+ @Override
+ public void runTest() {
+ try {
+ map.put("one", "1");
+ assertEquals("size should be one", 1, map.size());
+ map.clear();
+ assertEquals("size should be zero", 0, map.size());
+ assertTrue("Should not have entries", !map.entrySet().iterator()
+ .hasNext());
+ assertTrue("Should not have keys", !map.keySet().iterator()
+ .hasNext());
+ assertTrue("Should not have values", !map.values().iterator()
+ .hasNext());
+ } catch (UnsupportedOperationException e) {
+ }
+
+ try {
+ map.put("one", "1");
+ assertEquals("size should be one", 1, map.size());
+ map.remove("one");
+ assertEquals("size should be zero", 0, map.size());
+ assertTrue("Should not have entries", !map.entrySet().iterator()
+ .hasNext());
+ assertTrue("Should not have keys", !map.keySet().iterator()
+ .hasNext());
+ assertTrue("Should not have values", !map.values().iterator()
+ .hasNext());
+ } catch (UnsupportedOperationException e) {
+ }
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_MessageFormat.java b/support/src/test/java/tests/support/Support_MessageFormat.java
new file mode 100644
index 0000000..361144c
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_MessageFormat.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.DateFormat;
+import java.text.MessageFormat;
+import java.text.NumberFormat;
+import java.text.MessageFormat.Field;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.Vector;
+
+public class Support_MessageFormat extends Support_Format {
+
+ public Support_MessageFormat(String p1) {
+ super(p1);
+ }
+
+ @Override
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_MessageFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
+ MessageFormat format = new MessageFormat(pattern, Locale.US);
+
+ Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
+ Integer hamburgers = new Integer(8);
+ Object[] objects = new Object[] { hamburgers, new Double(3.5),
+ hamburgers, date, date };
+
+ super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!";
+
+ // test with MessageFormat.Field.ARGUMENT
+ t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
+
+ // test other format fields that are included in the formatted text
+ t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0,
+ 0);
+ t_FormatWithField(3, format, objects, null,
+ NumberFormat.Field.FRACTION, 0, 0);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
+ t_FormatWithField(5, format, objects, null,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ }
+
+ public void t_formatToCharacterIterator() {
+
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
+ MessageFormat format = new MessageFormat(pattern, Locale.US);
+
+ Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
+ Integer hamburgers = new Integer(8);
+ Object[] objects = new Object[] { hamburgers, new Double(3.5),
+ hamburgers, date, date };
+
+ t_Format(1, objects, format, getMessageVector1());
+ }
+
+ private Vector<FieldContainer> getMessageVector1() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(3, 6, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(3, 6, DateFormat.Field.MONTH));
+ v.add(new FieldContainer(6, 7, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(7, 9, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(7, 9, DateFormat.Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(9, 11, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(11, 15, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(11, 15, DateFormat.Field.YEAR));
+ v.add(new FieldContainer(19, 20, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(19, 20, DateFormat.Field.HOUR1));
+ v.add(new FieldContainer(20, 21, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(21, 23, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(21, 23, DateFormat.Field.MINUTE));
+ v.add(new FieldContainer(23, 24, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(24, 26, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(24, 26, DateFormat.Field.SECOND));
+ v.add(new FieldContainer(26, 27, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(27, 29, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(27, 29, DateFormat.Field.AM_PM));
+ v.add(new FieldContainer(38, 39, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(38, 39, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(49, 50, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(61, 62, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(61, 62, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(62, 63, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(62, 63, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(63, 64, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(63, 64, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(90, 106, Field.ARGUMENT, 0));
+ return v;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_NetworkInterface.java b/support/src/test/java/tests/support/Support_NetworkInterface.java
new file mode 100644
index 0000000..d801a26
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_NetworkInterface.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.net.NetworkInterface;
+
+public class Support_NetworkInterface {
+
+ /**
+ * On windows platforms with IPV6 enabled there are a number of pseudo
+ * interfaces which don't work with our tests. This function is called to
+ * make sure we only use the non-pseudo interfaces
+ */
+ public static boolean useInterface(NetworkInterface theInterface) {
+ boolean result = true;
+ String platform = System.getProperty("os.name");
+ // only use these on windows platforms
+ if (platform.startsWith("Windows")) {
+ if ((theInterface.getDisplayName()
+ .equals("Teredo Tunneling Pseudo-Interface"))
+ || (theInterface.getDisplayName()
+ .equals("6to4 Tunneling Pseudo-Interface"))
+ || (theInterface.getDisplayName()
+ .equals("Automatic Tunneling Pseudo-Interface"))
+ || (theInterface.getDisplayName()
+ .equals("Loopback Pseudo-Interface"))) {
+ result = false;
+ }
+ }
+ return result;
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_PlatformFile.java b/support/src/test/java/tests/support/Support_PlatformFile.java
new file mode 100644
index 0000000..78b03c5
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_PlatformFile.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_PlatformFile {
+
+ private static String platformId = null;
+
+ public static String getNewPlatformFile(String pre, String post) {
+ if (platformId == null) {
+ String property = System.getProperty("com.ibm.oti.configuration");
+ if (property == null) {
+ property = "JDK";
+ }
+ platformId = property
+ + System.getProperty("java.vm.version").replace('.', '-');
+ }
+ return pre + platformId + post;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_PortManager.java b/support/src/test/java/tests/support/Support_PortManager.java
new file mode 100644
index 0000000..81f5e8d
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_PortManager.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.net.DatagramSocket;
+import java.net.ServerSocket;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+/**
+ * The port manager is supposed to help finding a free
+ * network port on the machine; however, it uses strange
+ * logic, so leave it to the OS.
+ *
+ * @deprecated Use OS to find free ports.
+ */
+public class Support_PortManager {
+
+ private static int lastAssignedPort = somewhatRandomPort();
+ private static boolean failedOnce = false;
+
+ public static synchronized int getNextPort() {
+ if (!failedOnce) {
+ try {
+ ServerSocket ss = new ServerSocket(0);
+ int port = ss.getLocalPort();
+
+ ss.close();
+ return port;
+ } catch (Exception ex) {
+ failedOnce = true;
+ }
+ }
+ return getNextPort_unsafe();
+ }
+
+ /**
+ * Returns 1 free ports to be used.
+ */
+ public static synchronized int getNextPortForUDP() {
+ return getNextPortsForUDP(1)[0];
+ }
+
+ /**
+ * Returns the specified number of free ports to be used.
+ */
+ public static synchronized int[] getNextPortsForUDP(int num) {
+ if (num <= 0) {
+ throw new IllegalArgumentException("Invalid ports number: " + num);
+ }
+ DatagramSocket[] dss = new DatagramSocket[num];
+ int[] ports = new int[num];
+
+ try {
+ for (int i = 0; i < num; ++i) {
+ dss[i] = new DatagramSocket(0);
+ ports[i] = dss[i].getLocalPort();
+ }
+ } catch (Exception ex) {
+ throw new Error("Unable to get " + num + " ports for UDP: " + ex);
+ } finally {
+ for (int i = 0; i < num; ++i) {
+ if (dss[i] != null) {
+ dss[i].close();
+ }
+ }
+ }
+ return ports;
+ }
+
+ public static synchronized int getNextPort_unsafe() {
+ if (++lastAssignedPort > 65534) {
+ lastAssignedPort = 6000;
+ }
+ return lastAssignedPort;
+ }
+
+ /*
+ * Returns a different port number every 6 seconds or so. The port number
+ * should be about += 100 at each 6 second interval
+ */
+ private static int somewhatRandomPort() {
+ Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ int minutes = c.get(Calendar.MINUTE);
+ int seconds = c.get(Calendar.SECOND);
+
+ return 6000 + (1000 * minutes) + ((seconds / 6) * 100);
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_ProviderTrust.java b/support/src/test/java/tests/support/Support_ProviderTrust.java
new file mode 100644
index 0000000..cf441e1
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_ProviderTrust.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.Provider;
+
+/**
+ * This class implements a dummy provider.
+ *
+ */
+public class Support_ProviderTrust extends Provider {
+ private static final long serialVersionUID = 1L;
+
+ // Provider name
+ private static final String NAME = "ProviderTrust";
+
+ // Version of the services
+ private static final double VERSION = 1.0;
+
+ private static final String INFO = NAME
+ + " DSA key, parameter generation and signing; SHA-1 digest; SHA1PRNG SecureRandom";
+
+ /**
+ * Constructs a new instance of the dummy provider.
+ *
+ */
+ public Support_ProviderTrust() {
+ super(NAME, VERSION, INFO);
+ registerServices();
+ }
+
+ /**
+ * Register the services the receiver provides.
+ */
+ private void registerServices() {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ // Digest engine
+ put("MessageDigest.SHA",
+ "made.up.provider.name.MessageDigestSHA");
+ put("MessageDigest.MD5",
+ "made.up.provider.name.MessageDigestMD5");
+
+ // Algorithm parameter generator
+ put("AlgorithmParameterGenerator.DSA",
+ "made.up.provider.name.AlgorithmParameterGeneratorDSA");
+
+ // Algorithm parameters
+ put("AlgorithmParameters.DSA",
+ "made.up.provider.name.AlgorithmParametersDSA");
+
+ // Key pair generator
+ put("KeyPairGenerator.DSA",
+ "made.up.provider.name.KeyPairGeneratorDSA");
+
+ // Key factory
+ put("KeyFactory.DSA", "made.up.provider.name.KeyFactoryDSA");
+ put("KeyFactory.RSA", "made.up.provider.name.KeyFactoryRSA");
+
+ // Signature algorithm
+ put("Signature.SHA1withDSA",
+ "made.up.provider.name.SignatureDSA");
+
+ // KeyStore
+ put("KeyStore.PKCS#12/Netscape",
+ "made.up.provider.name.KeyStore");
+
+ // Certificate
+ put("CertificateFactory.X509",
+ "made.up.provider.name.CertificateFactoryX509");
+
+ return null;
+ }
+ });
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/tests/support/Support_Proxy_I1.java b/support/src/test/java/tests/support/Support_Proxy_I1.java
new file mode 100644
index 0000000..66296c9
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Proxy_I1.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 interface Support_Proxy_I1 {
+ boolean equals(Object o);
+
+ int[] array(long[] f);
+
+ void foo(int i, boolean b);
+
+ String string(String s) throws Support_Proxy_ParentException, LinkageError;
+}
diff --git a/support/src/test/java/tests/support/Support_Proxy_I2.java b/support/src/test/java/tests/support/Support_Proxy_I2.java
new file mode 100644
index 0000000..e6e5394
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Proxy_I2.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 interface Support_Proxy_I2 {
+
+ int[] array(long[] f);
+
+ void foo(boolean b, int i);
+
+ String string(String s) throws Support_Proxy_SubException, Error;
+}
diff --git a/support/src/test/java/tests/support/Support_Proxy_ParentException.java b/support/src/test/java/tests/support/Support_Proxy_ParentException.java
new file mode 100644
index 0000000..13ac4c0
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Proxy_ParentException.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_Proxy_ParentException extends Exception {
+ private static final long serialVersionUID = -2760151845410887038L;
+}
diff --git a/support/src/test/java/tests/support/Support_Proxy_SubException.java b/support/src/test/java/tests/support/Support_Proxy_SubException.java
new file mode 100644
index 0000000..0d43630
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_Proxy_SubException.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_Proxy_SubException extends Support_Proxy_ParentException {
+ private static final long serialVersionUID = -2615472925826542925L;
+
+}
diff --git a/support/src/test/java/tests/support/Support_SetTest.java b/support/src/test/java/tests/support/Support_SetTest.java
new file mode 100644
index 0000000..51ac1c4
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_SetTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Set;
+
+public class Support_SetTest extends junit.framework.TestCase {
+
+ Set<Integer> set; // must contain only the Integers 0 to 99
+
+ public Support_SetTest(String p1) {
+ super(p1);
+ }
+
+ public Support_SetTest(String p1, Set<Integer> s) {
+ super(p1);
+ set = s;
+ }
+
+ @Override
+ public void runTest() {
+ // add
+ assertTrue("Set Test - Adding a duplicate element changed the set",
+ !set.add(new Integer(50)));
+ assertTrue("Set Test - Removing an element did not change the set", set
+ .remove(new Integer(50)));
+ assertTrue(
+ "Set Test - Adding and removing a duplicate element failed to remove it",
+ !set.contains(new Integer(50)));
+ set.add(new Integer(50));
+ new Support_CollectionTest("", set).runTest();
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_SimpleDateFormat.java b/support/src/test/java/tests/support/Support_SimpleDateFormat.java
new file mode 100644
index 0000000..93257da
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_SimpleDateFormat.java
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.DateFormat;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat.Field;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.Vector;
+
+public class Support_SimpleDateFormat extends Support_Format {
+
+ public Support_SimpleDateFormat(String p1) {
+ super(p1);
+ }
+
+ @Override
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_SimpleDateFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat
+ .getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ // test with all pattern chars, and multiple occurances
+ format
+ .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
+
+ StringBuffer textbuffer = new StringBuffer(
+ "AD AD 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5 05");
+ textbuffer
+ .append(" 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003 PM");
+ textbuffer.append(" PM 5 005 EDT Eastern Daylight Time -0400 -0400");
+
+ // to avoid passing the huge Stringbuffer each time.
+ super.text = textbuffer.toString();
+
+ // test if field positions are set correctly for these fields occuring
+ // multiple times.
+ t_FormatWithField(0, format, date, null, Field.ERA, 0, 2);
+ t_FormatWithField(1, format, date, null, Field.YEAR, 6, 8);
+ t_FormatWithField(2, format, date, null, Field.MONTH, 17, 18);
+ t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 36, 38);
+ t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 46, 48);
+ t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 56, 58);
+ t_FormatWithField(6, format, date, null, Field.HOUR1, 66, 67);
+ t_FormatWithField(7, format, date, null, Field.MINUTE, 75, 77);
+ t_FormatWithField(8, format, date, null, Field.SECOND, 82, 83);
+ t_FormatWithField(9, format, date, null, Field.MILLISECOND, 91, 92);
+ t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 100, 103);
+ t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 111, 114);
+ t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
+ 123, 124);
+ t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 128, 130);
+ t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 135, 136);
+ t_FormatWithField(15, format, date, null, Field.AM_PM, 141, 143);
+ t_FormatWithField(16, format, date, null, Field.HOUR0, 149, 150);
+ t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 155, 158);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(18, format, date, null,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+
+ // test with simple example
+ format.applyPattern("h:m z");
+
+ super.text = "5:19 EDT";
+ t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 8);
+
+ // test fields that are not included in the formatted text
+
+ t_FormatWithField(24, format, date, null, Field.ERA, 0, 0);
+ t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0);
+ t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0);
+ t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0);
+ t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0);
+ t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0);
+ t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0);
+ t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0);
+ t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0);
+ t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0);
+ t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
+ 0, 0);
+ t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0);
+ t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0);
+ t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0);
+ t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0);
+
+ t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT,
+ 0, 0);
+
+ // test with simple example with pattern char Z
+ format.applyPattern("h:m Z z");
+ super.text = "5:19 -0400 EDT";
+ t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
+ }
+
+ public void t_formatToCharacterIterator() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat
+ .getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ format.applyPattern("yyyyMMddHHmmss");
+ t_Format(1, date, format, getDateVector1());
+
+ format.applyPattern("w W dd MMMM yyyy EEEE");
+ t_Format(2, date, format, getDateVector2());
+
+ format.applyPattern("h:m z");
+ t_Format(3, date, format, getDateVector3());
+
+ format.applyPattern("h:m Z");
+ t_Format(5, date, format, getDateVector5());
+
+ // with all pattern chars, and multiple occurances
+ format
+ .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
+ t_Format(4, date, format, getDateVector4());
+ }
+
+ private Vector<FieldContainer> getDateVector1() {
+ // "19990913171901"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 4, Field.YEAR));
+ v.add(new FieldContainer(4, 6, Field.MONTH));
+ v.add(new FieldContainer(6, 8, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 10, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(10, 12, Field.MINUTE));
+ v.add(new FieldContainer(12, 14, Field.SECOND));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector2() {
+ // "12 3 5 March 2002 Monday"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 2, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(3, 4, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(5, 7, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 17, Field.MONTH));
+ v.add(new FieldContainer(18, 22, Field.YEAR));
+ v.add(new FieldContainer(23, 29, Field.DAY_OF_WEEK));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector3() {
+ // "5:19 EDT"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 8, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector5() {
+ // "5:19 -0400"
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 10, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector<FieldContainer> getDateVector4() {
+ Vector<FieldContainer> v = new Vector<FieldContainer>();
+
+ // "AD AD 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5
+ // 05
+ // 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003
+ // PM
+ // PM 5 005 EDT Eastern Daylight Time -0400 -0400"
+ v.add(new FieldContainer(0, 2, Field.ERA));
+ v.add(new FieldContainer(3, 5, Field.ERA));
+ v.add(new FieldContainer(6, 8, Field.YEAR));
+ v.add(new FieldContainer(9, 11, Field.YEAR));
+ v.add(new FieldContainer(12, 16, Field.YEAR));
+ v.add(new FieldContainer(17, 18, Field.MONTH));
+ v.add(new FieldContainer(19, 21, Field.MONTH));
+ v.add(new FieldContainer(22, 25, Field.MONTH));
+ v.add(new FieldContainer(26, 35, Field.MONTH));
+ v.add(new FieldContainer(36, 38, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(39, 41, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(42, 45, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(46, 48, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(49, 51, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(52, 55, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(56, 58, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(59, 61, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(62, 65, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(66, 67, Field.HOUR1));
+ v.add(new FieldContainer(68, 70, Field.HOUR1));
+ v.add(new FieldContainer(71, 74, Field.HOUR1));
+ v.add(new FieldContainer(75, 77, Field.MINUTE));
+ v.add(new FieldContainer(78, 81, Field.MINUTE));
+ v.add(new FieldContainer(82, 83, Field.SECOND));
+ v.add(new FieldContainer(84, 86, Field.SECOND));
+ v.add(new FieldContainer(87, 90, Field.SECOND));
+ v.add(new FieldContainer(91, 92, Field.MILLISECOND));
+ v.add(new FieldContainer(93, 95, Field.MILLISECOND));
+ v.add(new FieldContainer(96, 99, Field.MILLISECOND));
+ v.add(new FieldContainer(100, 103, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(104, 110, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(111, 114, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(115, 118, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(119, 122, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(123, 124, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(125, 127, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(128, 130, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(131, 134, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(135, 136, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(137, 140, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(141, 143, Field.AM_PM));
+ v.add(new FieldContainer(145, 147, Field.AM_PM));
+ v.add(new FieldContainer(149, 150, Field.HOUR0));
+ v.add(new FieldContainer(151, 154, Field.HOUR0));
+ v.add(new FieldContainer(155, 158, Field.TIME_ZONE));
+ v.add(new FieldContainer(159, 180, Field.TIME_ZONE));
+ v.add(new FieldContainer(181, 186, Field.TIME_ZONE));
+ v.add(new FieldContainer(187, 192, Field.TIME_ZONE));
+ return v;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_StringReader.java b/support/src/test/java/tests/support/Support_StringReader.java
new file mode 100644
index 0000000..f2d9a94
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_StringReader.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Reader;
+
+public class Support_StringReader extends Reader {
+ private String str;
+
+ private int markpos = -1;
+
+ private int pos = 0;
+
+ private int count;
+
+ /**
+ * Construct a StringReader on the String <code>str</code>. The size of
+ * the reader is set to the <code>length()</code> of the String and the
+ * Object to synchronize access through is set to <code>str</code>.
+ *
+ * @param str
+ * the String to filter reads on.
+ */
+ public Support_StringReader(String str) {
+ super(str);
+ this.str = str;
+ this.count = str.length();
+ }
+
+ /**
+ * This method closes this StringReader. Once it is closed, you can no
+ * longer read from it. Only the first invocation of this method has any
+ * effect.
+ *
+ */
+ @Override
+ public void close() {
+ synchronized (lock) {
+ if (isOpen()) {
+ str = null;
+ }
+ }
+ }
+
+ /**
+ * Answer a boolean indicating whether or not this StringReader is open.
+ */
+ private boolean isOpen() {
+ return str != null;
+ }
+
+ /**
+ * Set a Mark position in this Reader. The parameter <code>readLimit</code>
+ * is ignored for StringReaders. Sending reset() will reposition the reader
+ * back to the marked position provided the mark has not been invalidated.
+ *
+ * @param readlimit
+ * ignored for StringReaders.
+ *
+ * @exception java.io.IOException
+ * If an error occurs attempting mark this StringReader.
+ */
+ @Override
+ public void mark(int readLimit) throws IOException {
+ if (readLimit >= 0) {
+ synchronized (lock) {
+ if (isOpen()) {
+ markpos = pos;
+ } else {
+ throw new IOException("StringReader is closed");
+ }
+ }
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * Answers a boolean indicating whether or not this StringReader supports
+ * mark() and reset(). This method always returns true.
+ *
+ * @return <code>true</code> if mark() and reset() are supported,
+ * <code>false</code> otherwise. This implementation always
+ * returns <code>true</code>.
+ */
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ /**
+ * Reads a single character from this StringReader and returns the result as
+ * an int. The 2 higher-order bytes are set to 0. If the end of reader was
+ * encountered then return -1.
+ *
+ * @return the character read or -1 if end of reader.
+ *
+ * @exception java.io.IOException
+ * If the StringReader is already closed.
+ */
+ @Override
+ public int read() throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ if (pos != count) {
+ return str.charAt(pos++);
+ }
+ return -1;
+ }
+ throw new IOException("StringReader is closed");
+ }
+ }
+
+ /**
+ * Reads at most <code>count</code> characters from this StringReader and
+ * stores them at <code>offset</code> in the character array
+ * <code>buf</code>. Returns the number of characters actually read or -1
+ * if the end of reader was encountered.
+ *
+ * @param buf
+ * character array to store the read characters
+ * @param offset
+ * offset in buf to store the read characters
+ * @param count
+ * maximum number of characters to read
+ * @return the number of characters read or -1 if end of reader.
+ *
+ * @exception java.io.IOException
+ * If the StringReader is closed.
+ */
+ @Override
+ public int read(char buf[], int offset, int count) throws IOException {
+ // avoid int overflow
+ if (0 <= offset && offset <= buf.length && 0 <= count
+ && count <= buf.length - offset) {
+ synchronized (lock) {
+ if (isOpen()) {
+ if (pos == this.count) {
+ return -1;
+ }
+ int end = pos + count > this.count ? this.count : pos
+ + count;
+ str.getChars(pos, end, buf, offset);
+ int read = end - pos;
+ pos = end;
+ return read;
+ }
+ throw new IOException("StringReader is closed");
+ }
+ }
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ /**
+ * Answers a <code>boolean</code> indicating whether or not this
+ * StringReader is ready to be read without blocking. If the result is
+ * <code>true</code>, the next <code>read()</code> will not block. If
+ * the result is <code>false</code> this Reader may or may not block when
+ * <code>read()</code> is sent. The implementation in StringReader always
+ * returns <code>true</code> even when it has been closed.
+ *
+ * @return <code>true</code> if the receiver will not block when
+ * <code>read()</code> is called, <code>false</code> if unknown
+ * or blocking will occur.
+ *
+ * @exception java.io.IOException
+ * If an IO error occurs.
+ */
+ @Override
+ public boolean ready() throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ return true;
+ }
+ throw new IOException("StringReader is closed");
+ }
+ }
+
+ /**
+ * Reset this StringReader's position to the last <code>mark()</code>
+ * location. Invocations of <code>read()/skip()</code> will occur from
+ * this new location. If this Reader was not marked, the StringReader is
+ * reset to the beginning of the String.
+ *
+ * @exception java.io.IOException
+ * If this StringReader has already been closed.
+ */
+ @Override
+ public void reset() throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ pos = markpos != -1 ? markpos : 0;
+ } else {
+ throw new IOException("StringReader is closed");
+ }
+ }
+ }
+
+ /**
+ * Skips <code>count</code> number of characters in this StringReader.
+ * Subsequent <code>read()</code>'s will not return these characters
+ * unless <code>reset()</code> is used.
+ *
+ * @param count
+ * The number of characters to skip.
+ * @return the number of characters actually skipped.
+ *
+ * @exception java.io.IOException
+ * If this StringReader has already been closed.
+ */
+ @Override
+ public long skip(long count) throws IOException {
+ synchronized (lock) {
+ if (isOpen()) {
+ if (count <= 0) {
+ return 0;
+ }
+ long skipped = 0;
+ if (count < this.count - pos) {
+ pos = pos + (int) count;
+ skipped = count;
+ } else {
+ skipped = this.count - pos;
+ pos = this.count;
+ }
+ return skipped;
+ }
+ throw new IOException("StringReader is closed");
+ }
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_StringWriter.java b/support/src/test/java/tests/support/Support_StringWriter.java
new file mode 100644
index 0000000..348f547
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_StringWriter.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Writer;
+
+public class Support_StringWriter extends Writer {
+ private StringBuffer buf;
+
+ /**
+ * Constructs a new StringWriter which has a StringBuffer allocated with the
+ * default size of 16 characters. The StringBuffer is also the
+ * <code>lock</code> used to synchronize access to this Writer.
+ */
+ public Support_StringWriter() {
+ super();
+ buf = new StringBuffer(16);
+ lock = buf;
+ }
+
+ /**
+ * Constructs a new StringWriter which has a StringBuffer allocated with the
+ * size of <code>initialSize</code> characters. The StringBuffer is also
+ * the <code>lock</code> used to synchronize access to this Writer.
+ */
+ public Support_StringWriter(int initialSize) {
+ if (initialSize >= 0) {
+ buf = new StringBuffer(initialSize);
+ lock = buf;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * Close this Writer. This is the concrete implementation required. This
+ * particular implementation does nothing.
+ *
+ * @exception java.io.IOException
+ * If an IO error occurs closing this StringWriter.
+ */
+ @Override
+ public void close() throws IOException {
+ }
+
+ /**
+ * Flush this Writer. This is the concrete implementation required. This
+ * particular implementation does nothing.
+ *
+ */
+ @Override
+ public void flush() {
+ }
+
+ /**
+ * Answer the contents of this StringWriter as a StringBuffer. Any changes
+ * made to the StringBuffer by the receiver or the caller are reflected in
+ * this StringWriter.
+ *
+ * @return this StringWriters local StringBuffer.
+ */
+ public StringBuffer getBuffer() {
+ synchronized (lock) {
+ return buf;
+ }
+ }
+
+ /**
+ * Answer the contents of this StringWriter as a String. Any changes made to
+ * the StringBuffer by the receiver after returning will not be reflected in
+ * the String returned to the caller.
+ *
+ * @return this StringWriters current contents as a String.
+ */
+ @Override
+ public String toString() {
+ synchronized (lock) {
+ return buf.toString();
+ }
+ }
+
+ /**
+ * Writes <code>count</code> characters starting at <code>offset</code>
+ * in <code>buf</code> to this StringWriter.
+ *
+ * @param buf
+ * the non-null array containing characters to write.
+ * @param offset
+ * offset in buf to retrieve characters
+ * @param count
+ * maximum number of characters to write
+ *
+ * @exception java.lang.ArrayIndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ */
+ @Override
+ public void write(char[] buf, int offset, int count) {
+ // avoid int overflow
+ if (0 <= offset && offset <= buf.length && 0 <= count
+ && count <= buf.length - offset) {
+ synchronized (lock) {
+ this.buf.append(buf, offset, count);
+ }
+ } else {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ /**
+ * Writes the specified character <code>oneChar</code> to this
+ * StringWriter. This implementation writes the low order two bytes to the
+ * Stream.
+ *
+ * @param oneChar
+ * The character to write
+ *
+ */
+ @Override
+ public void write(int oneChar) {
+ synchronized (lock) {
+ buf.append((char) oneChar);
+ }
+ }
+
+ /**
+ * Writes the characters from the String <code>str</code> to this
+ * StringWriter.
+ *
+ * @param str
+ * the non-null String containing the characters to write.
+ *
+ */
+ @Override
+ public void write(String str) {
+ synchronized (lock) {
+ buf.append(str);
+ }
+ }
+
+ /**
+ * Writes <code>count</code> number of characters starting at
+ * <code>offset</code> from the String <code>str</code> to this
+ * StringWriter.
+ *
+ * @param str
+ * the non-null String containing the characters to write.
+ * @param offset
+ * the starting point to retrieve characters.
+ * @param count
+ * the number of characters to retrieve and write.
+ *
+ * @exception java.lang.ArrayIndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ */
+ @Override
+ public void write(String str, int offset, int count) {
+ String sub = str.substring(offset, offset + count);
+ synchronized (lock) {
+ buf.append(sub);
+ }
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_TestProvider.java b/support/src/test/java/tests/support/Support_TestProvider.java
new file mode 100644
index 0000000..e425ad6
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestProvider.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.Provider;
+
+/**
+ * This class implements a dummy provider.
+ */
+public class Support_TestProvider extends Provider {
+ private static final long serialVersionUID = 1L;
+
+ // Provider name
+ private static final String NAME = "TestProvider";
+
+ // Version of the services provided
+ private static final double VERSION = 1.0;
+
+ private static final String INFO = NAME
+ + " DSA key, parameter generation and signing; SHA-1 digest; "
+ + "SHA1PRNG SecureRandom; PKCS#12/Netscape KeyStore";
+
+ /**
+ * Constructs a new instance of the dummy provider.
+ */
+ public Support_TestProvider() {
+ super(NAME, VERSION, INFO);
+ registerServices();
+ }
+
+ /**
+ * Register the services the receiver provides.
+ */
+ private void registerServices() {
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ // Digest engine
+ put("MessageDigest.SHA",
+ "made.up.provider.name.MessageDigestSHA");
+ put("MessageDigest.MD2",
+ "made.up.provider.name.MessageDigestMD2");
+ // aliases
+ put("Alg.Alias.MessageDigest.SHA1", "SHA");
+ put("Alg.Alias.MessageDigest.SHA-1", "SHA");
+ put("Alg.Alias.MessageDigest.OID.1.3.14.3.2.26", "SHA");
+ put("Alg.Alias.MessageDigest.1.3.14.3.2.26", "SHA");
+
+ // Algorithm parameter generator
+ put("AlgorithmParameterGenerator.DSA",
+ "made.up.provider.name.AlgorithmParameterGeneratorDSA");
+
+ // Algorithm parameters
+ put("AlgorithmParameters.DSA",
+ "made.up.provider.name.AlgorithmParametersDSA");
+ // aliases
+ put("Alg.Alias.AlgorithmParameters.1.2.840.10040.4.1", "DSA");
+ put("Alg.Alias.AlgorithmParameters.1.3.14.3.2.12", "DSA");
+
+ // Key pair generator
+ put("KeyPairGenerator.DSA",
+ "made.up.provider.name.KeyPairGeneratorDSA");
+ // aliases
+ put("Alg.Alias.KeyPairGenerator.OID.1.2.840.10040.4.1", "DSA");
+ put("Alg.Alias.KeyPairGenerator.1.2.840.10040.4.1", "DSA");
+ put("Alg.Alias.KeyPairGenerator.1.3.14.3.2.12", "DSA");
+
+ // Key factory
+ put("KeyFactory.DSA", "made.up.provider.name.KeyFactoryDSA");
+ put("KeyFactory.RSA", "made.up.provider.name.KeyFactoryRSA");
+ // aliases
+ put("Alg.Alias.KeyFactory.1.2.840.10040.4.1", "DSA");
+ put("Alg.Alias.KeyFactory.1.3.14.3.2.12", "DSA");
+
+ // Signature algorithm
+ put("Signature.SHA1withDSA",
+ "made.up.provider.name.SignatureDSA");
+
+ // aliases
+ put("Alg.Alias.Signature.DSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.DSS", "SHA1withDSA");
+ put("Alg.Alias.Signature.SHA/DSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.SHA1/DSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.SHA-1/DSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.SHAwithDSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.DSAwithSHA1", "SHA1withDSA");
+ put("Alg.Alias.Signature.DSAWithSHA1", "SHA1withDSA");
+ put("Alg.Alias.Signature.SHA-1withDSA", "SHA1withDSA");
+ put("Alg.Alias.Signature.OID.1.2.840.10040.4.3", "SHA1withDSA");
+ put("Alg.Alias.Signature.1.2.840.10040.4.3", "SHA1withDSA");
+ put("Alg.Alias.Signature.1.3.14.3.2.13", "SHA1withDSA");
+ put("Alg.Alias.Signature.1.3.14.3.2.27", "SHA1withDSA");
+ put("Alg.Alias.Signature.OID.1.3.14.3.2.13", "SHA1withDSA");
+ put("Alg.Alias.Signature.OID.1.3.14.3.2.27", "SHA1withDSA");
+
+ put("KeyStore.PKCS#12/Netscape",
+ "tests.support.Support_DummyPKCS12Keystore");
+
+ // Certificate
+ put("CertificateFactory.X509",
+ "made.up.provider.name.CertificateFactoryX509");
+ // aliases
+ put("Alg.Alias.CertificateFactory.X.509", "X509");
+
+ return null;
+ }
+ });
+ }
+} \ No newline at end of file
diff --git a/support/src/test/java/tests/support/Support_TestResource.java b/support/src/test/java/tests/support/Support_TestResource.java
new file mode 100644
index 0000000..e16b518
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource extends java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent1", "parentValue1" },
+ { "parent2", "parentValue2" }, { "parent3", "parentValue3" },
+ { "parent4", "parentValue4" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TestResource_en.java b/support/src/test/java/tests/support/Support_TestResource_en.java
new file mode 100644
index 0000000..4a69d7f
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource_en.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource_en extends java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent2", "enValue2" },
+ { "parent3", "enValue3" }, { "parent4", "enValue4" },
+ { "child1", "enChildValue1" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TestResource_en_US.java b/support/src/test/java/tests/support/Support_TestResource_en_US.java
new file mode 100644
index 0000000..4d73675
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource_en_US.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource_en_US extends java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent3", "enUSValue3" },
+ { "parent4", "enUSValue4" }, { "child1", "enUSChildValue1" },
+ { "child2", "enUSChildValue2" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TestResource_fr.java b/support/src/test/java/tests/support/Support_TestResource_fr.java
new file mode 100644
index 0000000..8bc0829
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource_fr.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource_fr extends java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent2", "frValue2" },
+ { "parent3", "frValue3" }, { "parent4", "frValue4" },
+ { "child1", "frChildValue1" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TestResource_fr_FR.java b/support/src/test/java/tests/support/Support_TestResource_fr_FR.java
new file mode 100644
index 0000000..59c56bd
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource_fr_FR.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource_fr_FR extends java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent3", "frFRValue3" },
+ { "parent4", "frFRValue4" }, { "child1", "frFRChildValue1" },
+ { "child2", "frFRChildValue2" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TestResource_fr_FR_VAR.java b/support/src/test/java/tests/support/Support_TestResource_fr_FR_VAR.java
new file mode 100644
index 0000000..b9f4d60
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TestResource_fr_FR_VAR.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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_TestResource_fr_FR_VAR extends
+ java.util.ListResourceBundle {
+
+ @Override
+ protected Object[][] getContents() {
+ Object[][] contents = { { "parent4", "frFRVARValue4" },
+ { "child1", "frFRVARChildValue1" },
+ { "child2", "frFRVARChildValue2" },
+ { "child3", "frFRVARChildValue3" }, };
+ return contents;
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_TimeZone.java b/support/src/test/java/tests/support/Support_TimeZone.java
new file mode 100644
index 0000000..750f98e
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_TimeZone.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Calendar;
+import java.util.GregorianCalendar;
+import java.util.TimeZone;
+
+/**
+ * Sample java.util.TimeZone subclass to test getDSTSavings() and getOffset(long)
+ * APIs
+ *
+ */
+public class Support_TimeZone extends TimeZone {
+ private static final long serialVersionUID = 1L;
+
+ int rawOffset;
+
+ boolean useDaylightTime;
+
+ public Support_TimeZone(int rawOffset, boolean useDaylightTime) {
+ this.rawOffset = rawOffset;
+ this.useDaylightTime = useDaylightTime;
+ }
+
+ @Override
+ public int getRawOffset() {
+ return rawOffset;
+ }
+
+ /**
+ * let's assume this timezone has daylight savings from the 4th month till
+ * the 10th month of the year to ame things simple.
+ */
+ @Override
+ public boolean inDaylightTime(java.util.Date p1) {
+ if (!useDaylightTime) {
+ return false;
+ }
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTime(p1);
+ int month = cal.get(Calendar.MONTH);
+
+ if (month > 4 && month < 10) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean useDaylightTime() {
+ return useDaylightTime;
+ }
+
+ /*
+ * return 0 to keep it simple, since this subclass is not used to test this
+ * method..
+ */
+ @Override
+ public int getOffset(int p1, int p2, int p3, int p4, int p5, int p6) {
+ return 0;
+ }
+
+ @Override
+ public void setRawOffset(int p1) {
+ rawOffset = p1;
+ }
+}
diff --git a/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java b/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java
new file mode 100644
index 0000000..96619bd
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_UnmodifiableCollectionTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.HashSet;
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import junit.framework.TestCase;
+
+public class Support_UnmodifiableCollectionTest extends TestCase {
+
+ Collection<Integer> col;
+
+ // must be a collection containing the Integers 0 to 99 (which will iterate
+ // in order)
+
+ public Support_UnmodifiableCollectionTest(String p1) {
+ super(p1);
+ }
+
+ public Support_UnmodifiableCollectionTest(String p1, Collection<Integer> c) {
+ super(p1);
+ col = c;
+ }
+
+ @Override
+ public void runTest() {
+
+ // contains
+ assertTrue("UnmodifiableCollectionTest - should contain 0", col
+ .contains(new Integer(0)));
+ assertTrue("UnmodifiableCollectionTest - should contain 50", col
+ .contains(new Integer(50)));
+ assertTrue("UnmodifiableCollectionTest - should not contain 100", !col
+ .contains(new Integer(100)));
+
+ // containsAll
+ HashSet<Integer> hs = new HashSet<Integer>();
+ hs.add(new Integer(0));
+ hs.add(new Integer(25));
+ hs.add(new Integer(99));
+ assertTrue(
+ "UnmodifiableCollectionTest - should contain set of 0, 25, and 99",
+ col.containsAll(hs));
+ hs.add(new Integer(100));
+ assertTrue(
+ "UnmodifiableCollectionTest - should not contain set of 0, 25, 99 and 100",
+ !col.containsAll(hs));
+
+ // isEmpty
+ assertTrue("UnmodifiableCollectionTest - should not be empty", !col
+ .isEmpty());
+
+ // iterator
+ Iterator<Integer> it = col.iterator();
+ SortedSet<Integer> ss = new TreeSet<Integer>();
+ while (it.hasNext()) {
+ ss.add(it.next());
+ }
+ it = ss.iterator();
+ for (int counter = 0; it.hasNext(); counter++) {
+ int nextValue = it.next().intValue();
+ assertTrue(
+ "UnmodifiableCollectionTest - Iterator returned wrong value. Wanted: "
+ + counter + " got: " + nextValue,
+ nextValue == counter);
+ }
+
+ // size
+ assertTrue(
+ "UnmodifiableCollectionTest - returned wrong size. Wanted 100, got: "
+ + col.size(), col.size() == 100);
+
+ // toArray
+ Object[] objArray;
+ objArray = col.toArray();
+ for (int counter = 0; it.hasNext(); counter++) {
+ assertTrue(
+ "UnmodifiableCollectionTest - toArray returned incorrect array",
+ objArray[counter] == it.next());
+ }
+
+ // toArray (Object[])
+ objArray = new Object[100];
+ col.toArray(objArray);
+ for (int counter = 0; it.hasNext(); counter++) {
+ assertTrue(
+ "UnmodifiableCollectionTest - toArray(Object) filled array incorrectly",
+ objArray[counter] == it.next());
+ }
+
+ }
+
+}
diff --git a/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java b/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java
new file mode 100644
index 0000000..9648074
--- /dev/null
+++ b/support/src/test/java/tests/support/Support_UnmodifiableMapTest.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.TestCase;
+
+public class Support_UnmodifiableMapTest extends TestCase {
+
+ Map<String, Integer> map;
+
+ // must be a map containing the string keys "0"-"99" paired with the Integer
+ // values Integer(0) to Integer(99)
+
+ public Support_UnmodifiableMapTest(String p1) {
+ super(p1);
+ }
+
+ public Support_UnmodifiableMapTest(String p1, Map<String, Integer> m) {
+ super(p1);
+ map = m;
+ }
+
+ @Override
+ public void runTest() {
+ // containsKey
+ assertTrue("UnmodifiableMapTest - Should contain the key \"0\"", map
+ .containsKey("0"));
+ assertTrue("UnmodifiableMapTest - Should contain the key \"50\"", map
+ .containsKey("50"));
+ assertTrue("UnmodifiableMapTest - Should not contain the key \"100\"",
+ !map.containsKey("100"));
+
+ // containsValue
+ assertTrue("UnmodifiableMapTest - Should contain the value 0", map
+ .containsValue(new Integer(0)));
+ assertTrue("UnmodifiableMapTest - Should contain the value 50", map
+ .containsValue(new Integer(50)));
+ assertTrue("UnmodifiableMapTest - Should not contain value 100", !map
+ .containsValue(new Integer(100)));
+
+ // entrySet
+ Set<?> entrySet = map.entrySet();
+ Iterator<?> entrySetIterator = entrySet.iterator();
+ int myCounter = 0;
+ while (entrySetIterator.hasNext()) {
+ Map.Entry<?, ?> me = (Map.Entry<?, ?>) entrySetIterator.next();
+ assertTrue("UnmodifiableMapTest - Incorrect Map.Entry returned",
+ map.get(me.getKey()).equals(me.getValue()));
+ myCounter++;
+ }
+ assertEquals("UnmodifiableMapTest - Incorrect number of map entries returned",
+ 100, myCounter);
+
+ // get
+ assertTrue("UnmodifiableMapTest - getting \"0\" didn't return 0",
+ map.get("0").intValue() == 0);
+ assertTrue("UnmodifiableMapTest - getting \"50\" didn't return 0",
+ map.get("0").intValue() == 0);
+ assertNull("UnmodifiableMapTest - getting \"100\" didn't return null",
+ map.get("100"));
+
+ // isEmpty
+ assertTrue(
+ "UnmodifiableMapTest - should have returned false to isEmpty",
+ !map.isEmpty());
+
+ // keySet
+ Set<?> keySet = map.keySet();
+ t_KeySet(keySet);
+
+ // size
+ assertTrue("Size should return 100, returned: " + map.size(), map
+ .size() == 100);
+
+ // values
+ new Support_UnmodifiableCollectionTest("Unmod--from map test", map
+ .values());
+
+ }
+
+ void t_KeySet(Set<?> keySet) {
+ // keySet should be a set of the strings "0" to "99"
+
+ // contains
+ assertTrue("UnmodifiableMapTest - keySetTest - should contain \"0\"",
+ keySet.contains("0"));
+ assertTrue("UnmodifiableMapTest - keySetTest - should contain \"50\"",
+ keySet.contains("50"));
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - should not contain \"100\"",
+ !keySet.contains("100"));
+
+ // containsAll
+ HashSet<String> hs = new HashSet<String>();
+ hs.add("0");
+ hs.add("25");
+ hs.add("99");
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - should contain set of \"0\", \"25\", and \"99\"",
+ keySet.containsAll(hs));
+ hs.add("100");
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - should not contain set of \"0\", \"25\", \"99\" and \"100\"",
+ !keySet.containsAll(hs));
+
+ // isEmpty
+ assertTrue("UnmodifiableMapTest - keySetTest - should not be empty",
+ !keySet.isEmpty());
+
+ // iterator
+ Iterator<?> it = keySet.iterator();
+ while (it.hasNext()) {
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - Iterator returned wrong values",
+ keySet.contains(it.next()));
+ }
+
+ // size
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - returned wrong size. Wanted 100, got: "
+ + keySet.size(), keySet.size() == 100);
+
+ // toArray
+ Object[] objArray;
+ objArray = keySet.toArray();
+ for (int counter = 0; it.hasNext(); counter++) {
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - toArray returned incorrect array",
+ objArray[counter] == it.next());
+ }
+
+ // toArray (Object[])
+ objArray = new Object[100];
+ keySet.toArray(objArray);
+ for (int counter = 0; it.hasNext(); counter++) {
+ assertTrue(
+ "UnmodifiableMapTest - keySetTest - toArray(Object) filled array incorrectly",
+ objArray[counter] == it.next());
+ }
+ }
+
+}
diff --git a/support/src/test/java/tests/support/resource/Support_Resources.java b/support/src/test/java/tests/support/resource/Support_Resources.java
new file mode 100644
index 0000000..b1e63f6
--- /dev/null
+++ b/support/src/test/java/tests/support/resource/Support_Resources.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.resource;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import tests.support.Support_Configuration;
+
+public class Support_Resources {
+
+ public static final String RESOURCE_PACKAGE = "/tests/resources/";
+
+ public static final String RESOURCE_PACKAGE_NAME = "tests.resources";
+
+ public static InputStream getStream(String name) {
+ return Support_Resources.class.getResourceAsStream(RESOURCE_PACKAGE
+ + name);
+ }
+
+ public static String getURL(String name) {
+ String folder = null;
+ String fileName = name;
+ File resources = createTempFolder();
+ int index = name.lastIndexOf("/");
+ if (index != -1) {
+ folder = name.substring(0, index);
+ name = name.substring(index + 1);
+ }
+ copyFile(resources, folder, name);
+ URL url = null;
+ String resPath = resources.toString();
+ if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
+ resPath = resPath.substring(1);
+ }
+ try {
+ url = new URL("file:/" + resPath + "/" + fileName);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return url.toString();
+ }
+
+ public static File createTempFolder() {
+
+ File folder = null;
+ try {
+ folder = File.createTempFile("hyts_resources", "", null);
+ folder.delete();
+ folder.mkdirs();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ folder.deleteOnExit();
+ return folder;
+ }
+
+ public static void copyFile(File root, String folder, String file) {
+ File f;
+ if (folder != null) {
+ f = new File(root.toString() + "/" + folder);
+ if (!f.exists()) {
+ f.mkdirs();
+ f.deleteOnExit();
+ }
+ } else {
+ f = root;
+ }
+
+ File dest = new File(f.toString() + "/" + file);
+
+ InputStream in = Support_Resources.getStream(folder == null ? file
+ : folder + "/" + file);
+ try {
+ copyLocalFileto(dest, in);
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static File createTempFile(String suffix) throws IOException {
+ return File.createTempFile("hyts_", suffix, null);
+ }
+
+ public static void copyLocalFileto(File dest, InputStream in)
+ throws FileNotFoundException, IOException {
+ if (!dest.exists()) {
+ FileOutputStream out = new FileOutputStream(dest);
+ int result;
+ byte[] buf = new byte[4096];
+ while ((result = in.read(buf)) != -1) {
+ out.write(buf, 0, result);
+ }
+ in.close();
+ out.close();
+ dest.deleteOnExit();
+ }
+ }
+
+ public static File getExternalLocalFile(String url) throws IOException,
+ MalformedURLException {
+ File resources = createTempFolder();
+ InputStream in = new URL(url).openStream();
+ File temp = new File(resources.toString() + "/local.tmp");
+ copyLocalFileto(temp, in);
+ return temp;
+ }
+
+ public static String getResourceURL(String resource) {
+ return "http://" + Support_Configuration.TestResources + resource;
+ }
+
+ /**
+ * Util method to load resource files
+ *
+ * @param name - name of resource file
+ * @return - resource input stream
+ */
+ public static InputStream getResourceStream(String name) {
+
+ InputStream is = ClassLoader.getSystemClassLoader()
+ .getResourceAsStream(name);
+
+ if (is == null) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+
+ return is;
+ }
+
+ /**
+ * Util method to get absolute path to resource file
+ *
+ * @param name - name of resource file
+ * @return - path to resource
+ */
+ public static String getAbsoluteResourcePath(String name) {
+
+ URL url = ClassLoader.getSystemClassLoader().getResource(name);
+ if (url == null) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+
+ try {
+ return new File(url.toURI()).getAbsolutePath();
+ } catch (URISyntaxException e) {
+ throw new RuntimeException("Failed to load resource: " + name);
+ }
+ }
+}
diff --git a/support/src/test/java/tests/util/CallVerificationStack.java b/support/src/test/java/tests/util/CallVerificationStack.java
new file mode 100644
index 0000000..5646a77
--- /dev/null
+++ b/support/src/test/java/tests/util/CallVerificationStack.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.util;
+
+import java.util.Stack;
+
+/**
+ * A stack to store the parameters of a call, as well as the call stack.
+ *
+ */
+public class CallVerificationStack extends Stack<Object> {
+
+ /*
+ * --------------------------------------------------------------------
+ * Class variables
+ * --------------------------------------------------------------------
+ */
+
+ private static final long serialVersionUID = 1L;
+
+ // the singleton
+ private static final CallVerificationStack _instance = new CallVerificationStack();
+
+ /*
+ * --------------------------------------------------------------------
+ * Instance variables
+ * --------------------------------------------------------------------
+ */
+
+ // the call stack, store StackTraceElement
+ private final Stack<StackTraceElement> callStack = new Stack<StackTraceElement>();
+
+ /*
+ * -------------------------------------------------------------------
+ * Constructors
+ * -------------------------------------------------------------------
+ */
+
+ /**
+ * Can't be instantiated.
+ */
+ private CallVerificationStack() {
+ // empty
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ /**
+ * Gets the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static CallVerificationStack getInstance() {
+ return _instance;
+ }
+
+ /**
+ * Pushes the call stack.
+ */
+ private void pushCallStack() {
+ StackTraceElement[] eles = (new Throwable()).getStackTrace();
+ int i;
+ for (i = 1; i < eles.length; i++) {
+ if (!eles[i].getClassName().equals(this.getClass().getName())) {
+ break;
+ }
+ }
+ this.callStack.push(eles[i]);
+ }
+
+ /**
+ * Gets the "current" calling class name.
+ *
+ * @return the "current" calling class name
+ */
+ public String getCurrentSourceClass() {
+ return this.callStack.peek().getClassName();
+ }
+
+ /**
+ * Gets the "current" calling method name.
+ *
+ * @return the "current" calling method name
+ */
+ public String getCurrentSourceMethod() {
+ return this.callStack.peek().getMethodName();
+ }
+
+ /**
+ * Clear the parameter stack and the call stack.
+ *
+ */
+ @Override
+ public void clear() {
+ this.callStack.clear();
+ super.clear();
+ }
+
+ @Override
+ public Object push(Object o) {
+ pushCallStack();
+ return super.push(o);
+ }
+
+ /**
+ * Pushes a boolean onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(boolean val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes a char onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(char val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes a double onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(double val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes a float onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(float val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes an int onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(int val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes a long onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(long val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pushes a short onto the top of this stack.
+ *
+ * @param val
+ * the value to push
+ */
+ public void push(short val) {
+ this.push(new BaseTypeWrapper(val));
+ }
+
+ /**
+ * Pop an object.
+ *
+ * @return the object
+ */
+ @Override
+ public Object pop() {
+ this.callStack.pop();
+ return super.pop();
+ }
+
+ /**
+ * Pop a boolean.
+ *
+ * @return the value
+ */
+ public boolean popBoolean() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Boolean value = (Boolean) wrapper.getValue();
+ return value.booleanValue();
+ }
+
+ /**
+ * Pop a char.
+ *
+ * @return the value
+ */
+ public char popChar() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Character value = (Character) wrapper.getValue();
+ return value.charValue();
+ }
+
+ /**
+ * Pop a double.
+ *
+ * @return the value
+ */
+ public double popDouble() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Double value = (Double) wrapper.getValue();
+ return value.doubleValue();
+ }
+
+ /**
+ * Pop a float.
+ *
+ * @return the value
+ */
+ public float popFloat() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Float value = (Float) wrapper.getValue();
+ return value.floatValue();
+ }
+
+ /**
+ * Pop a int.
+ *
+ * @return the value
+ */
+ public int popInt() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Integer value = (Integer) wrapper.getValue();
+ return value.intValue();
+ }
+
+ /**
+ * Pop a long.
+ *
+ * @return the value
+ */
+ public long popLong() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Long value = (Long) wrapper.getValue();
+ return value.longValue();
+ }
+
+ /**
+ * Pop a short.
+ *
+ * @return the value
+ */
+ public short popShort() {
+ BaseTypeWrapper wrapper = (BaseTypeWrapper) this.pop();
+ Short value = (Short) wrapper.getValue();
+ return value.shortValue();
+ }
+
+ /*
+ * Wrapper of base types.
+ */
+ class BaseTypeWrapper {
+
+ // the internal value
+ private Object value;
+
+ /*
+ * Constructs a wrapper object for the base type <code> boolean </code> .
+ */
+ public BaseTypeWrapper(boolean val) {
+ this.value = new Boolean(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> c </code> .
+ */
+ public BaseTypeWrapper(byte val) {
+ this.value = new Byte(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> char </code> .
+ */
+ public BaseTypeWrapper(char val) {
+ this.value = new Character(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> double </code> .
+ */
+ public BaseTypeWrapper(double val) {
+ this.value = new Double(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> float </code> .
+ */
+ public BaseTypeWrapper(float val) {
+ this.value = new Float(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> int </code> .
+ */
+ public BaseTypeWrapper(int val) {
+ this.value = new Integer(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> long </code> .
+ */
+ public BaseTypeWrapper(long val) {
+ this.value = new Long(val);
+ }
+
+ /*
+ * Constructs a wrapper object for the base type <code> short </code> .
+ */
+ public BaseTypeWrapper(short val) {
+ this.value = new Short(val);
+ }
+
+ /*
+ * Gets the internal value.
+ */
+ public Object getValue() {
+ return this.value;
+ }
+ }
+}
diff --git a/support/src/test/java/tests/util/SerializationTester.java b/support/src/test/java/tests/util/SerializationTester.java
new file mode 100644
index 0000000..c69d591
--- /dev/null
+++ b/support/src/test/java/tests/util/SerializationTester.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/**
+ * This class simplifies the serialization test.
+ *
+ */
+public class SerializationTester {
+
+ /*
+ * --------------------------------------------------------------------
+ * Class variables
+ * --------------------------------------------------------------------
+ */
+
+ // the last deserialized object
+ private static Object lastOutput = null;
+
+ /*
+ * -------------------------------------------------------------------
+ * Constructors
+ * -------------------------------------------------------------------
+ */
+
+ private SerializationTester() {
+
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ /**
+ * Serialize an object and then deserialize it.
+ *
+ * @param inputObject
+ * the input object
+ * @return the deserialized object
+ */
+ public static Object getDeserilizedObject(Object inputObject)
+ throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(inputObject);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ Object outputObject = ois.readObject();
+ lastOutput = outputObject;
+ ois.close();
+ return outputObject;
+ }
+
+ /**
+ * Tests the serialization and deserialization of const objects.
+ *
+ * @param inputObject
+ * A const object
+ * @return true if the deserialized object is the same as the input object,
+ * otherwise false
+ * @throws Exception
+ * If any occurs.
+ */
+ public static boolean assertSame(Object inputObject) throws Exception {
+ return inputObject == getDeserilizedObject(inputObject);
+ }
+
+ /**
+ * Tests the serialization and deserialization of instance objects.
+ *
+ * @param inputObject
+ * An object
+ * @return true if the deserialized object is equal to the input object,
+ * otherwise false
+ * @throws Exception
+ * If any occurs.
+ */
+ public static boolean assertEquals(Object inputObject) throws Exception {
+ return inputObject.equals(getDeserilizedObject(inputObject));
+ }
+
+ /**
+ * Tests the serialization compatibility with reference const objects.
+ *
+ * @param obj
+ * the object to be checked
+ * @param fileName
+ * the serialization output file generated by reference
+ * @return true if compatible, otherwise false
+ * @throws Exception
+ * If any occurs.
+ */
+ public static boolean assertCompabilitySame(Object obj, String fileName)
+ throws Exception {
+ return obj == readObject(obj, fileName);
+ }
+
+ /**
+ * Tests the serialization compatibility with reference for instance
+ * objects.
+ *
+ * @param obj
+ * the object to be checked
+ * @param fileName
+ * the serialization output file generated by reference
+ * @return true if compatible, otherwise false
+ * @throws Exception
+ * If any occurs.
+ */
+ public static boolean assertCompabilityEquals(Object obj, String fileName)
+ throws Exception {
+ return obj.equals(readObject(obj, fileName));
+ }
+
+ /**
+ * Deserialize an object from a file.
+ *
+ * @param obj
+ * the object to be serialized if no serialization file is found
+ * @param fileName
+ * the serialization file
+ * @return the deserialized object
+ * @throws Exception
+ * If any occurs.
+ */
+ public static Object readObject(Object obj, String fileName)
+ throws Exception {
+ InputStream input = null;
+ ObjectInputStream oinput = null;
+ URL url = SerializationTester.class.getResource(
+ fileName);
+ if (null == url) {
+ // serialization file does not exist, create one in the current dir
+ writeObject(obj, new File(fileName).getName());
+ throw new Error(
+ "Serialization file does not exist, created in the current dir.");
+ }
+ input = url.openStream();
+ try {
+ oinput = new ObjectInputStream(input);
+ Object newObj = oinput.readObject();
+ return newObj;
+ } finally {
+ try {
+ if (null != oinput) {
+ oinput.close();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ try {
+ if (null != input) {
+ input.close();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ /*
+ * Creates a serialization output.
+ *
+ * @param obj the object to be serialized @param fileName the output file
+ * @throws Exception If any occurs.
+ */
+ public static void writeObject(Object obj, String fileName)
+ throws Exception {
+ // String path = SerializationTester.class.getResource(".").getPath();
+ // if (path.endsWith(".")) {
+ // path = path.substring(0, path.length() - 1);
+ // }
+ // if (!path.endsWith("/")) {
+ // path += "/";
+ // }
+ // path += fileName;
+ // System.out.println(path);
+ OutputStream output = null;
+ ObjectOutputStream ooutput = null;
+ try {
+ output = new FileOutputStream(fileName);
+ ooutput = new ObjectOutputStream(output);
+ ooutput.writeObject(obj);
+ } finally {
+ try {
+ if (null != ooutput) {
+ ooutput.close();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ try {
+ if (null != output) {
+ output.close();
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Gets the last deserialized object.
+ *
+ * @return the last deserialized object
+ */
+ public static Object getLastOutput() {
+ return lastOutput;
+ }
+
+ /*
+ * For test purpose.
+ */
+ public static void main(String[] args) {
+ }
+}
diff --git a/support/src/test/resources/hyts_Foo.c b/support/src/test/resources/hyts_Foo.c
new file mode 100644
index 0000000..907de59
--- /dev/null
+++ b/support/src/test/resources/hyts_Foo.c
@@ -0,0 +1 @@
+/* Some random file for it to look at. */ \ No newline at end of file