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_unique_conf_array(int x
[], int n
)
204 return s_sum_conf_array(x
, n
);
208 s_sum_unique_conf_ptr(int *x
, int n
)
210 return x
? s_sum_conf_array(x
, n
) : 0;
214 s_sum_var_array(int x
[20], int n
)
216 ok(0 <= n
, "RPC sum_var_array\n");
217 ok(n
<= 20, "RPC sum_var_array\n");
219 return s_sum_conf_array(x
, n
);
223 s_dot_two_vectors(vector_t vs
[2])
225 return vs
[0].x
* vs
[1].x
+ vs
[0].y
* vs
[1].y
+ vs
[0].z
* vs
[1].z
;
231 return s_sum_conf_array(cs
->ca
, cs
->n
);
235 s_sum_cps(cps_t
*cps
)
240 for (i
= 0; i
< *cps
->pn
; ++i
)
243 for (i
= 0; i
< 2 * cps
->n
; ++i
)
250 s_sum_cpsc(cpsc_t
*cpsc
)
254 for (i
= 0; i
< (cpsc
->c
? cpsc
->a
: cpsc
->b
); ++i
)
260 s_square_puint(puint_t p
)
267 s_dot_copy_vectors(vector_t u
, vector_t v
)
269 return u
.x
* v
.x
+ u
.y
* v
.y
+ u
.z
* v
.z
;
273 s_square_test_us(test_us_t
*tus
)
275 int n
= atoi(tus
->us
.x
);
280 s_square_encu(encu_t
*eu
)
284 case ENCU_I
: return eu
->tagged_union
.i
* eu
->tagged_union
.i
;
285 case ENCU_F
: return eu
->tagged_union
.f
* eu
->tagged_union
.f
;
292 s_sum_parr(int *a
[3])
294 return s_sum_pcarr(a
, 3);
298 s_sum_pcarr(int *a
[], int n
)
301 for (i
= 0; i
< n
; ++i
)
321 s_square_encue(encue_t
*eue
)
325 case E1
: return eue
->tagged_union
.i1
* eue
->tagged_union
.i1
;
326 case E2
: return eue
->tagged_union
.f2
* eue
->tagged_union
.f2
;
333 s_sum_toplev_conf_2n(int *x
, int n
)
337 for (i
= 0; i
< 2 * n
; ++i
)
343 s_sum_toplev_conf_cond(int *x
, int a
, int b
, int c
)
348 for (i
= 0; i
< n
; ++i
)
354 s_sum_aligns(aligns_t
*a
)
356 return a
->c
+ a
->i
+ a
->s
+ a
->d
;
360 s_sum_padded(padded_t
*p
)
366 s_sum_padded2(padded_t ps
[2])
368 return s_sum_padded(&ps
[0]) + s_sum_padded(&ps
[1]);
372 s_sum_padded_conf(padded_t
*ps
, int n
)
376 for (i
= 0; i
< n
; ++i
)
377 sum
+= s_sum_padded(&ps
[i
]);
382 s_sum_bogus(bogus_t
*b
)
384 return *b
->h
.p1
+ *b
->p2
+ *b
->p3
+ b
->c
;
388 s_check_null(int *null
)
390 ok(!null
, "RPC check_null\n");
394 s_str_struct_len(str_struct_t
*s
)
396 return lstrlenA(s
->s
);
400 s_wstr_struct_len(wstr_struct_t
*s
)
402 return lstrlenW(s
->s
);
408 ok(RPC_S_OK
== RpcMgmtStopServerListening(NULL
), "RpcMgmtStopServerListening\n");
409 ok(RPC_S_OK
== RpcServerUnregisterIf(NULL
, NULL
, FALSE
), "RpcServerUnregisterIf\n");
410 ok(SetEvent(stop_event
), "SetEvent\n");
414 make_cmdline(char buffer
[MAX_PATH
], const char *test
)
416 sprintf(buffer
, "%s server %s", progname
, test
);
420 run_client(const char *test
)
422 char cmdline
[MAX_PATH
];
423 PROCESS_INFORMATION info
;
424 STARTUPINFOA startup
;
427 memset(&startup
, 0, sizeof startup
);
428 startup
.cb
= sizeof startup
;
430 make_cmdline(cmdline
, test
);
431 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
432 ok(WaitForSingleObject(info
.hProcess
, 30000) == WAIT_OBJECT_0
, "Child process termination\n");
433 ok(GetExitCodeProcess(info
.hProcess
, &exitcode
), "GetExitCodeProcess\n");
434 ok(CloseHandle(info
.hProcess
), "CloseHandle\n");
435 ok(CloseHandle(info
.hThread
), "CloseHandle\n");
437 return exitcode
== 0;
443 char string
[] = "I am a string";
444 WCHAR wstring
[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
445 int f
[5] = {1, 3, 0, -2, -4};
446 vector_t a
= {1, 3, 7};
447 vector_t vec1
= {4, -2, 1}, vec2
= {-5, 2, 3}, *pvec2
= &vec2
;
448 pvectors_t pvecs
= {&vec1
, &pvec2
};
449 sp_inner_t spi
= {42};
450 sp_t sp
= {-13, &spi
};
451 aligns_t aligns
= {3, 4, 5, 6.0};
457 int i1
, i2
, i3
, *pi2
, *pi3
, **ppi3
;
464 str_struct_t ss
= {string
};
465 wstr_struct_t ws
= {wstring
};
467 ok(int_return() == INT_CODE
, "RPC int_return\n");
469 ok(square(7) == 49, "RPC square\n");
470 ok(sum(23, -4) == 19, "RPC sum\n");
474 ok(x
== 121, "RPC square_out\n");
478 ok(x
== 25, "RPC square_ref\n");
480 ok(str_length(string
) == strlen(string
), "RPC str_length\n");
481 ok(dot_self(&a
) == 59, "RPC dot_self\n");
483 ok(str_struct_len(&ss
) == lstrlenA(string
), "RPC str_struct_len\n");
484 ok(wstr_struct_len(&ws
) == lstrlenW(wstring
), "RPC str_struct_len\n");
487 u
= square_half(3.0, &v
);
488 ok(u
== 9.0, "RPC square_half\n");
489 ok(v
== 1.5, "RPC square_half\n");
492 s
= square_half_float(3.0f
, &t
);
493 ok(s
== 9.0f
, "RPC square_half_float\n");
494 ok(t
== 1.5f
, "RPC square_half_float\n");
497 q
= square_half_long(3, &r
);
498 ok(q
== 9, "RPC square_half_long\n");
499 ok(r
== 1, "RPC square_half_long\n");
510 ok(pints_sum(&pints
) == -13, "RPC pints_sum\n");
522 ok(ptypes_sum(&ptypes
) == 33.0, "RPC ptypes_sum\n");
524 ok(dot_pvectors(&pvecs
) == -21, "RPC dot_pvectors\n");
525 ok(dot_copy_vectors(vec1
, vec2
) == -21, "RPC dot_copy_vectors\n");
526 ok(sum_fixed_array(f
) == -2, "RPC sum_fixed_array\n");
527 ok(sum_sp(&sp
) == 29, "RPC sum_sp\n");
529 ok(enum_ord(E1
) == 1, "RPC enum_ord\n");
530 ok(enum_ord(E2
) == 2, "RPC enum_ord\n");
531 ok(enum_ord(E3
) == 3, "RPC enum_ord\n");
532 ok(enum_ord(E4
) == 4, "RPC enum_ord\n");
534 ok(sum_aligns(&aligns
) == 18.0, "RPC sum_aligns\n");
538 ok(sum_padded(&padded
) == 5, "RPC sum_padded\n");
543 ok(sum_padded2(padded2
) == 6, "RPC sum_padded2\n");
548 ok(sum_padded_conf(padded2
, 2) == 6, "RPC sum_padded_conf\n");
557 ok(sum_bogus(&bogus
) == 12, "RPC sum_bogus\n");
572 ok(square_sun(&su
) == 81.0, "RPC square_sun\n");
576 ok(square_sun(&su
) == 25.0, "RPC square_sun\n");
580 ok(square_sun(&su
) == 4.0, "RPC square_sun\n");
585 ok(square_sun(&su
) == 121.0, "RPC square_sun\n");
588 eu
.tagged_union
.i
= 7;
589 ok(square_encu(&eu
) == 49.0, "RPC square_encu\n");
592 eu
.tagged_union
.f
= 3.0;
593 ok(square_encu(&eu
) == 9.0, "RPC square_encu\n");
596 eue
.tagged_union
.i1
= 8;
597 ok(square_encue(&eue
) == 64.0, "RPC square_encue\n");
600 eue
.tagged_union
.f2
= 10.0;
601 ok(square_encue(&eue
) == 100.0, "RPC square_encue\n");
607 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
613 make_list(test_list_t
*tail
)
615 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
622 free_list(test_list_t
*list
)
624 if (list
->t
== TL_LIST
)
625 free_list(list
->u
.tail
);
626 HeapFree(GetProcessHeap(), 0, list
);
630 puint_t_UserSize(ULONG
*flags
, ULONG start
, puint_t
*p
)
632 return start
+ sizeof(int);
635 unsigned char * __RPC_USER
636 puint_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
639 memcpy(buffer
, &n
, sizeof n
);
640 return buffer
+ sizeof n
;
643 unsigned char * __RPC_USER
644 puint_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
647 memcpy(&n
, buffer
, sizeof n
);
648 *p
= HeapAlloc(GetProcessHeap(), 0, 10);
649 sprintf(*p
, "%d", n
);
650 return buffer
+ sizeof n
;
654 puint_t_UserFree(ULONG
*flags
, puint_t
*p
)
656 HeapFree(GetProcessHeap(), 0, *p
);
660 us_t_UserSize(ULONG
*flags
, ULONG start
, us_t
*pus
)
662 return start
+ sizeof(struct wire_us
);
665 unsigned char * __RPC_USER
666 us_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
669 wus
.x
= atoi(pus
->x
);
670 memcpy(buffer
, &wus
, sizeof wus
);
671 return buffer
+ sizeof wus
;
674 unsigned char * __RPC_USER
675 us_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
678 memcpy(&wus
, buffer
, sizeof wus
);
679 pus
->x
= HeapAlloc(GetProcessHeap(), 0, 10);
680 sprintf(pus
->x
, "%d", wus
.x
);
681 return buffer
+ sizeof wus
;
685 us_t_UserFree(ULONG
*flags
, us_t
*pus
)
687 HeapFree(GetProcessHeap(), 0, pus
->x
);
693 int a
[] = {1, 2, 3, 4};
695 test_list_t
*list
= make_list(make_list(make_list(null_list())));
696 test_us_t tus
= {{p1
}};
699 ok(test_list_length(list
) == 3, "RPC test_list_length\n");
700 ok(square_puint(p1
) == 121, "RPC square_puint\n");
701 ok(square_test_us(&tus
) == 121, "RPC square_test_us\n");
706 ok(sum_parr(pa
) == 6, "RPC sum_parr\n");
712 ok(sum_pcarr(pa
, 4) == 10, "RPC sum_pcarr\n");
720 const char str1
[25] = "Hello";
723 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
724 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
726 int c
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
727 vector_t vs
[2] = {{1, -2, 3}, {4, -5, -6}};
732 int ca
[5] = {1, -2, 3, -4, 5};
734 ok(cstr_length(str1
, sizeof str1
) == strlen(str1
), "RPC cstr_length\n");
736 ok(sum_fixed_int_3d(m
) == 4116, "RPC sum_fixed_int_3d\n");
738 ok(sum_conf_array(c
, 10) == 45, "RPC sum_conf_array\n");
739 ok(sum_conf_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
740 ok(sum_conf_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
741 ok(sum_conf_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
743 ok(sum_unique_conf_array(ca
, 4) == -2, "RPC sum_unique_conf_array\n");
744 ok(sum_unique_conf_ptr(ca
, 5) == 3, "RPC sum_unique_conf_array\n");
745 ok(sum_unique_conf_ptr(NULL
, 10) == 0, "RPC sum_unique_conf_array\n");
747 ok(sum_var_array(c
, 10) == 45, "RPC sum_conf_array\n");
748 ok(sum_var_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
749 ok(sum_var_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
750 ok(sum_var_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
752 ok(dot_two_vectors(vs
) == -4, "RPC dot_two_vectors\n");
753 cs
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t
, ca
[5]));
760 ok(sum_cs(cs
) == 1, "RPC sum_cs\n");
761 HeapFree(GetProcessHeap(), 0, cs
);
768 todo_wine
ok(sum_cps(&cps
) == 53, "RPC sum_cps\n");
774 todo_wine
ok(sum_cpsc(&cpsc
) == 6, "RPC sum_cpsc\n");
779 todo_wine
ok(sum_cpsc(&cpsc
) == 10, "RPC sum_cpsc\n");
781 ok(sum_toplev_conf_2n(c
, 3) == 15, "RPC sum_toplev_conf_2n\n");
782 ok(sum_toplev_conf_cond(c
, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
783 ok(sum_toplev_conf_cond(c
, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
796 client(const char *test
)
798 if (strcmp(test
, "tcp_basic") == 0)
800 static unsigned char iptcp
[] = "ncacn_ip_tcp";
801 static unsigned char address
[] = "127.0.0.1";
802 static unsigned char port
[] = PORT
;
803 unsigned char *binding
;
805 ok(RPC_S_OK
== RpcStringBindingCompose(NULL
, iptcp
, address
, port
, NULL
, &binding
), "RpcStringBindingCompose\n");
806 ok(RPC_S_OK
== RpcBindingFromStringBinding(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
810 ok(RPC_S_OK
== RpcStringFree(&binding
), "RpcStringFree\n");
811 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
813 else if (strcmp(test
, "np_basic") == 0)
815 static unsigned char np
[] = "ncacn_np";
816 static unsigned char address
[] = "\\\\.";
817 static unsigned char pipe
[] = PIPE
;
818 unsigned char *binding
;
820 ok(RPC_S_OK
== RpcStringBindingCompose(NULL
, np
, address
, pipe
, NULL
, &binding
), "RpcStringBindingCompose\n");
821 ok(RPC_S_OK
== RpcBindingFromStringBinding(binding
, &IServer_IfHandle
), "RpcBindingFromStringBinding\n");
826 ok(RPC_S_OK
== RpcStringFree(&binding
), "RpcStringFree\n");
827 ok(RPC_S_OK
== RpcBindingFree(&IServer_IfHandle
), "RpcBindingFree\n");
834 static unsigned char iptcp
[] = "ncacn_ip_tcp";
835 static unsigned char port
[] = PORT
;
836 static unsigned char np
[] = "ncacn_np";
837 static unsigned char pipe
[] = PIPE
;
839 ok(RPC_S_OK
== RpcServerUseProtseqEp(iptcp
, 20, port
, NULL
), "RpcServerUseProtseqEp\n");
840 ok(RPC_S_OK
== RpcServerRegisterIf(s_IServer_v0_0_s_ifspec
, NULL
, NULL
), "RpcServerRegisterIf\n");
841 ok(RPC_S_OK
== RpcServerListen(1, 20, TRUE
), "RpcServerListen\n");
843 stop_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
844 ok(stop_event
!= NULL
, "CreateEvent failed\n");
846 ok(run_client("tcp_basic"), "tcp_basic client test failed\n");
848 ok(RPC_S_OK
== RpcServerUseProtseqEp(np
, 0, pipe
, NULL
), "RpcServerUseProtseqEp\n");
849 ok(run_client("np_basic"), "np_basic client test failed\n");
851 ok(WAIT_OBJECT_0
== WaitForSingleObject(stop_event
, 60000), "WaitForSingleObject\n");
853 ok(RPC_S_OK
== RpcMgmtWaitServerListen(), "RpcMgmtWaitServerListening\n");
862 argc
= winetest_get_mainargs(&argv
);
873 trace("Exception %d\n", RpcExceptionCode());