1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
//
// File: ObjargTestDriver.java
// Copyright: (c) 2001 The Regents of the University of California
// Revision: @(#) $Revision: 4434 $
// Date: $Date: 2005-03-17 09:05:29 -0800 (Thu, 17 Mar 2005) $
// Description: Objects as arguments regression test cases for Java
// calling other languages
//
/**
* The following class runs the array regression test cases for Java.
*/
public class ObjargTestDriver {
private final static String[] s_results = {
"FAIL",
"XFAIL",
"synch.ResultType.PASS",
"Xsynch.ResultType.PASS",
"UNSUPPORTED"
};
private final static int ONE_D_SIZE = 345;
private final static int TEST_DIM1 = 13;
private final static int TEST_DIM2 = 16;
private static int s_part = 0;
private static int s_result = synch.ResultType.PASS;
private static synch.RegOut tracker;
/**
* Check the results of the test case.
*/
//Comments should really be passed in here.
private static void startTest(String test) {
tracker.startPart(++s_part);
if(test != null)
tracker.writeComment(test);
}
private static void check(int expected, boolean pass, String test ) {
if (test != null)
tracker.writeComment(test);
if(expected == synch.ResultType.PASS)
if(pass)
tracker.endPart(s_part, synch.ResultType.PASS);
else
tracker.endPart(s_part, synch.ResultType.FAIL);
else if (expected == synch.ResultType.XFAIL)
if(pass)
tracker.endPart(s_part, synch.ResultType.XPASS);
else
tracker.endPart(s_part, synch.ResultType.XFAIL);
else
tracker.endPart(s_part, synch.ResultType.FAIL);
}
/**
* The main test driver takes no command-line arguments and runs the
* regression tests.
*/
public static void main(String args[]) {
try {
tracker = new synch.RegOut();
tracker.setExpectations(-1);
s_part = 0;
s_result = synch.ResultType.PASS;
//Prepare For The Test
final int numEmp = 7;
TmpData[] tdata = null;
tdata =new TmpData[numEmp];
tdata[0] = new TmpData("John Smith", 35, 75.7e3F, 'c');
tdata[1] = new TmpData("Jane Doe", 40, 85.5e3F, 'm');
tdata[2] = new TmpData("Ella Vader", 64, 144.2e3F, 'r');
tdata[3] = new TmpData("Marge Inovera", 32, 483.2e3F, 's');
tdata[4] = new TmpData("Hughy Louis Dewey", 45, 182.9e3F, 'm');
tdata[5] = new TmpData("Heywood Yubuzof", 12, 20.8e3F, 'x');
tdata[6] = new TmpData("Picov Andropov", 90, 120.6e3F, 'r');
//Load the Employee array
//And begin the initial tests
objarg.EmployeeArray a = new objarg.EmployeeArray();
for(int i = 0; i < numEmp; ++i) {
objarg.Employee e = new objarg.Employee();
startTest(null);
check(synch.ResultType.PASS, (e != null), "Create Employee " + tdata[i].name);
startTest(null);
check(synch.ResultType.PASS,
e.init(tdata[i].name, tdata[i].age, tdata[i].salary,
tdata[i].status),
"Initialize Employee");
startTest(null);
check(synch.ResultType.PASS, a.appendEmployee(e), "Append Employee");
startTest(null);
check(synch.ResultType.PASS, (a.getLength() == (i+1)), "Correct Array Length");
startTest(null);
check(synch.ResultType.PASS, e.isSame(a.at(i+1)), "Check Name in Array");
startTest(null);
check(synch.ResultType.PASS, (e.getAge() == tdata[i].age), "Check Age in Array");
startTest(null);
check(synch.ResultType.PASS, (e.getSalary() == tdata[i].salary), "Check Salary in Array");
startTest(null);
check(synch.ResultType.PASS, (e.getStatus() == tdata[i].status), "Check Status in Array");
}
for(int i = 0; i < numEmp; ++i) {
objarg.Employee.Holder e_hold = new objarg.Employee.Holder();
int empInd = a.findByName(tdata[i].name, e_hold);
startTest(null);
check(synch.ResultType.PASS, (empInd == (i+1)), "Check find by Name Ind Result");
if (empInd != 0) {
startTest(null);
check(synch.ResultType.PASS, e_hold.get().isSame(a.at(empInd)), "Double Check Name");
}
}
objarg.Employee f = new objarg.Employee();
f.init("Hire High", 21, 0, 's');
objarg.Employee.Holder f_hold = new objarg.Employee.Holder(f);
startTest(null);
check(synch.ResultType.PASS, a.promoteToMaxSalary(f_hold), "Promote to Max Salary");
startTest(null);
check(synch.ResultType.PASS, (f.getSalary() == (float)483.2e3F),
"Hire has been upgraded to the correct salary");
startTest(null);
check(synch.ResultType.PASS, a.appendEmployee(f), "Append Hire");
f = new objarg.Employee();
f.init("Amadeo Avogadro, conte di Quaregna", 225, 6.022045e23F, 'd');
startTest(null);
check(synch.ResultType.PASS, !a.promoteToMaxSalary(f_hold), "Amadeo can't get a higher salary");
/**
* Feasability of java object arrays
*/
objarg.Employee.Array1 orray = new objarg.Employee.Array1(5,true);
for(int i = 0; i < 5; ++i) {
orray.set(i, a.at(i+1));
}
for(int i = 0; i < 5; ++i) {
startTest(null);
check(synch.ResultType.PASS, (orray.get(i).getName().compareTo(a.at(i+1).getName()) == 0),
"Object " + i + " correctly copied to Sidl Array");
}
objarg.Employee[] gotArray = orray.toArray();
for(int i = 0; i < 5; ++i) {
startTest(null);
check(synch.ResultType.PASS, (orray.get(i).getName().compareTo(gotArray[i].getName()) == 0),
"Object " + i + " correctly copied from Sidl Array");
}
objarg.Employee.Array1 orray2 = new objarg.Employee.Array1(gotArray, true);
for(int i = 0; i < 5; ++i) {
startTest(null);
check(synch.ResultType.PASS, (orray.get(i).getName().compareTo(orray2.get(i).getName()) == 0),
"Object " + i + " correctly copied from Java Array");
}
/*
* Output final test results
*/
tracker.close();
// System.out.println("TEST_RESULT " + s_results[s_result]);
Runtime.getRuntime().exit(0); /* workaround for Linux JVM 1.3.1 bug */
/*
* Catch any unexpected exceptions and return a test failure
*/
} catch (Throwable ex) {
tracker.close();
//System.out.println("TEST_RESULT FAIL");
System.out.println(ex.toString());
System.exit(1);
}
}
}
/** A little class to hold the Data used for the test*/
class TmpData {
String name;
int age;
float salary;
char status;
public TmpData(String s, int a, float sal, char stat) {
name = s;
age = a;
salary = sal;
status = stat;
}
}
|