Initial commit from SVN.
This commit is contained in:
9
Common Test/.classpath
Normal file
9
Common Test/.classpath
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Class File Services"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Common"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Orb"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Common Test/.project
Normal file
17
Common Test/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Common Test</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.softwarezealot.common.io.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.util.*;
|
||||
import com.common.io.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
*/
|
||||
public class BufferedOutputStreamTest {
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args An array of command-line arguments.
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
byte[] bytes = null;
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(50, false);
|
||||
BufferedOutputStream bufOut = new BufferedOutputStream(bout, 100);
|
||||
BufferedOutputStream bufOut2 = null;
|
||||
StandardOutputStream sout = new StandardOutputStream(bufOut);
|
||||
StandardOutputStream sout2 = null;
|
||||
|
||||
sout.writeByte(0);
|
||||
sout.writeByte(1);
|
||||
sout.writeByte(2);
|
||||
bufOut2 = bufOut.getInsertOutputStream(10, 10);
|
||||
sout2 = new StandardOutputStream(bufOut2);
|
||||
sout.writeByte(5);
|
||||
sout.writeByte(6);
|
||||
sout.writeByte(7);
|
||||
sout2.writeByte(3);
|
||||
sout2.writeByte(4);
|
||||
|
||||
sout2.close();
|
||||
sout.flush();
|
||||
bytes = bout.toByteArray();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
}
|
||||
@@ -0,0 +1,591 @@
|
||||
package com.softwarezealot.common.io.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.util.*;
|
||||
import com.common.io.*;
|
||||
import com.common.security.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class SecurityStreamTests {
|
||||
/**
|
||||
* SecurityStreamTests constructor comment.
|
||||
*/
|
||||
public SecurityStreamTests() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
//testHash();
|
||||
testSymmetricEncryption();
|
||||
//testSignatureEncryption();
|
||||
//testAsymmetricEncryption();
|
||||
//testWritePrivateKey();
|
||||
//testWriteCompressedData();
|
||||
//testWriteCompressedEncryptedData();
|
||||
//testReadKey();
|
||||
//testWriteCompressedHashedData();
|
||||
|
||||
|
||||
//testDeflation();
|
||||
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testAsymmetricEncryption() {
|
||||
System.out.println("Testing Asymmetric");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
IAsymmetricAlgorithm privateAlgorithm = new RsaAlgorithm(1024);
|
||||
IAsymmetricAlgorithm publicAlgorithm = privateAlgorithm.getPublicAsymmetricAlgorithm();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
AsymmetricOutputStream out = new AsymmetricOutputStream(bout, publicAlgorithm);
|
||||
byte[] source = new byte[500];
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(source);
|
||||
out.encrypt(true);
|
||||
out.write(source);
|
||||
out.encrypt(false);
|
||||
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
AsymmetricInputStream in = new AsymmetricInputStream(bin, privateAlgorithm);
|
||||
byte[] received = new byte[500];
|
||||
|
||||
in.decrypt(true);
|
||||
in.read(received);
|
||||
in.decrypt(false);
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(source[i] != received[i]) {
|
||||
System.out.println("Failed Asymmetric Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Asymmetric; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testDeflation() {
|
||||
System.out.println("Testing deflation");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 100;
|
||||
byte[] data = new byte[size << 1];
|
||||
Random random = new Random();
|
||||
java.util.zip.Deflater deflater = new java.util.zip.Deflater(5, true);
|
||||
java.util.zip.Inflater inflater = new java.util.zip.Inflater(true);
|
||||
byte[] deflated = new byte[size << 2];
|
||||
byte[] inflated = new byte[size << 1];
|
||||
int inflatedCount = 0;
|
||||
int deflatedCount = 0;
|
||||
|
||||
random.nextBytes(data);
|
||||
deflater.setInput(data, 0, size);
|
||||
deflatedCount += deflater.deflate(deflated, deflatedCount, deflated.length - deflatedCount);
|
||||
deflater.finish();
|
||||
deflatedCount += deflater.deflate(deflated, deflatedCount, deflated.length - deflatedCount);
|
||||
|
||||
deflater.reset();
|
||||
deflater.setInput(data, size, size);
|
||||
deflatedCount += deflater.deflate(deflated, deflatedCount, deflated.length - deflatedCount);
|
||||
deflater.finish();
|
||||
deflatedCount += deflater.deflate(deflated, deflatedCount, deflated.length - deflatedCount);
|
||||
|
||||
System.out.println("Deflated " + deflatedCount + " bytes.");
|
||||
|
||||
/*
|
||||
for(int i = 0, incrementSize = 105; i < deflatedCount; i += incrementSize) {
|
||||
int count = 0;
|
||||
|
||||
inflater.setInput(deflated, i, incrementSize);
|
||||
|
||||
do {
|
||||
count = inflater.inflate(inflated, inflatedCount, 1);
|
||||
inflatedCount += count;
|
||||
} while(count > 0);
|
||||
}//for//
|
||||
*/
|
||||
int count = 0;
|
||||
int deflatedIndex = 0;
|
||||
//Read the first 100 data elements.//
|
||||
while(inflatedCount < 100) {
|
||||
if((count = inflater.inflate(inflated, inflatedCount, 100 - inflatedCount)) == 0) {
|
||||
if((inflater.finished()) || (inflater.needsDictionary())) {
|
||||
//What to do?//
|
||||
break;
|
||||
}//if//
|
||||
|
||||
if(inflater.needsInput()) {
|
||||
inflater.setInput(deflated, deflatedIndex, 1);
|
||||
deflatedIndex += 1;
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
inflatedCount += count;
|
||||
}//else//
|
||||
}//while//
|
||||
|
||||
//Read the second 100 data elements.//
|
||||
while(inflatedCount < 200) {
|
||||
if((count = inflater.inflate(inflated, inflatedCount, 200 - inflatedCount)) == 0) {
|
||||
if((inflater.finished()) || (inflater.needsDictionary())) {
|
||||
//What to do?//
|
||||
inflater.reset();
|
||||
}//if//
|
||||
|
||||
if(inflater.needsInput()) {
|
||||
inflater.setInput(deflated, deflatedIndex, 1);
|
||||
deflatedIndex += 1;
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
inflatedCount += count;
|
||||
}//else//
|
||||
}//while//
|
||||
|
||||
//Test the received data.//
|
||||
if(inflatedCount == data.length) {
|
||||
boolean isOk = true;
|
||||
|
||||
for(int i = 0; (isOk) && (i < data.length); i++) {
|
||||
if(inflated[i] != data[i]) {
|
||||
isOk = false;
|
||||
System.out.println("Error: Data validation failed on index " + i);
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
if(isOk) {
|
||||
System.out.println("Data validated sucessfully.");
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
System.out.println("Error: Only inflated " + inflatedCount + " bytes.");
|
||||
}//else//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Deflation; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testHash() {
|
||||
System.out.println("Testing Hash");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
IHashAlgorithm algorithm = new Sha1();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
HashedOutputStream out = new HashedOutputStream(bout, algorithm);
|
||||
byte[] source = new byte[500];
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(source);
|
||||
out.hash(true);
|
||||
out.write(source);
|
||||
out.writeHash();
|
||||
out.hash(false);
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
HashedInputStream in = new HashedInputStream(bin, algorithm);
|
||||
byte[] received = new byte[500];
|
||||
byte[] remoteHash = new byte[algorithm.getHashSize()];
|
||||
byte[] localHash = null;
|
||||
|
||||
in.hash(true);
|
||||
in.read(received);
|
||||
localHash = in.getHash();
|
||||
in.read(remoteHash);
|
||||
in.hash(false);
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(source[i] != received[i]) {
|
||||
System.out.println("Hashed Stream Failed");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
for(int i = 0; i < localHash.length; i++) {
|
||||
if(remoteHash[i] != localHash[i]) {
|
||||
System.out.println("Hash Failed");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Hash; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testReadKey() {
|
||||
System.out.println("Testing reading a private key from file: c:\\temp\\temp.prk");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 20;
|
||||
ISymmetricAlgorithm algorithm = new Rijndael("bane");
|
||||
java.io.FileInputStream fin = new java.io.FileInputStream("c:\\temp\\test.prk");
|
||||
SymmetricInputStream sin = new SymmetricInputStream(fin, algorithm);
|
||||
ObjectInputStream in = new ObjectInputStream(sin, null, null);
|
||||
ISignatureAlgorithm receivedSignature = null;
|
||||
|
||||
in.decrypt(true);
|
||||
receivedSignature = (ISignatureAlgorithm) in.readObject();
|
||||
in.decrypt(false);
|
||||
fin.close();
|
||||
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Key File Reading; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testSignatureEncryption() {
|
||||
System.out.println("Testing Signature");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
ISignatureAlgorithm privateAlgorithm = new RsaAlgorithm(1024);
|
||||
ISignatureAlgorithm publicAlgorithm = privateAlgorithm.getPublicSignatureAlgorithm();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
SignatureOutputStream out = new SignatureOutputStream(bout, privateAlgorithm);
|
||||
byte[] source = new byte[500];
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(source);
|
||||
out.encrypt(true);
|
||||
out.write(source);
|
||||
out.encrypt(false);
|
||||
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
SignatureInputStream in = new SignatureInputStream(bin, publicAlgorithm);
|
||||
byte[] received = new byte[500];
|
||||
|
||||
in.decrypt(true);
|
||||
in.read(received);
|
||||
in.decrypt(false);
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(source[i] != received[i]) {
|
||||
System.out.println("Failed Signature");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Signature; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testSymmetricEncryption() {
|
||||
System.out.println("Testing Symmetric");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 1400;
|
||||
ISymmetricAlgorithm algorithm = new Rijndael("test");
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
SymmetricOutputStream out = new SymmetricOutputStream(bout, algorithm);
|
||||
byte[] source = new byte[size];
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(source);
|
||||
out.encrypt(true);
|
||||
out.write(source);
|
||||
out.encrypt(false);
|
||||
out.flush();
|
||||
|
||||
algorithm = new Rijndael("test");
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
SymmetricInputStream in = new SymmetricInputStream(bin, algorithm);
|
||||
byte[] received = new byte[size];
|
||||
|
||||
in.decrypt(true);
|
||||
in.read(received);
|
||||
in.decrypt(false);
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(source[i] != received[i]) {
|
||||
System.out.println("Failed Symmetric Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing Symmetric; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testWriteCompressedData() {
|
||||
System.out.println("Testing writing a random data to file in c:\\temp");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 3050;
|
||||
byte[] data = new byte[size];
|
||||
java.io.FileOutputStream fout = new java.io.FileOutputStream("c:\\temp\\test.tmp", false);
|
||||
CompressionOutputStream cout = new CompressionOutputStream(fout);
|
||||
ObjectOutputStream out = new ObjectOutputStream(cout, null);
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(data);
|
||||
out.write(data);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
java.io.FileInputStream fin = new java.io.FileInputStream("c:\\temp\\test.tmp");
|
||||
CompressionInputStream cin = new CompressionInputStream(fin);
|
||||
ObjectInputStream in = new ObjectInputStream(cin, null, null);
|
||||
ISignatureAlgorithm receivedSignature = null;
|
||||
byte[] received = new byte[size];
|
||||
|
||||
in.read(received);
|
||||
in.close();
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(data[i] != received[i]) {
|
||||
System.out.println("Failed Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
new java.io.File("c:\\temp\\test.tmp").delete();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing File Writing; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void testWriteCompressedEncryptedData() {
|
||||
System.out.println("Testing writing a random data to file in c:\\temp");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 3050;
|
||||
byte[] data = new byte[size];
|
||||
ISymmetricAlgorithm algorithm = new Rijndael("test");
|
||||
java.io.FileOutputStream fout = new java.io.FileOutputStream("c:\\temp\\test.tmp", false);
|
||||
SymmetricOutputStream sout = new SymmetricOutputStream(fout, algorithm);
|
||||
CompressionOutputStream cout = new CompressionOutputStream(sout);
|
||||
ObjectOutputStream out = new ObjectOutputStream(cout, null);
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(data);
|
||||
out.encrypt(true);
|
||||
out.write(data);
|
||||
out.encrypt(false);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
algorithm = new Rijndael("test");
|
||||
java.io.FileInputStream fin = new java.io.FileInputStream("c:\\temp\\test.tmp");
|
||||
SymmetricInputStream sin = new SymmetricInputStream(fin, algorithm);
|
||||
CompressionInputStream cin = new CompressionInputStream(sin);
|
||||
ObjectInputStream in = new ObjectInputStream(cin, null, null);
|
||||
ISignatureAlgorithm receivedSignature = null;
|
||||
byte[] received = new byte[size];
|
||||
|
||||
in.decrypt(true);
|
||||
in.read(received);
|
||||
in.decrypt(false);
|
||||
in.close();
|
||||
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(data[i] != received[i]) {
|
||||
System.out.println("Failed Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
new java.io.File("c:\\temp\\test.tmp").delete();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing File Writing; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void testWriteCompressedHashedData() {
|
||||
System.out.println("Preparing test...");
|
||||
ISignatureAlgorithm privateKey = new RsaAlgorithm(2048);
|
||||
System.out.println("Testing writing a hashed stream where the hash is signed.");
|
||||
long t = System.currentTimeMillis();
|
||||
int streamSize = 0;
|
||||
|
||||
try {
|
||||
boolean isValid = false;
|
||||
int size = 10;
|
||||
byte[] data = new byte[] {1, 30, 20, -10, 100, 80, 90, -11, 55, 11}; //new byte[size];
|
||||
ISignatureAlgorithm publicKey = privateKey.getPublicSignatureAlgorithm();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000, false);
|
||||
SignatureOutputStream sout = new SignatureOutputStream(bout, privateKey);
|
||||
HashedOutputStream hout = new HashedOutputStream(sout, new Sha1());
|
||||
CompressionOutputStream cout = new CompressionOutputStream(hout);
|
||||
ObjectOutputStream out = new ObjectOutputStream(cout, null);
|
||||
|
||||
out.writeObject(data);
|
||||
out.encrypt(true);
|
||||
hout.writeHash();
|
||||
out.encrypt(false);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
streamSize = bout.getSize();
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
SignatureInputStream sin = new SignatureInputStream(bin, publicKey);
|
||||
HashedInputStream hin = new HashedInputStream(sin, new Sha1());
|
||||
CompressionInputStream cin = new CompressionInputStream(hin);
|
||||
ObjectInputStream in = new ObjectInputStream(cin, null, null);
|
||||
byte[] received = null;
|
||||
|
||||
received = (byte[]) in.readObject();
|
||||
in.decrypt(true);
|
||||
isValid = hin.validateHash();
|
||||
in.decrypt(false);
|
||||
in.close();
|
||||
|
||||
if(!isValid) {
|
||||
System.out.println("Failed Validation");
|
||||
}//if//
|
||||
else if(data.length == received.length) {
|
||||
for(int i = 0; i < received.length; i++) {
|
||||
if(data[i] != received[i]) {
|
||||
System.out.println("Failed Comparison");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//else if//
|
||||
else {
|
||||
System.out.println("Failed Read");
|
||||
}//else//
|
||||
|
||||
new java.io.File("c:\\temp\\test.tmp").delete();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing hashed stream; Time: " + t + "ms");
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void testWritePrivateKey() {
|
||||
System.out.println("Testing writing a private key to file in c:\\temp");
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
int size = 20;
|
||||
ISignatureAlgorithm privateSignature = new RsaAlgorithm(1024);
|
||||
ISignatureAlgorithm publicSignature = privateSignature.getPublicSignatureAlgorithm();
|
||||
ISymmetricAlgorithm algorithm = new Rijndael("test");
|
||||
java.io.FileOutputStream fout = new java.io.FileOutputStream("c:\\temp\\test.tmp", false);
|
||||
SymmetricOutputStream sout = new SymmetricOutputStream(fout, algorithm);
|
||||
CompressionOutputStream cout = new CompressionOutputStream(sout);
|
||||
ObjectOutputStream out = new ObjectOutputStream(cout, null);
|
||||
|
||||
out.encrypt(true);
|
||||
out.writeObject(privateSignature);
|
||||
out.encrypt(false);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
algorithm = new Rijndael("test");
|
||||
java.io.FileInputStream fin = new java.io.FileInputStream("c:\\temp\\test.tmp");
|
||||
SymmetricInputStream sin = new SymmetricInputStream(fin, algorithm);
|
||||
CompressionInputStream cin = new CompressionInputStream(sin);
|
||||
ObjectInputStream in = new ObjectInputStream(cin, null, null);
|
||||
ISignatureAlgorithm receivedSignature = null;
|
||||
|
||||
in.decrypt(true);
|
||||
receivedSignature = (ISignatureAlgorithm) in.readObject();
|
||||
in.decrypt(false);
|
||||
in.close();
|
||||
|
||||
byte[] source = new byte[size];
|
||||
Random random = new Random();
|
||||
byte[] signed = new byte[receivedSignature.getSignedSize(size)];
|
||||
byte[] unsigned = new byte[size];
|
||||
|
||||
random.nextBytes(source);
|
||||
receivedSignature.sign(source, 0, source.length, signed, 0);
|
||||
publicSignature.verify(signed, 0, signed.length, unsigned, 0);
|
||||
|
||||
for(int i = 0; i < unsigned.length; i++) {
|
||||
if(source[i] != unsigned[i]) {
|
||||
System.out.println("Failed Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
new java.io.File("c:\\temp\\test.tmp").delete();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println("Finished Testing File Writing; Time: " + t + "ms");
|
||||
}
|
||||
}
|
||||
185
Common Test/src/com/softwarezealot/common/io/test/Test.java
Normal file
185
Common Test/src/com/softwarezealot/common/io/test/Test.java
Normal file
@@ -0,0 +1,185 @@
|
||||
package com.softwarezealot.common.io.test;
|
||||
|
||||
import com.common.system.SystemManager;
|
||||
import com.common.io.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999<p>
|
||||
*/
|
||||
public class Test {
|
||||
/**
|
||||
* Test constructor comment.
|
||||
*/
|
||||
public Test() {
|
||||
super();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//char t = '\uAAAA';
|
||||
//System.out.println("\\uAAAA\t" + ((int)t) + "\t" + 0xAAAA);
|
||||
printUnicode16ToUTF8HexCodes();
|
||||
//System.out.println("" + (0xFFFF));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
/**
|
||||
* see JDK documentation (JNI section) types.doc.html.
|
||||
*/
|
||||
public static void printUnicode16ToUTF8HexCodes() {
|
||||
try {
|
||||
byte[] character = new byte[2];
|
||||
char[] characters = new char[1];
|
||||
int max = 0xFFFF;
|
||||
String UTF8 = "UTF8";
|
||||
String Unicode = "Unicode";
|
||||
int count = 0;
|
||||
StringBuffer buffer = new StringBuffer(10000);
|
||||
byte[] oldUtf8 = null;
|
||||
int loopNumber = 0;
|
||||
|
||||
for(characters[0] = '\u0000'; characters[0] < max; characters[0]++, loopNumber++) {
|
||||
String str = new String(characters);
|
||||
byte[] utf8 = str.getBytes(UTF8);
|
||||
byte[] unicode16 = str.getBytes(Unicode);
|
||||
int intValue = (int) characters[0];
|
||||
boolean isSequential = false;
|
||||
|
||||
if((oldUtf8 != null) && (oldUtf8.length == utf8.length)) {
|
||||
int diffCount = 0;
|
||||
boolean isMoreThanOne = false;
|
||||
boolean nextByteMustIncrement = false;
|
||||
|
||||
for(int index = oldUtf8.length - 1; (!isMoreThanOne) && (index >= 0); index--) {
|
||||
if((nextByteMustIncrement) && ((oldUtf8[index] + 1) != utf8[index])) {
|
||||
isMoreThanOne = true;
|
||||
nextByteMustIncrement = false;
|
||||
}//if//
|
||||
else if(oldUtf8[index] != utf8[index]) {
|
||||
diffCount++;
|
||||
|
||||
if((oldUtf8[index] + 1) != utf8[index]) {
|
||||
if((oldUtf8[index] == 0xFF) && (utf8[index] == 0x00)) {
|
||||
nextByteMustIncrement = true;
|
||||
}//if//
|
||||
else {
|
||||
isMoreThanOne = true;
|
||||
}//else//
|
||||
}//if//
|
||||
}//else if//
|
||||
}//for//
|
||||
|
||||
if((!isMoreThanOne) && (diffCount == 1)) {
|
||||
isSequential = true;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
if(!isSequential) {
|
||||
buffer.append(intValue);
|
||||
buffer.append('\t');
|
||||
buffer.append(StreamSupport.getHexString(unicode16));
|
||||
buffer.append('\t');
|
||||
buffer.append(StreamSupport.getHexString(utf8));
|
||||
buffer.append('\r');
|
||||
buffer.append('\n');
|
||||
|
||||
if(count++ > 1000) {
|
||||
System.out.print(buffer);
|
||||
buffer.setLength(0);
|
||||
//com.common.debug.DebugSupport.halt();
|
||||
count = 0;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
oldUtf8 = utf8;
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
}//printUnicode16ToUTF8HexCodes()//
|
||||
public static void test() {
|
||||
byte[] bytes = null;
|
||||
String str = "abcd\u0aaa\u8488\u0799\uffff";
|
||||
|
||||
//Test the java conversion.//
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
bytes = str.getBytes("UTF8");
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + bytes.length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
//Test the software zealot conversion.//
|
||||
try {
|
||||
SystemManager.setupSystem(new com.common.system.WindowsSystem(), null, null);
|
||||
int length = SystemManager.getUtf8StringLength(str);
|
||||
bytes = new byte[length];
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
com.common.system.SystemManager.convertUtf8StringToBytes(str, bytes, 0);
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
//Test the software zealot conversion.//
|
||||
try {
|
||||
//SystemManager.setupSystem(new com.common.system.WindowsSystem(), null, null);
|
||||
int length = SystemManager.getUtf8StringLength(str);
|
||||
bytes = new byte[length];
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int index = 0; index < 10000; index++) {
|
||||
int strLength = str.length();
|
||||
|
||||
for(int characterIndex = 0; characterIndex < strLength; characterIndex++) {
|
||||
char ch = str.charAt(characterIndex);
|
||||
//byte upper = ch >> 8;
|
||||
//byte lower = ch && 0xFF;
|
||||
|
||||
if(ch == 0) {
|
||||
}//if//
|
||||
else if(ch < 0x7F) {
|
||||
}//else if//
|
||||
else if(ch < 0xFFFF) {
|
||||
}//else if//
|
||||
else {
|
||||
}//else//
|
||||
}//for//
|
||||
}//for//
|
||||
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - t));
|
||||
System.out.println("Before: " + str);
|
||||
System.out.println("After: " + (new String(bytes, "UTF8")));
|
||||
System.out.println("Length: " + length);
|
||||
System.out.println("Bytes: " + StreamSupport.getHexString(bytes));
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.softwarezealot.common.security.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.security.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ElGamalTest {
|
||||
/**
|
||||
* ElGamalTest constructor comment.
|
||||
*/
|
||||
public ElGamalTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
try {
|
||||
/*
|
||||
ElGamal2 a = new ElGamal2(1024, new Random(100L));
|
||||
String t = "Hello world! Hello world!";
|
||||
byte[] m = t.getBytes("UTF8");
|
||||
byte[] c = null;
|
||||
|
||||
c = a.encrypt(m);
|
||||
System.out.println(m.length + " " + c.length);
|
||||
m = a.decrypt(c);
|
||||
System.out.println(new String(m, "UTF8"));
|
||||
*/
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.softwarezealot.common.security.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.security.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class RijndaelTest {
|
||||
/**
|
||||
* RijndaelTest constructor comment.
|
||||
*/
|
||||
public RijndaelTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Starting Rijdael Test");
|
||||
|
||||
try {
|
||||
int size = 236;
|
||||
Rijndael a = new Rijndael("test");
|
||||
byte[] source = new byte[size];
|
||||
byte[] encrypted = new byte[a.getEncryptedSize(size)];
|
||||
a.getUnencryptedSize(encrypted.length);
|
||||
a.getOptimalEncryptionBlockSize();
|
||||
a.getOptimalDecryptionBlockSize();
|
||||
byte[] decrypted = new byte[size];
|
||||
Random random = new Random();
|
||||
|
||||
random.nextBytes(source);
|
||||
a.encrypt(source, 0, source.length, encrypted, 0);
|
||||
a.decrypt(encrypted, 0, encrypted.length, decrypted, 0);
|
||||
|
||||
for(int i = 0; i < decrypted.length; i++) {
|
||||
if(source[i] != decrypted[i]) {
|
||||
System.out.println("Failed Rijdael Test");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
System.out.println("Finished Rijdael Test");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.softwarezealot.common.security.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.security.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class RsaTest {
|
||||
/**
|
||||
* RsaTest constructor comment.
|
||||
*/
|
||||
public RsaTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
long t = System.currentTimeMillis();
|
||||
IAsymmetricAlgorithm pri = new RsaAlgorithm();
|
||||
System.out.println("RSA Startup Time: " + (System.currentTimeMillis() - t));
|
||||
IAsymmetricAlgorithm pub = null;
|
||||
Random r = new Random();
|
||||
byte[] u = new byte[1000];
|
||||
byte[] d = null;
|
||||
byte[] e = null;
|
||||
|
||||
pri.getPublicKeyBytes();
|
||||
pub = pri.getPublicAsymmetricAlgorithm();
|
||||
r.nextBytes(u);
|
||||
e = pub.encrypt(u);
|
||||
d = pri.decrypt(e);
|
||||
|
||||
if(d.length == u.length) {
|
||||
for(int index = 0; index < d.length; index++) {
|
||||
if(d[index] != u[index]) {
|
||||
Debug.log("Failed");
|
||||
break;
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
else {
|
||||
Debug.log("Incorrect Size");
|
||||
}//else//
|
||||
|
||||
Debug.log("Finished");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.softwarezealot.common.security.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
* This class supports and tests the com.common.security.Sha1 algorithm.
|
||||
*/
|
||||
public class Sha1Test {
|
||||
//
|
||||
// Only two known sets of data!
|
||||
// Using Hex format 0xAB results in needing casts.
|
||||
//
|
||||
private static String[] texts = { "abc", // t 1
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", // t 2
|
||||
"", // empty, added
|
||||
};
|
||||
private static byte[][] bytes = { { -87, -103, 62, 54, 71, 6, -127, 106, -70, 62, 37, 113, 120, 80, -62, 108, -100, -48, -40, -99, }, {
|
||||
-124, -104, 62, 68, 28, 59, -46, 110, -70, -82, 74, -95, -7, 81, 41, -27, -27, 70, 112, -15, }, {
|
||||
-38, 57, -93, -18, 94, 107, 75, 13, 50, 85, -65, -17, -107, 96, 24, -112, -81, -40, 7, 9, }, };
|
||||
/**
|
||||
* Sha1 constructor.
|
||||
*/
|
||||
public Sha1Test() {
|
||||
super();
|
||||
}//Sha1()//
|
||||
/**
|
||||
* Starts the self test.
|
||||
*/
|
||||
public static final void main(String argv[]) {
|
||||
try {
|
||||
selfTest();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
|
||||
Debug.log("Done.");
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
private static final boolean notEquals(byte[] a, byte[] b) {
|
||||
for(int i = 0; i < a.length; i++) {
|
||||
if(a[i] != b[i]) {
|
||||
return true;
|
||||
}//if//
|
||||
}//for//
|
||||
|
||||
return false;
|
||||
}//notEquals()//
|
||||
public static void selfTest() throws Throwable {
|
||||
/* Compared the old SHA algorithm with the new one to ensure compatability.
|
||||
com.common.security.Sha1Old algorithmOld = new com.common.security.Sha1Old();
|
||||
com.common.security.Sha1 algorithm = new com.common.security.Sha1();
|
||||
String fullSource = "This is a long long test of a lot of text and has many characters so that we can test the hash algorithm with quite a few frames of data. This way the test doesn't just include one frame which would make the test invalid. So if this test works then we can say the hash works very well!";
|
||||
String partialSource = null;
|
||||
byte[] hashOld = null;
|
||||
byte[] hash = null;
|
||||
|
||||
for(int index = 1; index < fullSource.length(); index++) {
|
||||
partialSource = fullSource.substring(0, index);
|
||||
algorithm.add(partialSource);
|
||||
hash = algorithm.hash();
|
||||
algorithmOld.includeSource(partialSource);
|
||||
hashOld = algorithmOld.generateDigest();
|
||||
|
||||
if(notEquals(hash, hashOld)) {
|
||||
com.ibm.uvm.tools.DebugSupport.halt();
|
||||
}
|
||||
}
|
||||
*/
|
||||
int length = bytes[0].length;
|
||||
|
||||
for(int i = 0; i < texts.length; i++) {
|
||||
com.common.security.Sha1 algorithm = new com.common.security.Sha1();
|
||||
byte[] text = texts[i].getBytes();
|
||||
|
||||
algorithm.add(texts[i]);
|
||||
|
||||
if(notEquals(algorithm.hash(), bytes[i])) {
|
||||
throw new Exception("hash #" + i + " failed");
|
||||
}//if//
|
||||
}//for//
|
||||
}//selfTest()//
|
||||
}//Sha1//
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.softwarezealot.common.thread.test;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2003<p>
|
||||
*/
|
||||
public class ThreadServiceTest {
|
||||
/**
|
||||
* ThreadServiceTest constructor comment.
|
||||
*/
|
||||
public ThreadServiceTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
new ThreadServiceTest().run();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public synchronized void run() {
|
||||
com.common.thread.ThreadService.run(new Runnable() {
|
||||
public void run() {
|
||||
System.out.println("Testing 123");
|
||||
|
||||
synchronized(ThreadServiceTest.this) {
|
||||
ThreadServiceTest.this.notify();
|
||||
}//synchronized//
|
||||
}//run()//
|
||||
});
|
||||
|
||||
try {
|
||||
wait();
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
System.out.println("Test complete");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import java.io.*;
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class AdvancedTextParserTest {
|
||||
|
||||
/**
|
||||
* AdvancedStringParserTest constructor comment.
|
||||
*/
|
||||
public AdvancedTextParserTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
//AdvancedStringParser parser = new AdvancedStringParser("This is a test of the AdvancedStringParser class. \r\nThis test will:\r\n\t-check that all parts are working properly\r\n\t-show the programmer what is broken");
|
||||
try {
|
||||
AdvancedTextParser.DelimiterSet delimiterSetA = null;
|
||||
File file = new File(args[0]);
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
byte[] bytes = new byte[fin.available()];
|
||||
String source = null;
|
||||
String[] delimiters = new String[args.length - 1];
|
||||
|
||||
fin.read(bytes);
|
||||
source = new String(bytes, "UTF8");
|
||||
System.arraycopy(args, 1, delimiters, 0, delimiters.length);
|
||||
|
||||
for(int index = 0; index < delimiters.length; index++) {
|
||||
delimiterSetA = AdvancedTextParser.addDelimiter(delimiterSetA, delimiters[index], true, false, null);
|
||||
}//for//
|
||||
|
||||
//parser.setDelimiterSet(delimiterSetA);
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
for(int count = 0; count < 50000; count++) {
|
||||
AdvancedTextParser parser = new AdvancedTextParser(source, delimiterSetA);
|
||||
|
||||
while(parser.hasNext()) {
|
||||
String segment = parser.next();
|
||||
|
||||
//Debug.log(segment);
|
||||
}//while//
|
||||
}//for//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
Debug.log("total time: " + t + "ms");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.util.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class HashMapTest {
|
||||
/**
|
||||
* HashMapTest constructor comment.
|
||||
*/
|
||||
public HashMapTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String prefix = "I02000";
|
||||
int keyCount = 150;
|
||||
LiteHashMap map = new LiteHashMap(10);
|
||||
IList keys = new LiteList(keyCount, 50);
|
||||
|
||||
for(int i = 0; i < keyCount; i++) {
|
||||
keys.add(prefix + i);
|
||||
}//for//
|
||||
|
||||
for(int i = 0; i < keys.getSize(); i++) {
|
||||
map.put(keys.get(i), new Integer(i));
|
||||
}//for//
|
||||
|
||||
for(int i = 0; i < keys.getSize(); i++) {
|
||||
Debug.log(map.get(keys.get(i)).toString());
|
||||
}//for//
|
||||
|
||||
System.exit(0);
|
||||
}//main()//
|
||||
}//HashMapTest//
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
import com.common.event.*;
|
||||
import com.common.thread.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
*/
|
||||
public class JobQueueTest {
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args An array of command-line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//Test the job queue.//
|
||||
JobQueue queue = new JobQueue(new Object[] {new Integer(1), new Integer(2)});
|
||||
LiteList jobs = new LiteList(1000, 10);
|
||||
|
||||
for(int index = 0; index < 1000; index++) {
|
||||
queue.addJob(new SampleJob(index), 0);
|
||||
}//for//
|
||||
|
||||
queue.close();
|
||||
ThreadService.shutdown();
|
||||
}//main()//
|
||||
}//JobQueue//
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.common.comparison.IComparator;
|
||||
import com.common.util.LiteList;
|
||||
|
||||
public class ListTest {
|
||||
private static class Combo {
|
||||
public String text;
|
||||
public Integer value;
|
||||
|
||||
public Combo(String text, Integer value) {
|
||||
this.text = text;
|
||||
this.value = value;
|
||||
}
|
||||
public String toString() {
|
||||
return value + " : " + text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
LiteList list = new LiteList(10, 20);
|
||||
|
||||
list.setOrderComparator(new Comparator() {
|
||||
public int hash(Object value) {
|
||||
return 0;
|
||||
}
|
||||
public int compare(Object value1, Object value2) {
|
||||
return ((Combo) value1).value.intValue() <= ((Combo) value2).value.intValue() ? Comparator.LESS_THAN : Comparator.GREATER_THAN;
|
||||
}
|
||||
});
|
||||
|
||||
list.add(new Combo("First", new Integer(10)));
|
||||
list.add(new Combo("Second", new Integer(5)));
|
||||
list.add(new Combo("Third", new Integer(15)));
|
||||
list.add(new Combo("Fourth", new Integer(20)));
|
||||
list.add(new Combo("Fifth", new Integer(0)));
|
||||
list.add(new Combo("Sixth", new Integer(5)));
|
||||
list.add(new Combo("Seventh", new Integer(0)));
|
||||
list.add(new Combo("Eight", new Integer(5)));
|
||||
list.add(new Combo("Nineth", new Integer(5)));
|
||||
list.add(new Combo("Tenth", new Integer(5)));
|
||||
list.add(new Combo("Eleventh", new Integer(5)));
|
||||
list.add(new Combo("Twelvth", new Integer(5)));
|
||||
list.add(new Combo("Thirteenth", new Integer(5)));
|
||||
list.add(new Combo("Fourteenth", new Integer(5)));
|
||||
list.add(new Combo("Fifteenth", new Integer(5)));
|
||||
|
||||
for(int index = 0; index < list.getSize(); index++) {
|
||||
System.out.println(list.get(index));
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import com.common.debug.*;
|
||||
import com.common.event.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999-2002<p>
|
||||
*/
|
||||
public class SampleJob extends com.common.event.VoidHandler1 {
|
||||
private int jobNumber = 0;
|
||||
/**
|
||||
* SampleJob constructor.
|
||||
*/
|
||||
public SampleJob(int jobNumber) {
|
||||
super();
|
||||
|
||||
this.jobNumber = jobNumber;
|
||||
}//SampleJob()//
|
||||
/**
|
||||
* Processes the job by printing the job number to the debug log.
|
||||
* @param resource The resource passed by the invoker (in this case the job queue).
|
||||
*/
|
||||
public void evaluate(Object resource) {
|
||||
//Simualate some work.//
|
||||
if((resource == null) || (resource.equals(new Integer(2)))) {
|
||||
synchronized(this) {
|
||||
try {
|
||||
wait(10);
|
||||
}//try//
|
||||
catch(InterruptedException e) {
|
||||
Debug.handle(e);
|
||||
}//catch//
|
||||
}//synchronized//
|
||||
}//if//
|
||||
|
||||
//Spit out the details to the logs.//
|
||||
Debug.log(jobNumber + " completed" + (resource != null ? (" on job processor: " + resource + ".") : "."));
|
||||
}//evaluate()//
|
||||
}//SampleJob//
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import java.io.*;
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class TextParserTest {
|
||||
|
||||
/**
|
||||
* AdvancedStringParserTest constructor comment.
|
||||
*/
|
||||
public TextParserTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
long t = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
File file = new File(args[0]);
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
byte[] bytes = new byte[fin.available()];
|
||||
String source = null;
|
||||
String[] delimiters = new String[args.length - 1];
|
||||
|
||||
fin.read(bytes);
|
||||
source = new String(bytes, "UTF8");
|
||||
System.arraycopy(args, 1, delimiters, 0, delimiters.length);
|
||||
|
||||
for(int count = 0; count < 50000; count++) {
|
||||
TextParser parser = new TextParser(source, delimiters, true);
|
||||
|
||||
parser.addDelimiter(" ", false);
|
||||
|
||||
while(parser.hasNext()) {
|
||||
String segment = parser.next();
|
||||
|
||||
//Debug.log(segment);
|
||||
}//while//
|
||||
}//for//
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
Debug.log("total time: " + t + "ms");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
Debug.log(e);
|
||||
}//catch//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.softwarezealot.common.util.test;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.common.debug.*;
|
||||
//import com.foundation.util.Tree;
|
||||
|
||||
/**
|
||||
* Copyright Wynne Crisman 1999,2005<p>
|
||||
*/
|
||||
public class TreeTest {
|
||||
/**
|
||||
* TreeTest constructor comment.
|
||||
*/
|
||||
public TreeTest() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* Starts the application.
|
||||
* @param args an array of command-line arguments
|
||||
*/
|
||||
public static void main(java.lang.String[] args) {
|
||||
/*
|
||||
Tree tree = new Tree();
|
||||
String root1 = "root1";
|
||||
String root1child1 = "root1child1";
|
||||
String root2 = "root2";
|
||||
String root2child1 = "root2child1";
|
||||
String root2child2 = "root2child2";
|
||||
String root2child2child1 = "root2child2child1";
|
||||
String root2child2child1child1 = "root2child2child1child1";
|
||||
String root2child2child1child2 = "root2child2child1child2";
|
||||
String root2child2child2 = "root2child2child2";
|
||||
String root2child2child3 = "root2child2child3";
|
||||
String root2child3 = "root2child3";
|
||||
String root3 = "root3";
|
||||
String root4 = "root4";
|
||||
String root4child1 = "root4child1";
|
||||
String root4child1child1 = "root4child1child1";
|
||||
String root4child2 = "root4child2";
|
||||
|
||||
tree.add(root1);
|
||||
tree.add(root1, root1child1);
|
||||
tree.add(root2);
|
||||
tree.add(root3);
|
||||
tree.add(root2, root2child1);
|
||||
tree.add(root2, root2child2);
|
||||
tree.add(root2, root2child3);
|
||||
tree.add(root2child2, root2child2child1);
|
||||
tree.add(root2child2child1, root2child2child1child1);
|
||||
tree.add(root2child2, root2child2child2);
|
||||
tree.add(root2child2, root2child2child3);
|
||||
tree.add(root2child2child1, root2child2child1child2);
|
||||
|
||||
Debug.log("");
|
||||
Debug.log("Top Down:");
|
||||
IIterator iterator = tree.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("" + iterator.next());
|
||||
}//while//
|
||||
|
||||
Debug.log("");
|
||||
Debug.log("Depth First:");
|
||||
iterator = tree.iteratorDepthFirst();
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("" + iterator.next());
|
||||
}//while//
|
||||
|
||||
Debug.log("");
|
||||
Debug.log("Top Down from root2child2:");
|
||||
iterator = tree.iterator(root2child2);
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("" + iterator.next());
|
||||
}//while//
|
||||
|
||||
tree.remove(root2child2);
|
||||
Debug.log("");
|
||||
Debug.log("Top Down after removing root2child2:");
|
||||
iterator = tree.iterator(root2child2);
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("" + iterator.next());
|
||||
}//while//
|
||||
|
||||
Tree subtree = new Tree();
|
||||
subtree.add(root4);
|
||||
subtree.add(root4, root4child1);
|
||||
subtree.add(root4child1, root4child1child1);
|
||||
subtree.add(root4, root4child2);
|
||||
tree.addAll((ICollection) subtree);
|
||||
|
||||
Debug.log("");
|
||||
Debug.log("Top Down after adding root4:");
|
||||
iterator = tree.iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Debug.log("" + iterator.next());
|
||||
}//while//
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.softwarezealot.orb.test;
|
||||
|
||||
import com.common.orb.Orb;
|
||||
import com.common.thread.ThreadService;
|
||||
import com.de22.orb.Address;
|
||||
import com.de22.orb.optional.ServerSocketOptions;
|
||||
import com.de22.orb.optional.SocketOptions;
|
||||
|
||||
/**
|
||||
* Copyright Declarative Engineering LLC 2009<p>
|
||||
*/
|
||||
public class OrbServerSocketTest {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Orb.setOrbWrapper(new com.de22.orb.optional.CommonOrbWrapper(new com.de22.orb.development.OrbClassLoader(), null, null, null, null));
|
||||
|
||||
try {
|
||||
Object serverSocketId = Orb.openServerSocket("TestServerSocket", new ServerSocketOptions(new Address("4000"), null, new SocketOptions()));
|
||||
|
||||
if(serverSocketId != null) {
|
||||
System.out.println("Test sucessful.");
|
||||
Orb.closeServerSocket(serverSocketId);
|
||||
}//if//
|
||||
else {
|
||||
System.out.println("Test failed.");
|
||||
}//else//
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}//catch//
|
||||
|
||||
Orb.shutdown();
|
||||
ThreadService.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user