aboutsummaryrefslogtreecommitdiff
path: root/gnu/testlet/org/omg/CORBA/Any/testAny.java
blob: defd521aa921cb27237a497580627949ff5b674f (plain)
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// Tags: JDK1.2
// Uses: ../Asserter

// Copyright (C) 2005 Audrius Meskauskas (AudriusA@Bioinformatics.org)

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */


package gnu.testlet.org.omg.CORBA.Any;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import gnu.testlet.org.omg.CORBA.Asserter;

import org.omg.CORBA.Any;
import org.omg.CORBA.BAD_INV_ORDER;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ORB;
import org.omg.CORBA.ShortHolder;
import org.omg.CORBA.ShortSeqHolder;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.portable.Streamable;

import java.math.BigDecimal;

import java.util.Random;

/**
 * Test the CORBA Any. The actual class being tested is obtained from
 * the ORB and depends from the implementation; in GNU Classpath it is
 * gnu.CORBA.gnuAny.
 *
 * @author Audrius Meskauskas (AudriusA@bluewin.ch)
 */
public class testAny
  extends Asserter
  implements Testlet
{
  private Any any;
  private ORB orb;
  private Random r = new Random();

  public void test(TestHarness harness)
  {
    h = harness;

    orb = ORB.init();
    any = orb.create_any();

    testEquals();
    testExtract_any();
    testExtract_boolean();
    testExtract_char();
    testExtract_double();
    testExtract_fixed();
    testExtract_float();
    testExtract_long();
    testExtract_longlong();
    testExtract_octet();
    testExtract_short();
    testExtract_Streamable();
    testExtract_string();
    testExtract_TypeCode();
    testExtract_ulong();
    testExtract_ulonglong();
    testExtract_ushort();
    testExtract_wchar();
    testExtract_wstring();
  }

  public void testEquals()
  {
    Any other = orb.create_any();
    other.insert_string("other");
    any.insert_string("this");

    assertFalse("eq1", any.equal(other));

    any.insert_string("other");
    assertTrue("eq2", any.equal(other));

    any.insert_long(1);
    assertFalse("eq3", any.equal(other));
  }

  public void testExtract_Streamable()
                              throws BAD_INV_ORDER
  {
    Streamable expectedReturn =
      new ShortHolder((short) r.nextInt(Short.MAX_VALUE));
    any.insert_Streamable(expectedReturn);

    Streamable actualReturn = any.extract_Streamable();
    assertEquals("Streamable", expectedReturn, actualReturn);
  }

  public void testExtract_TypeCode()
                            throws BAD_OPERATION
  {
    TypeCode expectedReturn = new ShortSeqHolder(new short[ 0 ])._type();
    any.insert_TypeCode(expectedReturn);

    TypeCode actualReturn = any.extract_TypeCode();
    assertEquals("typecode", expectedReturn, actualReturn);
  }

  public void testExtract_any()
                       throws BAD_OPERATION
  {
    Any expectedReturn = orb.create_any();
    expectedReturn.insert_longlong(r.nextLong());

    any.insert_any(expectedReturn);

    Any actualReturn = any.extract_any();
    assertEquals("Any inside Any", expectedReturn, actualReturn);
  }

  public void testExtract_boolean()
                           throws BAD_OPERATION
  {
    boolean expectedReturn = false;
    any.insert_boolean(expectedReturn);

    boolean actualReturn = any.extract_boolean();
    assertEquals("boolean", expectedReturn, actualReturn);

    expectedReturn = true;
    any.insert_boolean(expectedReturn);
    actualReturn = any.extract_boolean();
    assertEquals("boolean", expectedReturn, actualReturn);
  }

  public void testExtract_char()
                        throws BAD_OPERATION
  {
    char expectedReturn = 'z';
    any.insert_char(expectedReturn);

    char actualReturn = any.extract_char();
    assertEquals("char", expectedReturn, actualReturn);
  }

  public void testExtract_double()
                          throws BAD_OPERATION
  {
    double expectedReturn = r.nextDouble();
    any.insert_double(expectedReturn);

    double actualReturn = any.extract_double();
    assertEquals("double", expectedReturn, actualReturn, Double.MIN_VALUE);
  }

  public void testExtract_fixed()
                         throws BAD_OPERATION
  {
    BigDecimal expectedReturn = new BigDecimal("123.456");
    any.insert_fixed(expectedReturn,
                     orb.create_fixed_tc((short) 6,
                                         (short) expectedReturn.scale()
                                        )
                    );

    BigDecimal actualReturn = any.extract_fixed();
    assertEquals("fixed", expectedReturn, actualReturn);
  }

  public void testExtract_float()
                         throws BAD_OPERATION
  {
    float expectedReturn = r.nextFloat();
    any.insert_float(expectedReturn);

    float actualReturn = any.extract_float();
    assertEquals("float", expectedReturn, actualReturn, Float.MIN_VALUE);
  }

  public void testExtract_long()
                        throws BAD_OPERATION
  {
    int expectedReturn = r.nextInt() - Integer.MAX_VALUE / 2;
    any.insert_long(expectedReturn);

    int actualReturn = any.extract_long();
    assertEquals("long", expectedReturn, actualReturn);
  }

  public void testExtract_longlong()
                            throws BAD_OPERATION
  {
    long expectedReturn = r.nextLong() - (Long.MAX_VALUE / 2);
    any.insert_longlong(expectedReturn);

    long actualReturn = any.extract_longlong();
    assertEquals("long", expectedReturn, actualReturn);
  }

  public void testExtract_octet()
                         throws BAD_OPERATION
  {
    byte expectedReturn = (byte) r.nextInt(Byte.MAX_VALUE);
    any.insert_octet(expectedReturn);

    byte actualReturn = any.extract_octet();
    assertEquals("byte (octet)", expectedReturn, actualReturn);
  }

  public void testExtract_short()
                         throws BAD_OPERATION
  {
    short expectedReturn =
      (short) (r.nextInt(Short.MAX_VALUE) - Short.MAX_VALUE / 2);

    any.insert_short(expectedReturn);

    short actualReturn = any.extract_short();
    assertEquals("short", expectedReturn, actualReturn);
  }

  public void testExtract_string()
                          throws BAD_OPERATION
  {
    String expectedReturn = "http://www.lithuania.lt";
    any.insert_string(expectedReturn);

    String actualReturn = any.extract_string();
    assertEquals("string", expectedReturn, actualReturn);
  }

  public void testExtract_ulong()
                         throws BAD_OPERATION
  {
    int expectedReturn = r.nextInt(Integer.MAX_VALUE);
    any.insert_ulong(expectedReturn);

    int actualReturn = any.extract_ulong();
    assertEquals("unsigned long", expectedReturn, actualReturn);
  }

  public void testExtract_ulonglong()
                             throws BAD_OPERATION
  {
    long expectedReturn = Math.abs(r.nextLong());
    any.insert_ulonglong(expectedReturn);

    long actualReturn = any.extract_ulonglong();
    assertEquals("unsigned long long", expectedReturn, actualReturn);
  }

  public void testExtract_ushort()
                          throws BAD_OPERATION
  {
    short expectedReturn = (short) r.nextInt(Short.MAX_VALUE);
    any.insert_ushort(expectedReturn);

    short actualReturn = any.extract_ushort();
    assertEquals("unsigned short", expectedReturn, actualReturn);
  }

  public void testExtract_wchar()
                         throws BAD_OPERATION
  {
    char expectedReturn = '\u017E';
    any.insert_wchar(expectedReturn);

    char actualReturn = any.extract_wchar();
    assertEquals("wchar", expectedReturn, actualReturn);
  }

  public void testExtract_wstring()
                           throws BAD_OPERATION
  {
    String expectedReturn =
      "http://www.lithuania.lt and \u0105\u010D\u0119\u0117" +
      "\u012F\u0161\u0173\u016B\u017E\u0104\u0118.";
    any.insert_wstring(expectedReturn);

    String actualReturn = any.extract_wstring();
    assertEquals("wstring", expectedReturn, actualReturn);
  }
}