4
%% Copyright Ericsson AB 2004-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
%%-----------------------------------------------------------------
23
%% Test suite for the basic typecode functions
25
%%-----------------------------------------------------------------
28
-include_lib("test_server/include/test_server.hrl").
29
-include_lib("orber/src/orber_iiop.hrl").
31
-define(default_timeout, ?t:minutes(3)).
35
case (catch (Expr)) of
36
AcTuAlReS when is_binary(AcTuAlReS)->
37
io:format("###### ERROR ERROR ######~nRESULT: ~p~n",
44
-define(SUB_ELIST, [{"null", orber_tc:null()},
45
{"void", orber_tc:void()},
46
{"short", orber_tc:short()},
47
{"unsigned_short", orber_tc:unsigned_short()},
48
{"long", orber_tc:long()},
49
{"unsigned_long", orber_tc:unsigned_long()},
50
{"long_long", orber_tc:long_long()},
51
{"unsigned_long_long", orber_tc:unsigned_long_long()},
52
{"float", orber_tc:'float'()},
53
{"double", orber_tc:double()},
54
{"longdouble", orber_tc:longdouble()},
55
{"boolean", orber_tc:boolean()},
56
{"char", orber_tc:char()},
57
{"wchar", orber_tc:wchar()},
58
{"octet", orber_tc:octet()},
59
{"any", orber_tc:any()},
60
{"typecode", orber_tc:typecode()},
61
{"principal", orber_tc:principal()},
62
{"object_reference", orber_tc:object_reference("Id", "Name")}]).
64
-define(ELIST, [{"null", orber_tc:null()},
65
{"void", orber_tc:void()},
66
{"short", orber_tc:short()},
67
{"unsigned_short", orber_tc:unsigned_short()},
68
{"long", orber_tc:long()},
69
{"unsigned_long", orber_tc:unsigned_long()},
70
{"long_long", orber_tc:long_long()},
71
{"unsigned_long_long", orber_tc:unsigned_long_long()},
72
{"float", orber_tc:'float'()},
73
{"double", orber_tc:double()},
74
{"longdouble", orber_tc:longdouble()},
75
{"boolean", orber_tc:boolean()},
76
{"char", orber_tc:char()},
77
{"wchar", orber_tc:wchar()},
78
{"octet", orber_tc:octet()},
79
{"any", orber_tc:any()},
80
{"typecode", orber_tc:typecode()},
81
{"principal", orber_tc:principal()},
82
{"object_reference", orber_tc:object_reference("Id", "Name")},
83
{"struct", orber_tc:struct("Id", "Name", ?SUB_ELIST)},
84
{"enum", orber_tc:enum("Id", "Name", ["E1", "E2"])},
85
{"string", orber_tc:string(1)},
86
{"wstring", orber_tc:wstring(0)},
87
{"sequence", orber_tc:sequence(orber_tc:enum("Id", "Name",
89
{"array", orber_tc:array(orber_tc:enum("Id", "Name",
91
{"alias", orber_tc:alias("id", "name",
92
orber_tc:enum("Id", "Name",
94
{"exception", orber_tc:exception("Id", "Name", ?SUB_ELIST)}]).
96
-define(VELIST, [{"null", orber_tc:null(), 42},
97
{"void", orber_tc:void(), 42},
98
{"short", orber_tc:short(), 42},
99
{"unsigned_short", orber_tc:unsigned_short(), 42},
100
{"long", orber_tc:long(), 42},
101
{"unsigned_long", orber_tc:unsigned_long(), 42},
102
{"long_long", orber_tc:long_long(), 42},
103
{"unsigned_long_long", orber_tc:unsigned_long_long(), 42},
104
{"float", orber_tc:'float'(), 42},
105
{"double", orber_tc:double(), 42},
106
{"longdouble", orber_tc:longdouble(), 42},
107
{"boolean", orber_tc:boolean(), 42},
108
{"char", orber_tc:char(), 42},
109
{"wchar", orber_tc:wchar(), 42},
110
{"octet", orber_tc:octet(), 42},
111
{"any", orber_tc:any(), 42},
112
{"typecode", orber_tc:typecode(), 42},
113
{"principal", orber_tc:principal(), 42},
114
{"object_reference", orber_tc:object_reference("Id", "Name"), 42},
115
{"struct", orber_tc:struct("Id", "Name", ?SUB_ELIST), 42},
116
{"enum", orber_tc:enum("Id", "Name", ["E1", "E2"]), 42},
117
{"string", orber_tc:string(1), 42},
118
{"wstring", orber_tc:wstring(0), 42},
119
{"sequence", orber_tc:sequence(orber_tc:enum("Id", "Name",
120
["E1", "E2"]), 0), 42},
121
{"array", orber_tc:array(orber_tc:enum("Id", "Name",
122
["E1", "E2"]), 2), 42},
123
{"alias", orber_tc:alias("id", "name",
124
orber_tc:enum("Id", "Name",
126
{"exception", orber_tc:exception("Id", "Name", ?SUB_ELIST), 42}]).
128
%%-----------------------------------------------------------------
130
%%-----------------------------------------------------------------
131
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
132
init_per_group/2,end_per_group/2]).
134
%%-----------------------------------------------------------------
136
%%-----------------------------------------------------------------
137
-compile(export_all).
139
%%-----------------------------------------------------------------
143
%%-----------------------------------------------------------------
144
suite() -> [{ct_hooks,[ts_install_cth]}].
147
[null, void, short, ushort, long, ulong, longlong,
148
ulonglong, boolean, char, wchar, octet, float, double,
149
longdouble, any, typecode, principal, object_reference,
150
struct, union, enum, string, wstring, sequence, array,
151
alias, exception, fixed, value, value_box, native,
152
abstract_interface, indirection, get_tc].
157
init_per_suite(Config) ->
160
end_per_suite(_Config) ->
163
init_per_group(_GroupName, Config) ->
166
end_per_group(_GroupName, Config) ->
170
%%-----------------------------------------------------------------
171
%% Init and cleanup functions.
172
%%-----------------------------------------------------------------
174
init_per_testcase(_Case, Config) ->
175
?line Dog=test_server:timetrap(?default_timeout),
176
[{watchdog, Dog}|Config].
179
end_per_testcase(_Case, Config) ->
180
Dog = ?config(watchdog, Config),
181
test_server:timetrap_cancel(Dog),
184
%%-----------------------------------------------------------------
185
%% Test Case: null test
187
%%-----------------------------------------------------------------
191
?line true = orber_tc:check_tc(orber_tc:null()),
192
?line code(orber_tc:null()),
195
%%-----------------------------------------------------------------
196
%% Test Case: void test
198
%%-----------------------------------------------------------------
202
?line true = orber_tc:check_tc(orber_tc:void()),
203
?line code(orber_tc:void()),
206
%%-----------------------------------------------------------------
207
%% Test Case: short integer test
209
%%-----------------------------------------------------------------
213
?line true = orber_tc:check_tc(orber_tc:short()),
214
?line code(orber_tc:short()),
217
%%-----------------------------------------------------------------
218
%% Test Case: unsigned short integer test
220
%%-----------------------------------------------------------------
224
?line true = orber_tc:check_tc(orber_tc:unsigned_short()),
225
?line code(orber_tc:unsigned_short()),
228
%%-----------------------------------------------------------------
229
%% Test Case: long integer test
231
%%-----------------------------------------------------------------
235
?line true = orber_tc:check_tc(orber_tc:long()),
236
?line code(orber_tc:long()),
239
%%-----------------------------------------------------------------
240
%% Test Case: unsigned long integer test
242
%%-----------------------------------------------------------------
246
?line true = orber_tc:check_tc(orber_tc:unsigned_long()),
247
?line code(orber_tc:unsigned_long()),
251
%%-----------------------------------------------------------------
252
%% Test Case: long integer test
254
%%-----------------------------------------------------------------
256
longlong(suite) -> [];
258
?line true = orber_tc:check_tc(orber_tc:long_long()),
259
?line code(orber_tc:long_long()),
262
%%-----------------------------------------------------------------
263
%% Test Case: unsigned long integer test
265
%%-----------------------------------------------------------------
266
ulonglong(doc) -> [];
267
ulonglong(suite) -> [];
269
?line true = orber_tc:check_tc(orber_tc:unsigned_long_long()),
270
?line code(orber_tc:unsigned_long_long()),
274
%%-----------------------------------------------------------------
275
%% Test Case: float test
277
%%-----------------------------------------------------------------
281
?line true = orber_tc:check_tc(orber_tc:'float'()),
282
?line code(orber_tc:'float'()),
285
%%-----------------------------------------------------------------
286
%% Test Case: double test
288
%%-----------------------------------------------------------------
292
?line true = orber_tc:check_tc(orber_tc:double()),
293
?line code(orber_tc:double()),
296
%%-----------------------------------------------------------------
297
%% Test Case: longdouble test
299
%%-----------------------------------------------------------------
300
longdouble(doc) -> [];
301
longdouble(suite) -> [];
303
?line true = orber_tc:check_tc(orber_tc:longdouble()),
304
?line code(orber_tc:longdouble()),
307
%%-----------------------------------------------------------------
308
%% Test Case: boolean test
310
%%-----------------------------------------------------------------
312
boolean(suite) -> [];
314
?line true = orber_tc:check_tc(orber_tc:boolean()),
315
?line code(orber_tc:boolean()),
318
%%-----------------------------------------------------------------
319
%% Test Case: character test
321
%%-----------------------------------------------------------------
325
?line true = orber_tc:check_tc(orber_tc:char()),
326
?line code(orber_tc:char()),
329
%%-----------------------------------------------------------------
330
%% Test Case: character test
332
%%-----------------------------------------------------------------
336
?line true = orber_tc:check_tc(orber_tc:wchar()),
337
?line code(orber_tc:wchar()),
340
%%-----------------------------------------------------------------
341
%% Test Case: octet test
343
%%-----------------------------------------------------------------
347
?line true = orber_tc:check_tc(orber_tc:octet()),
348
?line code(orber_tc:octet()),
351
%%-----------------------------------------------------------------
352
%% Test Case: any test
354
%%-----------------------------------------------------------------
358
?line true = orber_tc:check_tc(orber_tc:any()),
359
?line code(orber_tc:any()),
362
%%-----------------------------------------------------------------
363
%% Test Case: typecode test
365
%%-----------------------------------------------------------------
367
typecode(suite) -> [];
369
?line true = orber_tc:check_tc(orber_tc:typecode()),
370
?line code(orber_tc:typecode()),
373
%%-----------------------------------------------------------------
374
%% Test Case: principal test
376
%%-----------------------------------------------------------------
377
principal(doc) -> [];
378
principal(suite) -> [];
380
?line true = orber_tc:check_tc(orber_tc:principal()),
381
?line code(orber_tc:principal()),
385
%%-----------------------------------------------------------------
386
%% Test Case: object_reference test
388
%%-----------------------------------------------------------------
389
object_reference(doc) -> [];
390
object_reference(suite) -> [];
391
object_reference(_) ->
392
?line true = orber_tc:check_tc(orber_tc:object_reference("Id", "Name")),
393
?line false = orber_tc:check_tc(orber_tc:object_reference(42, "Name")),
394
?line false = orber_tc:check_tc(orber_tc:object_reference("Id", 42)),
395
?line code(orber_tc:object_reference("Id", "Name")),
396
?line ?match(code(orber_tc:object_reference(42, "Name"))),
397
?line ?match(code(orber_tc:object_reference("Id", 42))),
400
%%-----------------------------------------------------------------
403
%%-----------------------------------------------------------------
407
?line true = orber_tc:check_tc(orber_tc:struct("Id", "Name", ?ELIST)),
408
?line false = orber_tc:check_tc(orber_tc:struct(42, "Name", ?ELIST)),
409
?line false = orber_tc:check_tc(orber_tc:struct("Id", false, ?ELIST)),
410
?line false = orber_tc:check_tc(orber_tc:struct("Id", "Name", ?VELIST)),
411
?line false = orber_tc:check_tc(orber_tc:struct("Id", "Name", "wrong")),
412
?line code(orber_tc:struct("Id", "Name", ?ELIST)),
413
?line ?match(code(orber_tc:struct(42, "Name", ?ELIST))),
414
?line ?match(code(orber_tc:struct("Id", false, ?ELIST))),
415
?line ?match(code(orber_tc:struct("Id", "Name", ?VELIST))),
416
?line ?match(code(orber_tc:struct("Id", "Name", "wrong"))),
419
%%-----------------------------------------------------------------
422
%%-----------------------------------------------------------------
426
?line true = orber_tc:check_tc(orber_tc:union("Id", "Name", orber_tc:long(),
427
-1, [{1, "long", orber_tc:long()},
428
{2, "longlong", orber_tc:long()}])),
429
?line false = orber_tc:check_tc(orber_tc:union("Id", "Name", orber_tc:long(),
431
?line false = orber_tc:check_tc(orber_tc:union(42, "Name", orber_tc:long(),
432
-1, [{1, "long", orber_tc:long()},
433
{2, "longlong", orber_tc:long()}])),
434
?line false = orber_tc:check_tc(orber_tc:union("Id", false, orber_tc:long(),
435
-1, [{1, "long", orber_tc:long()},
436
{2, "longlong", orber_tc:long()}])),
437
?line false = orber_tc:check_tc(orber_tc:union("Id", "Name", bad_tc,
438
-1, [{1, "long", orber_tc:long()},
439
{2, "longlong", orber_tc:long()}])),
440
?line false = orber_tc:check_tc(orber_tc:union("Id", "Name", orber_tc:long(),
441
"wrong", [{1, "long", orber_tc:long()},
442
{2, "longlong", orber_tc:long()}])),
444
?line code(orber_tc:union("Id", "Name", orber_tc:long(),
445
-1, [{1, "long", orber_tc:long()},
446
{2, "longlong", orber_tc:long()}])),
450
%%-----------------------------------------------------------------
451
%% Test Case: enum test
453
%%-----------------------------------------------------------------
457
?line true = orber_tc:check_tc(orber_tc:enum("Id", "Name",
458
["E1", "E2", "E3"])),
459
?line false = orber_tc:check_tc(orber_tc:enum(42, "Name",
460
["E1", "E2", "E3"])),
461
?line false = orber_tc:check_tc(orber_tc:enum("Id", false,
462
["E1", "E2", "E3"])),
463
?line false = orber_tc:check_tc(orber_tc:enum("Id", "Name",
464
["E1", false, "E3"])),
465
?line code(orber_tc:enum("Id", "Name", ["E1", "E2", "E3"])),
466
?line ?match(code(orber_tc:enum(false, "Name", ["E1", "E2", "E3"]))),
467
?line ?match(code(orber_tc:enum("Id", 42, ["E1", "E2", "E3"]))),
468
?line ?match(code(orber_tc:enum("Id", "Name", ["E1", false, "E3"]))),
471
%%-----------------------------------------------------------------
474
%%-----------------------------------------------------------------
478
?line true = orber_tc:check_tc(orber_tc:string(0)),
479
?line true = orber_tc:check_tc(orber_tc:string(1)),
480
?line false = orber_tc:check_tc(orber_tc:string("wrong")),
481
?line code(orber_tc:string(0)),
482
?line code(orber_tc:string(1)),
483
?line ?match(code(orber_tc:string(-1))),
484
?line ?match(code(orber_tc:string(?ULONGMAX+1))),
485
?line ?match(code(orber_tc:string("wrong"))),
488
%%-----------------------------------------------------------------
489
%% Test Case: wstring
491
%%-----------------------------------------------------------------
493
wstring(suite) -> [];
495
?line true = orber_tc:check_tc(orber_tc:wstring(0)),
496
?line true = orber_tc:check_tc(orber_tc:wstring(1)),
497
?line false = orber_tc:check_tc(orber_tc:wstring("wrong")),
498
?line code(orber_tc:wstring(0)),
499
?line code(orber_tc:wstring(1)),
500
?line ?match(code(orber_tc:wstring(-1))),
501
?line ?match(code(orber_tc:wstring(?ULONGMAX+1))),
502
?line ?match(code(orber_tc:wstring(false))),
505
%%-----------------------------------------------------------------
506
%% Test Case: sequence
508
%%-----------------------------------------------------------------
510
sequence(suite) -> [];
512
?line true = orber_tc:check_tc(orber_tc:sequence(orber_tc:struct("Id", "Name", ?ELIST), 0)),
513
?line code(orber_tc:sequence(orber_tc:struct("Id", "Name", ?ELIST), 0)),
516
%%-----------------------------------------------------------------
519
%%-----------------------------------------------------------------
523
?line true = orber_tc:check_tc(orber_tc:array(orber_tc:struct("Id", "Name", ?ELIST), 1)),
524
?line code(orber_tc:array(orber_tc:struct("Id", "Name", ?ELIST), 1)),
527
%%-----------------------------------------------------------------
530
%%-----------------------------------------------------------------
534
?line true = orber_tc:check_tc(orber_tc:alias("Id", "Name", orber_tc:struct("Id", "Name", ?ELIST))),
535
?line false = orber_tc:check_tc(orber_tc:alias(false, "Name", orber_tc:struct("Id", "Name", ?ELIST))),
536
?line false = orber_tc:check_tc(orber_tc:alias("Id", 42, orber_tc:struct("Id", "Name", ?ELIST))),
537
?line false = orber_tc:check_tc(orber_tc:alias("Id", "Name", "wrong")),
538
?line code(orber_tc:alias("Id", "Name", orber_tc:struct("Id", "Name", ?ELIST))),
539
?line ?match(code(orber_tc:alias("Id", "Name", orber_tc:struct("Id", "Name", ?VELIST)))),
542
%%-----------------------------------------------------------------
543
%% Test Case: exception
545
%%-----------------------------------------------------------------
546
exception(doc) -> [];
547
exception(suite) -> [];
549
?line true = orber_tc:check_tc(orber_tc:exception("Id", "Name", ?ELIST)),
550
?line false = orber_tc:check_tc(orber_tc:exception(42, "Name", ?ELIST)),
551
?line false = orber_tc:check_tc(orber_tc:exception("Id", false, ?ELIST)),
552
?line false = orber_tc:check_tc(orber_tc:exception("Id", "Name", "wrong")),
553
?line code(orber_tc:exception("Id", "Name", ?ELIST)),
554
?line ?match(code(orber_tc:exception(42, "Name", ?ELIST))),
555
?line ?match(code(orber_tc:exception("Id", false, ?ELIST))),
556
?line ?match(code(orber_tc:exception("Id", "Name", "wrong"))),
560
%%-----------------------------------------------------------------
563
%%-----------------------------------------------------------------
567
?line true = orber_tc:check_tc(orber_tc:fixed(25, 2)),
568
?line code(orber_tc:fixed(25, 2)),
571
%%-----------------------------------------------------------------
574
%%-----------------------------------------------------------------
578
?line true = orber_tc:check_tc(orber_tc:value("Id", "Name", 42,
579
orber_tc:fixed(25, 2), ?VELIST)),
580
?line false = orber_tc:check_tc(orber_tc:value(42, "Name", 42,
581
orber_tc:fixed(25, 2), ?VELIST)),
582
?line false = orber_tc:check_tc(orber_tc:value("Id", 42, 42,
583
orber_tc:fixed(25, 2), ?VELIST)),
584
?line false = orber_tc:check_tc(orber_tc:value("Id", "Name", "wrong",
585
orber_tc:fixed(25, 2), ?VELIST)),
586
?line false = orber_tc:check_tc(orber_tc:value("Id", "Name", "42",
587
orber_tc:fixed(25, 2), ?VELIST)),
588
?line false = orber_tc:check_tc(orber_tc:value("Id", "Name", "42",
590
?line false = orber_tc:check_tc(orber_tc:value("Id", "Name", "42",
591
orber_tc:fixed(25, 2), false)),
593
?line code(orber_tc:value("Id", "Name", 42, orber_tc:long(), ?VELIST)),
596
%%-----------------------------------------------------------------
597
%% Test Case: value_box
599
%%-----------------------------------------------------------------
600
value_box(doc) -> [];
601
value_box(suite) -> [];
603
?line true = orber_tc:check_tc(orber_tc:value_box("Id", "Name",
604
orber_tc:fixed(25, 2))),
605
?line false = orber_tc:check_tc(orber_tc:value_box(42, "Name",
606
orber_tc:fixed(25, 2))),
607
?line false = orber_tc:check_tc(orber_tc:value_box("Id", 42,
608
orber_tc:fixed(25, 2))),
609
?line false = orber_tc:check_tc(orber_tc:value_box("Id", "Name", "wrong")),
610
?line code(orber_tc:value_box("Id", "Name", orber_tc:long())),
611
?line ?match(code(orber_tc:value_box(42, "Name", orber_tc:short()))),
612
?line ?match(code(orber_tc:value_box("Id", 42, orber_tc:char()))),
613
?line ?match(code(orber_tc:value_box("Id", "Name", false))),
616
%%-----------------------------------------------------------------
619
%%-----------------------------------------------------------------
623
?line true = orber_tc:check_tc(orber_tc:native("Id", "Name")),
624
?line false = orber_tc:check_tc(orber_tc:native(42, "Name")),
625
?line false = orber_tc:check_tc(orber_tc:native("Id", 42)),
626
?line code(orber_tc:native("Id", "Name")),
627
?line ?match(code(orber_tc:native(42, "Name"))),
628
?line ?match(code(orber_tc:native("Id", 42))),
631
%%-----------------------------------------------------------------
632
%% Test Case: abstract_interface
634
%%-----------------------------------------------------------------
635
abstract_interface(doc) -> [];
636
abstract_interface(suite) -> [];
637
abstract_interface(_) ->
638
?line true = orber_tc:check_tc(orber_tc:abstract_interface("RepId", "Name")),
639
?line false = orber_tc:check_tc(orber_tc:abstract_interface(false, "Name")),
640
?line false = orber_tc:check_tc(orber_tc:abstract_interface("RepId", 42)),
641
?line code(orber_tc:abstract_interface("RepId", "Name")),
642
?line ?match(code(orber_tc:abstract_interface(42, "Name"))),
643
?line ?match(code(orber_tc:abstract_interface("Id", 42))),
648
%%-----------------------------------------------------------------
649
%% Test Case: indirection
651
%%-----------------------------------------------------------------
652
indirection(doc) -> [];
653
indirection(suite) -> [];
655
?line true = orber_tc:check_tc({'none', 42}),
658
%%-----------------------------------------------------------------
661
%%-----------------------------------------------------------------
665
TC = 'CosNaming_Binding':tc(),
666
?line TC = orber_tc:get_tc({'CosNaming_Binding', 42}),
667
?line ?match(orber_tc:get_tc({'none', 42})),
670
%%-----------------------------------------------------------------
672
%%-----------------------------------------------------------------
674
cdr_encode:enc_type({1,2}, tk_TypeCode, Value).