midltests: test encapsulated unions with 'ms_union'
[ira/wip.git] / testprogs / win32 / midltests / valid / midltests_union_align_20.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   ms_union,
30   pointer_default(unique)
31 ]
32 interface midltests
33 {
34         enum level_enum { ZERO = 0, ONE = 1, TWO = 2, FOUR = 4, EIGHT = 8 };
35
36         [switch_type(enum level_enum)] union u {
37                 [case(ZERO)];
38                 [case(ONE)] char c;
39                 [case(TWO)] short s;
40                 [case(FOUR)] long l;
41                 [case(EIGHT)] hyper h;
42         };
43
44         union ue switch(enum level_enum level) u { 
45                 case(ZERO):;
46                 case(ONE): char c;
47                 case(TWO): short s;
48                 case(FOUR): long l;
49                 case(EIGHT): hyper h;
50         };
51
52         void midltests_fn(
53                 [in,out,ref] enum level_enum *level,
54                 [in,switch_is(*level)] union u u,
55                 [out,ref] union ue *ue,
56                 [in,out,ref] char *c
57         );
58 }
59
60 #elif MIDLTESTS_C_CODE
61
62 static void midltests(void)
63 {
64         enum level_enum level;
65         unsigned char c = 'c';
66         struct ue ue;
67         union u u;
68         u.h = 0xFFFFFFFFFFFFFFFFLL;
69
70         level = ZERO;
71         cli_midltests_fn(&level, u, &ue, &c);
72         level = ONE;
73         cli_midltests_fn(&level, u, &ue, &c);
74         level = TWO;
75         cli_midltests_fn(&level, u, &ue, &c);
76         level = FOUR;
77         cli_midltests_fn(&level, u, &ue, &c);
78         level = EIGHT;
79         cli_midltests_fn(&level, u, &ue, &c);
80 }
81
82 void srv_midltests_fn(enum level_enum *level, union u u, struct ue *ue, unsigned char *c)
83 {
84         printf("srv_midltests_fn: Start\n");
85         ue->level = *level;
86         ue->u.h = u.h;
87         printf("srv_midltests_fn: End\n");
88         return;
89 }
90
91 #endif