midltests: add invalid/midltests_pipe_struct_union_01.idl
[ira/wip.git] / testprogs / win32 / midltests / invalid / midltests_pipe_struct_union_01.idl
1 #ifndef MIDLTESTS_C_CODE
2
3 [
4   uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
5   pointer_default(unique)
6 ]
7 interface midltests
8 {
9         typedef pipe char pipe_char;
10         typedef pipe hyper pipe_hyper;
11         typedef struct {
12                 long l;
13                 short s;
14                 [switch_is(l)] union {
15                         [case(0)];
16                         [case(1)] char c;
17                         [case(2)] short s;
18                         [case(4)] long l;
19                         [case(8)] hyper h;
20                 } u;
21         } structtype;
22         typedef pipe structtype pipe_structtype;
23
24         struct msg {
25                 long l;
26                 [size_is(l)] char *m;
27         };
28
29         long midltests_fn(
30                 [out,ref] struct msg *out1,
31                 [out,ref] pipe_structtype *outp,
32                 [in,ref] pipe_structtype *inp,
33                 [in] struct msg in1
34         );
35
36         long midltests_ping( [in] struct msg in1);
37
38 }
39
40 #elif MIDLTESTS_C_CODE
41
42 struct pipe_char_state {
43         const char *name;
44         unsigned long count;
45         unsigned long sleep;
46 };
47
48 void pipe_char_pull(
49             char * _state,
50             unsigned char * buf,
51             unsigned long esize,
52             unsigned long * ecount)
53 {
54         struct pipe_char_state *state = (struct pipe_char_state *)_state;
55
56         printf("pull1:%s: esize[%u] ecount[%u]\n",
57                 state->name, esize, *ecount);
58         *ecount = state->count--;
59         if (*ecount > esize) {
60                 *ecount = esize;
61         }
62         memset(buf, 0xDD, *ecount * sizeof(*buf));
63         printf("pull2:%s: esize[%u] ecount[%u]\n",
64                 state->name, esize, *ecount);
65 }
66
67 void pipe_char_push(
68             char * _state,
69             unsigned char * buf,
70             unsigned long ecount)
71 {
72         struct pipe_char_state *state = (struct pipe_char_state *)_state;
73
74         printf("push:%s: ecount[%u]\n",
75                 state->name, ecount);
76 }
77
78 void pipe_char_alloc(
79             char * _state,
80             unsigned long bsize,
81             unsigned char * * buf,
82             unsigned long * bcount)
83 {
84         struct pipe_char_state *state = (struct pipe_char_state *)_state;
85
86         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
87                 state->name, bsize, *bcount);
88         *bcount = bsize / sizeof(**buf);
89         *buf = malloc(*bcount * sizeof(**buf));
90         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
91                 state->name, bsize, *bcount);
92 }
93
94 struct pipe_hyper_state {
95         const char *name;
96         unsigned long count;
97         unsigned long sleep;
98 };
99
100 void pipe_hyper_pull(
101             char * _state,
102             hyper * buf,
103             unsigned long esize,
104             unsigned long * ecount)
105 {
106         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
107
108         printf("pull1:%s: esize[%u] ecount[%u]\n",
109                 state->name, esize, *ecount);
110         *ecount = state->count--;
111         if (*ecount > esize) {
112                 *ecount = esize;
113         }
114         memset(buf, 0xDD, *ecount * sizeof(*buf));
115         printf("pull2:%s: esize[%u] ecount[%u]\n",
116                 state->name, esize, *ecount);
117 }
118
119 void pipe_hyper_push(
120             char * _state,
121             hyper * buf,
122             unsigned long ecount)
123 {
124         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
125
126         printf("push:%s: ecount[%u]\n",
127                 state->name, ecount);
128 }
129
130 void pipe_hyper_alloc(
131             char * _state,
132             unsigned long bsize,
133             hyper * * buf,
134             unsigned long * bcount)
135 {
136         struct pipe_hyper_state *state = (struct pipe_hyper_state *)_state;
137
138         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
139                 state->name, bsize, *bcount);
140         *bcount = bsize / sizeof(**buf);
141         *buf = malloc(*bcount * sizeof(**buf));
142         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
143                 state->name, bsize, *bcount);
144 }
145 struct pipe_structtype_state {
146         const char *name;
147         unsigned long count;
148         unsigned long sleep;
149 };
150
151 void pipe_structtype_pull(
152             char * _state,
153             structtype * buf,
154             unsigned long esize,
155             unsigned long * ecount)
156 {
157         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
158
159         printf("pull1:%s: esize[%u] ecount[%u]\n",
160                 state->name, esize, *ecount);
161         *ecount = state->count--;
162         if (*ecount > esize) {
163                 *ecount = esize;
164         }
165         memset(buf, 0xDD, *ecount * sizeof(*buf));
166         printf("pull2:%s: esize[%u] ecount[%u]\n",
167                 state->name, esize, *ecount);
168 }
169
170 void pipe_structtype_push(
171             char * _state,
172             structtype * buf,
173             unsigned long ecount)
174 {
175         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
176
177         printf("push:%s: ecount[%u]\n",
178                 state->name, ecount);
179 }
180
181 void pipe_structtype_alloc(
182             char * _state,
183             unsigned long bsize,
184             structtype * * buf,
185             unsigned long * bcount)
186 {
187         struct pipe_structtype_state *state = (struct pipe_structtype_state *)_state;
188
189         printf("alloc1:%s: bsize[%u], bcount[%u]\n",
190                 state->name, bsize, *bcount);
191         *bcount = bsize / sizeof(**buf);
192         *buf = malloc(*bcount * sizeof(**buf));
193         printf("alloc2:%s: bsize[%u], bcount[%u]\n",
194                 state->name, bsize, *bcount);
195 }
196 static void midltests(void)
197 {
198         struct msg out1;
199         unsigned char out1b[3];
200         struct pipe_structtype_state outs;
201         pipe_structtype outp;
202         struct pipe_structtype_state ins;
203         pipe_structtype inp;
204         struct msg in1;
205         unsigned char in1b[3];
206
207         in1.l = sizeof(in1b);
208         memset(&in1b, 0xAA, sizeof(in1b));
209         in1.m = in1b;
210
211         memset(&outs, 0, sizeof(outs));
212         outs.name = "outp";
213         memset(&outp, 0, sizeof(outp));
214         outp.pull = pipe_structtype_pull;
215         outp.push = pipe_structtype_push;
216         outp.alloc = pipe_structtype_alloc;
217         outp.state = (char *)&outs;
218
219         memset(&ins, 0, sizeof(ins));
220         ins.name = "inp";
221         ins.count = 1;
222         memset(&inp, 0, sizeof(inp));
223         inp.pull = pipe_structtype_pull;
224         inp.push = pipe_structtype_push;
225         inp.alloc = pipe_structtype_alloc;
226         inp.state = (char *)&ins;
227
228         out1.l = sizeof(out1b);
229         memset(&out1b, 0xFF, sizeof(out1b));
230         out1.m = out1b;
231
232         cli_midltests_ping(in1);
233         cli_midltests_fn(&out1, outp, inp, in1);
234 }
235
236 long srv_midltests_fn(
237             /* [ref][out] */ struct msg *out1,
238     /* [out] */ pipe_structtype outp,
239     /* [in] */ pipe_structtype inp,
240     /* [in] */ struct msg in1)
241 {
242         structtype inb[500];
243         unsigned long inb_len = 0;
244         structtype *outb = NULL;
245         unsigned long outb_size = 0;
246         unsigned long outb_len = 0; 
247
248         printf("srv_midltests_fn: Start\n");
249
250         do {
251                 inp.pull(inp.state, inb, sizeof(inb), &inb_len);
252                 printf("pull inp_len[%u]\n", inb_len);
253         } while (inb_len > 0);
254
255         outb_size = 5;
256         do {
257                 outp.alloc(outp.state, outb_size, &outb, &outb_len);
258                 memset(outb, 0xCC, outb_len * sizeof(*outb));
259                 outp.push(outp.state, outb, outb_len);
260                 printf("push outb_len[%u]\n", outb_len);
261                 //Sleep(1000);
262                 outb_size--;
263         } while (outb_len > 0);
264
265         out1->l = 3;
266         out1->m = (unsigned char *)malloc(out1->l);
267         memset(out1->m, 0xBB, out1->l);
268         printf("srv_midltests_fn: End\n");
269         return 0x65757254;
270 }
271
272 long srv_midltests_ping(
273     /* [in] */ struct msg in1)
274 {
275         printf("srv_midltests_fn: Start\n");
276         printf("srv_midltests_fn: End\n");
277         return 0x65757254;
278 }
279 #endif