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