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 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);
42 static void InitFunctionPointers(void)
44 HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
46 pNDRSContextMarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextMarshall2");
47 pNDRSContextUnmarshall2 = (void *)GetProcAddress(hrpcrt4, "NDRSContextUnmarshall2");
50 void __RPC_FAR *__RPC_USER
51 midl_user_allocate(size_t n)
57 midl_user_free(void __RPC_FAR *p)
63 xstrdup(const char *s)
65 char *d = HeapAlloc(GetProcessHeap(), 0, strlen(s) + 1);
89 s_square_out(int x, int *y)
101 s_str_length(const char *s)
107 s_str_t_length(str_t s)
113 s_cstr_length(const char *s, int n)
116 while (0 < n-- && *s++)
122 s_dot_self(vector_t *v)
124 return s_square(v->x) + s_square(v->y) + s_square(v->z);
128 s_square_half(double x, double *y)
135 s_square_half_float(float x, float *y)
142 s_square_half_long(long x, long *y)
149 s_sum_fixed_array(int a[5])
151 return a[0] + a[1] + a[2] + a[3] + a[4];
155 s_pints_sum(pints_t *pints)
157 return *pints->pi + **pints->ppi + ***pints->pppi;
161 s_ptypes_sum(ptypes_t *pt)
163 return *pt->pc + *pt->ps + *pt->pl + *pt->pf + *pt->pd;
167 s_dot_pvectors(pvectors_t *p)
169 return p->pu->x * (*p->pv)->x + p->pu->y * (*p->pv)->y + p->pu->z * (*p->pv)->z;
175 return sp->x + sp->s->x;
179 s_square_sun(sun_t *su)
183 case SUN_I: return su->u.i * su->u.i;
185 case SUN_F2: return su->u.f * su->u.f;
186 case SUN_PI: return (*su->u.pi) * (*su->u.pi);
193 s_test_list_length(test_list_t *list)
195 return (list->t == TL_LIST
196 ? 1 + s_test_list_length(list->u.tail)
201 s_sum_fixed_int_3d(int m[2][3][4])
206 for (i = 0; i < 2; ++i)
207 for (j = 0; j < 3; ++j)
208 for (k = 0; k < 4; ++k)
215 s_sum_conf_array(int x[], int n)
217 int *p = x, *end = p + n;
227 s_sum_unique_conf_array(int x[], int n)
229 return s_sum_conf_array(x, n);
233 s_sum_unique_conf_ptr(int *x, int n)
235 return x ? s_sum_conf_array(x, n) : 0;
239 s_sum_var_array(int x[20], int n)
241 ok(0 <= n, "RPC sum_var_array\n");
242 ok(n <= 20, "RPC sum_var_array\n");
244 return s_sum_conf_array(x, n);
248 s_dot_two_vectors(vector_t vs[2])
250 return vs[0].x * vs[1].x + vs[0].y * vs[1].y + vs[0].z * vs[1].z;
256 return s_sum_conf_array(cs->ca, cs->n);
260 s_sum_cps(cps_t *cps)
265 for (i = 0; i < *cps->pn; ++i)
268 for (i = 0; i < 2 * cps->n; ++i)
275 s_sum_cpsc(cpsc_t *cpsc)
279 for (i = 0; i < (cpsc->c ? cpsc->a : cpsc->b); ++i)
285 s_square_puint(puint_t p)
292 s_sum_puints(puints_t *p)
296 for (i = 0; i < p->n; ++i)
297 sum += atoi(p->ps[i]);
302 s_sum_cpuints(cpuints_t *p)
306 for (i = 0; i < p->n; ++i)
307 sum += atoi(p->ps[i]);
312 s_dot_copy_vectors(vector_t u, vector_t v)
314 return u.x * v.x + u.y * v.y + u.z * v.z;
318 s_square_test_us(test_us_t *tus)
320 int n = atoi(tus->us.x);
325 s_square_encu(encu_t *eu)
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;
339 ok(s->f == E2, "check_se2\n");
343 s_sum_parr(int *a[3])
345 return s_sum_pcarr(a, 3);
349 s_sum_pcarr(int *a[], int n)
352 for (i = 0; i < n; ++i)
372 s_square_encue(encue_t *eue)
376 case E1: return eue->tagged_union.i1 * eue->tagged_union.i1;
377 case E2: return eue->tagged_union.f2 * eue->tagged_union.f2;
384 s_sum_toplev_conf_2n(int *x, int n)
388 for (i = 0; i < 2 * n; ++i)
394 s_sum_toplev_conf_cond(int *x, int a, int b, int c)
399 for (i = 0; i < n; ++i)
405 s_sum_aligns(aligns_t *a)
407 return a->c + a->i + a->s + a->d;
411 s_sum_padded(padded_t *p)
417 s_sum_padded2(padded_t ps[2])
419 return s_sum_padded(&ps[0]) + s_sum_padded(&ps[1]);
423 s_sum_padded_conf(padded_t *ps, int n)
427 for (i = 0; i < n; ++i)
428 sum += s_sum_padded(&ps[i]);
433 s_sum_bogus(bogus_t *b)
435 return *b->h.p1 + *b->p2 + *b->p3 + b->c;
439 s_check_null(int *null)
441 ok(!null, "RPC check_null\n");
445 s_str_struct_len(str_struct_t *s)
447 return lstrlenA(s->s);
451 s_wstr_struct_len(wstr_struct_t *s)
453 return lstrlenW(s->s);
457 s_sum_doub_carr(doub_carr_t *dc)
461 for (i = 0; i < dc->n; ++i)
462 for (j = 0; j < dc->a[i]->n; ++j)
463 sum += dc->a[i]->a[j];
468 s_make_pyramid_doub_carr(unsigned char n, doub_carr_t **dc)
472 t = MIDL_user_allocate(FIELD_OFFSET(doub_carr_t, a[n]));
474 for (i = 0; i < n; ++i)
477 t->a[i] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t, a[v]));
479 for (j = 0; j < v; ++j)
480 t->a[i]->a[j] = j + 1;
486 s_hash_bstr(bstr_t b)
492 for (i = 0; i < n; ++i)
493 hash = 5 * hash + (unsigned) s[i];
498 s_get_name(name_t *name)
500 const char bossman[] = "Jeremy White";
501 memcpy(name->name, bossman, min(name->size, sizeof(bossman)));
502 /* ensure nul-termination */
503 if (name->size < sizeof(bossman))
504 name->name[name->size - 1] = 0;
508 s_sum_pcarr2(int n, int **pa)
510 return s_sum_conf_array(*pa, n);
514 s_sum_L1_norms(int n, vector_t *vs)
518 for (i = 0; i < n; ++i)
519 sum += abs(vs[i].x) + abs(vs[i].y) + abs(vs[i].z);
526 s123_t *s = MIDL_user_allocate(sizeof *s);
536 return (char *)__FILE__;
540 s_context_handle_test(void)
543 RPC_BINDING_HANDLE binding;
545 unsigned char buf[20];
546 static RPC_SERVER_INTERFACE server_if =
548 sizeof(RPC_SERVER_INTERFACE),
549 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
550 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
559 binding = I_RpcGetCurrentCallHandle();
560 ok(binding != NULL, "I_RpcGetCurrentCallHandle returned NULL\n");
562 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
563 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
565 /* marshal a context handle with NULL userContext */
566 memset(buf, 0xcc, sizeof(buf));
567 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
568 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
569 ok(UuidIsNil((UUID *)&buf[4], &status), "uuid should have been nil\n");
571 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
572 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
574 /* marshal a context handle with non-NULL userContext */
575 memset(buf, 0xcc, sizeof(buf));
576 h->userContext = (void *)0xdeadbeef;
577 pNDRSContextMarshall2(binding, h, buf, NULL, NULL, 0);
578 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
579 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
581 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, NULL, 0);
582 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
583 ok(h->userContext == (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
585 /* marshal a context handle with an interface specified */
586 h = pNDRSContextUnmarshall2(binding, NULL, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
587 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
589 memset(buf, 0xcc, sizeof(buf));
590 h->userContext = (void *)0xcafebabe;
591 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
592 ok(*(ULONG *)buf == 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG *)buf);
593 ok(!UuidIsNil((UUID *)&buf[4], &status), "uuid should not have been nil\n");
595 h = pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if.InterfaceId, 0);
596 ok(h != NULL, "NDRSContextUnmarshall2 returned NULL\n");
597 ok(h->userContext == (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h->userContext);
599 /* test same interface data, but different pointer */
600 /* raises ERROR_INVALID_HANDLE exception */
603 RPC_SERVER_INTERFACE server_if_clone = server_if;
605 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if_clone.InterfaceId, 0);
608 /* test different interface data, but different pointer */
609 /* raises ERROR_INVALID_HANDLE exception */
612 static RPC_SERVER_INTERFACE server_if2 =
614 sizeof(RPC_SERVER_INTERFACE),
615 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
616 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
624 pNDRSContextMarshall2(binding, h, buf, NULL, &server_if.InterfaceId, 0);
626 pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
631 s_get_5numbers(int count, pints_t n[5])
634 for (i = 0; i < count; i++)
636 n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
644 s_get_numbers(int length, int size, pints_t n[])
647 for (i = 0; i < length; i++)
649 n[i].pi = midl_user_allocate(sizeof(*n[i].pi));
659 ok(RPC_S_OK == RpcMgmtStopServerListening(NULL), "RpcMgmtStopServerListening\n");
660 ok(RPC_S_OK == RpcServerUnregisterIf(NULL, NULL, FALSE), "RpcServerUnregisterIf\n");
661 ok(SetEvent(stop_event), "SetEvent\n");
665 make_cmdline(char buffer[MAX_PATH], const char *test)
667 sprintf(buffer, "%s server %s", progname, test);
671 run_client(const char *test)
673 char cmdline[MAX_PATH];
674 PROCESS_INFORMATION info;
675 STARTUPINFOA startup;
677 memset(&startup, 0, sizeof startup);
678 startup.cb = sizeof startup;
680 make_cmdline(cmdline, test);
681 ok(CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0L, NULL, NULL, &startup, &info), "CreateProcess\n");
682 winetest_wait_child_process( info.hProcess );
683 ok(CloseHandle(info.hProcess), "CloseHandle\n");
684 ok(CloseHandle(info.hThread), "CloseHandle\n");
690 char string[] = "I am a string";
691 WCHAR wstring[] = {'I',' ','a','m',' ','a',' ','w','s','t','r','i','n','g', 0};
692 int f[5] = {1, 3, 0, -2, -4};
693 vector_t a = {1, 3, 7};
694 vector_t vec1 = {4, -2, 1}, vec2 = {-5, 2, 3}, *pvec2 = &vec2;
695 pvectors_t pvecs = {&vec1, &pvec2};
696 sp_inner_t spi = {42};
697 sp_t sp = {-13, &spi};
704 int i1, i2, i3, *pi2, *pi3, **ppi3;
711 str_struct_t ss = {string};
712 wstr_struct_t ws = {wstring};
716 ok(int_return() == INT_CODE, "RPC int_return\n");
718 ok(square(7) == 49, "RPC square\n");
719 ok(sum(23, -4) == 19, "RPC sum\n");
723 ok(x == 121, "RPC square_out\n");
727 ok(x == 25, "RPC square_ref\n");
729 ok(str_length(string) == strlen(string), "RPC str_length\n");
730 ok(str_t_length(string) == strlen(string), "RPC str_length\n");
731 ok(dot_self(&a) == 59, "RPC dot_self\n");
733 ok(str_struct_len(&ss) == lstrlenA(string), "RPC str_struct_len\n");
734 ok(wstr_struct_len(&ws) == lstrlenW(wstring), "RPC str_struct_len\n");
737 u = square_half(3.0, &v);
738 ok(u == 9.0, "RPC square_half\n");
739 ok(v == 1.5, "RPC square_half\n");
742 s = square_half_float(3.0f, &t);
743 ok(s == 9.0f, "RPC square_half_float\n");
744 ok(t == 1.5f, "RPC square_half_float\n");
747 q = square_half_long(3, &r);
748 ok(q == 9, "RPC square_half_long\n");
749 ok(r == 1, "RPC square_half_long\n");
760 ok(pints_sum(&pints) == -13, "RPC pints_sum\n");
772 ok(ptypes_sum(&ptypes) == 33.0, "RPC ptypes_sum\n");
774 ok(dot_pvectors(&pvecs) == -21, "RPC dot_pvectors\n");
775 ok(dot_copy_vectors(vec1, vec2) == -21, "RPC dot_copy_vectors\n");
776 ok(sum_fixed_array(f) == -2, "RPC sum_fixed_array\n");
777 ok(sum_sp(&sp) == 29, "RPC sum_sp\n");
779 ok(enum_ord(E1) == 1, "RPC enum_ord\n");
780 ok(enum_ord(E2) == 2, "RPC enum_ord\n");
781 ok(enum_ord(E3) == 3, "RPC enum_ord\n");
782 ok(enum_ord(E4) == 4, "RPC enum_ord\n");
787 memset(&aligns, 0, sizeof(aligns));
792 ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
796 ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
801 ok(sum_padded2(padded2) == 6, "RPC sum_padded2\n");
806 ok(sum_padded_conf(padded2, 2) == 6, "RPC sum_padded_conf\n");
815 ok(sum_bogus(&bogus) == 12, "RPC sum_bogus\n");
819 str = get_filename();
820 ok(!strcmp(str, __FILE__), "get_filename() returned %s instead of %s\n", str, __FILE__);
834 ok(square_sun(&su) == 81.0, "RPC square_sun\n");
838 ok(square_sun(&su) == 25.0, "RPC square_sun\n");
842 ok(square_sun(&su) == 4.0, "RPC square_sun\n");
847 ok(square_sun(&su) == 121.0, "RPC square_sun\n");
850 eu.tagged_union.i = 7;
851 ok(square_encu(&eu) == 49.0, "RPC square_encu\n");
854 eu.tagged_union.f = 3.0;
855 ok(square_encu(&eu) == 9.0, "RPC square_encu\n");
858 eue.tagged_union.i1 = 8;
859 ok(square_encue(&eue) == 64.0, "RPC square_encue\n");
862 eue.tagged_union.f2 = 10.0;
863 ok(square_encue(&eue) == 100.0, "RPC square_encue\n");
869 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
876 make_list(test_list_t *tail)
878 test_list_t *n = HeapAlloc(GetProcessHeap(), 0, sizeof *n);
885 free_list(test_list_t *list)
887 if (list->t == TL_LIST)
888 free_list(list->u.tail);
889 HeapFree(GetProcessHeap(), 0, list);
893 puint_t_UserSize(ULONG *flags, ULONG start, puint_t *p)
895 return start + sizeof(int);
898 unsigned char * __RPC_USER
899 puint_t_UserMarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
902 memcpy(buffer, &n, sizeof n);
903 return buffer + sizeof n;
906 unsigned char * __RPC_USER
907 puint_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, puint_t *p)
910 memcpy(&n, buffer, sizeof n);
911 *p = HeapAlloc(GetProcessHeap(), 0, 10);
912 sprintf(*p, "%d", n);
913 return buffer + sizeof n;
917 puint_t_UserFree(ULONG *flags, puint_t *p)
919 HeapFree(GetProcessHeap(), 0, *p);
923 us_t_UserSize(ULONG *flags, ULONG start, us_t *pus)
925 return start + sizeof(struct wire_us);
928 unsigned char * __RPC_USER
929 us_t_UserMarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
932 wus.x = atoi(pus->x);
933 memcpy(buffer, &wus, sizeof wus);
934 return buffer + sizeof wus;
937 unsigned char * __RPC_USER
938 us_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, us_t *pus)
941 memcpy(&wus, buffer, sizeof wus);
942 pus->x = HeapAlloc(GetProcessHeap(), 0, 10);
943 sprintf(pus->x, "%d", wus.x);
944 return buffer + sizeof wus;
948 us_t_UserFree(ULONG *flags, us_t *pus)
950 HeapFree(GetProcessHeap(), 0, pus->x);
954 bstr_t_UserSize(ULONG *flags, ULONG start, bstr_t *b)
956 return start + FIELD_OFFSET(wire_bstr_t, data[(*b)[-1]]);
959 unsigned char * __RPC_USER
960 bstr_t_UserMarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
962 wire_bstr_t *wb = (wire_bstr_t *) buffer;
964 memcpy(&wb->data, *b, wb->n * sizeof wb->data[0]);
965 return buffer + FIELD_OFFSET(wire_bstr_t, data[wb->n]);
968 unsigned char * __RPC_USER
969 bstr_t_UserUnmarshal(ULONG *flags, unsigned char *buffer, bstr_t *b)
971 wire_bstr_t *wb = (wire_bstr_t *) buffer;
972 short *data = HeapAlloc(GetProcessHeap(), 0, (wb->n + 1) * sizeof *data);
974 memcpy(&data[1], wb->data, wb->n * sizeof data[1]);
976 return buffer + FIELD_OFFSET(wire_bstr_t, data[wb->n]);
980 bstr_t_UserFree(ULONG *flags, bstr_t *b)
982 HeapFree(GetProcessHeap(), 0, &((*b)[-1]));
988 int a[] = {1, 2, 3, 4};
990 test_list_t *list = make_list(make_list(make_list(null_list())));
991 test_us_t tus = {{p1}};
995 short bstr_data[] = { 5, 'H', 'e', 'l', 'l', 'o' };
996 bstr_t bstr = &bstr_data[1];
1002 ok(test_list_length(list) == 3, "RPC test_list_length\n");
1003 ok(square_puint(p1) == 121, "RPC square_puint\n");
1005 pus.ps = HeapAlloc(GetProcessHeap(), 0, pus.n * sizeof pus.ps[0]);
1006 pus.ps[0] = xstrdup("5");
1007 pus.ps[1] = xstrdup("6");
1008 pus.ps[2] = xstrdup("7");
1009 pus.ps[3] = xstrdup("8");
1010 ok(sum_puints(&pus) == 26, "RPC sum_puints\n");
1011 HeapFree(GetProcessHeap(), 0, pus.ps[0]);
1012 HeapFree(GetProcessHeap(), 0, pus.ps[1]);
1013 HeapFree(GetProcessHeap(), 0, pus.ps[2]);
1014 HeapFree(GetProcessHeap(), 0, pus.ps[3]);
1015 HeapFree(GetProcessHeap(), 0, pus.ps);
1017 cpus.ps = HeapAlloc(GetProcessHeap(), 0, cpus.n * sizeof cpus.ps[0]);
1018 cpus.ps[0] = xstrdup("5");
1019 cpus.ps[1] = xstrdup("6");
1020 cpus.ps[2] = xstrdup("7");
1021 cpus.ps[3] = xstrdup("8");
1022 ok(sum_cpuints(&cpus) == 26, "RPC sum_puints\n");
1023 HeapFree(GetProcessHeap(), 0, cpus.ps[0]);
1024 HeapFree(GetProcessHeap(), 0, cpus.ps[1]);
1025 HeapFree(GetProcessHeap(), 0, cpus.ps[2]);
1026 HeapFree(GetProcessHeap(), 0, cpus.ps[3]);
1027 HeapFree(GetProcessHeap(), 0, cpus.ps);
1028 ok(square_test_us(&tus) == 121, "RPC square_test_us\n");
1033 ok(sum_parr(pa) == 6, "RPC sum_parr\n");
1039 ok(sum_pcarr(pa, 4) == 10, "RPC sum_pcarr\n");
1041 ok(hash_bstr(bstr) == s_hash_bstr(bstr), "RPC hash_bstr_data\n");
1046 name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
1048 ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
1049 ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
1050 HeapFree(GetProcessHeap(), 0, name.name);
1053 ok(sum_pcarr2(4, &pa2) == 10, "RPC sum_pcarr2\n");
1056 ok(s123->f1 == 1 && s123->f2 == 2 && s123->f3 == 3, "RPC get_s123\n");
1057 MIDL_user_free(s123);
1061 check_pyramid_doub_carr(doub_carr_t *dc)
1064 for (i = 0; i < dc->n; ++i)
1065 for (j = 0; j < dc->a[i]->n; ++j)
1066 if (dc->a[i]->a[j] != j + 1)
1072 free_pyramid_doub_carr(doub_carr_t *dc)
1075 for (i = 0; i < dc->n; ++i)
1076 MIDL_user_free(dc->a[i]);
1083 const char str1[25] = "Hello";
1086 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1087 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1089 int c[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1090 vector_t vs[2] = {{1, -2, 3}, {4, -5, -6}};
1095 int ca[5] = {1, -2, 3, -4, 5};
1100 ok(cstr_length(str1, sizeof str1) == strlen(str1), "RPC cstr_length\n");
1102 ok(sum_fixed_int_3d(m) == 4116, "RPC sum_fixed_int_3d\n");
1104 ok(sum_conf_array(c, 10) == 45, "RPC sum_conf_array\n");
1105 ok(sum_conf_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1106 ok(sum_conf_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1107 ok(sum_conf_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1109 ok(sum_unique_conf_array(ca, 4) == -2, "RPC sum_unique_conf_array\n");
1110 ok(sum_unique_conf_ptr(ca, 5) == 3, "RPC sum_unique_conf_array\n");
1111 ok(sum_unique_conf_ptr(NULL, 10) == 0, "RPC sum_unique_conf_array\n");
1113 ok(sum_var_array(c, 10) == 45, "RPC sum_conf_array\n");
1114 ok(sum_var_array(&c[5], 2) == 11, "RPC sum_conf_array\n");
1115 ok(sum_var_array(&c[7], 1) == 7, "RPC sum_conf_array\n");
1116 ok(sum_var_array(&c[2], 0) == 0, "RPC sum_conf_array\n");
1118 ok(dot_two_vectors(vs) == -4, "RPC dot_two_vectors\n");
1119 cs = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t, ca[5]));
1126 ok(sum_cs(cs) == 1, "RPC sum_cs\n");
1127 HeapFree(GetProcessHeap(), 0, cs);
1134 ok(sum_cps(&cps) == 53, "RPC sum_cps\n");
1140 ok(sum_cpsc(&cpsc) == 6, "RPC sum_cpsc\n");
1145 ok(sum_cpsc(&cpsc) == 10, "RPC sum_cpsc\n");
1147 ok(sum_toplev_conf_2n(c, 3) == 15, "RPC sum_toplev_conf_2n\n");
1148 ok(sum_toplev_conf_cond(c, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1149 ok(sum_toplev_conf_cond(c, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1151 dc = malloc(FIELD_OFFSET(doub_carr_t, a[2]));
1153 dc->a[0] = malloc(FIELD_OFFSET(doub_carr_1_t, a[3]));
1158 dc->a[1] = malloc(FIELD_OFFSET(doub_carr_1_t, a[2]));
1162 ok(sum_doub_carr(dc) == 19, "RPC sum_doub_carr\n");
1168 make_pyramid_doub_carr(4, &dc);
1169 ok(check_pyramid_doub_carr(dc), "RPC make_pyramid_doub_carr\n");
1170 free_pyramid_doub_carr(dc);
1172 ok(sum_L1_norms(2, vs) == 21, "RPC sum_L1_norms\n");
1174 memset(api, 0, sizeof(api));
1175 pi = HeapAlloc(GetProcessHeap(), 0, sizeof(*pi));
1178 get_5numbers(1, api);
1179 ok(api[0].pi == pi, "RPC varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1180 ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *pi);
1183 get_numbers(1, 1, api);
1184 ok(api[0].pi == pi, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi, api[0].pi);
1185 ok(*api[0].pi == 0, "pi unmarshalled incorrectly %d\n", *pi);
1186 HeapFree(GetProcessHeap(), 0, pi);
1196 context_handle_test();
1200 client(const char *test)
1202 if (strcmp(test, "tcp_basic") == 0)
1204 static unsigned char iptcp[] = "ncacn_ip_tcp";
1205 static unsigned char address[] = "127.0.0.1";
1206 static unsigned char port[] = PORT;
1207 unsigned char *binding;
1209 ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
1210 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1214 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1215 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1217 else if (strcmp(test, "np_basic") == 0)
1219 static unsigned char np[] = "ncacn_np";
1220 static unsigned char address[] = "\\\\.";
1221 static unsigned char pipe[] = PIPE;
1222 unsigned char *binding;
1224 ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address, pipe, NULL, &binding), "RpcStringBindingCompose\n");
1225 ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
1230 ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
1231 ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
1238 static unsigned char iptcp[] = "ncacn_ip_tcp";
1239 static unsigned char port[] = PORT;
1240 static unsigned char np[] = "ncacn_np";
1241 static unsigned char pipe[] = PIPE;
1242 RPC_STATUS status, iptcp_status, np_status;
1243 RPC_STATUS (RPC_ENTRY *pRpcServerRegisterIfEx)(RPC_IF_HANDLE,UUID*,
1244 RPC_MGR_EPV*, unsigned int,unsigned int,RPC_IF_CALLBACK_FN*);
1247 iptcp_status = RpcServerUseProtseqEp(iptcp, 20, port, NULL);
1248 ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %ld\n", iptcp_status);
1249 np_status = RpcServerUseProtseqEp(np, 0, pipe, NULL);
1250 ok(np_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_np) failed with status %ld\n", np_status);
1252 pRpcServerRegisterIfEx = (void *)GetProcAddress(GetModuleHandle("rpcrt4.dll"), "RpcServerRegisterIfEx");
1253 if (pRpcServerRegisterIfEx)
1255 trace("Using RpcServerRegisterIfEx\n");
1256 status = pRpcServerRegisterIfEx(s_IServer_v0_0_s_ifspec, NULL, NULL,
1257 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH,
1258 RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
1261 status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
1262 ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %ld\n", status);
1263 status = RpcServerListen(1, 20, TRUE);
1264 ok(status == RPC_S_OK, "RpcServerListen failed with status %ld\n", status);
1265 stop_event = CreateEvent(NULL, FALSE, FALSE, NULL);
1266 ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
1268 if (iptcp_status == RPC_S_OK)
1269 run_client("tcp_basic");
1271 skip("tcp_basic tests skipped due to earlier failure\n");
1273 if (np_status == RPC_S_OK)
1274 run_client("np_basic");
1277 skip("np_basic tests skipped due to earlier failure\n");
1278 /* np client is what signals stop_event, so bail out if we didn't run do it */
1282 ret = WaitForSingleObject(stop_event, 1000);
1283 ok(WAIT_OBJECT_0 == ret, "WaitForSingleObject\n");
1284 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
1285 * forever, so don't bother calling it in this case */
1286 if (ret == WAIT_OBJECT_0)
1288 status = RpcMgmtWaitServerListen();
1290 ok(status == RPC_S_OK, "RpcMgmtWaitServerListening failed with status %ld\n", status);
1300 InitFunctionPointers();
1302 argc = winetest_get_mainargs(&argv);
1313 trace("Exception %d\n", RpcExceptionCode());