midltests/todo: add some random idl files I had tested month ago
[sharpe/samba-autobuild/.git] / testprogs / win32 / midltests / todo / midltests-pipe-02.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
11         struct msg {
12                 long l;
13                 [size_is(l)] char *m;
14         };
15
16         long midltests_fn(
17                 [out,ref] struct msg *out1,
18                 [out] pipe_char outp,
19                 [in] pipe_char inp,
20                 [in] struct msg in1
21         );
22 }
23
24 #elif MIDLTESTS_C_CODE
25 \r
26 struct pipe_char_state {\r
27         const char *name;\r
28         unsigned long count;\r
29         unsigned long sleep;\r
30 };\r
31 \r
32 void pipe_char_pull(\r
33             char * _state,\r
34             unsigned char * buf,\r
35             unsigned long esize,\r
36             unsigned long * ecount)\r
37 {\r
38         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
39 \r
40         printf("pull1:%s: esize[%u] ecount[%u]\n",\r
41                 state->name, esize, *ecount);\r
42         *ecount = state->count--;\r
43         if (*ecount > esize) {\r
44                 *ecount = esize;\r
45         }\r
46         memset(buf, 0xDD, *ecount);\r
47         printf("pull2:%s: esize[%u] ecount[%u]\n",\r
48                 state->name, esize, *ecount);\r
49 }\r
50 \r
51 void pipe_char_push(\r
52             char * _state,\r
53             unsigned char * buf,\r
54             unsigned long ecount)\r
55 {\r
56         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
57 \r
58         printf("push:%s: ecount[%u]\n",\r
59                 state->name, ecount);\r
60 }\r
61 \r
62 void pipe_char_alloc(\r
63             char * _state,\r
64             unsigned long bsize,\r
65             unsigned char * * buf,\r
66             unsigned long * bcount)\r
67 {\r
68         struct pipe_char_state *state = (struct pipe_char_state *)_state;\r
69 \r
70         printf("alloc1:%s: bsize[%u], bcount[%u]\n",\r
71                 state->name, bsize, *bcount);\r
72         *bcount = bsize / sizeof(**buf);\r
73         *buf = malloc(*bcount * sizeof(**buf));\r
74         printf("alloc2:%s: bsize[%u], bcount[%u]\n",\r
75                 state->name, bsize, *bcount);\r
76 }\r
77
78 static void midltests(void)
79 {
80     struct msg out1;
81         unsigned char out1b[3];
82         struct pipe_char_state outs;
83         pipe_char outp;
84         struct pipe_char_state ins;
85         pipe_char inp;
86         struct msg in1;
87         unsigned char in1b[3];
88
89         in1.l = sizeof(in1b);
90         memset(&in1b, 0xAA, sizeof(in1b));
91         in1.m = in1b;
92
93         memset(&outs, 0, sizeof(outs));
94         outs.name = "outp";
95         memset(&outp, 0, sizeof(outp));
96         outp.pull = pipe_char_pull;
97         outp.push = pipe_char_push;
98         outp.alloc = pipe_char_alloc;
99         outp.state = (char *)&outs;
100
101         memset(&ins, 0, sizeof(ins));
102         ins.name = "inp";
103         ins.count = 1;
104         memset(&inp, 0, sizeof(inp));
105         inp.pull = pipe_char_pull;
106         inp.push = pipe_char_push;
107         inp.alloc = pipe_char_alloc;
108         inp.state = (char *)&ins;
109
110         out1.l = sizeof(out1b);
111         memset(&out1b, 0xFF, sizeof(out1b));
112         out1.m = out1b;
113
114         cli_midltests_fn(&out1, outp, inp, in1);
115 }
116
117 long srv_midltests_fn(
118             /* [ref][out] */ struct msg *out1,\r
119     /* [out] */ pipe_char outp,\r
120     /* [in] */ pipe_char inp,\r
121     /* [in] */ struct msg in1)
122 {
123         char inb[500];
124         unsigned long inb_len = 0;
125         char *outb = NULL;
126         unsigned long outb_size = 0;
127         unsigned long outb_len = 0; 
128
129         printf("srv_midltests_fn: Start\n");
130
131         do {
132                 inp.pull(inp.state, inb, sizeof(inb), &inb_len);
133                 printf("pull inp_len[%u]\n", inb_len);
134         } while (inb_len > 0);
135
136         outb_size = 5;
137         do {
138                 outp.alloc(outp.state, outb_size, &outb, &outb_len);
139                 memset(outb, 0xCC, outb_len);
140                 outp.push(outp.state, outb, outb_len);
141                 printf("push outb_len[%u]\n", outb_len);
142                 //Sleep(1000);
143                 outb_size--;
144         } while (outb_len > 0);
145
146         out1->l = 3;
147         out1->m = (unsigned char *)malloc(out1->l);
148         memset(out1->m, 0xBB, out1->l);
149         printf("srv_midltests_fn: End\n");
150         return 0x65757254;
151 }
152
153 #endif