midltests: add examples of toplevel vs. embedded unions without 'ms_union'
[mimir/samba.git] / testprogs / win32 / midltests / valid / midltests_union_align_16.idl
1 #ifndef MIDLTESTS_C_CODE
2
3 /*
4  * For midltests_tcp.exe you may want to
5  * redirect the traffic via rinetd
6  * with a /etc/rinetd.conf like this:
7  *
8  * 172.31.9.1 5032 172.31.9.8 5032
9  * 172.31.9.1 5064 172.31.9.8 5064
10  *
11  * This is useful to watch the traffic with
12  * a network sniffer.
13  */
14 /*
15 cpp_quote("#define LISTEN_IP \"0.0.0.0\"")
16 cpp_quote("#define FORWARD_IP \"127.0.0.1\"")
17 cpp_quote("#define CONNECT_IP \"172.31.9.1\"")
18 */
19
20 /*
21  * With midltests_tcp.exe NDR64 is enforced by default.
22  * For testing it might be needed to allow downgrades
23  * to NDR32. This is needed when you use 'pipe'.
24  */
25 //cpp_quote("#define DONOT_FORCE_NDR64 1")
26
27 [
28   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
29   pointer_default(unique)
30 ]
31 interface midltests
32 {
33         enum level_enum { ZERO = 0, ONE = 1, TWO = 2, FOUR = 4, EIGHT = 8 };
34
35         [switch_type(enum level_enum)] union u {
36                 [case(ZERO)];
37                 [case(ONE)] char c;
38                 [case(TWO)] short s;
39                 [case(FOUR)] long l;
40                 [case(EIGHT)] hyper h;
41         };
42
43         struct us {
44                 enum level_enum level;
45                 [switch_is(level)] union {
46                         [case(ZERO)];
47                         [case(ONE)] char c;
48                         [case(TWO)] short s;
49                         [case(FOUR)] long l;
50                         [case(EIGHT)] hyper h;
51                 } u;
52         };
53
54         void midltests_fn(
55                 [in,ref] enum level_enum *level,
56                 [in,switch_is(*level)] union u u,
57                 [out,ref] struct us *us,
58                 [in,out,ref] char *c
59         );
60 }
61
62 #elif MIDLTESTS_C_CODE
63
64 static void midltests(void)
65 {
66         enum level_enum level;
67         unsigned char c = 'c';
68         struct us us;
69         union u u;
70         u.h = 0xFFFFFFFFFFFFFFFFLL;
71
72         level = ZERO;
73         cli_midltests_fn(&level, u, &us, &c);
74         level = ONE;
75         cli_midltests_fn(&level, u, &us, &c);
76         level = TWO;
77         cli_midltests_fn(&level, u, &us, &c);
78         level = FOUR;
79         cli_midltests_fn(&level, u, &us, &c);
80         level = EIGHT;
81         cli_midltests_fn(&level, u, &us, &c);
82 }
83
84 void srv_midltests_fn(enum level_enum *level, union u u, struct us *us, unsigned char *c)
85 {
86         printf("srv_midltests_fn: Start\n");
87         us->level = *level;
88         us->u.h = u.h;
89         printf("srv_midltests_fn: End\n");
90         return;
91 }
92
93 #endif