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