2 * Tests for WIDL and RPC server/clients.
4 * Copyright (C) Google 2007 (Dan Hipschman)
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.
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.
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
22 #include "wine/test.h"
24 #include "server_defines.h"
31 #define PIPE "\\pipe\\wine_rpcrt4_test"
35 static const char *progname;
37 static HANDLE stop_event;
39 void __RPC_FAR *__RPC_USER
40 midl_user_allocate(size_t n)
46 midl_user_free(void __RPC_FAR *p)
70 s_square_out(int x, int *y)
82 s_str_length(const char *s)
88 s_cstr_length(const char *s, int n)
91 while (0 < n-- && *s++)
97 s_dot_self(vector_t *v)
99 return s_square(v->x) + s_square(v->y) + s_square(v->z);
103 s_square_half(double x, double *y)
110 s_square_half_float(float x, float *y)
117 s_square_half_long(long x, long *y)
124 s_sum_fixed_array(int a[5])
126 return a[0] + a[1] + a[2] + a[3] + a[4];
130 s_pints_sum(pints_t *pints)
132 return *pints->pi + **pints->ppi + ***pints->pppi;
136 s_ptypes_sum(ptypes_t *pt)
138 return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
142 s_dot_pvectors(pvectors_t *p)
144 return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
150 return sp->x + sp->s->x;
154 s_square_sun(sun_t *su)
158 case SUN_I: return su->u.i * su->u.i;
160 case SUN_F2: return su->u.f * su->u.f;
161 case SUN_PI: return (*su->u.pi) * (*su->u.pi);
168 s_test_list_length(test_list_t *list)
170 return (list->t == TL_LIST
171 ? 1 + s_test_list_length(list->u.tail)
176 s_sum_fixed_int_3d(int m[2][3][4])
181 for (i = 0; i < 2; ++i)
182 for (j = 0; j < 3; ++j)
183 for (k = 0; k < 4; ++k)
190 s_sum_conf_array(int x[], int n)
192 int *p = x, *end = p + n;
202 s_sum_var_array(int x[20], int n)
204 ok(0 <= n, "RPC sum_var_array\n");
205 ok(n <= 20, "RPC sum_var_array\n");
207 return s_sum_conf_array(x, n);
211 s_dot_two_vectors(vector_t vs[2])
213 return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
219 return s_sum_conf_array(cs->ca, cs->n);
223 s_sum_cps(cps_t *cps)
228 for (i = 0; i < *cps->pn; ++i)
231 for (i = 0; i < 2 * cps->n; ++i)
238 s_sum_cpsc(cpsc_t *cpsc)
242 for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
248 s_square_puint(puint_t p)
255 s_dot_copy_vectors(vector_t u, vector_t v)
257 return u.x * v.x + u.y * v.y + u.z * v.z;
261 s_square_test_us(test_us_t *tus)
263 int n = atoi(tus->us.x);
268 s_square_encu(encu_t *eu)
272 case ENCU_I: return eu->tagged_union.i * eu->tagged_union.i;
273 case ENCU_F: return eu->tagged_union.f * eu->tagged_union.f;
280 s_sum_parr(int *a[3])
282 return s_sum_pcarr(a, 3);
286 s_sum_pcarr(int *a[], int n)
289 for (i = 0; i < n; ++i)
309 s_square_encue(encue_t *eue)
313 case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
314 case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
321 s_sum_toplev_conf_2n(int *x, int n)
325 for (i = 0; i < 2 * n; ++i)
331 s_sum_toplev_conf_cond(int *x, int a, int b, int c)
336 for (i = 0; i < n; ++i)
342 s_sum_aligns(aligns_t *a)
344 return a->c + a->i + a->s + a->d;
348 s_sum_padded(padded_t *p)
356 ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
357 ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
358 ok(SetEvent(stop_event), "SetEvent\n");
362 make_cmdline(char buffer[MAX_PATH], const char *test)
364 sprintf(buffer, "%s server %s", progname, test);
368 run_client(const char *test)
370 char cmdline[MAX_PATH];
371 PROCESS_INFORMATION info;
372 STARTUPINFOA startup;
375 memset(&startup, 0, sizeof startup);
376 startup.cb = sizeof startup;
378 make_cmdline(cmdline, test);
379 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
380 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination\n");
381 ok(GetExitCodeProcess(info.hProcess, &exitcode), "GetExitCodeProcess\n");
382 ok(CloseHandle(info.hProcess), "CloseHandle\n");
383 ok(CloseHandle(info.hThread), "CloseHandle\n");
385 return exitcode == 0;
391 static char string[] = "I am a string";
392 static int f[5] = {1, 3, 0, -2, -4};
393 static vector_t a = {1, 3, 7};
394 static vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
395 static pvectors_t pvecs = {&vec1, &pvec2};
396 static sp_inner_t spi = {42};
397 static sp_t sp = {-13, &spi};
398 static aligns_t aligns = {3, 4, 5, 6.0};
402 int i1, i2, i3, *pi2, *pi3, **ppi3;
410 ok(int_return() == INT_CODE, "RPC int_return\n");
412 ok(square(7) == 49, "RPC square\n");
413 ok(sum(23, -4) == 19, "RPC sum\n");
417 ok(x == 121, "RPC square_out\n");
421 ok(x == 25, "RPC square_ref\n");
423 ok(str_length(string) == strlen(string), "RPC str_length\n");
424 ok(dot_self(&a) == 59, "RPC dot_self\n");
427 u = square_half(3.0, &v);
428 ok(u == 9.0, "RPC square_half\n");
429 ok(v == 1.5, "RPC square_half\n");
432 s = square_half_float(3.0f, &t);
433 ok(s == 9.0f, "RPC square_half_float\n");
434 ok(t == 1.5f, "RPC square_half_float\n");
437 q = square_half_long(3, &r);
438 ok(q == 9, "RPC square_half_long\n");
439 ok(r == 1, "RPC square_half_long\n");
450 ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
462 ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
464 ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
465 ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
466 ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
467 ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
469 ok(enum_ord(E1) == 1, "RPC enum_ord\n");
470 ok(enum_ord(E2) == 2, "RPC enum_ord\n");
471 ok(enum_ord(E3) == 3, "RPC enum_ord\n");
472 ok(enum_ord(E4) == 4, "RPC enum_ord\n");
474 ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
478 ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
491 ok(square_sun(&su) == 81.0, "RPC square_sun\n");
495 ok(square_sun(&su) == 25.0, "RPC square_sun\n");
499 ok(square_sun(&su) == 4.0, "RPC square_sun\n");
504 ok(square_sun(&su) == 121.0, "RPC square_sun\n");
507 eu.tagged_union.i = 7;
508 ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
511 eu.tagged_union.f = 3.0;
512 ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
515 eue.tagged_union.i1 = 8;
516 ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
519 eue.tagged_union.f2 = 10.0;
520 ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
526 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
532 make_list(test_list_t *tail)
534 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
541 free_list(test_list_t *list)
543 if (list->t == TL_LIST)
544 free_list(list->u.tail);
545 HeapFree(GetProcessHeap(), 0, list);
549 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
551 return start + sizeof(int);
554 unsigned char * __RPC_USER
555 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
558 memcpy(buffer, &n, sizeof n);
559 return buffer + sizeof n;
562 unsigned char * __RPC_USER
563 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
566 memcpy(&n, buffer, sizeof n);
567 *p = HeapAlloc(GetProcessHeap(), 0, 10);
568 sprintf(*p, "%d", n);
569 return buffer + sizeof n;
573 puint_t_UserFree(ULONG *flags, puint_t *p)
575 HeapFree(GetProcessHeap(), 0, *p);
579 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
581 return start + sizeof(struct wire_us);
584 unsigned char * __RPC_USER
585 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
588 wus.x = atoi(pus->x);
589 memcpy(buffer, &wus, sizeof wus);
590 return buffer + sizeof wus;
593 unsigned char * __RPC_USER
594 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
597 memcpy(&wus, buffer, sizeof wus);
598 pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
599 sprintf(pus->x, "%d", wus.x);
600 return buffer + sizeof wus;
604 us_t_UserFree(ULONG *flags, us_t *pus)
606 HeapFree(GetProcessHeap(), 0, pus->x);
612 static int a[] = {1, 2, 3, 4};
613 static char p1[] = "11";
614 test_list_t *list = make_list(make_list(make_list(null_list())));
615 static test_us_t tus = {{p1}};
618 ok(test_list_length(list) == 3, "RPC test_list_length\n");
619 ok(square_puint(p1) == 121, "RPC square_puint\n");
620 ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
625 ok(sum_parr(pa) == 6, "RPC sum_parr\n");
631 ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
639 static const char str1[25] = "Hello";
640 static int m[2][3][4] =
642 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
643 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
645 static int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
646 static vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
652 ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
654 ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
656 ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
657 ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
658 ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
659 ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
661 ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
662 ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
663 ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
664 ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
666 ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
667 cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
674 ok(sum_cs(cs) == 1, "RPC sum_cs\n");
675 HeapFree(GetProcessHeap(), 0, cs);
682 ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
688 ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
693 ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
695 ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
696 ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
697 ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
710 client(const char *test)
712 if (strcmp(test, "tcp_basic") == 0)
714 static unsigned char iptcp[] = "ncacn_ip_tcp";
715 static unsigned char address[] = "127.0.0.1";
716 static unsigned char port[] = PORT;
717 unsigned char *binding;
719 ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
720 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
724 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
725 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
727 else if (strcmp(test, "np_basic") == 0)
729 static unsigned char np[] = "ncacn_np";
730 static unsigned char address[] = "\\\\.";
731 static unsigned char pipe[] = PIPE;
732 unsigned char *binding;
734 ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address, pipe, NULL, &binding), "RpcStringBindingCompose\n");
735 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
740 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
741 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
748 static unsigned char iptcp[] = "ncacn_ip_tcp";
749 static unsigned char port[] = PORT;
750 static unsigned char np[] = "ncacn_np";
751 static unsigned char pipe[] = PIPE;
753 ok(RPC_S_OK == RpcServerUseProtseqEp(iptcp, 20, port, NULL), "RpcServerUseProtseqEp\n");
754 ok(RPC_S_OK == RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL), "RpcServerRegisterIf\n");
755 ok(RPC_S_OK == RpcServerListen(1, 20, TRUE), "RpcServerListen\n");
757 stop_event = CreateEvent(NULL, FALSE, FALSE, NULL);
758 ok(stop_event != NULL, "CreateEvent failed\n");
760 ok(run_client("tcp_basic"), "tcp_basic client test failed\n");
762 ok(RPC_S_OK == RpcServerUseProtseqEp(np, 0, pipe, NULL), "RpcServerUseProtseqEp\n");
763 ok(run_client("np_basic"), "np_basic client test failed\n");
765 ok(WAIT_OBJECT_0 == WaitForSingleObject(stop_event, 60000), "WaitForSingleObject\n");
767 ok(RPC_S_OK == RpcMgmtWaitServerListen(), "RpcMgmtWaitServerListening\n");
776 argc = winetest_get_mainargs(&argv);
787 trace("Exception %d\n", RpcExceptionCode());