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