rpcrt4: Fix context handle test on Vista upwards.
[wine] / dlls / rpcrt4 / tests / server.c
1 /*
2  * Tests for WIDL and RPC server/clients.
3  *
4  * Copyright (C) Google 2007 (Dan Hipschman)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <windows.h>
22 #include "wine/test.h"
23 #include "server.h"
24 #include "server_defines.h"
25
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #define PORT "4114"
31 #define PIPE "\\pipe\\wine_rpcrt4_test"
32
33 #define INT_CODE 4198
34
35 static const char *progname;
36
37 static HANDLE stop_event;
38
39 static void (WINAPI *pNDRSContextMarshall2)(RPC_BINDING_HANDLE, NDR_SCONTEXT, void*, NDR_RUNDOWN, void*, ULONG);
40 static NDR_SCONTEXT (WINAPI *pNDRSContextUnmarshall2)(RPC_BINDING_HANDLE, void*, ULONG, void*, ULONG);
41 static RPC_STATUS (WINAPI *pRpcServerRegisterIfEx)(RPC_IF_HANDLE,UUID*, RPC_MGR_EPV*, unsigned int,
42                    unsigned int,RPC_IF_CALLBACK_FN*);
43
44 static void InitFunctionPointers(void)
45 {
46     HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
47
48     pNDRSContextMarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextMarshall2");
49     pNDRSContextUnmarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextUnmarshall2");
50     pRpcServerRegisterIfEx = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterIfEx");
51 }
52
53 void __RPC_FAR *__RPC_USER
54 midl_user_allocate(SIZE_T n)
55 {
56   return malloc(n);
57 }
58
59 void __RPC_USER
60 midl_user_free(void __RPC_FAR *p)
61 {
62   free(p);
63 }
64
65 static char *
66 xstrdup(const char *s)
67 {
68   char *d = HeapAlloc(GetProcessHeap(), 0, strlen(s) + 1);
69   strcpy(d, s);
70   return d;
71 }
72
73 int
74 s_int_return(void)
75 {
76   return INT_CODE;
77 }
78
79 int
80 s_square(int x)
81 {
82   return x * x;
83 }
84
85 int
86 s_sum(int x, int y)
87 {
88   return x + y;
89 }
90
91 void
92 s_square_out(int x, int *y)
93 {
94   *y = s_square(x);
95 }
96
97 void
98 s_square_ref(int *x)
99 {
100   *x = s_square(*x);
101 }
102
103 int
104 s_str_length(const char *s)
105 {
106   return strlen(s);
107 }
108
109 int
110 s_str_t_length(str_t s)
111 {
112   return strlen(s);
113 }
114
115 int
116 s_cstr_length(const char *s, int n)
117 {
118   int len = 0;
119   while (0 < n-- && *s++)
120     ++len;
121   return len;
122 }
123
124 int
125 s_dot_self(vector_t *v)
126 {
127   return s_square(v->x) + s_square(v->y) + s_square(v->z);
128 }
129
130 double
131 s_square_half(double x, double *y)
132 {
133   *y = x / 2.0;
134   return x * x;
135 }
136
137 float
138 s_square_half_float(float x, float *y)
139 {
140   *y = x / 2.0f;
141   return x * x;
142 }
143
144 LONG
145 s_square_half_long(LONG x, LONG *y)
146 {
147   *y = x / 2;
148   return x * x;
149 }
150
151 int
152 s_sum_fixed_array(int a[5])
153 {
154   return a[0] + a[1] + a[2] + a[3] + a[4];
155 }
156
157 int
158 s_pints_sum(pints_t *pints)
159 {
160   return *pints->pi + **pints->ppi + ***pints->pppi;
161 }
162
163 double
164 s_ptypes_sum(ptypes_t *pt)
165 {
166   return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
167 }
168
169 int
170 s_dot_pvectors(pvectors_t *p)
171 {
172   return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
173 }
174
175 int
176 s_sum_sp(sp_t *sp)
177 {
178   return sp->x + sp->s->x;
179 }
180
181 double
182 s_square_sun(sun_t *su)
183 {
184   switch (su->s)
185   {
186   case SUN_I: return su->u.i * su->u.i;
187   case SUN_F1:
188   case SUN_F2: return su->u.f * su->u.f;
189   case SUN_PI: return (*su->u.pi) * (*su->u.pi);
190   default:
191     return 0.0;
192   }
193 }
194
195 int
196 s_test_list_length(test_list_t *list)
197 {
198   return (list->t == TL_LIST
199           ? 1 + s_test_list_length(list->u.tail)
200           : 0);
201 }
202
203 int
204 s_sum_fixed_int_3d(int m[2][3][4])
205 {
206   int i, j, k;
207   int sum = 0;
208
209   for (i = 0; i < 2; ++i)
210     for (j = 0; j < 3; ++j)
211       for (k = 0; k < 4; ++k)
212         sum += m[i][j][k];
213
214   return sum;
215 }
216
217 int
218 s_sum_conf_array(int x[], int n)
219 {
220   int *p = x, *end = p + n;
221   int sum = 0;
222
223   while (p < end)
224     sum += *p++;
225
226   return sum;
227 }
228
229 int
230 s_sum_conf_ptr_by_conf_ptr(int n1, int *n2_then_x1, int *x2)
231 {
232   int i;
233   int sum = 0;
234   if(n1 == 0)
235     return 0;
236
237   for(i = 1; i < n1; ++i)
238     sum += n2_then_x1[i];
239
240   for(i = 0; i < *n2_then_x1; ++i)
241     sum += x2[i];
242
243   return sum;
244 }
245
246 int
247 s_sum_unique_conf_array(int x[], int n)
248 {
249   return s_sum_conf_array(x, n);
250 }
251
252 int
253 s_sum_unique_conf_ptr(int *x, int n)
254 {
255   return x ? s_sum_conf_array(x, n) : 0;
256 }
257
258 int
259 s_sum_var_array(int x[20], int n)
260 {
261   ok(0 <= n, "RPC sum_var_array\n");
262   ok(n <= 20, "RPC sum_var_array\n");
263
264   return s_sum_conf_array(x, n);
265 }
266
267 int
268 s_dot_two_vectors(vector_t vs[2])
269 {
270   return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
271 }
272
273 int
274 s_sum_cs(cs_t *cs)
275 {
276   return s_sum_conf_array(cs->ca, cs->n);
277 }
278
279 int
280 s_sum_cps(cps_t *cps)
281 {
282   int sum = 0;
283   int i;
284
285   for (i = 0; i < *cps->pn; ++i)
286     sum += cps->ca1[i];
287
288   for (i = 0; i < 2 * cps->n; ++i)
289     sum += cps->ca2[i];
290
291   return sum;
292 }
293
294 int
295 s_sum_cpsc(cpsc_t *cpsc)
296 {
297   int sum = 0;
298   int i;
299   for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
300     sum += cpsc->ca[i];
301   return sum;
302 }
303
304 int
305 s_square_puint(puint_t p)
306 {
307   int n = atoi(p);
308   return n * n;
309 }
310
311 int
312 s_sum_puints(puints_t *p)
313 {
314   int sum = 0;
315   int i;
316   for (i = 0; i < p->n; ++i)
317     sum += atoi(p->ps[i]);
318   return sum;
319 }
320
321 int
322 s_sum_cpuints(cpuints_t *p)
323 {
324   int sum = 0;
325   int i;
326   for (i = 0; i < p->n; ++i)
327     sum += atoi(p->ps[i]);
328   return sum;
329 }
330
331 int
332 s_dot_copy_vectors(vector_t u, vector_t v)
333 {
334   return u.x * v.x + u.y * v.y + u.z * v.z;
335 }
336
337 int
338 s_square_test_us(test_us_t *tus)
339 {
340   int n = atoi(tus->us.x);
341   return n * n;
342 }
343
344 double
345 s_square_encu(encu_t *eu)
346 {
347   switch (eu->t)
348   {
349   case ENCU_I: return eu->tagged_union.i * eu->tagged_union.i;
350   case ENCU_F: return eu->tagged_union.f * eu->tagged_union.f;
351   default:
352     return 0.0;
353   }
354 }
355
356 double
357 s_square_unencu(int t, unencu_t *eu)
358 {
359   switch (t)
360   {
361   case ENCU_I: return eu->i * eu->i;
362   case ENCU_F: return eu->f * eu->f;
363   default:
364     return 0.0;
365   }
366 }
367
368 void
369 s_check_se2(se_t *s)
370 {
371   ok(s->f == E2, "check_se2\n");
372 }
373
374 int
375 s_sum_parr(int *a[3])
376 {
377   return s_sum_pcarr(a, 3);
378 }
379
380 int
381 s_sum_pcarr(int *a[], int n)
382 {
383   int i, s = 0;
384   for (i = 0; i < n; ++i)
385     s += *a[i];
386   return s;
387 }
388
389 int
390 s_enum_ord(e_t e)
391 {
392   switch (e)
393   {
394   case E1: return 1;
395   case E2: return 2;
396   case E3: return 3;
397   case E4: return 4;
398   default:
399     return 0;
400   }
401 }
402
403 double
404 s_square_encue(encue_t *eue)
405 {
406   switch (eue->t)
407   {
408   case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
409   case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
410   default:
411     return 0.0;
412   }
413 }
414
415 int
416 s_sum_toplev_conf_2n(int *x, int n)
417 {
418   int sum = 0;
419   int i;
420   for (i = 0; i < 2 * n; ++i)
421     sum += x[i];
422   return sum;
423 }
424
425 int
426 s_sum_toplev_conf_cond(int *x, int a, int b, int c)
427 {
428   int sum = 0;
429   int n = c ? a : b;
430   int i;
431   for (i = 0; i < n; ++i)
432     sum += x[i];
433   return sum;
434 }
435
436 double
437 s_sum_aligns(aligns_t *a)
438 {
439   return a->c + a->i + a->s + a->d;
440 }
441
442 int
443 s_sum_padded(padded_t *p)
444 {
445   return p->i + p->c;
446 }
447
448 int
449 s_sum_padded2(padded_t ps[2])
450 {
451   return s_sum_padded(&ps[0]) + s_sum_padded(&ps[1]);
452 }
453
454 int
455 s_sum_padded_conf(padded_t *ps, int n)
456 {
457   int sum = 0;
458   int i;
459   for (i = 0; i < n; ++i)
460     sum += s_sum_padded(&ps[i]);
461   return sum;
462 }
463
464 int
465 s_sum_bogus(bogus_t *b)
466 {
467   return *b->h.p1 + *b->p2 + *b->p3 + b->c;
468 }
469
470 void
471 s_check_null(int *null)
472 {
473   ok(!null, "RPC check_null\n");
474 }
475
476 int
477 s_str_struct_len(str_struct_t *s)
478 {
479   return lstrlenA(s->s);
480 }
481
482 int
483 s_wstr_struct_len(wstr_struct_t *s)
484 {
485   return lstrlenW(s->s);
486 }
487
488 int
489 s_sum_doub_carr(doub_carr_t *dc)
490 {
491   int i, j;
492   int sum = 0;
493   for (i = 0; i < dc->n; ++i)
494     for (j = 0; j < dc->a[i]->n; ++j)
495       sum += dc->a[i]->a[j];
496   return sum;
497 }
498
499 void
500 s_make_pyramid_doub_carr(unsigned char n, doub_carr_t **dc)
501 {
502   doub_carr_t *t;
503   int i, j;
504   t = MIDL_user_allocate(FIELD_OFFSET(doub_carr_t, a[n]));
505   t->n = n;
506   for (i = 0; i < n; ++i)
507   {
508     int v = i + 1;
509     t->a[i] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t, a[v]));
510     t->a[i]->n = v;
511     for (j = 0; j < v; ++j)
512       t->a[i]->a[j] = j + 1;
513   }
514   *dc = t;
515 }
516
517 unsigned
518 s_hash_bstr(bstr_t b)
519 {
520   short n = b[-1];
521   short *s = b;
522   unsigned hash = 0;
523   short i;
524   for (i = 0; i < n; ++i)
525     hash = 5 * hash + (unsigned) s[i];
526   return hash;
527 }
528
529 void
530 s_get_name(name_t *name)
531 {
532   const char bossman[] = "Jeremy White";
533   memcpy(name->name, bossman, min(name->size, sizeof(bossman)));
534   /* ensure nul-termination */
535   if (name->size < sizeof(bossman))
536     name->name[name->size - 1] = 0;
537 }
538
539 int
540 s_sum_pcarr2(int n, int **pa)
541 {
542   return s_sum_conf_array(*pa, n);
543 }
544
545 int
546 s_sum_L1_norms(int n, vector_t *vs)
547 {
548   int i;
549   int sum = 0;
550   for (i = 0; i < n; ++i)
551     sum += abs(vs[i].x) + abs(vs[i].y) + abs(vs[i].z);
552   return sum;
553 }
554
555 s123_t *
556 s_get_s123(void)
557 {
558   s123_t *s = MIDL_user_allocate(sizeof *s);
559   s->f1 = 1;
560   s->f2 = 2;
561   s->f3 = 3;
562   return s;
563 }
564
565 str_t
566 s_get_filename(void)
567 {
568     return (char *)__FILE__;
569 }
570
571 void
572 s_context_handle_test(void)
573 {
574     NDR_SCONTEXT h;
575     RPC_BINDING_HANDLE binding;
576     RPC_STATUS status;
577     unsigned char buf[20];
578     static RPC_SERVER_INTERFACE server_if =
579     {
580         sizeof(RPC_SERVER_INTERFACE),
581         {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
582         {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
583         NULL,
584         0,
585         0,
586         0,
587         0,
588         0,
589     };
590
591     binding = I_RpcGetCurrentCallHandle();
592     ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
593
594     if (!pNDRSContextMarshall2 || !pNDRSContextUnmarshall2)
595     {
596         win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
597         return;
598     }
599
600     h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
601     ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
602
603     /* marshal a context handle with NULL userContext */
604     memset(buf, 0xcc, sizeof(buf));
605     pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
606     ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
607     ok(UuidIsNil((UUID *)&buf[4], &status), "uuid should have been nil\n");
608
609     h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
610     ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
611
612     /* marshal a context handle with non-NULL userContext */
613     memset(buf, 0xcc, sizeof(buf));
614     h->userContext = (void *)0xdeadbeef;
615     pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
616     ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
617     ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
618
619     h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
620     ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
621     ok(h->userContext == (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
622
623     /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
624     if (0)
625     {
626     /* marshal a context handle with an interface specified */
627     h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
628     ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
629
630     memset(buf, 0xcc, sizeof(buf));
631     h->userContext = (void *)0xcafebabe;
632     pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
633     ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
634     ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
635
636     h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
637     ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
638     ok(h->userContext == (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
639     }
640
641     /* test same interface data, but different pointer */
642     /* raises ERROR_INVALID_HANDLE exception */
643     if (0)
644     {
645         RPC_SERVER_INTERFACE server_if_clone = server_if;
646
647         pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if_clone.InterfaceId, 0);
648     }
649
650     /* test different interface data, but different pointer */
651     /* raises ERROR_INVALID_HANDLE exception */
652     if (0)
653     {
654         static RPC_SERVER_INTERFACE server_if2 =
655         {
656             sizeof(RPC_SERVER_INTERFACE),
657             {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
658             {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
659             NULL,
660             0,
661             0,
662             0,
663             0,
664             0,
665         };
666         pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
667
668         pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
669     }
670 }
671
672 void
673 s_get_numbers(int length, int size, pints_t n[])
674 {
675     int i;
676     for (i = 0; i < length; i++)
677     {
678         n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
679         *n[i].pi = i;
680         n[i].ppi = NULL;
681         n[i].pppi = NULL;
682     }
683 }
684
685 void
686 s_get_numbers_struct(numbers_struct_t **ns)
687 {
688     int i;
689     *ns = midl_user_allocate(FIELD_OFFSET(numbers_struct_t, numbers[5]));
690     if (!*ns) return;
691     (*ns)->length = 5;
692     (*ns)->size = 5;
693     for (i = 0; i < (*ns)->length; i++)
694     {
695         (*ns)->numbers[i].pi = NULL;
696         (*ns)->numbers[i].ppi = NULL;
697         (*ns)->numbers[i].pppi = NULL;
698     }
699     (*ns)->numbers[0].pi = midl_user_allocate(sizeof(*(*ns)->numbers[i].pi));
700     *(*ns)->numbers[0].pi = 5;
701 }
702
703 void
704 s_stop(void)
705 {
706   ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
707   ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
708   ok(SetEvent(stop_event), "SetEvent\n");
709 }
710
711 static void
712 make_cmdline(char buffer[MAX_PATH], const char *test)
713 {
714   sprintf(buffer, "%s server %s", progname, test);
715 }
716
717 static void
718 run_client(const char *test)
719 {
720   char cmdline[MAX_PATH];
721   PROCESS_INFORMATION info;
722   STARTUPINFOA startup;
723
724   memset(&startup, 0, sizeof startup);
725   startup.cb = sizeof startup;
726
727   make_cmdline(cmdline, test);
728   ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
729   winetest_wait_child_process( info.hProcess );
730   ok(CloseHandle(info.hProcess), "CloseHandle\n");
731   ok(CloseHandle(info.hThread), "CloseHandle\n");
732 }
733
734 static void
735 basic_tests(void)
736 {
737   char string[] = "I am a string";
738   WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
739   int f[5] = {1, 3, 0, -2, -4};
740   vector_t a = {1, 3, 7};
741   vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
742   pvectors_t pvecs = {&vec1, &pvec2};
743   sp_inner_t spi = {42};
744   sp_t sp = {-13, &spi};
745   aligns_t aligns;
746   pints_t pints;
747   ptypes_t ptypes;
748   padded_t padded;
749   padded_t padded2[2];
750   bogus_t bogus;
751   int i1, i2, i3, *pi2, *pi3, **ppi3;
752   double u, v;
753   float s, t;
754   LONG q, r;
755   short h;
756   char c;
757   int x;
758   str_struct_t ss = {string};
759   wstr_struct_t ws = {wstring};
760   str_t str;
761   se_t se;
762
763   ok(int_return() == INT_CODE, "RPC int_return\n");
764
765   ok(square(7) == 49, "RPC square\n");
766   ok(sum(23, -4) == 19, "RPC sum\n");
767
768   x = 0;
769   square_out(11, &x);
770   ok(x == 121, "RPC square_out\n");
771
772   x = 5;
773   square_ref(&x);
774   ok(x == 25, "RPC square_ref\n");
775
776   ok(str_length(string) == strlen(string), "RPC str_length\n");
777   ok(str_t_length(string) == strlen(string), "RPC str_length\n");
778   ok(dot_self(&a) == 59, "RPC dot_self\n");
779
780   ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n");
781   ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n");
782
783   v = 0.0;
784   u = square_half(3.0, &v);
785   ok(u == 9.0, "RPC square_half\n");
786   ok(v == 1.5, "RPC square_half\n");
787
788   t = 0.0f;
789   s = square_half_float(3.0f, &t);
790   ok(s == 9.0f, "RPC square_half_float\n");
791   ok(t == 1.5f, "RPC square_half_float\n");
792
793   r = 0;
794   q = square_half_long(3, &r);
795   ok(q == 9, "RPC square_half_long\n");
796   ok(r == 1, "RPC square_half_long\n");
797
798   i1 = 19;
799   i2 = -3;
800   i3 = -29;
801   pi2 = &i2;
802   pi3 = &i3;
803   ppi3 = &pi3;
804   pints.pi = &i1;
805   pints.ppi = &pi2;
806   pints.pppi = &ppi3;
807   ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
808
809   c = 10;
810   h = 3;
811   q = 14;
812   s = -5.0f;
813   u = 11.0;
814   ptypes.pc = &c;
815   ptypes.ps = &h;
816   ptypes.pl = &q;
817   ptypes.pf = &s;
818   ptypes.pd = &u;
819   ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
820
821   ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
822   ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
823   ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
824   ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
825
826   ok(enum_ord(E1) == 1, "RPC enum_ord\n");
827   ok(enum_ord(E2) == 2, "RPC enum_ord\n");
828   ok(enum_ord(E3) == 3, "RPC enum_ord\n");
829   ok(enum_ord(E4) == 4, "RPC enum_ord\n");
830
831   se.f = E2;
832   check_se2(&se);
833
834   memset(&aligns, 0, sizeof(aligns));
835   aligns.c = 3;
836   aligns.i = 4;
837   aligns.s = 5;
838   aligns.d = 6.0;
839   ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
840
841   padded.i = -3;
842   padded.c = 8;
843   ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
844   padded2[0].i = -5;
845   padded2[0].c = 1;
846   padded2[1].i = 3;
847   padded2[1].c = 7;
848   ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n");
849   padded2[0].i = -5;
850   padded2[0].c = 1;
851   padded2[1].i = 3;
852   padded2[1].c = 7;
853   ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n");
854
855   i1 = 14;
856   i2 = -7;
857   i3 = -4;
858   bogus.h.p1 = &i1;
859   bogus.p2 = &i2;
860   bogus.p3 = &i3;
861   bogus.c = 9;
862   ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n");
863
864   check_null(NULL);
865
866   str = get_filename();
867   ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__);
868   midl_user_free(str);
869 }
870
871 static void
872 union_tests(void)
873 {
874   encue_t eue;
875   encu_t eu;
876   unencu_t uneu;
877   sun_t su;
878   int i;
879
880   su.s = SUN_I;
881   su.u.i = 9;
882   ok(square_sun(&su) == 81.0, "RPC square_sun\n");
883
884   su.s = SUN_F1;
885   su.u.f = 5.0;
886   ok(square_sun(&su) == 25.0, "RPC square_sun\n");
887
888   su.s = SUN_F2;
889   su.u.f = -2.0;
890   ok(square_sun(&su) == 4.0, "RPC square_sun\n");
891
892   su.s = SUN_PI;
893   su.u.pi = &i;
894   i = 11;
895   ok(square_sun(&su) == 121.0, "RPC square_sun\n");
896
897   eu.t = ENCU_I;
898   eu.tagged_union.i = 7;
899   ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
900
901   eu.t = ENCU_F;
902   eu.tagged_union.f = 3.0;
903   ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
904
905   uneu.i = 4;
906   ok(square_unencu(ENCU_I, &uneu) == 16.0, "RPC square_unencu\n");
907
908   uneu.f = 5.0;
909   ok(square_unencu(ENCU_F, &uneu) == 25.0, "RPC square_unencu\n");
910
911   eue.t = E1;
912   eue.tagged_union.i1 = 8;
913   ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
914
915   eue.t = E2;
916   eue.tagged_union.f2 = 10.0;
917   ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
918 }
919
920 static test_list_t *
921 null_list(void)
922 {
923   test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
924   n->t = TL_NULL;
925   n->u.x = 0;
926   return n;
927 }
928
929 static test_list_t *
930 make_list(test_list_t *tail)
931 {
932   test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
933   n->t = TL_LIST;
934   n->u.tail = tail;
935   return n;
936 }
937
938 static void
939 free_list(test_list_t *list)
940 {
941   if (list->t == TL_LIST)
942     free_list(list->u.tail);
943   HeapFree(GetProcessHeap(), 0, list);
944 }
945
946 ULONG __RPC_USER
947 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
948 {
949   return start + sizeof(int);
950 }
951
952 unsigned char * __RPC_USER
953 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
954 {
955   int n = atoi(*p);
956   memcpy(buffer, &n, sizeof n);
957   return buffer + sizeof n;
958 }
959
960 unsigned char * __RPC_USER
961 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
962 {
963   int n;
964   memcpy(&n, buffer, sizeof n);
965   *p = HeapAlloc(GetProcessHeap(), 0, 10);
966   sprintf(*p, "%d", n);
967   return buffer + sizeof n;
968 }
969
970 void __RPC_USER
971 puint_t_UserFree(ULONG *flags, puint_t *p)
972 {
973   HeapFree(GetProcessHeap(), 0, *p);
974 }
975
976 ULONG __RPC_USER
977 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
978 {
979   return start + sizeof(struct wire_us);
980 }
981
982 unsigned char * __RPC_USER
983 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
984 {
985   struct wire_us wus;
986   wus.x = atoi(pus->x);
987   memcpy(buffer, &wus, sizeof wus);
988   return buffer + sizeof wus;
989 }
990
991 unsigned char * __RPC_USER
992 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
993 {
994   struct wire_us wus;
995   memcpy(&wus, buffer, sizeof wus);
996   pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
997   sprintf(pus->x, "%d", wus.x);
998   return buffer + sizeof wus;
999 }
1000
1001 void __RPC_USER
1002 us_t_UserFree(ULONG *flags, us_t *pus)
1003 {
1004   HeapFree(GetProcessHeap(), 0, pus->x);
1005 }
1006
1007 ULONG __RPC_USER
1008 bstr_t_UserSize(ULONG *flags, ULONG start, bstr_t *b)
1009 {
1010   return start + FIELD_OFFSET(user_bstr_t, data[(*b)[-1]]);
1011 }
1012
1013 unsigned char * __RPC_USER
1014 bstr_t_UserMarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1015 {
1016   wire_bstr_t wb = (wire_bstr_t) buffer;
1017   wb->n = (*b)[-1];
1018   memcpy(&wb->data, *b, wb->n * sizeof wb->data[0]);
1019   return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1020 }
1021
1022 unsigned char * __RPC_USER
1023 bstr_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1024 {
1025   wire_bstr_t wb = (wire_bstr_t) buffer;
1026   short *data = HeapAlloc(GetProcessHeap(), 0, (wb->n + 1) * sizeof *data);
1027   data[0] = wb->n;
1028   memcpy(&data[1], wb->data, wb->n * sizeof data[1]);
1029   *b = &data[1];
1030   return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1031 }
1032
1033 void __RPC_USER
1034 bstr_t_UserFree(ULONG *flags, bstr_t *b)
1035 {
1036   HeapFree(GetProcessHeap(), 0, &((*b)[-1]));
1037 }
1038
1039 static void
1040 pointer_tests(void)
1041 {
1042   int a[] = {1, 2, 3, 4};
1043   char p1[] = "11";
1044   test_list_t *list = make_list(make_list(make_list(null_list())));
1045   test_us_t tus = {{p1}};
1046   int *pa[4];
1047   puints_t pus;
1048   cpuints_t cpus;
1049   short bstr_data[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1050   bstr_t bstr = &bstr_data[1];
1051   name_t name;
1052   void *buffer;
1053   int *pa2;
1054   s123_t *s123;
1055
1056   ok(test_list_length(list) == 3, "RPC test_list_length\n");
1057   ok(square_puint(p1) == 121, "RPC square_puint\n");
1058   pus.n = 4;
1059   pus.ps = HeapAlloc(GetProcessHeap(), 0, pus.n * sizeof pus.ps[0]);
1060   pus.ps[0] = xstrdup("5");
1061   pus.ps[1] = xstrdup("6");
1062   pus.ps[2] = xstrdup("7");
1063   pus.ps[3] = xstrdup("8");
1064   ok(sum_puints(&pus) == 26, "RPC sum_puints\n");
1065   HeapFree(GetProcessHeap(), 0, pus.ps[0]);
1066   HeapFree(GetProcessHeap(), 0, pus.ps[1]);
1067   HeapFree(GetProcessHeap(), 0, pus.ps[2]);
1068   HeapFree(GetProcessHeap(), 0, pus.ps[3]);
1069   HeapFree(GetProcessHeap(), 0, pus.ps);
1070   cpus.n = 4;
1071   cpus.ps = HeapAlloc(GetProcessHeap(), 0, cpus.n * sizeof cpus.ps[0]);
1072   cpus.ps[0] = xstrdup("5");
1073   cpus.ps[1] = xstrdup("6");
1074   cpus.ps[2] = xstrdup("7");
1075   cpus.ps[3] = xstrdup("8");
1076   ok(sum_cpuints(&cpus) == 26, "RPC sum_puints\n");
1077   HeapFree(GetProcessHeap(), 0, cpus.ps[0]);
1078   HeapFree(GetProcessHeap(), 0, cpus.ps[1]);
1079   HeapFree(GetProcessHeap(), 0, cpus.ps[2]);
1080   HeapFree(GetProcessHeap(), 0, cpus.ps[3]);
1081   HeapFree(GetProcessHeap(), 0, cpus.ps);
1082   ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
1083
1084   pa[0] = &a[0];
1085   pa[1] = &a[1];
1086   pa[2] = &a[2];
1087   ok(sum_parr(pa) == 6, "RPC sum_parr\n");
1088
1089   pa[0] = &a[0];
1090   pa[1] = &a[1];
1091   pa[2] = &a[2];
1092   pa[3] = &a[3];
1093   ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
1094
1095   ok(hash_bstr(bstr) == s_hash_bstr(bstr), "RPC hash_bstr_data\n");
1096
1097   free_list(list);
1098
1099   name.size = 10;
1100   name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
1101   get_name(&name);
1102   ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
1103   ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
1104   HeapFree(GetProcessHeap(), 0, name.name);
1105
1106   pa2 = a;
1107   ok(sum_pcarr2(4, &pa2) == 10, "RPC sum_pcarr2\n");
1108
1109   s123 = get_s123();
1110   ok(s123->f1 == 1 && s123->f2 == 2 && s123->f3 == 3, "RPC get_s123\n");
1111   MIDL_user_free(s123);
1112 }
1113
1114 static int
1115 check_pyramid_doub_carr(doub_carr_t *dc)
1116 {
1117   int i, j;
1118   for (i = 0; i < dc->n; ++i)
1119     for (j = 0; j < dc->a[i]->n; ++j)
1120       if (dc->a[i]->a[j] != j + 1)
1121         return FALSE;
1122   return TRUE;
1123 }
1124
1125 static void
1126 free_pyramid_doub_carr(doub_carr_t *dc)
1127 {
1128   int i;
1129   for (i = 0; i < dc->n; ++i)
1130     MIDL_user_free(dc->a[i]);
1131   MIDL_user_free(dc);
1132 }
1133
1134 static void
1135 array_tests(void)
1136 {
1137   const char str1[25] = "Hello";
1138   int m[2][3][4] =
1139   {
1140     {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1141     {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1142   };
1143   int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1144   int c2[] = {10, 100, 200};
1145   vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
1146   cps_t cps;
1147   cpsc_t cpsc;
1148   cs_t *cs;
1149   int n;
1150   int ca[5] = {1, -2, 3, -4, 5};
1151   doub_carr_t *dc;
1152   int *pi;
1153   pints_t api[5];
1154   numbers_struct_t *ns;
1155
1156   ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
1157
1158   ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
1159
1160   ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
1161   ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1162   ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1163   ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1164
1165   ok(sum_conf_ptr_by_conf_ptr(1, c2, c) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1166   ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1167   c2[0] = 0;
1168   ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1169
1170   ok(sum_unique_conf_array(ca, 4) == -2, "RPC sum_unique_conf_array\n");
1171   ok(sum_unique_conf_ptr(ca, 5) == 3, "RPC sum_unique_conf_array\n");
1172   ok(sum_unique_conf_ptr(NULL, 10) == 0, "RPC sum_unique_conf_array\n");
1173
1174   ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
1175   ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1176   ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1177   ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1178
1179   ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
1180   cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
1181   cs->n = 5;
1182   cs->ca[0] = 3;
1183   cs->ca[1] = 5;
1184   cs->ca[2] = -2;
1185   cs->ca[3] = -1;
1186   cs->ca[4] = -4;
1187   ok(sum_cs(cs) == 1, "RPC sum_cs\n");
1188   HeapFree(GetProcessHeap(), 0, cs);
1189
1190   n = 5;
1191   cps.pn = &n;
1192   cps.ca1 = &c[2];
1193   cps.n = 3;
1194   cps.ca2 = &c[3];
1195   ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
1196
1197   cpsc.a = 4;
1198   cpsc.b = 5;
1199   cpsc.c = 1;
1200   cpsc.ca = c;
1201   ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
1202   cpsc.a = 4;
1203   cpsc.b = 5;
1204   cpsc.c = 0;
1205   cpsc.ca = c;
1206   ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
1207
1208   ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
1209   ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1210   ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1211
1212   dc = malloc(FIELD_OFFSET(doub_carr_t, a[2]));
1213   dc->n = 2;
1214   dc->a[0] = malloc(FIELD_OFFSET(doub_carr_1_t, a[3]));
1215   dc->a[0]->n = 3;
1216   dc->a[0]->a[0] = 5;
1217   dc->a[0]->a[1] = 1;
1218   dc->a[0]->a[2] = 8;
1219   dc->a[1] = malloc(FIELD_OFFSET(doub_carr_1_t, a[2]));
1220   dc->a[1]->n = 2;
1221   dc->a[1]->a[0] = 2;
1222   dc->a[1]->a[1] = 3;
1223   ok(sum_doub_carr(dc) == 19, "RPC sum_doub_carr\n");
1224   free(dc->a[0]);
1225   free(dc->a[1]);
1226   free(dc);
1227
1228   dc = NULL;
1229   make_pyramid_doub_carr(4, &dc);
1230   ok(check_pyramid_doub_carr(dc), "RPC make_pyramid_doub_carr\n");
1231   free_pyramid_doub_carr(dc);
1232
1233   ok(sum_L1_norms(2, vs) == 21, "RPC sum_L1_norms\n");
1234
1235   memset(api, 0, sizeof(api));
1236   pi = HeapAlloc(GetProcessHeap(), 0, sizeof(*pi));
1237   *pi = -1;
1238   api[0].pi = pi;
1239   get_numbers(1, 1, api);
1240   ok(api[0].pi == pi, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1241   ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *api[0].pi);
1242
1243   ns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(numbers_struct_t, numbers[5]));
1244   ns->length = 5;
1245   ns->size = 5;
1246   ns->numbers[0].pi = pi;
1247   get_numbers_struct(&ns);
1248   ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
1249   ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
1250
1251   HeapFree(GetProcessHeap(), 0, ns);
1252   HeapFree(GetProcessHeap(), 0, pi);
1253 }
1254
1255 static void
1256 run_tests(void)
1257 {
1258   basic_tests();
1259   union_tests();
1260   pointer_tests();
1261   array_tests();
1262   context_handle_test();
1263 }
1264
1265 static void
1266 client(const char *test)
1267 {
1268   if (strcmp(test, "tcp_basic") == 0)
1269   {
1270     static unsigned char iptcp[] = "ncacn_ip_tcp";
1271     static unsigned char address[] = "127.0.0.1";
1272     static unsigned char port[] = PORT;
1273     unsigned char *binding;
1274
1275     ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1276     ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1277
1278     run_tests();
1279
1280     ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1281     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1282   }
1283   else if (strcmp(test, "np_basic") == 0)
1284   {
1285     static unsigned char np[] = "ncacn_np";
1286     static unsigned char address[] = "\\\\.";
1287     static unsigned char pipe[] = PIPE;
1288     unsigned char *binding;
1289
1290     ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address, pipe, NULL, &binding), "RpcStringBindingCompose\n");
1291     ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1292
1293     run_tests();
1294     stop();
1295
1296     ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1297     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1298   }
1299 }
1300
1301 static void
1302 server(void)
1303 {
1304   static unsigned char iptcp[] = "ncacn_ip_tcp";
1305   static unsigned char port[] = PORT;
1306   static unsigned char np[] = "ncacn_np";
1307   static unsigned char pipe[] = PIPE;
1308   RPC_STATUS status, iptcp_status, np_status;
1309   DWORD ret;
1310
1311   iptcp_status = RpcServerUseProtseqEp(iptcp, 20, port, NULL);
1312   ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status);
1313   np_status = RpcServerUseProtseqEp(np, 0, pipe, NULL);
1314   if (np_status == RPC_S_PROTSEQ_NOT_SUPPORTED)
1315     skip("Protocol sequence ncacn_np is not supported\n");
1316   else
1317     ok(np_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status);
1318
1319   if (pRpcServerRegisterIfEx)
1320   {
1321     trace("Using RpcServerRegisterIfEx\n");
1322     status = pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec, NULL, NULL,
1323                                     RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
1324                                     RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
1325   }
1326   else
1327     status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
1328   ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %d\n", status);
1329   status = RpcServerListen(1, 20, TRUE);
1330   ok(status == RPC_S_OK, "RpcServerListen failed with status %d\n", status);
1331   stop_event = CreateEvent(NULL, FALSE, FALSE, NULL);
1332   ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
1333
1334   if (iptcp_status == RPC_S_OK)
1335     run_client("tcp_basic");
1336   else
1337     skip("tcp_basic tests skipped due to earlier failure\n");
1338
1339   if (np_status == RPC_S_OK)
1340     run_client("np_basic");
1341   else
1342   {
1343     skip("np_basic tests skipped due to earlier failure\n");
1344     /* np client is what signals stop_event, so bail out if we didn't run do it */
1345     return;
1346   }
1347
1348   ret = WaitForSingleObject(stop_event, 1000);
1349   ok(WAIT_OBJECT_0 == ret, "WaitForSingleObject\n");
1350   /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1351    * forever, so don't bother calling it in this case */
1352   if (ret == WAIT_OBJECT_0)
1353   {
1354     status = RpcMgmtWaitServerListen();
1355     todo_wine {
1356       ok(status == RPC_S_OK, "RpcMgmtWaitServerListening failed with status %d\n", status);
1357     }
1358   }
1359 }
1360
1361 START_TEST(server)
1362 {
1363   int argc;
1364   char **argv;
1365
1366   InitFunctionPointers();
1367
1368   argc = winetest_get_mainargs(&argv);
1369   progname = argv[0];
1370
1371   if (argc == 3)
1372   {
1373     RpcTryExcept
1374     {
1375       client(argv[2]);
1376     }
1377     RpcExcept(TRUE)
1378     {
1379       trace("Exception %d\n", RpcExceptionCode());
1380     }
1381     RpcEndExcept
1382   }
1383   else
1384     server();
1385 }