Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / IDL_Test / union.idl
blobfdee107e2cffcb58421dc1b40ba746e169a20c0a
2 //=============================================================================
3 /**
4 * @file union.idl
6 * This file contains examples of IDL code that has
7 * caused problems in the past for the TAO IDL
8 * compiler. This test is to make sure the problems
9 * stay fixed.
12 * @author Jeff Parsons <parsons@cs.wustl.edu> and TAO users.
14 //=============================================================================
17 // Implicit default case
19 enum DataType
21 dtEmpty,
22 dtLong,
23 dtShort
26 union Data switch (DataType)
28 case dtLong: long longData;
29 case dtShort: short shortData;
30 // by default, empty union
33 // Explicit default case
35 module Necessary
37 // It is important to have a module, in which
38 // the following union is declared.
40 typedef long Result;
42 enum Kind
44 e_Result,
45 e_Unused
48 union WhichResult switch (Kind )
50 case e_Result: Result m_Result;
51 default: long m_Unused;
55 // Union with negative cases
56 union foo switch (short)
58 case -3:
59 case 4:
60 case -1: string foo_str_member;
61 default: long foo_iface_member;
62 case 0: long foo_iface_member2;
65 // Make sure that CORBA_Any::to_* is used everywhere.
66 module UnionDiscTest
68 union BooleanUnion switch (boolean)
70 case TRUE: string value;
73 union CharUnion switch (char)
75 case 'a': string value;
79 module AllBoolUnions
81 union OneBranchT switch (boolean) { case TRUE: octet val; };
82 union OneBranchF switch (boolean) { case FALSE: octet val; };
83 union OneBranchD switch (boolean) { default: octet val; };
84 union OneBranchTF switch (boolean) { case TRUE: case FALSE: octet val; };
85 union OneBranchFT switch (boolean) { case FALSE: case TRUE: octet val; };
86 union OneBranchTD switch (boolean) { case TRUE: default: octet val; };
87 union OneBranchDT switch (boolean) { default: case TRUE: octet val; };
88 union OneBranchFD switch (boolean) { case FALSE: default : octet val; };
89 union OneBranchDF switch (boolean) { default: case FALSE: octet val; };
90 union TwoBranchesTF switch (boolean) { case TRUE: octet val1; case FALSE: char val2; };
91 union TwoBranchesFT switch (boolean) { case FALSE: octet val1; case TRUE: char val2; };
92 union TwoBranchesTD switch (boolean) { case TRUE: octet val1; default: char val2; };
93 union TwoBranchesDT switch (boolean) { default: octet val1; case TRUE: char val2; };
94 union TwoBranchesFD switch (boolean) { case FALSE: octet val1; default: char val2; };
95 union TwoBranchesDF switch (boolean) { default: octet val1; case FALSE: char val2; };
98 // Nested unions
100 enum disc1
102 one,
106 enum disc2
112 enum disc_outer
114 out1,
115 out2
118 union inner1 switch (disc1)
120 case one: short s;
121 case two: long l;
124 union inner2 switch (disc2)
126 case a: char c;
127 case b: long lng;
130 union outer switch (disc_outer)
132 case out1: inner1 first;
133 case out2: inner2 second;
136 module UnionTest3
138 enum ValChoice
140 intVal,
141 realVal
144 union ValType switch(ValChoice)
146 case intVal: long integerValue;
147 case realVal: double realValue;
150 struct UpType
152 ValType high;
153 ValType low;
156 struct DownType
158 ValType high;
159 ValType low;
162 enum IndChoice
164 up_Level,
165 down_Level
168 union IndType switch(IndChoice)
170 case up_Level: UpType up;
171 case down_Level: DownType down;
175 // Make sure inner union is generated in header file with
176 // proper scoping (or lack thereof) in its name, depending
177 // on the platform.
178 enum XType
183 enum ZType
188 union X switch (XType)
190 case X_A:
191 struct Y
193 union Z switch (ZType)
195 case Z_A: long a;
196 } u;
197 } a;
200 // Example involving union members with multiple case labels.
201 enum FieldType
203 FTYPE_CHAR,
204 FTYPE_VARCHAR,
205 FTYPE_DEFCHAR
208 union FieldValue switch (FieldType)
210 case FTYPE_CHAR:
211 case FTYPE_VARCHAR:
212 string strValue;
213 default:
214 string defstr;
218 struct Field
220 FieldValue value;
223 // A fix to the IDL compiler's typecode generation created
224 // a problem with unions that have more than one member,
225 // where any member except the last is itself a scoped type.
226 // This is the simplest example that will reproduce the problem,
227 // if it ever reappears.
228 enum TestOneEnum
230 TALL,
231 SCHORT
234 enum TestTwoEnum
236 LIGHT,
237 DARK
240 union TestUnion switch (short)
242 case 1: TestOneEnum oneEnum;
243 case 2: TestTwoEnum twoEnum;
246 typedef long U41[2][3];
247 typedef long U42[2];
249 union U85 switch (long) {
250 case 1: U41 b_85_1;
251 case 2: U42 b_85_2;
254 typedef string UString[2];
255 union U86 switch (long) {
256 case 1: string b_86_1;
257 case 2: long b_86_2;
259 union U88 switch (long) {
260 case 1: UString b_86_1;
261 case 2: long b_86_2;
264 struct UBar {
265 long foo;
267 typedef UBar UBarArray[2];
269 union U87 switch (long) {
270 case 1: UBar b_87_1;
271 case 2: long b_87_2;
273 union U89 switch (long) {
274 case 1: UBarArray b_87_1;
275 case 2: long b_87_2;
278 enum U90
280 U90_1,
281 U90_2
284 typedef U90 U90Array[2];
286 union U91 switch (long) {
287 case 1: U90Array b_91_1;
288 case 2: long b_92_2;
291 union U92 switch (long) {
292 case 1: UBar b_92_1;
293 case 2: long b_92_2;
294 default: UBar b_92_3;
297 union U93 switch (long) {
298 case 1: UBarArray b_93_1;
299 case 2: long b_93_2;
300 default: UBarArray b_93_3;
303 union U94 switch (long) {
304 case 1: U90Array b_94_1;
305 case 2: long b_94_2;
306 default: U90Array b_94_3;