rpcrt4: Compile tests with -D__WINESRC__.
[wine.git] / dlls / rpcrt4 / tests / server.c
blobf32d3f7b6b92ccf58e52729f831c8b810707778a
1 /*
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
21 #include <windows.h>
22 #include <ole2.h>
23 #include <secext.h>
24 #include <rpcdce.h>
25 #include "wine/test.h"
26 #include "server.h"
27 #include "server_defines.h"
29 #include <stddef.h>
30 #include <stdio.h>
31 #include <stdlib.h>
33 #define PORT "4114"
34 #define PIPE "\\pipe\\wine_rpcrt4_test"
36 #define INT_CODE 4198
38 static const char *progname;
39 static BOOL old_windows_version;
41 static HANDLE stop_event;
43 static void (WINAPI *pNDRSContextMarshall2)(RPC_BINDING_HANDLE, NDR_SCONTEXT, void*, NDR_RUNDOWN, void*, ULONG);
44 static NDR_SCONTEXT (WINAPI *pNDRSContextUnmarshall2)(RPC_BINDING_HANDLE, void*, ULONG, void*, ULONG);
45 static RPC_STATUS (WINAPI *pRpcServerRegisterIfEx)(RPC_IF_HANDLE,UUID*, RPC_MGR_EPV*, unsigned int,
46 unsigned int,RPC_IF_CALLBACK_FN*);
47 static BOOLEAN (WINAPI *pGetUserNameExA)(EXTENDED_NAME_FORMAT, LPSTR, PULONG);
48 static RPC_STATUS (WINAPI *pRpcBindingSetAuthInfoExA)(RPC_BINDING_HANDLE, RPC_CSTR, ULONG, ULONG,
49 RPC_AUTH_IDENTITY_HANDLE, ULONG, RPC_SECURITY_QOS *);
50 static RPC_STATUS (WINAPI *pRpcServerRegisterAuthInfoA)(RPC_CSTR, ULONG, RPC_AUTH_KEY_RETRIEVAL_FN, LPVOID);
52 static char *domain_and_user;
54 /* type check statements generated in header file */
55 fnprintf *p_printf = printf;
57 static void InitFunctionPointers(void)
59 HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
60 HMODULE hsecur32 = LoadLibraryA("secur32.dll");
62 pNDRSContextMarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextMarshall2");
63 pNDRSContextUnmarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextUnmarshall2");
64 pRpcServerRegisterIfEx = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterIfEx");
65 pRpcBindingSetAuthInfoExA = (void *)GetProcAddress(hrpcrt4, "RpcBindingSetAuthInfoExA");
66 pRpcServerRegisterAuthInfoA = (void *)GetProcAddress(hrpcrt4, "RpcServerRegisterAuthInfoA");
67 pGetUserNameExA = (void *)GetProcAddress(hsecur32, "GetUserNameExA");
69 if (!pNDRSContextMarshall2) old_windows_version = TRUE;
72 void __RPC_FAR *__RPC_USER
73 midl_user_allocate(SIZE_T n)
75 return HeapAlloc(GetProcessHeap(), 0, n);
78 void __RPC_USER
79 midl_user_free(void __RPC_FAR *p)
81 HeapFree(GetProcessHeap(), 0, p);
84 static char *
85 xstrdup(const char *s)
87 char *d = HeapAlloc(GetProcessHeap(), 0, strlen(s) + 1);
88 strcpy(d, s);
89 return d;
92 int __cdecl s_int_return(void)
94 return INT_CODE;
97 int __cdecl s_square(int x)
99 return x * x;
102 int __cdecl s_sum(int x, int y)
104 return x + y;
107 signed char __cdecl s_sum_char(signed char x, signed char y)
109 return x + y;
112 short __cdecl s_sum_short(short x, short y)
114 return x + y;
117 int __cdecl s_sum_float(float x, float y)
119 return x + y;
122 int __cdecl s_sum_double_int(int x, double y)
124 return x + y;
127 hyper __cdecl s_sum_hyper(hyper x, hyper y)
129 return x + y;
132 int __cdecl s_sum_hyper_int(hyper x, hyper y)
134 return x + y;
137 int __cdecl s_sum_char_hyper(signed char x, hyper y)
139 return x + y;
142 void __cdecl s_square_out(int x, int *y)
144 *y = s_square(x);
147 void __cdecl s_square_ref(int *x)
149 *x = s_square(*x);
152 int __cdecl s_str_length(const char *s)
154 return strlen(s);
157 int __cdecl s_str_t_length(str_t s)
159 return strlen(s);
162 int __cdecl s_cstr_length(const char *s, int n)
164 int len = 0;
165 while (0 < n-- && *s++)
166 ++len;
167 return len;
170 int __cdecl s_dot_self(vector_t *v)
172 return s_square(v->x) + s_square(v->y) + s_square(v->z);
175 double __cdecl s_square_half(double x, double *y)
177 *y = x / 2.0;
178 return x * x;
181 float __cdecl s_square_half_float(float x, float *y)
183 *y = x / 2.0f;
184 return x * x;
187 LONG __cdecl s_square_half_long(LONG x, LONG *y)
189 *y = x / 2;
190 return x * x;
193 int __cdecl s_sum_fixed_array(int a[5])
195 return a[0] + a[1] + a[2] + a[3] + a[4];
198 int __cdecl s_pints_sum(pints_t *pints)
200 return *pints->pi + **pints->ppi + ***pints->pppi;
203 double __cdecl s_ptypes_sum(ptypes_t *pt)
205 return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
208 int __cdecl s_dot_pvectors(pvectors_t *p)
210 return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
213 int __cdecl s_sum_sp(sp_t *sp)
215 return sp->x + sp->s->x;
218 double __cdecl s_square_sun(sun_t *su)
220 switch (su->s)
222 case SUN_I: return su->u.i * su->u.i;
223 case SUN_F1:
224 case SUN_F2: return su->u.f * su->u.f;
225 case SUN_PI: return (*su->u.pi) * (*su->u.pi);
226 default:
227 return 0.0;
231 int __cdecl s_test_list_length(test_list_t *list)
233 return (list->t == TL_LIST
234 ? 1 + s_test_list_length(list->u.tail)
235 : 0);
238 int __cdecl s_sum_fixed_int_3d(int m[2][3][4])
240 int i, j, k;
241 int sum = 0;
243 for (i = 0; i < 2; ++i)
244 for (j = 0; j < 3; ++j)
245 for (k = 0; k < 4; ++k)
246 sum += m[i][j][k];
248 return sum;
251 int __cdecl s_sum_conf_array(int x[], int n)
253 int *p = x, *end = p + n;
254 int sum = 0;
256 while (p < end)
257 sum += *p++;
259 return sum;
262 int __cdecl s_sum_conf_ptr_by_conf_ptr(int n1, int *n2_then_x1, int *x2)
264 int i;
265 int sum = 0;
266 if(n1 == 0)
267 return 0;
269 for(i = 1; i < n1; ++i)
270 sum += n2_then_x1[i];
272 for(i = 0; i < *n2_then_x1; ++i)
273 sum += x2[i];
275 return sum;
278 int __cdecl s_sum_unique_conf_array(int x[], int n)
280 return s_sum_conf_array(x, n);
283 int __cdecl s_sum_unique_conf_ptr(int *x, int n)
285 return x ? s_sum_conf_array(x, n) : 0;
288 int __cdecl s_sum_var_array(int x[20], int n)
290 ok(0 <= n, "RPC sum_var_array\n");
291 ok(n <= 20, "RPC sum_var_array\n");
293 return s_sum_conf_array(x, n);
296 int __cdecl s_sum_complex_array(int n, refpint_t pi[])
298 int total = 0;
299 for (; n > 0; n--)
300 total += *pi[n - 1];
301 return total;
304 int __cdecl s_dot_two_vectors(vector_t vs[2])
306 return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
309 void __cdecl s_get_number_array(int x[20], int *n)
311 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
312 memcpy(x, c, sizeof(c));
313 *n = sizeof(c)/sizeof(c[0]);
316 int __cdecl s_sum_cs(cs_t *cs)
318 return s_sum_conf_array(cs->ca, cs->n);
321 int __cdecl s_sum_cps(cps_t *cps)
323 int sum = 0;
324 int i;
326 for (i = 0; i < *cps->pn; ++i)
327 sum += cps->ca1[i];
329 for (i = 0; i < 2 * cps->n; ++i)
330 sum += cps->ca2[i];
332 return sum;
335 int __cdecl s_sum_cpsc(cpsc_t *cpsc)
337 int sum = 0;
338 int i;
339 for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
340 sum += cpsc->ca[i];
341 return sum;
344 int __cdecl s_get_cpsc(int n, cpsc_t *cpsc)
346 int i, ret;
348 cpsc->a = 2 * n;
349 cpsc->b = 2;
350 cpsc->c = 1;
351 cpsc->ca = MIDL_user_allocate( cpsc->a * sizeof(int) );
352 for (i = ret = 0; i < cpsc->a; i++) cpsc->ca[i] = i;
353 for (i = ret = 0; i < cpsc->a; i++) ret += cpsc->ca[i];
354 return ret;
357 int __cdecl s_square_puint(puint_t p)
359 int n = atoi(p);
360 return n * n;
363 int __cdecl s_sum_puints(puints_t *p)
365 int sum = 0;
366 int i;
367 for (i = 0; i < p->n; ++i)
368 sum += atoi(p->ps[i]);
369 return sum;
372 int __cdecl s_sum_cpuints(cpuints_t *p)
374 int sum = 0;
375 int i;
376 for (i = 0; i < p->n; ++i)
377 sum += atoi(p->ps[i]);
378 return sum;
381 int __cdecl s_dot_copy_vectors(vector_t u, vector_t v)
383 return u.x * v.x + u.y * v.y + u.z * v.z;
386 int __cdecl s_square_test_us(test_us_t *tus)
388 int n = atoi(tus->us.x);
389 return n * n;
392 double __cdecl s_square_encu(encu_t *eu)
394 switch (eu->t)
396 case ENCU_I: return eu->tagged_union.i * eu->tagged_union.i;
397 case ENCU_F: return eu->tagged_union.f * eu->tagged_union.f;
398 default:
399 return 0.0;
403 double __cdecl s_square_unencu(int t, unencu_t *eu)
405 switch (t)
407 case ENCU_I: return eu->i * eu->i;
408 case ENCU_F: return eu->f * eu->f;
409 default:
410 return 0.0;
414 void __cdecl s_check_se2(se_t *s)
416 ok(s->f == E2, "check_se2\n");
419 int __cdecl s_sum_parr(int *a[3])
421 return s_sum_pcarr(a, 3);
424 int __cdecl s_sum_pcarr(int *a[], int n)
426 int i, s = 0;
427 for (i = 0; i < n; ++i)
428 s += *a[i];
429 return s;
432 int __cdecl s_enum_ord(e_t e)
434 switch (e)
436 case E1: return 1;
437 case E2: return 2;
438 case E3: return 3;
439 case E4: return 4;
440 default:
441 return 0;
445 double __cdecl s_square_encue(encue_t *eue)
447 switch (eue->t)
449 case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
450 case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
451 default:
452 return 0.0;
456 int __cdecl s_sum_toplev_conf_2n(int *x, int n)
458 int sum = 0;
459 int i;
460 for (i = 0; i < 2 * n; ++i)
461 sum += x[i];
462 return sum;
465 int __cdecl s_sum_toplev_conf_cond(int *x, int a, int b, int c)
467 int sum = 0;
468 int n = c ? a : b;
469 int i;
470 for (i = 0; i < n; ++i)
471 sum += x[i];
472 return sum;
475 double __cdecl s_sum_aligns(aligns_t *a)
477 return a->c + a->i + a->s + a->d;
480 int __cdecl s_sum_padded(padded_t *p)
482 return p->i + p->c;
485 int __cdecl s_sum_padded2(padded_t ps[2])
487 return s_sum_padded(&ps[0]) + s_sum_padded(&ps[1]);
490 int __cdecl s_sum_padded_conf(padded_t *ps, int n)
492 int sum = 0;
493 int i;
494 for (i = 0; i < n; ++i)
495 sum += s_sum_padded(&ps[i]);
496 return sum;
499 int __cdecl s_sum_bogus(bogus_t *b)
501 return *b->h.p1 + *b->p2 + *b->p3 + b->c;
504 void __cdecl s_check_null(int *null)
506 ok(!null, "RPC check_null\n");
509 int __cdecl s_str_struct_len(str_struct_t *s)
511 return lstrlenA(s->s);
514 int __cdecl s_wstr_struct_len(wstr_struct_t *s)
516 return lstrlenW(s->s);
519 int __cdecl s_sum_doub_carr(doub_carr_t *dc)
521 int i, j;
522 int sum = 0;
523 for (i = 0; i < dc->n; ++i)
524 for (j = 0; j < dc->a[i]->n; ++j)
525 sum += dc->a[i]->a[j];
526 return sum;
529 void __cdecl s_make_pyramid_doub_carr(unsigned char n, doub_carr_t **dc)
531 doub_carr_t *t;
532 int i, j;
533 t = MIDL_user_allocate(FIELD_OFFSET(doub_carr_t, a[n]));
534 t->n = n;
535 for (i = 0; i < n; ++i)
537 int v = i + 1;
538 t->a[i] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t, a[v]));
539 t->a[i]->n = v;
540 for (j = 0; j < v; ++j)
541 t->a[i]->a[j] = j + 1;
543 *dc = t;
546 unsigned __cdecl s_hash_bstr(bstr_t b)
548 short n = b[-1];
549 short *s = b;
550 unsigned hash = 0;
551 short i;
552 for (i = 0; i < n; ++i)
553 hash = 5 * hash + (unsigned) s[i];
554 return hash;
557 void __cdecl s_get_a_bstr(bstr_t *b)
559 bstr_t bstr;
560 short str[] = {5, 'W', 'i', 'n', 'e', 0};
561 bstr = HeapAlloc(GetProcessHeap(), 0, sizeof(str));
562 memcpy(bstr, str, sizeof(str));
563 *b = bstr + 1;
566 void __cdecl s_get_name(name_t *name)
568 const char bossman[] = "Jeremy White";
569 memcpy(name->name, bossman, min(name->size, sizeof(bossman)));
570 /* ensure nul-termination */
571 if (name->size < sizeof(bossman))
572 name->name[name->size - 1] = 0;
575 int __cdecl s_sum_pcarr2(int n, int **pa)
577 return s_sum_conf_array(*pa, n);
580 int __cdecl s_sum_L1_norms(int n, vector_t *vs)
582 int i;
583 int sum = 0;
584 for (i = 0; i < n; ++i)
585 sum += abs(vs[i].x) + abs(vs[i].y) + abs(vs[i].z);
586 return sum;
589 s123_t * __cdecl s_get_s123(void)
591 s123_t *s = MIDL_user_allocate(sizeof *s);
592 s->f1 = 1;
593 s->f2 = 2;
594 s->f3 = 3;
595 return s;
598 str_t __cdecl s_get_filename(void)
600 return (char *)__FILE__;
603 int __cdecl s_echo_ranged_int(int i, int j, int k)
605 return min( 100, i + j + k );
608 int __cdecl s_echo_ranged_int2(int i)
610 return i;
613 void __cdecl s_get_ranged_enum(renum_t *re)
615 *re = RE3;
618 void __cdecl s_context_handle_test(void)
620 NDR_SCONTEXT h;
621 RPC_BINDING_HANDLE binding;
622 RPC_STATUS status;
623 unsigned char buf[20];
624 static RPC_SERVER_INTERFACE server_if =
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,
637 binding = I_RpcGetCurrentCallHandle();
638 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
640 if (!pNDRSContextMarshall2 || !pNDRSContextUnmarshall2)
642 win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
643 return;
646 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
647 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
649 /* marshal a context handle with NULL userContext */
650 memset(buf, 0xcc, sizeof(buf));
651 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
652 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
653 ok(UuidIsNil((UUID *)&buf[4], &status), "uuid should have been nil\n");
655 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
656 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
658 /* marshal a context handle with non-NULL userContext */
659 memset(buf, 0xcc, sizeof(buf));
660 h->userContext = (void *)0xdeadbeef;
661 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
662 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
663 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
665 /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
666 if (0)
668 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
669 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
670 ok(h->userContext == (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
672 /* marshal a context handle with an interface specified */
673 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
674 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
676 memset(buf, 0xcc, sizeof(buf));
677 h->userContext = (void *)0xcafebabe;
678 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
679 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
680 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
682 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
683 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
684 ok(h->userContext == (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
687 /* test same interface data, but different pointer */
688 /* raises ERROR_INVALID_HANDLE exception */
689 if (0)
691 RPC_SERVER_INTERFACE server_if_clone = server_if;
693 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if_clone.InterfaceId, 0);
696 /* test different interface data, but different pointer */
697 /* raises ERROR_INVALID_HANDLE exception */
698 if (0)
700 static RPC_SERVER_INTERFACE server_if2 =
702 sizeof(RPC_SERVER_INTERFACE),
703 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
704 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
705 NULL,
712 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
714 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
718 void __cdecl s_get_numbers(int length, int size, pints_t n[])
720 int i;
721 for (i = 0; i < length; i++)
723 n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
724 *n[i].pi = i;
725 n[i].ppi = NULL;
726 n[i].pppi = NULL;
730 void __cdecl s_get_numbers_struct(numbers_struct_t **ns)
732 int i;
733 *ns = midl_user_allocate(FIELD_OFFSET(numbers_struct_t, numbers[5]));
734 if (!*ns) return;
735 (*ns)->length = 5;
736 (*ns)->size = 5;
737 for (i = 0; i < (*ns)->length; i++)
739 (*ns)->numbers[i].pi = NULL;
740 (*ns)->numbers[i].ppi = NULL;
741 (*ns)->numbers[i].pppi = NULL;
743 (*ns)->numbers[0].pi = midl_user_allocate(sizeof(*(*ns)->numbers[i].pi));
744 *(*ns)->numbers[0].pi = 5;
747 void __cdecl s_full_pointer_test(int *a, int *b)
749 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
750 ok(*b == 42, "Expected *b to be 42 instead of %d\n", *a);
751 ok(a == b, "Expected a (%p) to point to the same memory as b (%p)\n", a, b);
754 void __cdecl s_full_pointer_null_test(int *a, int *b)
756 ok(*a == 42, "Expected *a to be 42 instead of %d\n", *a);
757 ok(b == NULL, "Expected b to be NULL instead of %p\n", b);
760 void __cdecl s_stop(void)
762 ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
763 ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
764 ok(SetEvent(stop_event), "SetEvent\n");
767 static void
768 make_cmdline(char buffer[MAX_PATH], const char *test)
770 sprintf(buffer, "%s server %s", progname, test);
773 static void
774 run_client(const char *test)
776 char cmdline[MAX_PATH];
777 PROCESS_INFORMATION info;
778 STARTUPINFOA startup;
780 memset(&startup, 0, sizeof startup);
781 startup.cb = sizeof startup;
783 make_cmdline(cmdline, test);
784 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
785 winetest_wait_child_process( info.hProcess );
786 ok(CloseHandle(info.hProcess), "CloseHandle\n");
787 ok(CloseHandle(info.hThread), "CloseHandle\n");
790 static void
791 basic_tests(void)
793 char string[] = "I am a string";
794 WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
795 int f[5] = {1, 3, 0, -2, -4};
796 vector_t a = {1, 3, 7};
797 vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
798 pvectors_t pvecs = {&vec1, &pvec2};
799 sp_inner_t spi = {42};
800 sp_t sp = {-13, &spi};
801 aligns_t aligns;
802 pints_t pints;
803 ptypes_t ptypes;
804 padded_t padded;
805 padded_t padded2[2];
806 bogus_t bogus;
807 int i1, i2, i3, *pi2, *pi3, **ppi3;
808 double u, v;
809 float s, t;
810 LONG q, r;
811 short h;
812 char c;
813 int x;
814 hyper y;
815 str_struct_t ss = {string};
816 wstr_struct_t ws = {wstring};
817 str_t str;
818 se_t se;
819 renum_t re;
821 ok(int_return() == INT_CODE, "RPC int_return\n");
823 ok(square(7) == 49, "RPC square\n");
824 x = sum(23, -4);
825 ok(x == 19, "RPC sum got %d\n", x);
826 c = sum_char(-23, 50);
827 ok(c == 27, "RPC sum_char got %d\n", (int)c);
828 h = sum_short(1122, -344);
829 ok(h == 778, "RPC sum_short got %d\n", (int)h);
830 x = sum_float(123.45, -32.2);
831 ok(x == 91, "RPC sum_float got %d\n", x);
832 x = sum_double_int(-78, 148.46);
833 ok(x == 70, "RPC sum_double_int got %d\n", x);
834 y = sum_hyper((hyper)0x12345678 << 16, (hyper)0x33557799 << 16);
835 ok(y == (hyper)0x4589ce11 << 16, "RPC hyper got %x%08x\n", (DWORD)(y >> 32), (DWORD)y);
836 x = sum_hyper_int((hyper)0x24242424 << 16, -((hyper)0x24241212 << 16));
837 ok(x == 0x12120000, "RPC hyper_int got 0x%x\n", x);
838 x = sum_char_hyper( 12, ((hyper)0x42424242 << 32) | 0x33334444 );
839 ok(x == 0x33334450, "RPC char_hyper got 0x%x\n", x);
841 x = 0;
842 square_out(11, &x);
843 ok(x == 121, "RPC square_out\n");
845 x = 5;
846 square_ref(&x);
847 ok(x == 25, "RPC square_ref\n");
849 ok(str_length(string) == strlen(string), "RPC str_length\n");
850 ok(str_t_length(string) == strlen(string), "RPC str_length\n");
851 ok(dot_self(&a) == 59, "RPC dot_self\n");
853 ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n");
854 ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n");
856 v = 0.0;
857 u = square_half(3.0, &v);
858 ok(u == 9.0, "RPC square_half\n");
859 ok(v == 1.5, "RPC square_half\n");
861 t = 0.0f;
862 s = square_half_float(3.0f, &t);
863 ok(s == 9.0f, "RPC square_half_float\n");
864 ok(t == 1.5f, "RPC square_half_float\n");
866 r = 0;
867 q = square_half_long(3, &r);
868 ok(q == 9, "RPC square_half_long\n");
869 ok(r == 1, "RPC square_half_long\n");
871 i1 = 19;
872 i2 = -3;
873 i3 = -29;
874 pi2 = &i2;
875 pi3 = &i3;
876 ppi3 = &pi3;
877 pints.pi = &i1;
878 pints.ppi = &pi2;
879 pints.pppi = &ppi3;
880 ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
882 c = 10;
883 h = 3;
884 q = 14;
885 s = -5.0f;
886 u = 11.0;
887 ptypes.pc = &c;
888 ptypes.ps = &h;
889 ptypes.pl = &q;
890 ptypes.pf = &s;
891 ptypes.pd = &u;
892 ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
894 ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
895 ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
896 ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
897 ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
899 ok(enum_ord(E1) == 1, "RPC enum_ord\n");
900 ok(enum_ord(E2) == 2, "RPC enum_ord\n");
901 ok(enum_ord(E3) == 3, "RPC enum_ord\n");
902 ok(enum_ord(E4) == 4, "RPC enum_ord\n");
904 se.f = E2;
905 check_se2(&se);
907 memset(&aligns, 0, sizeof(aligns));
908 aligns.c = 3;
909 aligns.i = 4;
910 aligns.s = 5;
911 aligns.d = 6.0;
912 ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
914 padded.i = -3;
915 padded.c = 8;
916 ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
917 padded2[0].i = -5;
918 padded2[0].c = 1;
919 padded2[1].i = 3;
920 padded2[1].c = 7;
921 ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n");
922 padded2[0].i = -5;
923 padded2[0].c = 1;
924 padded2[1].i = 3;
925 padded2[1].c = 7;
926 ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n");
928 i1 = 14;
929 i2 = -7;
930 i3 = -4;
931 bogus.h.p1 = &i1;
932 bogus.p2 = &i2;
933 bogus.p3 = &i3;
934 bogus.c = 9;
935 ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n");
937 check_null(NULL);
939 str = get_filename();
940 ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__);
941 midl_user_free(str);
943 x = echo_ranged_int(0,0,0);
944 ok(x == 0, "echo_ranged_int() returned %d instead of 0\n", x);
945 x = echo_ranged_int(10,20,100);
946 ok(x == 100, "echo_ranged_int() returned %d instead of 100\n", x);
947 x = echo_ranged_int2(40);
948 ok(x == 40, "echo_ranged_int() returned %d instead of 40\n", x);
950 if (!old_windows_version)
952 get_ranged_enum(&re);
953 ok(re == RE3, "get_ranged_enum() returned %d instead of RE3\n", re);
957 static void
958 union_tests(void)
960 encue_t eue;
961 encu_t eu;
962 unencu_t uneu;
963 sun_t su;
964 int i;
966 su.s = SUN_I;
967 su.u.i = 9;
968 ok(square_sun(&su) == 81.0, "RPC square_sun\n");
970 su.s = SUN_F1;
971 su.u.f = 5.0;
972 ok(square_sun(&su) == 25.0, "RPC square_sun\n");
974 su.s = SUN_F2;
975 su.u.f = -2.0;
976 ok(square_sun(&su) == 4.0, "RPC square_sun\n");
978 su.s = SUN_PI;
979 su.u.pi = &i;
980 i = 11;
981 ok(square_sun(&su) == 121.0, "RPC square_sun\n");
983 eu.t = ENCU_I;
984 eu.tagged_union.i = 7;
985 ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
987 eu.t = ENCU_F;
988 eu.tagged_union.f = 3.0;
989 ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
991 uneu.i = 4;
992 ok(square_unencu(ENCU_I, &uneu) == 16.0, "RPC square_unencu\n");
994 uneu.f = 5.0;
995 ok(square_unencu(ENCU_F, &uneu) == 25.0, "RPC square_unencu\n");
997 eue.t = E1;
998 eue.tagged_union.i1 = 8;
999 ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
1001 eue.t = E2;
1002 eue.tagged_union.f2 = 10.0;
1003 ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
1006 static test_list_t *
1007 null_list(void)
1009 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
1010 n->t = TL_NULL;
1011 n->u.x = 0;
1012 return n;
1015 static test_list_t *
1016 make_list(test_list_t *tail)
1018 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
1019 n->t = TL_LIST;
1020 n->u.tail = tail;
1021 return n;
1024 static void
1025 free_list(test_list_t *list)
1027 if (list->t == TL_LIST)
1028 free_list(list->u.tail);
1029 HeapFree(GetProcessHeap(), 0, list);
1032 ULONG __RPC_USER
1033 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
1035 return start + sizeof(int);
1038 unsigned char * __RPC_USER
1039 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1041 int n = atoi(*p);
1042 memcpy(buffer, &n, sizeof n);
1043 return buffer + sizeof n;
1046 unsigned char * __RPC_USER
1047 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
1049 int n;
1050 memcpy(&n, buffer, sizeof n);
1051 *p = HeapAlloc(GetProcessHeap(), 0, 10);
1052 sprintf(*p, "%d", n);
1053 return buffer + sizeof n;
1056 void __RPC_USER
1057 puint_t_UserFree(ULONG *flags, puint_t *p)
1059 HeapFree(GetProcessHeap(), 0, *p);
1062 ULONG __RPC_USER
1063 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
1065 return start + sizeof(struct wire_us);
1068 unsigned char * __RPC_USER
1069 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1071 struct wire_us wus;
1072 wus.x = atoi(pus->x);
1073 memcpy(buffer, &wus, sizeof wus);
1074 return buffer + sizeof wus;
1077 unsigned char * __RPC_USER
1078 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
1080 struct wire_us wus;
1081 memcpy(&wus, buffer, sizeof wus);
1082 pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
1083 sprintf(pus->x, "%d", wus.x);
1084 return buffer + sizeof wus;
1087 void __RPC_USER
1088 us_t_UserFree(ULONG *flags, us_t *pus)
1090 HeapFree(GetProcessHeap(), 0, pus->x);
1093 ULONG __RPC_USER
1094 bstr_t_UserSize(ULONG *flags, ULONG start, bstr_t *b)
1096 return start + FIELD_OFFSET(user_bstr_t, data[(*b)[-1]]);
1099 unsigned char * __RPC_USER
1100 bstr_t_UserMarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1102 wire_bstr_t wb = (wire_bstr_t) buffer;
1103 wb->n = (*b)[-1];
1104 memcpy(&wb->data, *b, wb->n * sizeof wb->data[0]);
1105 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1108 unsigned char * __RPC_USER
1109 bstr_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
1111 wire_bstr_t wb = (wire_bstr_t) buffer;
1112 short *data = HeapAlloc(GetProcessHeap(), 0, (wb->n + 1) * sizeof *data);
1113 data[0] = wb->n;
1114 memcpy(&data[1], wb->data, wb->n * sizeof data[1]);
1115 *b = &data[1];
1116 return buffer + FIELD_OFFSET(user_bstr_t, data[wb->n]);
1119 void __RPC_USER
1120 bstr_t_UserFree(ULONG *flags, bstr_t *b)
1122 HeapFree(GetProcessHeap(), 0, &((*b)[-1]));
1125 static void
1126 pointer_tests(void)
1128 int a[] = {1, 2, 3, 4};
1129 char p1[] = "11";
1130 test_list_t *list = make_list(make_list(make_list(null_list())));
1131 test_us_t tus = {{p1}};
1132 int *pa[4];
1133 puints_t pus;
1134 cpuints_t cpus;
1135 short bstr_data[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1136 bstr_t bstr = &bstr_data[1], bstr2;
1137 name_t name;
1138 void *buffer;
1139 int *pa2;
1140 s123_t *s123;
1141 int val = 42;
1143 ok(test_list_length(list) == 3, "RPC test_list_length\n");
1144 ok(square_puint(p1) == 121, "RPC square_puint\n");
1145 pus.n = 4;
1146 pus.ps = HeapAlloc(GetProcessHeap(), 0, pus.n * sizeof pus.ps[0]);
1147 pus.ps[0] = xstrdup("5");
1148 pus.ps[1] = xstrdup("6");
1149 pus.ps[2] = xstrdup("7");
1150 pus.ps[3] = xstrdup("8");
1151 ok(sum_puints(&pus) == 26, "RPC sum_puints\n");
1152 HeapFree(GetProcessHeap(), 0, pus.ps[0]);
1153 HeapFree(GetProcessHeap(), 0, pus.ps[1]);
1154 HeapFree(GetProcessHeap(), 0, pus.ps[2]);
1155 HeapFree(GetProcessHeap(), 0, pus.ps[3]);
1156 HeapFree(GetProcessHeap(), 0, pus.ps);
1157 cpus.n = 4;
1158 cpus.ps = HeapAlloc(GetProcessHeap(), 0, cpus.n * sizeof cpus.ps[0]);
1159 cpus.ps[0] = xstrdup("5");
1160 cpus.ps[1] = xstrdup("6");
1161 cpus.ps[2] = xstrdup("7");
1162 cpus.ps[3] = xstrdup("8");
1163 ok(sum_cpuints(&cpus) == 26, "RPC sum_puints\n");
1164 HeapFree(GetProcessHeap(), 0, cpus.ps[0]);
1165 HeapFree(GetProcessHeap(), 0, cpus.ps[1]);
1166 HeapFree(GetProcessHeap(), 0, cpus.ps[2]);
1167 HeapFree(GetProcessHeap(), 0, cpus.ps[3]);
1168 HeapFree(GetProcessHeap(), 0, cpus.ps);
1169 ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
1171 pa[0] = &a[0];
1172 pa[1] = &a[1];
1173 pa[2] = &a[2];
1174 ok(sum_parr(pa) == 6, "RPC sum_parr\n");
1176 pa[0] = &a[0];
1177 pa[1] = &a[1];
1178 pa[2] = &a[2];
1179 pa[3] = &a[3];
1180 ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
1182 ok(hash_bstr(bstr) == s_hash_bstr(bstr), "RPC hash_bstr_data\n");
1184 get_a_bstr(&bstr);
1185 s_get_a_bstr(&bstr2);
1186 ok(!lstrcmpW((LPCWSTR)bstr, (LPCWSTR)bstr2), "bstr mismatch\n");
1187 HeapFree(GetProcessHeap(), 0, bstr - 1);
1188 HeapFree(GetProcessHeap(), 0, bstr2 - 1);
1190 free_list(list);
1192 if (!old_windows_version)
1194 name.size = 10;
1195 name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
1196 get_name(&name);
1197 ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
1198 ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
1199 HeapFree(GetProcessHeap(), 0, name.name);
1202 pa2 = a;
1203 ok(sum_pcarr2(4, &pa2) == 10, "RPC sum_pcarr2\n");
1205 s123 = get_s123();
1206 ok(s123->f1 == 1 && s123->f2 == 2 && s123->f3 == 3, "RPC get_s123\n");
1207 MIDL_user_free(s123);
1209 full_pointer_test(&val, &val);
1210 full_pointer_null_test(&val, NULL);
1213 static int
1214 check_pyramid_doub_carr(doub_carr_t *dc)
1216 int i, j;
1217 for (i = 0; i < dc->n; ++i)
1218 for (j = 0; j < dc->a[i]->n; ++j)
1219 if (dc->a[i]->a[j] != j + 1)
1220 return FALSE;
1221 return TRUE;
1224 static void
1225 free_pyramid_doub_carr(doub_carr_t *dc)
1227 int i;
1228 for (i = 0; i < dc->n; ++i)
1229 MIDL_user_free(dc->a[i]);
1230 MIDL_user_free(dc);
1233 static void
1234 array_tests(void)
1236 int m[2][3][4] =
1238 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1239 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1241 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1242 int c2[] = {10, 100, 200};
1243 int c3[20];
1244 vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
1245 cps_t cps;
1246 cpsc_t cpsc;
1247 cs_t *cs;
1248 int n;
1249 int ca[5] = {1, -2, 3, -4, 5};
1250 int tmp[10];
1251 doub_carr_t *dc;
1252 int *pi;
1253 pints_t api[5];
1254 numbers_struct_t *ns;
1255 refpint_t rpi[5];
1257 if (!old_windows_version)
1259 const char str1[25] = "Hello";
1260 ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
1263 ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
1265 ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
1266 ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1267 ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1268 ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1270 ok(sum_conf_ptr_by_conf_ptr(1, c2, c) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1271 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1272 c2[0] = 0;
1273 ok(sum_conf_ptr_by_conf_ptr(3, c2, c) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1275 ok(sum_unique_conf_array(ca, 4) == -2, "RPC sum_unique_conf_array\n");
1276 ok(sum_unique_conf_ptr(ca, 5) == 3, "RPC sum_unique_conf_array\n");
1277 ok(sum_unique_conf_ptr(NULL, 10) == 0, "RPC sum_unique_conf_array\n");
1279 get_number_array(c3, &n);
1280 ok(n == 10, "RPC get_num_array\n");
1281 for (; n > 0; n--)
1282 ok(c3[n-1] == c[n-1], "get_num_array returned wrong value %d @ %d\n",
1283 c3[n-1], n);
1284 ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
1285 ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1286 ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1287 ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1289 ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
1290 cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
1291 cs->n = 5;
1292 cs->ca[0] = 3;
1293 cs->ca[1] = 5;
1294 cs->ca[2] = -2;
1295 cs->ca[3] = -1;
1296 cs->ca[4] = -4;
1297 ok(sum_cs(cs) == 1, "RPC sum_cs\n");
1298 HeapFree(GetProcessHeap(), 0, cs);
1300 n = 5;
1301 cps.pn = &n;
1302 cps.ca1 = &c[2];
1303 cps.n = 3;
1304 cps.ca2 = &c[3];
1305 ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
1307 cpsc.a = 4;
1308 cpsc.b = 5;
1309 cpsc.c = 1;
1310 cpsc.ca = c;
1311 ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
1312 cpsc.a = 4;
1313 cpsc.b = 5;
1314 cpsc.c = 0;
1315 cpsc.ca = c;
1316 ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
1318 cpsc.ca = NULL;
1319 ok(get_cpsc(5, &cpsc) == 45, "RPC sum_cpsc\n");
1320 ok( cpsc.a == 10, "RPC get_cpsc %u\n", cpsc.a );
1321 for (n = 0; n < 10; n++) ok( cpsc.ca[n] == n, "RPC get_cpsc[%d] = %d\n", n, cpsc.ca[n] );
1323 memset( tmp, 0x33, sizeof(tmp) );
1324 cpsc.ca = tmp;
1325 ok(get_cpsc(4, &cpsc) == 28, "RPC sum_cpsc\n");
1326 ok( cpsc.a == 8, "RPC get_cpsc %u\n", cpsc.a );
1327 ok( cpsc.ca == tmp, "RPC get_cpsc %p/%p\n", cpsc.ca, tmp );
1328 for (n = 0; n < 8; n++) ok( cpsc.ca[n] == n, "RPC get_cpsc[%d] = %d\n", n, cpsc.ca[n] );
1330 ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
1331 ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1332 ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1334 dc = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_t, a[2]));
1335 dc->n = 2;
1336 dc->a[0] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[3]));
1337 dc->a[0]->n = 3;
1338 dc->a[0]->a[0] = 5;
1339 dc->a[0]->a[1] = 1;
1340 dc->a[0]->a[2] = 8;
1341 dc->a[1] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t, a[2]));
1342 dc->a[1]->n = 2;
1343 dc->a[1]->a[0] = 2;
1344 dc->a[1]->a[1] = 3;
1345 ok(sum_doub_carr(dc) == 19, "RPC sum_doub_carr\n");
1346 HeapFree(GetProcessHeap(), 0, dc->a[0]);
1347 HeapFree(GetProcessHeap(), 0, dc->a[1]);
1348 HeapFree(GetProcessHeap(), 0, dc);
1350 dc = NULL;
1351 make_pyramid_doub_carr(4, &dc);
1352 ok(check_pyramid_doub_carr(dc), "RPC make_pyramid_doub_carr\n");
1353 free_pyramid_doub_carr(dc);
1355 ok(sum_L1_norms(2, vs) == 21, "RPC sum_L1_norms\n");
1357 memset(api, 0, sizeof(api));
1358 pi = HeapAlloc(GetProcessHeap(), 0, sizeof(*pi));
1359 *pi = -1;
1360 api[0].pi = pi;
1361 get_numbers(1, 1, api);
1362 ok(api[0].pi == pi, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1363 ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *api[0].pi);
1365 if (!old_windows_version)
1367 ns = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(numbers_struct_t, numbers[5]));
1368 ns->length = 5;
1369 ns->size = 5;
1370 ns->numbers[0].pi = pi;
1371 get_numbers_struct(&ns);
1372 ok(ns->numbers[0].pi == pi, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi, ns->numbers[0].pi);
1373 ok(*ns->numbers[0].pi == 5, "pi unmarshalled incorrectly %d\n", *ns->numbers[0].pi);
1374 HeapFree(GetProcessHeap(), 0, ns);
1376 HeapFree(GetProcessHeap(), 0, pi);
1378 pi = HeapAlloc(GetProcessHeap(), 0, 5 * sizeof(*pi));
1379 pi[0] = 3; rpi[0] = &pi[0];
1380 pi[1] = 5; rpi[1] = &pi[1];
1381 pi[2] = -2; rpi[2] = &pi[2];
1382 pi[3] = -1; rpi[3] = &pi[3];
1383 pi[4] = -4; rpi[4] = &pi[4];
1384 ok(sum_complex_array(5, rpi) == 1, "RPC sum_complex_array\n");
1385 HeapFree(GetProcessHeap(), 0, pi);
1388 void __cdecl s_authinfo_test(unsigned int protseq, int secure)
1390 RPC_BINDING_HANDLE binding;
1391 RPC_STATUS status;
1392 ULONG level, authnsvc;
1393 RPC_AUTHZ_HANDLE privs;
1394 unsigned char *principal;
1396 binding = I_RpcGetCurrentCallHandle();
1397 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
1399 level = authnsvc = 0xdeadbeef;
1400 privs = (RPC_AUTHZ_HANDLE)0xdeadbeef;
1401 principal = (unsigned char *)0xdeadbeef;
1403 if (secure || protseq == RPC_PROTSEQ_LRPC)
1405 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1406 if (status == RPC_S_CANNOT_SUPPORT)
1408 win_skip("RpcBindingInqAuthClientA not supported\n");
1409 return;
1411 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1412 ok(privs != (RPC_AUTHZ_HANDLE)0xdeadbeef, "privs unchanged\n");
1413 ok(principal != (unsigned char *)0xdeadbeef, "principal unchanged\n");
1414 if (protseq != RPC_PROTSEQ_LRPC)
1416 todo_wine
1417 ok(principal != NULL, "NULL principal\n");
1419 if (protseq == RPC_PROTSEQ_LRPC && principal && pGetUserNameExA)
1421 int len;
1422 char *spn;
1424 len = WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, NULL, 0, NULL, NULL);
1425 spn = HeapAlloc( GetProcessHeap(), 0, len );
1426 WideCharToMultiByte(CP_ACP, 0, (const WCHAR *)privs, -1, spn, len, NULL, NULL);
1428 ok(!strcmp(domain_and_user, spn), "expected %s got %s\n", domain_and_user, spn);
1429 HeapFree( GetProcessHeap(), 0, spn );
1431 ok(level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY, "level unchanged\n");
1432 ok(authnsvc == RPC_C_AUTHN_WINNT, "authnsvc unchanged\n");
1434 status = RpcImpersonateClient(NULL);
1435 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1436 status = RpcRevertToSelf();
1437 ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
1440 else
1442 status = RpcBindingInqAuthClientA(binding, &privs, &principal, &level, &authnsvc, NULL);
1443 ok(status == RPC_S_BINDING_HAS_NO_AUTH, "expected RPC_S_BINDING_HAS_NO_AUTH got %u\n", status);
1444 ok(privs == (RPC_AUTHZ_HANDLE)0xdeadbeef, "got %p\n", privs);
1445 ok(principal == (unsigned char *)0xdeadbeef, "got %s\n", principal);
1446 ok(level == 0xdeadbeef, "got %u\n", level);
1447 ok(authnsvc == 0xdeadbeef, "got %u\n", authnsvc);
1451 static void
1452 run_tests(void)
1454 basic_tests();
1455 union_tests();
1456 pointer_tests();
1457 array_tests();
1458 context_handle_test();
1461 static void
1462 set_auth_info(RPC_BINDING_HANDLE handle)
1464 RPC_STATUS status;
1465 RPC_SECURITY_QOS qos;
1467 if (!pGetUserNameExA)
1468 return;
1470 qos.Version = 1;
1471 qos.Capabilities = RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
1472 qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
1473 qos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;
1475 status = pRpcBindingSetAuthInfoExA(handle, (RPC_CSTR)domain_and_user, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
1476 RPC_C_AUTHN_WINNT, NULL, 0, &qos);
1477 ok(status == RPC_S_OK, "RpcBindingSetAuthInfoExA failed %d\n", status);
1480 static void
1481 client(const char *test)
1483 static unsigned char iptcp[] = "ncacn_ip_tcp";
1484 static unsigned char np[] = "ncacn_np";
1485 static unsigned char ncalrpc[] = "ncalrpc";
1486 static unsigned char address[] = "127.0.0.1";
1487 static unsigned char address_np[] = "\\\\.";
1488 static unsigned char port[] = PORT;
1489 static unsigned char pipe[] = PIPE;
1490 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1492 unsigned char *binding;
1494 if (strcmp(test, "tcp_basic") == 0)
1496 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1497 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1499 run_tests();
1500 authinfo_test(RPC_PROTSEQ_TCP, 0);
1502 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1503 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1505 else if (strcmp(test, "tcp_secure") == 0)
1507 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1508 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1510 set_auth_info(IServer_IfHandle);
1511 authinfo_test(RPC_PROTSEQ_TCP, 1);
1513 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1514 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1516 else if (strcmp(test, "ncalrpc_basic") == 0)
1518 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1519 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1521 run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
1522 authinfo_test(RPC_PROTSEQ_LRPC, 0);
1524 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1525 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1527 else if (strcmp(test, "ncalrpc_secure") == 0)
1529 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
1530 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1532 set_auth_info(IServer_IfHandle);
1533 authinfo_test(RPC_PROTSEQ_LRPC, 1);
1535 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1536 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1538 else if (strcmp(test, "np_basic") == 0)
1540 ok(RPC_S_OK == RpcStringBindingComposeA(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n");
1541 ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1543 run_tests();
1544 authinfo_test(RPC_PROTSEQ_NMP, 0);
1545 stop();
1547 ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
1548 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1552 static void
1553 server(void)
1555 static unsigned char iptcp[] = "ncacn_ip_tcp";
1556 static unsigned char port[] = PORT;
1557 static unsigned char np[] = "ncacn_np";
1558 static unsigned char pipe[] = PIPE;
1559 static unsigned char ncalrpc[] = "ncalrpc";
1560 static unsigned char guid[] = "00000000-4114-0704-2301-000000000000";
1561 RPC_STATUS status, iptcp_status, np_status, ncalrpc_status;
1562 DWORD ret;
1564 iptcp_status = RpcServerUseProtseqEpA(iptcp, 20, port, NULL);
1565 ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status);
1567 ncalrpc_status = RpcServerUseProtseqEpA(ncalrpc, 0, guid, NULL);
1568 ok(ncalrpc_status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status);
1570 np_status = RpcServerUseProtseqEpA(np, 0, pipe, NULL);
1571 if (np_status == RPC_S_PROTSEQ_NOT_SUPPORTED)
1572 skip("Protocol sequence ncacn_np is not supported\n");
1573 else
1574 ok(np_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status);
1576 if (pRpcServerRegisterIfEx)
1578 trace("Using RpcServerRegisterIfEx\n");
1579 status = pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec, NULL, NULL,
1580 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
1581 RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
1583 else
1584 status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
1585 ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %d\n", status);
1586 status = RpcServerListen(1, 20, TRUE);
1587 ok(status == RPC_S_OK, "RpcServerListen failed with status %d\n", status);
1588 stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
1589 ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
1591 if (iptcp_status == RPC_S_OK)
1592 run_client("tcp_basic");
1593 else
1594 skip("tcp tests skipped due to earlier failure\n");
1596 if (ncalrpc_status == RPC_S_OK)
1598 run_client("ncalrpc_basic");
1599 if (pGetUserNameExA)
1601 /* we don't need to register RPC_C_AUTHN_WINNT for ncalrpc */
1602 run_client("ncalrpc_secure");
1605 else
1606 skip("lrpc tests skipped due to earlier failure\n");
1608 if (np_status == RPC_S_OK)
1609 run_client("np_basic");
1610 else
1612 skip("np_basic tests skipped due to earlier failure\n");
1613 /* np client is what signals stop_event, so bail out if we didn't run do it */
1614 return;
1617 ret = WaitForSingleObject(stop_event, 1000);
1618 ok(WAIT_OBJECT_0 == ret, "WaitForSingleObject\n");
1619 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1620 * forever, so don't bother calling it in this case */
1621 if (ret == WAIT_OBJECT_0)
1623 status = RpcMgmtWaitServerListen();
1624 todo_wine {
1625 ok(status == RPC_S_OK, "RpcMgmtWaitServerListening failed with status %d\n", status);
1630 START_TEST(server)
1632 int argc;
1633 char **argv;
1635 InitFunctionPointers();
1637 if (pGetUserNameExA)
1639 ULONG size = 0;
1640 ok(!pGetUserNameExA(NameSamCompatible, NULL, &size), "GetUserNameExA\n");
1641 domain_and_user = HeapAlloc(GetProcessHeap(), 0, size);
1642 ok(pGetUserNameExA(NameSamCompatible, domain_and_user, &size), "GetUserNameExA\n");
1644 else
1645 win_skip("GetUserNameExA is needed for some authentication tests\n");
1647 argc = winetest_get_mainargs(&argv);
1648 progname = argv[0];
1650 if (argc == 3)
1652 RpcTryExcept
1654 client(argv[2]);
1656 RpcExcept(TRUE)
1658 trace("Exception %d\n", RpcExceptionCode());
1660 RpcEndExcept
1662 else
1663 server();
1665 HeapFree(GetProcessHeap(), 0, domain_and_user);