File: OverloadTestDriver.java

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (179 lines) | stat: -rw-r--r-- 5,588 bytes parent folder | download
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
// 
// File:        OverloadTestDriver.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: overload regression test case for Java calling other languages
// 

/**
 * The following class runs the exception regression test cases for Java.
 */
public class OverloadTestDriver {


  private final static String[] s_results = {
    "FAIL",
    "XFAIL",
    "synch.ResultType.PASS",
    "Xsynch.ResultType.PASS",
    "UNSUPPORTED"
  };

  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[]) {
    boolean b1   = true;
    int     i1   = 1;
    double  d1   = 1.0;
    float   f1   = 1.0F;
    double  did  = 2.0;
    double  difd = 3.0;
    String  s1   = "AnException";

    sidl.DoubleComplex dcret = null;
    sidl.DoubleComplex dc1   = new sidl.DoubleComplex(1.1, 1.1);
    sidl.FloatComplex  fcret = null;
    sidl.FloatComplex  fc1   = new sidl.FloatComplex(2.2F, 2.2F);

    try {
      /*
       * Begin the test
       */
      tracker = new synch.RegOut();
      tracker.setExpectations(-1);

      s_part   = 0;
      s_result = synch.ResultType.PASS;

      Overload.Test t = new Overload.Test();

      if (t != null) {
        /*
         * Zero argument test
         */
startTest(null);
        check(synch.ResultType.PASS, t.getValue() == 1, "Zero arguments, expecting a 1");

        /*
         * One-argument tests
         */
startTest(null);
        check(synch.ResultType.PASS, t.getValue(b1) == b1, "boolean argument");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(d1) == d1, "double argument");
        dcret = t.getValue(dc1);
startTest(null);
        check(synch.ResultType.PASS, dcret.real() == dc1.real() && dcret.imag() == dc1.imag(), 
              "dcomplex argument");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(f1) == f1, "float argument");
        fcret = t.getValue(fc1);
startTest(null);
        check(synch.ResultType.PASS, fcret.real() == fc1.real() && fcret.imag() == fc1.imag(), 
              "fcomplex argument");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(i1) == i1, "integer argument");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(s1).equals(s1), "string argument");

        Overload.AnException ae = new Overload.AnException();
startTest(null);
        check(synch.ResultType.PASS, t.getValue(ae).equals(s1), "AnException argument");

        Overload.AClass ac = new Overload.AClass();
startTest(null);
        check(synch.ResultType.PASS, t.getValue(ac) == 2, "AClass argument");

        Overload.BClass bc = new Overload.BClass();
startTest(null);
        check(synch.ResultType.PASS, t.getValue(bc) == 2, "BClass argument");

        /*
         * Two-argument tests
         */
startTest(null);
        check(synch.ResultType.PASS, t.getValue(d1, i1) == did, "Double, Int arguments");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(i1, d1) == did, "Int, Double arguments");

        /*
         * Three-argument tests
         */
startTest(null);
        check(synch.ResultType.PASS, t.getValue(d1, i1, f1) == difd, 
              "Double, Int, Float args");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(i1, d1, f1) == difd, 
              "Int, Double, Float args");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(d1, f1, i1) == difd, 
              "Double, Float, Int args");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(i1, f1, d1) == difd, 
              "Int, Float, Double args");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(f1, d1, i1) == difd, 
              "Float, Double, Int args");
startTest(null);
        check(synch.ResultType.PASS, t.getValue(f1, i1, d1) == difd, 
              "Float, Int, Double args");
      } else {
        System.out.println("TEST_RESULT FAIL");
        System.out.println("COMMENT:  ** No test object was created! **");
        System.exit(1);
      }

      /*
       * 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 (Throwable ex) {
      /*
       * Catch any unexpected exceptions and return a test failure
       */
      tracker.close();
      //System.out.println("TEST_RESULT FAIL");
      System.out.println(ex.toString());
      System.exit(1);
    }
  }
}