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
28 #include "wine/test.h"
30 #define SKIP_TYPE_DECLS
31 #include "server_interp.h"
32 #include "server_defines.h"
39 #define PIPE "\\pipe\\wine_rpcrt4_test"
43 static const char *progname
;
44 static BOOL old_windows_version
;
46 static HANDLE stop_event
, stop_wait_event
;
48 static void (WINAPI
*pNDRSContextMarshall2
)(RPC_BINDING_HANDLE
, NDR_SCONTEXT
, void*, NDR_RUNDOWN
, void*, ULONG
);
49 static NDR_SCONTEXT (WINAPI
*pNDRSContextUnmarshall2
)(RPC_BINDING_HANDLE
, void*, ULONG
, void*, ULONG
);
50 static RPC_STATUS (WINAPI
*pRpcServerRegisterIfEx
)(RPC_IF_HANDLE
,UUID
*, RPC_MGR_EPV
*, unsigned int,
51 unsigned int,RPC_IF_CALLBACK_FN
*);
52 static RPC_STATUS (WINAPI
*pRpcBindingSetAuthInfoExA
)(RPC_BINDING_HANDLE
, RPC_CSTR
, ULONG
, ULONG
,
53 RPC_AUTH_IDENTITY_HANDLE
, ULONG
, RPC_SECURITY_QOS
*);
54 static RPC_STATUS (WINAPI
*pRpcServerRegisterAuthInfoA
)(RPC_CSTR
, ULONG
, RPC_AUTH_KEY_RETRIEVAL_FN
, LPVOID
);
56 static char *domain_and_user
;
58 static int (__cdecl
*int_return
)(void);
59 static int (__cdecl
*square
)(int x
);
60 static int (__cdecl
*sum
)(int x
, int y
);
61 static signed char (__cdecl
*sum_char
)(signed char x
, signed char y
);
62 static short (__cdecl
*sum_short
)(short x
, short y
);
63 static int (__cdecl
*sum_float
)(float x
, float y
);
64 static int (__cdecl
*sum_double_int
)(int x
, double y
);
65 static hyper (__cdecl
*sum_hyper
)(hyper x
, hyper y
);
66 static int (__cdecl
*sum_hyper_int
)(hyper x
, hyper y
);
67 static int (__cdecl
*sum_char_hyper
)(signed char x
, hyper y
);
68 static void (__cdecl
*square_out
)(int x
, int *y
);
69 static void (__cdecl
*square_ref
)(int *x
);
70 static int (__cdecl
*str_length
)(const char *s
);
71 static int (__cdecl
*str_t_length
)(str_t s
);
72 static int (__cdecl
*cstr_length
)(const char *s
, int n
);
73 static int (__cdecl
*dot_self
)(vector_t
*v
);
74 static double (__cdecl
*square_half
)(double x
, double *y
);
75 static float (__cdecl
*square_half_float
)(float x
, float *y
);
76 static LONG (__cdecl
*square_half_long
)(LONG x
, LONG
*y
);
77 static int (__cdecl
*sum_fixed_array
)(int a
[5]);
78 static int (__cdecl
*pints_sum
)(pints_t
*pints
);
79 static double (__cdecl
*ptypes_sum
)(ptypes_t
*ptypes
);
80 static int (__cdecl
*dot_pvectors
)(pvectors_t
*pvectors
);
81 static int (__cdecl
*sum_sp
)(sp_t
*sp
);
82 static double (__cdecl
*square_sun
)(sun_t
*su
);
83 static int (__cdecl
*test_list_length
)(test_list_t
*ls
);
84 static int (__cdecl
*sum_fixed_int_3d
)(int m
[2][3][4]);
85 static int (__cdecl
*sum_conf_array
)(int x
[], int n
);
86 static int (__cdecl
*sum_conf_ptr_by_conf_ptr
)(int n1
, int *n2_then_x1
, int *x2
);
87 static int (__cdecl
*sum_unique_conf_array
)(int x
[], int n
);
88 static int (__cdecl
*sum_unique_conf_ptr
)(int *x
, int n
);
89 static int (__cdecl
*sum_var_array
)(int x
[20], int n
);
90 static int (__cdecl
*dot_two_vectors
)(vector_t vs
[2]);
91 static void (__cdecl
*get_number_array
)(int x
[20], int *n
);
92 static int (__cdecl
*sum_cs
)(cs_t
*cs
);
93 static int (__cdecl
*sum_cps
)(cps_t
*cps
);
94 static int (__cdecl
*sum_cpsc
)(cpsc_t
*cpsc
);
95 static int (__cdecl
*get_cpsc
)(int n
, cpsc_t
*cpsc
);
96 static int (__cdecl
*sum_complex_array
)(int n
, refpint_t pi
[]);
97 static int (__cdecl
*sum_blob
)(cs_blob_t
*blob
);
98 static int (__cdecl
*sum_data
)(cs_data_t
*data
);
99 static int (__cdecl
*sum_container
)(cs_container_t
*container
);
100 static int (__cdecl
*square_puint
)(puint_t p
);
101 static int (__cdecl
*sum_puints
)(puints_t
*p
);
102 static int (__cdecl
*sum_cpuints
)(cpuints_t
*p
);
103 static int (__cdecl
*dot_copy_vectors
)(vector_t u
, vector_t v
);
104 static double (__cdecl
*square_encu
)(encu_t
*eu
);
105 static double (__cdecl
*square_unencu
)(int t
, unencu_t
*eu
);
106 static int (__cdecl
*sum_parr
)(int *a
[3]);
107 static int (__cdecl
*sum_pcarr
)(int *a
[], int n
);
108 static int (__cdecl
*enum_ord
)(e_t e
);
109 static double (__cdecl
*square_encue
)(encue_t
*eue
);
110 static void (__cdecl
*check_se2
)(se_t
*s
);
111 static int (__cdecl
*sum_toplev_conf_2n
)(int *x
, int n
);
112 static int (__cdecl
*sum_toplev_conf_cond
)(int *x
, int a
, int b
, int c
);
113 static int (__cdecl
*square_test_us
)(test_us_t
*tus
);
114 static double (__cdecl
*sum_aligns
)(aligns_t
*a
);
115 static int (__cdecl
*sum_padded
)(padded_t
*p
);
116 static int (__cdecl
*sum_padded2
)(padded_t ps
[2]);
117 static int (__cdecl
*sum_padded_conf
)(padded_t
*ps
, int n
);
118 static int (__cdecl
*sum_bogus
)(bogus_t
*b
);
119 static void (__cdecl
*check_null
)(int *null
);
120 static int (__cdecl
*str_struct_len
)(str_struct_t
*s
);
121 static int (__cdecl
*wstr_struct_len
)(wstr_struct_t
*s
);
122 static int (__cdecl
*sum_doub_carr
)(doub_carr_t
*dc
);
123 static void (__cdecl
*make_pyramid_doub_carr
)(unsigned char n
, doub_carr_t
**dc
);
124 static unsigned (__cdecl
*hash_bstr
)(bstr_t s
);
125 static void (__cdecl
*get_a_bstr
)(bstr_t
*s
);
126 static void (__cdecl
*get_name
)(name_t
*name
);
127 static void (__cdecl
*get_names
)(int *n
, str_array_t
*names
);
128 static void (__cdecl
*get_namesw
)(int *n
, wstr_array_t
*names
);
129 static int (__cdecl
*sum_pcarr2
)(int n
, int **pa
);
130 static int (__cdecl
*sum_L1_norms
)(int n
, vector_t
*vs
);
131 static s123_t
* (__cdecl
*get_s123
)(void);
132 static void (__cdecl
*get_numbers
)(int length
, int size
, pints_t pn
[]);
133 static void (__cdecl
*get_numbers_struct
)(numbers_struct_t
**ns
);
134 static str_t (__cdecl
*get_filename
)(void);
135 static rint_t (__cdecl
*echo_ranged_int
)(int i
, int j
, int k
);
136 static rint_t (__cdecl
*echo_ranged_int2
)(int i
);
137 static void (__cdecl
*get_ranged_enum
)(renum_t
*re
);
138 static void (__cdecl
*context_handle_test
)(void);
139 static void (__cdecl
*full_pointer_test
)(int *a
, int *b
);
140 static void (__cdecl
*full_pointer_null_test
)(int *a
, int *b
);
141 static void (__cdecl
*authinfo_test
)(unsigned int protseq
, int secure
);
142 static void (__cdecl
*stop
)(void);
143 static void (__cdecl
*stop_autolisten
)(void);
144 static void (__cdecl
*ip_test
)(ipu_t
*a
);
145 static int (__cdecl
*sum_ptr_array
)(int *a
[2]);
146 static int (__cdecl
*sum_array_ptr
)(int (*a
)[2]);
147 static ctx_handle_t (__cdecl
*get_handle
)(void);
148 static void (__cdecl
*get_handle_by_ptr
)(ctx_handle_t
*r
);
149 static void (__cdecl
*test_handle
)(ctx_handle_t ctx_handle
);
151 #define SERVER_FUNCTIONS \
169 X(square_half_float) \
170 X(square_half_long) \
177 X(test_list_length) \
178 X(sum_fixed_int_3d) \
180 X(sum_conf_ptr_by_conf_ptr) \
181 X(sum_unique_conf_array) \
182 X(sum_unique_conf_ptr) \
185 X(get_number_array) \
190 X(sum_complex_array) \
197 X(dot_copy_vectors) \
205 X(sum_toplev_conf_2n) \
206 X(sum_toplev_conf_cond) \
217 X(make_pyramid_doub_carr) \
227 X(get_numbers_struct) \
230 X(echo_ranged_int2) \
232 X(context_handle_test) \
233 X(full_pointer_test) \
234 X(full_pointer_null_test) \
242 X(get_handle_by_ptr) \
245 /* type check statements generated in header file */
246 fnprintf
*p_printf
= printf
;
248 static BOOL is_interp
;
250 static void set_interp_interface(void)
254 #define X(name) name = interp_##name;
259 static void set_mixed_interface(void)
263 #define X(name) name = mixed_##name;
268 static void InitFunctionPointers(void)
270 HMODULE hrpcrt4
= GetModuleHandleA("rpcrt4.dll");
272 pNDRSContextMarshall2
= (void *)GetProcAddress(hrpcrt4
, "NDRSContextMarshall2");
273 pNDRSContextUnmarshall2
= (void *)GetProcAddress(hrpcrt4
, "NDRSContextUnmarshall2");
274 pRpcServerRegisterIfEx
= (void *)GetProcAddress(hrpcrt4
, "RpcServerRegisterIfEx");
275 pRpcBindingSetAuthInfoExA
= (void *)GetProcAddress(hrpcrt4
, "RpcBindingSetAuthInfoExA");
276 pRpcServerRegisterAuthInfoA
= (void *)GetProcAddress(hrpcrt4
, "RpcServerRegisterAuthInfoA");
278 if (!pNDRSContextMarshall2
) old_windows_version
= TRUE
;
281 void __RPC_FAR
*__RPC_USER
282 midl_user_allocate(SIZE_T n
)
284 return HeapAlloc(GetProcessHeap(), 0, n
);
288 midl_user_free(void __RPC_FAR
*p
)
290 HeapFree(GetProcessHeap(), 0, p
);
294 xstrdup(const char *s
)
296 char *d
= HeapAlloc(GetProcessHeap(), 0, strlen(s
) + 1);
301 int __cdecl
s_int_return(void)
306 int __cdecl
s_square(int x
)
311 int __cdecl
s_sum(int x
, int y
)
316 signed char __cdecl
s_sum_char(signed char x
, signed char y
)
321 short __cdecl
s_sum_short(short x
, short y
)
326 int __cdecl
s_sum_float(float x
, float y
)
331 int __cdecl
s_sum_double_int(int x
, double y
)
336 hyper __cdecl
s_sum_hyper(hyper x
, hyper y
)
341 int __cdecl
s_sum_hyper_int(hyper x
, hyper y
)
346 int __cdecl
s_sum_char_hyper(signed char x
, hyper y
)
351 void __cdecl
s_square_out(int x
, int *y
)
356 void __cdecl
s_square_ref(int *x
)
361 int __cdecl
s_str_length(const char *s
)
366 int __cdecl
s_str_t_length(str_t s
)
371 int __cdecl
s_cstr_length(const char *s
, int n
)
374 while (0 < n
-- && *s
++)
379 int __cdecl
s_dot_self(vector_t
*v
)
381 return s_square(v
->x
) + s_square(v
->y
) + s_square(v
->z
);
384 double __cdecl
s_square_half(double x
, double *y
)
390 float __cdecl
s_square_half_float(float x
, float *y
)
396 LONG __cdecl
s_square_half_long(LONG x
, LONG
*y
)
402 int __cdecl
s_sum_fixed_array(int a
[5])
404 return a
[0] + a
[1] + a
[2] + a
[3] + a
[4];
407 int __cdecl
s_pints_sum(pints_t
*pints
)
409 return *pints
->pi
+ **pints
->ppi
+ ***pints
->pppi
;
412 double __cdecl
s_ptypes_sum(ptypes_t
*pt
)
414 return *pt
->pc
+ *pt
->ps
+ *pt
->pl
+ *pt
->pf
+ *pt
->pd
;
417 int __cdecl
s_dot_pvectors(pvectors_t
*p
)
419 return p
->pu
->x
* (*p
->pv
)->x
+ p
->pu
->y
* (*p
->pv
)->y
+ p
->pu
->z
* (*p
->pv
)->z
;
422 int __cdecl
s_sum_sp(sp_t
*sp
)
424 return sp
->x
+ sp
->s
->x
;
427 double __cdecl
s_square_sun(sun_t
*su
)
431 case SUN_I
: return su
->u
.i
* su
->u
.i
;
433 case SUN_F2
: return su
->u
.f
* su
->u
.f
;
434 case SUN_PI
: return (*su
->u
.pi
) * (*su
->u
.pi
);
440 int __cdecl
s_test_list_length(test_list_t
*list
)
442 return (list
->t
== TL_LIST
443 ? 1 + s_test_list_length(list
->u
.tail
)
447 int __cdecl
s_sum_fixed_int_3d(int m
[2][3][4])
452 for (i
= 0; i
< 2; ++i
)
453 for (j
= 0; j
< 3; ++j
)
454 for (k
= 0; k
< 4; ++k
)
460 int __cdecl
s_sum_conf_array(int x
[], int n
)
462 int *p
= x
, *end
= p
+ n
;
471 int __cdecl
s_sum_conf_ptr_by_conf_ptr(int n1
, int *n2_then_x1
, int *x2
)
478 for(i
= 1; i
< n1
; ++i
)
479 sum
+= n2_then_x1
[i
];
481 for(i
= 0; i
< *n2_then_x1
; ++i
)
487 int __cdecl
s_sum_unique_conf_array(int x
[], int n
)
489 return s_sum_conf_array(x
, n
);
492 int __cdecl
s_sum_unique_conf_ptr(int *x
, int n
)
494 return x
? s_sum_conf_array(x
, n
) : 0;
497 int __cdecl
s_sum_var_array(int x
[20], int n
)
499 ok(0 <= n
, "RPC sum_var_array\n");
500 ok(n
<= 20, "RPC sum_var_array\n");
502 return s_sum_conf_array(x
, n
);
505 int __cdecl
s_sum_complex_array(int n
, refpint_t pi
[])
513 int __cdecl
s_sum_blob(cs_blob_t
*blob
)
517 for (i
= 0; i
< blob
->n
; i
++)
518 total
+= blob
->ca
[i
];
523 int __cdecl
s_sum_data(cs_data_t
*data
)
527 for (i
= 0; i
< data
->blob
.n
; i
++)
528 total
+= data
->blob
.ca
[i
];
533 int __cdecl
s_sum_container(cs_container_t
*container
)
537 for (i
= 0; i
< container
->data
.blob
.n
; i
++)
538 total
+= container
->data
.blob
.ca
[i
];
543 int __cdecl
s_dot_two_vectors(vector_t vs
[2])
545 return vs
[0].x
* vs
[1].x
+ vs
[0].y
* vs
[1].y
+ vs
[0].z
* vs
[1].z
;
548 void __cdecl
s_get_number_array(int x
[20], int *n
)
550 int c
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
551 memcpy(x
, c
, sizeof(c
));
555 int __cdecl
s_sum_cs(cs_t
*cs
)
557 return s_sum_conf_array(cs
->ca
, cs
->n
);
560 int __cdecl
s_sum_cps(cps_t
*cps
)
565 for (i
= 0; i
< *cps
->pn
; ++i
)
568 for (i
= 0; i
< 2 * cps
->n
; ++i
)
574 int __cdecl
s_sum_cpsc(cpsc_t
*cpsc
)
578 for (i
= 0; i
< (cpsc
->c
? cpsc
->a
: cpsc
->b
); ++i
)
583 int __cdecl
s_get_cpsc(int n
, cpsc_t
*cpsc
)
590 cpsc
->ca
= MIDL_user_allocate( cpsc
->a
* sizeof(int) );
591 for (i
= ret
= 0; i
< cpsc
->a
; i
++) cpsc
->ca
[i
] = i
;
592 for (i
= ret
= 0; i
< cpsc
->a
; i
++) ret
+= cpsc
->ca
[i
];
596 int __cdecl
s_square_puint(puint_t p
)
602 int __cdecl
s_sum_puints(puints_t
*p
)
606 for (i
= 0; i
< p
->n
; ++i
)
607 sum
+= atoi(p
->ps
[i
]);
611 int __cdecl
s_sum_cpuints(cpuints_t
*p
)
615 for (i
= 0; i
< p
->n
; ++i
)
616 sum
+= atoi(p
->ps
[i
]);
620 int __cdecl
s_dot_copy_vectors(vector_t u
, vector_t v
)
622 return u
.x
* v
.x
+ u
.y
* v
.y
+ u
.z
* v
.z
;
625 int __cdecl
s_square_test_us(test_us_t
*tus
)
627 int n
= atoi(tus
->us
.x
);
631 double __cdecl
s_square_encu(encu_t
*eu
)
635 case ENCU_I
: return eu
->tagged_union
.i
* eu
->tagged_union
.i
;
636 case ENCU_F
: return eu
->tagged_union
.f
* eu
->tagged_union
.f
;
642 double __cdecl
s_square_unencu(int t
, unencu_t
*eu
)
646 case ENCU_I
: return eu
->i
* eu
->i
;
647 case ENCU_F
: return eu
->f
* eu
->f
;
653 void __cdecl
s_check_se2(se_t
*s
)
655 ok(s
->f
== E2
, "check_se2\n");
658 int __cdecl
s_sum_parr(int *a
[3])
660 return s_sum_pcarr(a
, 3);
663 int __cdecl
s_sum_pcarr(int *a
[], int n
)
666 for (i
= 0; i
< n
; ++i
)
671 int __cdecl
s_enum_ord(e_t e
)
684 double __cdecl
s_square_encue(encue_t
*eue
)
688 case E1
: return eue
->tagged_union
.i1
* eue
->tagged_union
.i1
;
689 case E2
: return eue
->tagged_union
.f2
* eue
->tagged_union
.f2
;
695 int __cdecl
s_sum_toplev_conf_2n(int *x
, int n
)
699 for (i
= 0; i
< 2 * n
; ++i
)
704 int __cdecl
s_sum_toplev_conf_cond(int *x
, int a
, int b
, int c
)
709 for (i
= 0; i
< n
; ++i
)
714 double __cdecl
s_sum_aligns(aligns_t
*a
)
716 return a
->c
+ a
->i
+ a
->s
+ a
->d
;
719 int __cdecl
s_sum_padded(padded_t
*p
)
724 int __cdecl
s_sum_padded2(padded_t ps
[2])
726 return s_sum_padded(&ps
[0]) + s_sum_padded(&ps
[1]);
729 int __cdecl
s_sum_padded_conf(padded_t
*ps
, int n
)
733 for (i
= 0; i
< n
; ++i
)
734 sum
+= s_sum_padded(&ps
[i
]);
738 int __cdecl
s_sum_bogus(bogus_t
*b
)
740 return *b
->h
.p1
+ *b
->p2
+ *b
->p3
+ b
->c
;
743 void __cdecl
s_check_null(int *null
)
745 ok(!null
, "RPC check_null\n");
748 int __cdecl
s_str_struct_len(str_struct_t
*s
)
750 return lstrlenA(s
->s
);
753 int __cdecl
s_wstr_struct_len(wstr_struct_t
*s
)
755 return lstrlenW(s
->s
);
758 int __cdecl
s_sum_doub_carr(doub_carr_t
*dc
)
762 for (i
= 0; i
< dc
->n
; ++i
)
763 for (j
= 0; j
< dc
->a
[i
]->n
; ++j
)
764 sum
+= dc
->a
[i
]->a
[j
];
768 void __cdecl
s_make_pyramid_doub_carr(unsigned char n
, doub_carr_t
**dc
)
772 t
= MIDL_user_allocate(FIELD_OFFSET(doub_carr_t
, a
[n
]));
774 for (i
= 0; i
< n
; ++i
)
777 t
->a
[i
] = MIDL_user_allocate(FIELD_OFFSET(doub_carr_1_t
, a
[v
]));
779 for (j
= 0; j
< v
; ++j
)
780 t
->a
[i
]->a
[j
] = j
+ 1;
785 unsigned __cdecl
s_hash_bstr(bstr_t b
)
791 for (i
= 0; i
< n
; ++i
)
792 hash
= 5 * hash
+ (unsigned) s
[i
];
796 void __cdecl
s_get_a_bstr(bstr_t
*b
)
799 short str
[] = {5, 'W', 'i', 'n', 'e', 0};
800 bstr
= HeapAlloc(GetProcessHeap(), 0, sizeof(str
));
801 memcpy(bstr
, str
, sizeof(str
));
805 void __cdecl
s_get_name(name_t
*name
)
807 const char bossman
[] = "Jeremy White";
808 memcpy(name
->name
, bossman
, min(name
->size
, sizeof(bossman
)));
809 /* ensure nul-termination */
810 if (name
->size
< sizeof(bossman
))
811 name
->name
[name
->size
- 1] = 0;
814 void __cdecl
s_get_names(int *n
, str_array_t
*names
)
818 list
= MIDL_user_allocate(2 * sizeof(list
[0]));
819 list
[0] = MIDL_user_allocate(6);
820 strcpy(list
[0], "Hello");
821 list
[1] = MIDL_user_allocate(7);
822 strcpy(list
[1], "World!");
828 void __cdecl
s_get_namesw(int *n
, wstr_array_t
*names
)
832 list
= MIDL_user_allocate(2 * sizeof(list
[0]));
833 list
[0] = MIDL_user_allocate(sizeof(L
"Hello"));
834 lstrcpyW(list
[0], L
"Hello");
835 list
[1] = MIDL_user_allocate(sizeof(L
"World!"));
836 lstrcpyW(list
[1], L
"World!");
842 int __cdecl
s_sum_pcarr2(int n
, int **pa
)
844 return s_sum_conf_array(*pa
, n
);
847 int __cdecl
s_sum_L1_norms(int n
, vector_t
*vs
)
851 for (i
= 0; i
< n
; ++i
)
852 sum
+= abs(vs
[i
].x
) + abs(vs
[i
].y
) + abs(vs
[i
].z
);
856 s123_t
* __cdecl
s_get_s123(void)
858 s123_t
*s
= MIDL_user_allocate(sizeof *s
);
865 str_t __cdecl
s_get_filename(void)
867 return (char *)__FILE__
;
870 int __cdecl
s_echo_ranged_int(int i
, int j
, int k
)
872 return min( 100, i
+ j
+ k
);
875 int __cdecl
s_echo_ranged_int2(int i
)
880 void __cdecl
s_get_ranged_enum(renum_t
*re
)
885 void __cdecl
s_context_handle_test(void)
888 RPC_BINDING_HANDLE binding
;
890 unsigned char buf
[20];
891 static RPC_SERVER_INTERFACE server_if
=
893 sizeof(RPC_SERVER_INTERFACE
),
894 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
895 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
904 binding
= I_RpcGetCurrentCallHandle();
905 ok(binding
!= NULL
, "I_RpcGetCurrentCallHandle returned NULL\n");
907 if (!pNDRSContextMarshall2
|| !pNDRSContextUnmarshall2
)
909 win_skip("NDRSContextMarshall2 or NDRSContextUnmarshall2 not exported from rpcrt4.dll\n");
913 h
= pNDRSContextUnmarshall2(binding
, NULL
, NDR_LOCAL_DATA_REPRESENTATION
, NULL
, 0);
914 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
916 /* marshal a context handle with NULL userContext */
917 memset(buf
, 0xcc, sizeof(buf
));
918 pNDRSContextMarshall2(binding
, h
, buf
, NULL
, NULL
, 0);
919 ok(*(ULONG
*)buf
== 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG
*)buf
);
920 ok(UuidIsNil((UUID
*)&buf
[4], &status
), "uuid should have been nil\n");
922 h
= pNDRSContextUnmarshall2(binding
, NULL
, NDR_LOCAL_DATA_REPRESENTATION
, NULL
, 0);
923 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
925 /* marshal a context handle with non-NULL userContext */
926 memset(buf
, 0xcc, sizeof(buf
));
927 h
->userContext
= (void *)0xdeadbeef;
928 pNDRSContextMarshall2(binding
, h
, buf
, NULL
, NULL
, 0);
929 ok(*(ULONG
*)buf
== 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG
*)buf
);
930 ok(!UuidIsNil((UUID
*)&buf
[4], &status
), "uuid should not have been nil\n");
932 /* raises ERROR_INVALID_HANDLE exception on Vista upwards */
935 h
= pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, NULL
, 0);
936 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
937 ok(h
->userContext
== (void *)0xdeadbeef, "userContext of interface didn't unmarshal properly: %p\n", h
->userContext
);
939 /* marshal a context handle with an interface specified */
940 h
= pNDRSContextUnmarshall2(binding
, NULL
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if
.InterfaceId
, 0);
941 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
943 memset(buf
, 0xcc, sizeof(buf
));
944 h
->userContext
= (void *)0xcafebabe;
945 pNDRSContextMarshall2(binding
, h
, buf
, NULL
, &server_if
.InterfaceId
, 0);
946 ok(*(ULONG
*)buf
== 0, "attributes should have been set to 0 instead of 0x%x\n", *(ULONG
*)buf
);
947 ok(!UuidIsNil((UUID
*)&buf
[4], &status
), "uuid should not have been nil\n");
949 h
= pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if
.InterfaceId
, 0);
950 ok(h
!= NULL
, "NDRSContextUnmarshall2 returned NULL\n");
951 ok(h
->userContext
== (void *)0xcafebabe, "userContext of interface didn't unmarshal properly: %p\n", h
->userContext
);
954 /* test same interface data, but different pointer */
955 /* raises ERROR_INVALID_HANDLE exception */
958 RPC_SERVER_INTERFACE server_if_clone
= server_if
;
960 pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if_clone
.InterfaceId
, 0);
963 /* test different interface data, but different pointer */
964 /* raises ERROR_INVALID_HANDLE exception */
967 static RPC_SERVER_INTERFACE server_if2
=
969 sizeof(RPC_SERVER_INTERFACE
),
970 {{0x00000000,0x4114,0x0704,{0x23,0x01,0x00,0x00,0x00,0x00,0x00,0x00}},{1,0}},
971 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
979 pNDRSContextMarshall2(binding
, h
, buf
, NULL
, &server_if
.InterfaceId
, 0);
981 pNDRSContextUnmarshall2(binding
, buf
, NDR_LOCAL_DATA_REPRESENTATION
, &server_if2
.InterfaceId
, 0);
985 status
= RpcBindingServerFromClient(NULL
, &binding
);
987 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
988 ok(binding
!= NULL
, "binding is NULL\n");
990 if (status
== RPC_S_OK
&& binding
!= NULL
)
992 unsigned char* string_binding
= NULL
;
993 unsigned char* object_uuid
= NULL
;
994 unsigned char* protseq
= NULL
;
995 unsigned char* network_address
= NULL
;
996 unsigned char* endpoint
= NULL
;
997 unsigned char* network_options
= NULL
;
999 status
= RpcBindingToStringBindingA(binding
, &string_binding
);
1000 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1001 ok(string_binding
!= NULL
, "string_binding is NULL\n");
1003 status
= RpcStringBindingParseA(string_binding
, &object_uuid
, &protseq
, &network_address
, &endpoint
, &network_options
);
1004 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1005 ok(protseq
!= NULL
&& *protseq
!= '\0', "protseq is %s\n", protseq
);
1006 ok(network_address
!= NULL
&& *network_address
!= '\0', "network_address is %s\n", network_address
);
1010 ok(object_uuid
!= NULL
&& *object_uuid
== '\0', "object_uuid is %s\n", object_uuid
);
1011 ok(endpoint
!= NULL
&& *endpoint
== '\0', "endpoint is %s\n", endpoint
);
1012 ok(network_options
!= NULL
&& *network_options
== '\0', "network_options is %s\n", network_options
);
1015 RpcStringFreeA(&string_binding
);
1016 RpcStringFreeA(&object_uuid
);
1017 RpcStringFreeA(&protseq
);
1018 RpcStringFreeA(&network_address
);
1019 RpcStringFreeA(&endpoint
);
1020 RpcStringFreeA(&network_options
);
1021 RpcBindingFree(&binding
);
1025 void __cdecl
s_get_numbers(int length
, int size
, pints_t n
[])
1028 for (i
= 0; i
< length
; i
++)
1030 n
[i
].pi
= midl_user_allocate(sizeof(*n
[i
].pi
));
1037 void __cdecl
s_get_numbers_struct(numbers_struct_t
**ns
)
1040 *ns
= midl_user_allocate(FIELD_OFFSET(numbers_struct_t
, numbers
[5]));
1044 for (i
= 0; i
< (*ns
)->length
; i
++)
1046 (*ns
)->numbers
[i
].pi
= NULL
;
1047 (*ns
)->numbers
[i
].ppi
= NULL
;
1048 (*ns
)->numbers
[i
].pppi
= NULL
;
1050 (*ns
)->numbers
[0].pi
= midl_user_allocate(sizeof(*(*ns
)->numbers
[i
].pi
));
1051 *(*ns
)->numbers
[0].pi
= 5;
1054 void __cdecl
s_full_pointer_test(int *a
, int *b
)
1056 ok(*a
== 42, "Expected *a to be 42 instead of %d\n", *a
);
1057 ok(*b
== 42, "Expected *b to be 42 instead of %d\n", *a
);
1058 ok(a
== b
, "Expected a (%p) to point to the same memory as b (%p)\n", a
, b
);
1061 void __cdecl
s_full_pointer_null_test(int *a
, int *b
)
1063 ok(*a
== 42, "Expected *a to be 42 instead of %d\n", *a
);
1064 ok(b
== NULL
, "Expected b to be NULL instead of %p\n", b
);
1067 void __cdecl
s_stop(void)
1069 if (!stop_wait_event
)
1071 ok(RPC_S_OK
== RpcMgmtStopServerListening(NULL
), "RpcMgmtStopServerListening\n");
1072 ok(RPC_S_OK
== RpcServerUnregisterIf(NULL
, NULL
, FALSE
), "RpcServerUnregisterIf\n");
1074 ok(SetEvent(stop_event
), "SetEvent\n");
1075 if (stop_wait_event
)
1078 ret
= WaitForSingleObject(stop_wait_event
, 10000);
1079 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
1083 void __cdecl
s_stop_autolisten(void)
1086 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
1088 ok(status
== RPC_S_UNKNOWN_MGR_TYPE
, "got %u\n", status
);
1091 void __cdecl
s_ip_test(ipu_t
*a
)
1096 hr
= IStream_Stat(a
->tagged_union
.stream
, &st
, STATFLAG_NONAME
);
1097 ok(hr
== S_OK
, "got %#x\n", hr
);
1100 int __cdecl
s_sum_ptr_array(int *a
[2])
1102 return *a
[0] + *a
[1];
1105 int __cdecl
s_sum_array_ptr(int (*a
)[2])
1107 return (*a
)[0] + (*a
)[1];
1110 ctx_handle_t __cdecl
s_get_handle(void)
1112 return (ctx_handle_t
)0xdeadbeef;
1115 void __cdecl
s_get_handle_by_ptr(ctx_handle_t
*r
)
1117 *r
= (ctx_handle_t
)0xdeadbeef;
1120 void __cdecl
s_test_handle(ctx_handle_t ctx_handle
)
1122 ok(ctx_handle
== (ctx_handle_t
)0xdeadbeef, "Unexpected ctx_handle %p\n", ctx_handle
);
1125 void __RPC_USER
ctx_handle_t_rundown(ctx_handle_t ctx_handle
)
1127 ok(ctx_handle
== (ctx_handle_t
)0xdeadbeef, "Unexpected ctx_handle %p\n", ctx_handle
);
1131 make_cmdline(char buffer
[MAX_PATH
], const char *test
)
1133 sprintf(buffer
, "%s server %s", progname
, test
);
1137 run_client(const char *test
)
1139 char cmdline
[MAX_PATH
];
1140 PROCESS_INFORMATION info
;
1141 STARTUPINFOA startup
;
1143 memset(&startup
, 0, sizeof startup
);
1144 startup
.cb
= sizeof startup
;
1146 make_cmdline(cmdline
, test
);
1147 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
1148 wait_child_process( info
.hProcess
);
1149 ok(CloseHandle(info
.hProcess
), "CloseHandle\n");
1150 ok(CloseHandle(info
.hThread
), "CloseHandle\n");
1156 char string
[] = "I am a string";
1157 WCHAR wstring
[] = L
"I am a wstring";
1158 int f
[5] = {1, 3, 0, -2, -4};
1159 vector_t a
= {1, 3, 7};
1160 vector_t vec1
= {4, -2, 1}, vec2
= {-5, 2, 3}, *pvec2
= &vec2
;
1161 pvectors_t pvecs
= {&vec1
, &pvec2
};
1162 sp_inner_t spi
= {42};
1163 sp_t sp
= {-13, &spi
};
1168 padded_t padded2
[2];
1170 int i1
, i2
, i3
, *pi2
, *pi3
, **ppi3
;
1178 str_struct_t ss
= {string
};
1179 wstr_struct_t ws
= {wstring
};
1184 ok(int_return() == INT_CODE
, "RPC int_return\n");
1186 ok(square(7) == 49, "RPC square\n");
1188 ok(x
== 19, "RPC sum got %d\n", x
);
1189 c
= sum_char(-23, 50);
1190 ok(c
== 27, "RPC sum_char got %d\n", (int)c
);
1191 h
= sum_short(1122, -344);
1192 ok(h
== 778, "RPC sum_short got %d\n", (int)h
);
1193 x
= sum_float(123.45, -32.2);
1194 ok(x
== 91, "RPC sum_float got %d\n", x
);
1195 x
= sum_double_int(-78, 148.46);
1196 ok(x
== 70, "RPC sum_double_int got %d\n", x
);
1197 y
= sum_hyper((hyper
)0x12345678 << 16, (hyper
)0x33557799 << 16);
1198 ok(y
== (hyper
)0x4589ce11 << 16, "RPC hyper got %s\n", wine_dbgstr_longlong(y
));
1199 x
= sum_hyper_int((hyper
)0x24242424 << 16, -((hyper
)0x24241212 << 16));
1200 ok(x
== 0x12120000, "RPC hyper_int got 0x%x\n", x
);
1201 x
= sum_char_hyper( 12, ((hyper
)0x42424242 << 32) | 0x33334444 );
1202 ok(x
== 0x33334450, "RPC char_hyper got 0x%x\n", x
);
1206 ok(x
== 121, "RPC square_out\n");
1210 ok(x
== 25, "RPC square_ref\n");
1212 ok(str_length(string
) == strlen(string
), "RPC str_length\n");
1213 ok(str_t_length(string
) == strlen(string
), "RPC str_length\n");
1214 ok(dot_self(&a
) == 59, "RPC dot_self\n");
1216 ok(str_struct_len(&ss
) == lstrlenA(string
), "RPC str_struct_len\n");
1217 ok(wstr_struct_len(&ws
) == lstrlenW(wstring
), "RPC str_struct_len\n");
1220 u
= square_half(3.0, &v
);
1221 ok(u
== 9.0, "RPC square_half\n");
1222 ok(v
== 1.5, "RPC square_half\n");
1225 s
= square_half_float(3.0f
, &t
);
1226 ok(s
== 9.0f
, "RPC square_half_float\n");
1227 ok(t
== 1.5f
, "RPC square_half_float\n");
1230 q
= square_half_long(3, &r
);
1231 ok(q
== 9, "RPC square_half_long\n");
1232 ok(r
== 1, "RPC square_half_long\n");
1243 ok(pints_sum(&pints
) == -13, "RPC pints_sum\n");
1255 ok(ptypes_sum(&ptypes
) == 33.0, "RPC ptypes_sum\n");
1257 ok(dot_pvectors(&pvecs
) == -21, "RPC dot_pvectors\n");
1258 ok(dot_copy_vectors(vec1
, vec2
) == -21, "RPC dot_copy_vectors\n");
1259 ok(sum_fixed_array(f
) == -2, "RPC sum_fixed_array\n");
1260 ok(sum_sp(&sp
) == 29, "RPC sum_sp\n");
1262 ok(enum_ord(E1
) == 1, "RPC enum_ord\n");
1263 ok(enum_ord(E2
) == 2, "RPC enum_ord\n");
1264 ok(enum_ord(E3
) == 3, "RPC enum_ord\n");
1265 ok(enum_ord(E4
) == 4, "RPC enum_ord\n");
1270 memset(&aligns
, 0, sizeof(aligns
));
1275 ok(sum_aligns(&aligns
) == 18.0, "RPC sum_aligns\n");
1279 ok(sum_padded(&padded
) == 5, "RPC sum_padded\n");
1284 ok(sum_padded2(padded2
) == 6, "RPC sum_padded2\n");
1289 ok(sum_padded_conf(padded2
, 2) == 6, "RPC sum_padded_conf\n");
1298 ok(sum_bogus(&bogus
) == 12, "RPC sum_bogus\n");
1302 if (!is_interp
|| sizeof(void*) != 8) { /* broken in widl for win64 */
1303 str
= get_filename();
1304 ok(!strcmp(str
, __FILE__
), "get_filename() returned %s instead of %s\n", str
, __FILE__
);
1305 midl_user_free(str
);
1308 x
= echo_ranged_int(0,0,0);
1309 ok(x
== 0, "echo_ranged_int() returned %d instead of 0\n", x
);
1310 x
= echo_ranged_int(10,20,100);
1311 ok(x
== 100, "echo_ranged_int() returned %d instead of 100\n", x
);
1312 x
= echo_ranged_int2(40);
1313 ok(x
== 40, "echo_ranged_int() returned %d instead of 40\n", x
);
1315 if (!old_windows_version
)
1318 get_ranged_enum(&re
);
1320 broken(re
== MAKELONG(re
, 0xdead)), /* Win 8, Win 10 */
1321 "get_ranged_enum() returned %x instead of RE3\n", re
);
1338 ok(square_sun(&su
) == 81.0, "RPC square_sun\n");
1342 ok(square_sun(&su
) == 25.0, "RPC square_sun\n");
1346 ok(square_sun(&su
) == 4.0, "RPC square_sun\n");
1351 ok(square_sun(&su
) == 121.0, "RPC square_sun\n");
1354 eu
.tagged_union
.i
= 7;
1355 ok(square_encu(&eu
) == 49.0, "RPC square_encu\n");
1358 eu
.tagged_union
.f
= 3.0;
1359 ok(square_encu(&eu
) == 9.0, "RPC square_encu\n");
1362 ok(square_unencu(ENCU_I
, &uneu
) == 16.0, "RPC square_unencu\n");
1365 ok(square_unencu(ENCU_F
, &uneu
) == 25.0, "RPC square_unencu\n");
1368 eue
.tagged_union
.i1
= 8;
1369 ok(square_encue(&eue
) == 64.0, "RPC square_encue\n");
1372 eue
.tagged_union
.f2
= 10.0;
1373 ok(square_encue(&eue
) == 100.0, "RPC square_encue\n");
1375 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1377 CreateStreamOnHGlobal(NULL
, TRUE
, &ipu
.tagged_union
.stream
);
1379 ref
= IStream_Release(ipu
.tagged_union
.stream
);
1380 ok(!ref
, "got %u refs\n", ref
);
1385 static test_list_t
*
1388 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
1394 static test_list_t
*
1395 make_list(test_list_t
*tail
)
1397 test_list_t
*n
= HeapAlloc(GetProcessHeap(), 0, sizeof *n
);
1404 free_list(test_list_t
*list
)
1406 if (list
->t
== TL_LIST
)
1407 free_list(list
->u
.tail
);
1408 HeapFree(GetProcessHeap(), 0, list
);
1412 puint_t_UserSize(ULONG
*flags
, ULONG start
, puint_t
*p
)
1414 return start
+ sizeof(int);
1417 unsigned char * __RPC_USER
1418 puint_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
1421 memcpy(buffer
, &n
, sizeof n
);
1422 return buffer
+ sizeof n
;
1425 unsigned char * __RPC_USER
1426 puint_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, puint_t
*p
)
1429 memcpy(&n
, buffer
, sizeof n
);
1430 *p
= HeapAlloc(GetProcessHeap(), 0, 10);
1431 sprintf(*p
, "%d", n
);
1432 return buffer
+ sizeof n
;
1436 puint_t_UserFree(ULONG
*flags
, puint_t
*p
)
1438 HeapFree(GetProcessHeap(), 0, *p
);
1442 us_t_UserSize(ULONG
*flags
, ULONG start
, us_t
*pus
)
1444 return start
+ sizeof(struct wire_us
);
1447 unsigned char * __RPC_USER
1448 us_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
1451 wus
.x
= atoi(pus
->x
);
1452 memcpy(buffer
, &wus
, sizeof wus
);
1453 return buffer
+ sizeof wus
;
1456 unsigned char * __RPC_USER
1457 us_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, us_t
*pus
)
1460 memcpy(&wus
, buffer
, sizeof wus
);
1461 pus
->x
= HeapAlloc(GetProcessHeap(), 0, 10);
1462 sprintf(pus
->x
, "%d", wus
.x
);
1463 return buffer
+ sizeof wus
;
1467 us_t_UserFree(ULONG
*flags
, us_t
*pus
)
1469 HeapFree(GetProcessHeap(), 0, pus
->x
);
1473 bstr_t_UserSize(ULONG
*flags
, ULONG start
, bstr_t
*b
)
1475 return start
+ FIELD_OFFSET(user_bstr_t
, data
[(*b
)[-1]]);
1478 unsigned char * __RPC_USER
1479 bstr_t_UserMarshal(ULONG
*flags
, unsigned char *buffer
, bstr_t
*b
)
1481 wire_bstr_t wb
= (wire_bstr_t
) buffer
;
1483 memcpy(&wb
->data
, *b
, wb
->n
* sizeof wb
->data
[0]);
1484 return buffer
+ FIELD_OFFSET(user_bstr_t
, data
[wb
->n
]);
1487 unsigned char * __RPC_USER
1488 bstr_t_UserUnmarshal(ULONG
*flags
, unsigned char *buffer
, bstr_t
*b
)
1490 wire_bstr_t wb
= (wire_bstr_t
) buffer
;
1491 short *data
= HeapAlloc(GetProcessHeap(), 0, (wb
->n
+ 1) * sizeof *data
);
1493 memcpy(&data
[1], wb
->data
, wb
->n
* sizeof data
[1]);
1495 return buffer
+ FIELD_OFFSET(user_bstr_t
, data
[wb
->n
]);
1499 bstr_t_UserFree(ULONG
*flags
, bstr_t
*b
)
1501 HeapFree(GetProcessHeap(), 0, &((*b
)[-1]));
1507 int a
[] = {1, 2, 3, 4};
1509 test_list_t
*list
= make_list(make_list(make_list(null_list())));
1510 test_us_t tus
= {{p1
}};
1514 short bstr_data
[] = { 5, 'H', 'e', 'l', 'l', 'o' };
1515 bstr_t bstr
= &bstr_data
[1], bstr2
;
1522 ok(test_list_length(list
) == 3, "RPC test_list_length\n");
1523 ok(square_puint(p1
) == 121, "RPC square_puint\n");
1525 pus
.ps
= HeapAlloc(GetProcessHeap(), 0, pus
.n
* sizeof pus
.ps
[0]);
1526 pus
.ps
[0] = xstrdup("5");
1527 pus
.ps
[1] = xstrdup("6");
1528 pus
.ps
[2] = xstrdup("7");
1529 pus
.ps
[3] = xstrdup("8");
1530 ok(sum_puints(&pus
) == 26, "RPC sum_puints\n");
1531 HeapFree(GetProcessHeap(), 0, pus
.ps
[0]);
1532 HeapFree(GetProcessHeap(), 0, pus
.ps
[1]);
1533 HeapFree(GetProcessHeap(), 0, pus
.ps
[2]);
1534 HeapFree(GetProcessHeap(), 0, pus
.ps
[3]);
1535 HeapFree(GetProcessHeap(), 0, pus
.ps
);
1537 cpus
.ps
= HeapAlloc(GetProcessHeap(), 0, cpus
.n
* sizeof cpus
.ps
[0]);
1538 cpus
.ps
[0] = xstrdup("5");
1539 cpus
.ps
[1] = xstrdup("6");
1540 cpus
.ps
[2] = xstrdup("7");
1541 cpus
.ps
[3] = xstrdup("8");
1542 ok(sum_cpuints(&cpus
) == 26, "RPC sum_puints\n");
1543 HeapFree(GetProcessHeap(), 0, cpus
.ps
[0]);
1544 HeapFree(GetProcessHeap(), 0, cpus
.ps
[1]);
1545 HeapFree(GetProcessHeap(), 0, cpus
.ps
[2]);
1546 HeapFree(GetProcessHeap(), 0, cpus
.ps
[3]);
1547 HeapFree(GetProcessHeap(), 0, cpus
.ps
);
1548 ok(square_test_us(&tus
) == 121, "RPC square_test_us\n");
1553 ok(sum_parr(pa
) == 6, "RPC sum_parr\n");
1559 ok(sum_pcarr(pa
, 4) == 10, "RPC sum_pcarr\n");
1561 ok(hash_bstr(bstr
) == s_hash_bstr(bstr
), "RPC hash_bstr_data\n");
1564 s_get_a_bstr(&bstr2
);
1565 ok(!lstrcmpW((LPCWSTR
)bstr
, (LPCWSTR
)bstr2
), "bstr mismatch\n");
1566 HeapFree(GetProcessHeap(), 0, bstr
- 1);
1567 HeapFree(GetProcessHeap(), 0, bstr2
- 1);
1571 if (!old_windows_version
)
1575 wstr_array_t namesw
;
1578 name
.name
= buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, name
.size
);
1580 ok(name
.name
== buffer
, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name
.name
, buffer
);
1581 ok(!strcmp(name
.name
, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name
.name
);
1582 HeapFree(GetProcessHeap(), 0, name
.name
);
1584 if (!is_interp
) { /* broken in widl */
1587 get_names(&n
, &names
);
1588 ok(n
== 2, "expected 2, got %d\n", n
);
1589 ok(!strcmp(names
[0], "Hello"), "expected Hello, got %s\n", names
[0]);
1590 ok(!strcmp(names
[1], "World!"), "expected World!, got %s\n", names
[1]);
1591 MIDL_user_free(names
[0]);
1592 MIDL_user_free(names
[1]);
1593 MIDL_user_free(names
);
1597 get_namesw(&n
, &namesw
);
1598 ok(n
== 2, "expected 2, got %d\n", n
);
1599 ok(!lstrcmpW(namesw
[0], L
"Hello"), "expected Hello, got %s\n", wine_dbgstr_w(namesw
[0]));
1600 ok(!lstrcmpW(namesw
[1], L
"World!"), "expected World!, got %s\n", wine_dbgstr_w(namesw
[1]));
1601 MIDL_user_free(namesw
[0]);
1602 MIDL_user_free(namesw
[1]);
1603 MIDL_user_free(namesw
);
1607 if (!is_interp
) { /* broken in widl */
1609 ok(sum_pcarr2(4, &pa2
) == 10, "RPC sum_pcarr2\n");
1613 ok(s123
->f1
== 1 && s123
->f2
== 2 && s123
->f3
== 3, "RPC get_s123\n");
1614 MIDL_user_free(s123
);
1616 full_pointer_test(&val
, &val
);
1617 full_pointer_null_test(&val
, NULL
);
1621 check_pyramid_doub_carr(doub_carr_t
*dc
)
1624 for (i
= 0; i
< dc
->n
; ++i
)
1625 for (j
= 0; j
< dc
->a
[i
]->n
; ++j
)
1626 if (dc
->a
[i
]->a
[j
] != j
+ 1)
1632 free_pyramid_doub_carr(doub_carr_t
*dc
)
1635 for (i
= 0; i
< dc
->n
; ++i
)
1636 MIDL_user_free(dc
->a
[i
]);
1645 {{1, 2, 3, 4}, {-1, -3, -5, -7}, {0, 2, 4, 6}},
1646 {{1, -2, 3, -4}, {2, 3, 5, 7}, {-4, -1, -14, 4114}}
1648 int c
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
1649 int c2
[] = {10, 100, 200};
1651 vector_t vs
[2] = {{1, -2, 3}, {4, -5, -6}};
1656 cs_container_t container
;
1659 int ca
[5] = {1, -2, 3, -4, 5};
1664 numbers_struct_t
*ns
;
1666 int i0
= 1, i1
= 2, *ptr_array
[2] = {&i0
, &i1
}, array
[2] = {3, 4};
1668 if (!old_windows_version
)
1670 const char str1
[25] = "Hello";
1671 ok(cstr_length(str1
, sizeof str1
) == strlen(str1
), "RPC cstr_length\n");
1674 ok(sum_fixed_int_3d(m
) == 4116, "RPC sum_fixed_int_3d\n");
1676 ok(sum_conf_array(c
, 10) == 45, "RPC sum_conf_array\n");
1677 ok(sum_conf_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
1678 ok(sum_conf_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
1679 ok(sum_conf_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
1681 ok(sum_conf_ptr_by_conf_ptr(1, c2
, c
) == 45, "RPC sum_conf_ptr_by_conf_ptr\n");
1682 ok(sum_conf_ptr_by_conf_ptr(3, c2
, c
) == 345, "RPC sum_conf_ptr_by_conf_ptr\n");
1684 ok(sum_conf_ptr_by_conf_ptr(3, c2
, c
) == 300, "RPC sum_conf_ptr_by_conf_ptr\n");
1686 ok(sum_unique_conf_array(ca
, 4) == -2, "RPC sum_unique_conf_array\n");
1687 ok(sum_unique_conf_ptr(ca
, 5) == 3, "RPC sum_unique_conf_array\n");
1688 ok(sum_unique_conf_ptr(NULL
, 10) == 0, "RPC sum_unique_conf_array\n");
1690 get_number_array(c3
, &n
);
1691 ok(n
== 10, "RPC get_num_array\n");
1693 ok(c3
[n
-1] == c
[n
-1], "get_num_array returned wrong value %d @ %d\n",
1695 ok(sum_var_array(c
, 10) == 45, "RPC sum_conf_array\n");
1696 ok(sum_var_array(&c
[5], 2) == 11, "RPC sum_conf_array\n");
1697 ok(sum_var_array(&c
[7], 1) == 7, "RPC sum_conf_array\n");
1698 ok(sum_var_array(&c
[2], 0) == 0, "RPC sum_conf_array\n");
1700 ok(dot_two_vectors(vs
) == -4, "RPC dot_two_vectors\n");
1701 cs
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(cs_t
, ca
[5]));
1708 ok(sum_cs(cs
) == 1, "RPC sum_cs\n");
1709 HeapFree(GetProcessHeap(), 0, cs
);
1716 ok(sum_cps(&cps
) == 53, "RPC sum_cps\n");
1722 ok(sum_cpsc(&cpsc
) == 6, "RPC sum_cpsc\n");
1727 ok(sum_cpsc(&cpsc
) == 10, "RPC sum_cpsc\n");
1730 ok(get_cpsc(5, &cpsc
) == 45, "RPC sum_cpsc\n");
1731 ok( cpsc
.a
== 10, "RPC get_cpsc %u\n", cpsc
.a
);
1732 for (n
= 0; n
< 10; n
++) ok( cpsc
.ca
[n
] == n
, "RPC get_cpsc[%d] = %d\n", n
, cpsc
.ca
[n
] );
1734 memset( tmp
, 0x33, sizeof(tmp
) );
1736 ok(get_cpsc(4, &cpsc
) == 28, "RPC sum_cpsc\n");
1737 ok( cpsc
.a
== 8, "RPC get_cpsc %u\n", cpsc
.a
);
1738 ok( cpsc
.ca
== tmp
, "RPC get_cpsc %p/%p\n", cpsc
.ca
, tmp
);
1739 for (n
= 0; n
< 8; n
++) ok( cpsc
.ca
[n
] == n
, "RPC get_cpsc[%d] = %d\n", n
, cpsc
.ca
[n
] );
1741 ok(sum_toplev_conf_2n(c
, 3) == 15, "RPC sum_toplev_conf_2n\n");
1742 ok(sum_toplev_conf_cond(c
, 5, 6, 1) == 10, "RPC sum_toplev_conf_cond\n");
1743 ok(sum_toplev_conf_cond(c
, 5, 6, 0) == 15, "RPC sum_toplev_conf_cond\n");
1745 dc
= HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_t
, a
[2]));
1747 dc
->a
[0] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t
, a
[3]));
1752 dc
->a
[1] = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(doub_carr_1_t
, a
[2]));
1756 ok(sum_doub_carr(dc
) == 19, "RPC sum_doub_carr\n");
1757 HeapFree(GetProcessHeap(), 0, dc
->a
[0]);
1758 HeapFree(GetProcessHeap(), 0, dc
->a
[1]);
1759 HeapFree(GetProcessHeap(), 0, dc
);
1762 make_pyramid_doub_carr(4, &dc
);
1763 ok(check_pyramid_doub_carr(dc
), "RPC make_pyramid_doub_carr\n");
1764 free_pyramid_doub_carr(dc
);
1766 ok(sum_L1_norms(2, vs
) == 21, "RPC sum_L1_norms\n");
1768 memset(api
, 0, sizeof(api
));
1769 pi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pi
));
1772 get_numbers(1, 1, api
);
1773 ok(api
[0].pi
== pi
, "RPC conformant varying array [out] pointer changed from %p to %p\n", pi
, api
[0].pi
);
1774 ok(*api
[0].pi
== 0, "pi unmarshalled incorrectly %d\n", *api
[0].pi
);
1776 if (!old_windows_version
)
1778 ns
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, FIELD_OFFSET(numbers_struct_t
, numbers
[5]));
1781 ns
->numbers
[0].pi
= pi
;
1782 get_numbers_struct(&ns
);
1783 ok(ns
->numbers
[0].pi
== pi
, "RPC conformant varying struct embedded pointer changed from %p to %p\n", pi
, ns
->numbers
[0].pi
);
1784 ok(*ns
->numbers
[0].pi
== 5, "pi unmarshalled incorrectly %d\n", *ns
->numbers
[0].pi
);
1785 HeapFree(GetProcessHeap(), 0, ns
);
1787 HeapFree(GetProcessHeap(), 0, pi
);
1789 pi
= HeapAlloc(GetProcessHeap(), 0, 5 * sizeof(*pi
));
1790 pi
[0] = 3; rpi
[0] = &pi
[0];
1791 pi
[1] = 5; rpi
[1] = &pi
[1];
1792 pi
[2] = -2; rpi
[2] = &pi
[2];
1793 pi
[3] = -1; rpi
[3] = &pi
[3];
1794 pi
[4] = -4; rpi
[4] = &pi
[4];
1795 ok(sum_complex_array(5, rpi
) == 1, "RPC sum_complex_array\n");
1796 HeapFree(GetProcessHeap(), 0, pi
);
1798 ok(sum_ptr_array(ptr_array
) == 3, "RPC sum_ptr_array\n");
1799 ok(sum_array_ptr(&array
) == 7, "RPC sum_array_ptr\n");
1801 blob
.n
= ARRAY_SIZE(c
);
1803 n
= sum_blob(&blob
);
1804 ok(n
== 45, "RPC sum_blob = %d\n", n
);
1806 data
.blob
.n
= ARRAY_SIZE(c
);
1808 n
= sum_data(&data
);
1809 ok(n
== 45, "RPC sum_data = %d\n", n
);
1811 container
.data
.blob
.n
= ARRAY_SIZE(c
);
1812 container
.data
.blob
.ca
= c
;
1813 n
= sum_container(&container
);
1814 ok(n
== 45, "RPC sum_container = %d\n", n
);
1817 void __cdecl
s_authinfo_test(unsigned int protseq
, int secure
)
1819 RPC_BINDING_HANDLE binding
;
1821 ULONG level
, authnsvc
;
1822 RPC_AUTHZ_HANDLE privs
;
1823 unsigned char *principal
;
1825 binding
= I_RpcGetCurrentCallHandle();
1826 ok(binding
!= NULL
, "I_RpcGetCurrentCallHandle returned NULL\n");
1828 level
= authnsvc
= 0xdeadbeef;
1829 privs
= (RPC_AUTHZ_HANDLE
)0xdeadbeef;
1830 principal
= (unsigned char *)0xdeadbeef;
1832 if (secure
|| protseq
== RPC_PROTSEQ_LRPC
)
1834 status
= RpcBindingInqAuthClientA(binding
, &privs
, &principal
, &level
, &authnsvc
, NULL
);
1835 if (status
== RPC_S_CANNOT_SUPPORT
)
1837 win_skip("RpcBindingInqAuthClientA not supported\n");
1840 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1841 ok(privs
!= (RPC_AUTHZ_HANDLE
)0xdeadbeef, "privs unchanged\n");
1842 ok(principal
!= (unsigned char *)0xdeadbeef, "principal unchanged\n");
1843 if (protseq
!= RPC_PROTSEQ_LRPC
)
1846 ok(principal
!= NULL
, "NULL principal\n");
1848 if (protseq
== RPC_PROTSEQ_LRPC
&& principal
)
1853 len
= WideCharToMultiByte(CP_ACP
, 0, (const WCHAR
*)privs
, -1, NULL
, 0, NULL
, NULL
);
1854 spn
= HeapAlloc( GetProcessHeap(), 0, len
);
1855 WideCharToMultiByte(CP_ACP
, 0, (const WCHAR
*)privs
, -1, spn
, len
, NULL
, NULL
);
1857 ok(!strcmp(domain_and_user
, spn
), "expected %s got %s\n", domain_and_user
, spn
);
1858 HeapFree( GetProcessHeap(), 0, spn
);
1860 ok(level
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
, "level unchanged\n");
1861 ok(authnsvc
== RPC_C_AUTHN_WINNT
, "authnsvc unchanged\n");
1862 RpcStringFreeA(&principal
);
1864 status
= RpcBindingInqAuthClientA(NULL
, &privs
, &principal
, &level
, &authnsvc
, NULL
);
1865 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1866 RpcStringFreeA(&principal
);
1868 status
= RpcBindingInqAuthClientExA(NULL
, &privs
, &principal
, &level
, &authnsvc
, NULL
, 0);
1869 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1870 RpcStringFreeA(&principal
);
1872 status
= RpcImpersonateClient(NULL
);
1873 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1874 status
= RpcRevertToSelf();
1875 ok(status
== RPC_S_OK
, "expected RPC_S_OK got %u\n", status
);
1880 status
= RpcBindingInqAuthClientA(binding
, &privs
, &principal
, &level
, &authnsvc
, NULL
);
1881 ok(status
== RPC_S_BINDING_HAS_NO_AUTH
, "expected RPC_S_BINDING_HAS_NO_AUTH got %u\n", status
);
1882 ok(privs
== (RPC_AUTHZ_HANDLE
)0xdeadbeef, "got %p\n", privs
);
1883 ok(principal
== (unsigned char *)0xdeadbeef, "got %s\n", principal
);
1884 ok(level
== 0xdeadbeef, "got %u\n", level
);
1885 ok(authnsvc
== 0xdeadbeef, "got %u\n", authnsvc
);
1889 static void test_handle_return(void)
1891 ctx_handle_t handle
, handle2
;
1893 handle
= get_handle();
1894 test_handle(handle
);
1895 get_handle_by_ptr(&handle2
);
1896 test_handle(handle2
);
1906 context_handle_test();
1907 test_handle_return();
1911 set_auth_info(RPC_BINDING_HANDLE handle
)
1914 RPC_SECURITY_QOS qos
;
1917 qos
.Capabilities
= RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH
;
1918 qos
.IdentityTracking
= RPC_C_QOS_IDENTITY_STATIC
;
1919 qos
.ImpersonationType
= RPC_C_IMP_LEVEL_IMPERSONATE
;
1921 status
= pRpcBindingSetAuthInfoExA(handle
, (RPC_CSTR
)domain_and_user
, RPC_C_AUTHN_LEVEL_PKT_PRIVACY
,
1922 RPC_C_AUTHN_WINNT
, NULL
, 0, &qos
);
1923 ok(status
== RPC_S_OK
, "RpcBindingSetAuthInfoExA failed %d\n", status
);
1926 #define test_is_server_listening(a,b) _test_is_server_listening(__LINE__,a,b)
1927 static void _test_is_server_listening(unsigned line
, RPC_BINDING_HANDLE binding
, RPC_STATUS expected_status
)
1930 status
= RpcMgmtIsServerListening(binding
);
1931 ok_(__FILE__
,line
)(status
== expected_status
, "RpcMgmtIsServerListening returned %u, expected %u\n",
1932 status
, expected_status
);
1935 #define test_is_server_listening2(a,b,c) _test_is_server_listening2(__LINE__,a,b,c)
1936 static void _test_is_server_listening2(unsigned line
, RPC_BINDING_HANDLE binding
, RPC_STATUS expected_status
,
1937 RPC_STATUS expected_status2
)
1940 status
= RpcMgmtIsServerListening(binding
);
1941 ok_(__FILE__
,line
)(status
== expected_status
|| status
== expected_status2
,
1942 "RpcMgmtIsServerListening returned %u, expected %u or %u\n",
1943 status
, expected_status
, expected_status2
);
1947 client(const char *test
)
1949 static unsigned char iptcp
[] = "ncacn_ip_tcp";
1950 static unsigned char np
[] = "ncacn_np";
1951 static unsigned char ncalrpc
[] = "ncalrpc";
1952 static unsigned char address
[] = "127.0.0.1";
1953 static unsigned char address_np
[] = "\\\\.";
1954 static unsigned char port
[] = PORT
;
1955 static unsigned char pipe
[] = PIPE
;
1956 static unsigned char guid
[] = "00000000-4114-0704-2301-000000000000";
1958 unsigned char *binding
;
1960 if (strcmp(test
, "tcp_basic") == 0)
1962 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, iptcp
, address
, port
, NULL
, &binding
), "RpcStringBindingCompose\n");
1963 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
1966 authinfo_test(RPC_PROTSEQ_TCP
, 0);
1967 test_is_server_listening2(IMixedServer_IfHandle
, RPC_S_OK
, RPC_S_ACCESS_DENIED
);
1969 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1970 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
1972 else if (strcmp(test
, "tcp_secure") == 0)
1974 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, iptcp
, address
, port
, NULL
, &binding
), "RpcStringBindingCompose\n");
1975 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
1977 set_auth_info(IMixedServer_IfHandle
);
1978 authinfo_test(RPC_PROTSEQ_TCP
, 1);
1979 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_ACCESS_DENIED
);
1981 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1982 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
1984 else if (strcmp(test
, "ncalrpc_basic") == 0)
1986 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
), "RpcStringBindingCompose\n");
1987 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
1989 run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
1990 authinfo_test(RPC_PROTSEQ_LRPC
, 0);
1991 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_OK
);
1993 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
1994 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
1996 else if (strcmp(test
, "ncalrpc_autolisten") == 0)
1998 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
), "RpcStringBindingCompose\n");
1999 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
2002 authinfo_test(RPC_PROTSEQ_LRPC
, 0);
2004 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_NOT_LISTENING
);
2007 ok(int_return() == INT_CODE
, "RPC int_return\n");
2009 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
2010 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
2012 else if (strcmp(test
, "ncalrpc_secure") == 0)
2014 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
), "RpcStringBindingCompose\n");
2015 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
2017 set_auth_info(IMixedServer_IfHandle
);
2018 authinfo_test(RPC_PROTSEQ_LRPC
, 1);
2019 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_OK
);
2021 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
2022 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
2024 else if (strcmp(test
, "np_basic") == 0)
2026 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, np
, address_np
, pipe
, NULL
, &binding
), "RpcStringBindingCompose\n");
2027 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
2029 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_OK
);
2031 authinfo_test(RPC_PROTSEQ_NMP
, 0);
2032 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_OK
);
2034 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_NOT_LISTENING
);
2036 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
2037 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
2039 else if (strcmp(test
, "np_basic_interp") == 0)
2041 set_interp_interface();
2043 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, np
, address_np
, pipe
, NULL
, &binding
), "RpcStringBindingCompose\n");
2044 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IInterpServer_IfHandle
), "RpcBindingFromStringBinding\n");
2046 test_is_server_listening(IInterpServer_IfHandle
, RPC_S_OK
);
2048 authinfo_test(RPC_PROTSEQ_NMP
, 0);
2049 test_is_server_listening(IInterpServer_IfHandle
, RPC_S_OK
);
2051 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
2052 ok(RPC_S_OK
== RpcBindingFree(&IInterpServer_IfHandle
), "RpcBindingFree\n");
2059 static unsigned char iptcp
[] = "ncacn_ip_tcp";
2060 static unsigned char port
[] = PORT
;
2061 static unsigned char np
[] = "ncacn_np";
2062 static unsigned char pipe
[] = PIPE
;
2063 static unsigned char ncalrpc
[] = "ncalrpc";
2064 static unsigned char guid
[] = "00000000-4114-0704-2301-000000000000";
2065 RPC_STATUS status
, iptcp_status
, np_status
, ncalrpc_status
;
2068 /* needed for tests involving interface pointers */
2069 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2071 iptcp_status
= RpcServerUseProtseqEpA(iptcp
, 20, port
, NULL
);
2072 ok(iptcp_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status
);
2074 ncalrpc_status
= RpcServerUseProtseqEpA(ncalrpc
, 0, guid
, NULL
);
2075 ok(ncalrpc_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status
);
2077 np_status
= RpcServerUseProtseqEpA(np
, 0, pipe
, NULL
);
2078 if (np_status
== RPC_S_PROTSEQ_NOT_SUPPORTED
)
2079 skip("Protocol sequence ncacn_np is not supported\n");
2081 ok(np_status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", np_status
);
2083 if (pRpcServerRegisterIfEx
)
2085 trace("Using RpcServerRegisterIfEx\n");
2086 status
= pRpcServerRegisterIfEx(s_IMixedServer_v0_0_s_ifspec
, NULL
, NULL
,
2087 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH
,
2088 RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
2089 ok(status
== RPC_S_OK
, "RpcServerRegisterIfEx failed with status %d\n", status
);
2090 status
= pRpcServerRegisterIfEx(s_IInterpServer_v0_0_s_ifspec
, NULL
, NULL
,
2091 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH
,
2092 RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
2093 ok(status
== RPC_S_OK
, "RpcServerRegisterIfEx failed with status %d\n", status
);
2097 status
= RpcServerRegisterIf(s_IMixedServer_v0_0_s_ifspec
, NULL
, NULL
);
2098 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed with status %d\n", status
);
2099 status
= RpcServerRegisterIf(s_IInterpServer_v0_0_s_ifspec
, NULL
, NULL
);
2100 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed with status %d\n", status
);
2102 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
2103 status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
);
2104 ok(status
== RPC_S_OK
, "RpcServerListen failed with status %d\n", status
);
2105 test_is_server_listening(NULL
, RPC_S_OK
);
2106 stop_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2107 ok(stop_event
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2109 if (iptcp_status
== RPC_S_OK
)
2110 run_client("tcp_basic");
2112 skip("tcp tests skipped due to earlier failure\n");
2114 if (ncalrpc_status
== RPC_S_OK
)
2116 run_client("ncalrpc_basic");
2118 /* we don't need to register RPC_C_AUTHN_WINNT for ncalrpc */
2119 run_client("ncalrpc_secure");
2122 skip("lrpc tests skipped due to earlier failure\n");
2124 if (np_status
== RPC_S_OK
)
2126 run_client("np_basic_interp");
2127 run_client("np_basic");
2131 skip("np_basic tests skipped due to earlier failure\n");
2132 /* np client is what signals stop_event, so bail out if we didn't run do it */
2136 ret
= WaitForSingleObject(stop_event
, 1000);
2137 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
2139 /* if the stop event didn't fire then RpcMgmtWaitServerListen will wait
2140 * forever, so don't bother calling it in this case */
2141 if (ret
== WAIT_OBJECT_0
)
2143 status
= RpcMgmtWaitServerListen();
2144 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
2147 CloseHandle(stop_event
);
2150 if (pRpcServerRegisterIfEx
)
2152 status
= pRpcServerRegisterIfEx(s_IMixedServer_v0_0_s_ifspec
, NULL
, NULL
,
2153 RPC_IF_ALLOW_CALLBACKS_WITH_NO_AUTH
| RPC_IF_AUTOLISTEN
,
2154 RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
2155 ok(status
== RPC_S_OK
, "RpcServerRegisterIf() failed: %u\n", status
);
2157 run_client("ncalrpc_autolisten");
2159 status
= RpcServerUnregisterIf(s_IMixedServer_v0_0_s_ifspec
, NULL
, TRUE
);
2160 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf() failed: %u\n", status
);
2166 static DWORD WINAPI
listen_test_client_thread(void *binding
)
2170 status
= RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
);
2171 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding\n");
2173 test_is_server_listening(IMixedServer_IfHandle
, RPC_S_OK
);
2177 status
= RpcBindingFree(&IMixedServer_IfHandle
);
2178 ok(status
== RPC_S_OK
, "RpcBindingFree\n");
2182 static DWORD WINAPI
wait_listen_proc(void *arg
)
2187 status
= RpcMgmtWaitServerListen();
2188 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
2194 static void test_stop_wait_for_call(unsigned char *binding
)
2196 HANDLE client_thread
, wait_listen_thread
;
2200 status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
);
2201 ok(status
== RPC_S_OK
, "RpcServerListen failed with status %d\n", status
);
2202 test_is_server_listening(NULL
, RPC_S_OK
);
2204 stop_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2205 ok(stop_wait_event
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2206 stop_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2207 ok(stop_event
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2209 wait_listen_thread
= CreateThread(NULL
, 0, wait_listen_proc
, 0, 0, NULL
);
2210 ok(wait_listen_thread
!= NULL
, "CreateThread failed\n");
2212 client_thread
= CreateThread(NULL
, 0, listen_test_client_thread
, binding
, 0, NULL
);
2213 ok(client_thread
!= NULL
, "CreateThread failed\n");
2214 CloseHandle(client_thread
);
2216 ret
= WaitForSingleObject(stop_event
, 10000);
2217 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
2219 status
= RpcMgmtStopServerListening(NULL
);
2220 ok(status
== RPC_S_OK
, "RpcMgmtStopServerListening\n");
2221 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
2223 ret
= WaitForSingleObject(wait_listen_thread
, 500);
2224 ok(WAIT_TIMEOUT
== ret
, "WaitForSingleObject\n");
2226 SetEvent(stop_wait_event
);
2228 ret
= WaitForSingleObject(wait_listen_thread
, 10000);
2229 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject returned %u\n", ret
);
2231 CloseHandle(wait_listen_thread
);
2233 CloseHandle(stop_wait_event
);
2234 stop_wait_event
= NULL
;
2235 CloseHandle(stop_event
);
2239 static void test_server_listening(void)
2241 static unsigned char np
[] = "ncacn_np";
2242 static unsigned char address_np
[] = "\\\\.";
2243 static unsigned char pipe
[] = PIPE
"listen_test";
2244 static unsigned char ncalrpc
[] = "ncalrpc";
2245 static unsigned char guid
[] = "00000000-4114-0704-2302-000000000000";
2246 unsigned char *binding
;
2249 status
= RpcServerUseProtseqEpA(np
, 0, pipe
, NULL
);
2250 ok(status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", status
);
2252 status
= RpcServerRegisterIf(s_IMixedServer_v0_0_s_ifspec
, NULL
, NULL
);
2253 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed with status %d\n", status
);
2255 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
2256 status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
);
2257 ok(status
== RPC_S_OK
, "RpcServerListen failed with status %d\n", status
);
2258 test_is_server_listening(NULL
, RPC_S_OK
);
2260 status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
);
2261 ok(status
== RPC_S_ALREADY_LISTENING
, "RpcServerListen failed with status %d\n", status
);
2263 status
= RpcMgmtStopServerListening(NULL
);
2264 ok(status
== RPC_S_OK
, "RpcMgmtStopServerListening\n");
2265 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
2267 status
= RpcMgmtWaitServerListen();
2268 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
2270 status
= RpcMgmtWaitServerListen();
2271 ok(status
== RPC_S_NOT_LISTENING
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
2273 /* test that server stop waits for a call in progress */
2274 status
= RpcStringBindingComposeA(NULL
, np
, address_np
, pipe
, NULL
, &binding
);
2275 ok(status
== RPC_S_OK
, "RpcStringBindingCompose\n");
2277 test_stop_wait_for_call(binding
);
2279 status
= RpcStringFreeA(&binding
);
2280 ok(status
== RPC_S_OK
, "RpcStringFree\n");
2282 /* repeat the test using ncalrpc */
2283 status
= RpcServerUseProtseqEpA(ncalrpc
, 0, guid
, NULL
);
2284 ok(status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status
);
2286 status
= RpcStringBindingComposeA(NULL
, ncalrpc
, NULL
, guid
, NULL
, &binding
);
2287 ok(status
== RPC_S_OK
, "RpcStringBindingCompose\n");
2289 test_stop_wait_for_call(binding
);
2291 status
= RpcStringFreeA(&binding
);
2292 ok(status
== RPC_S_OK
, "RpcStringFree\n");
2295 static HANDLE
create_server_process(void)
2297 SECURITY_ATTRIBUTES sec_attr
= { sizeof(sec_attr
), NULL
, TRUE
};
2299 char cmdline
[MAX_PATH
];
2300 PROCESS_INFORMATION info
;
2301 STARTUPINFOA startup
;
2304 memset(&startup
, 0, sizeof startup
);
2305 startup
.cb
= sizeof startup
;
2307 ready_event
= CreateEventW(&sec_attr
, TRUE
, FALSE
, NULL
);
2308 ok(ready_event
!= NULL
, "CreateEvent failed: %u\n", GetLastError());
2310 sprintf(cmdline
, "%s server run %lx", progname
, (UINT_PTR
)ready_event
);
2311 trace("running server process...\n");
2312 ok(CreateProcessA(NULL
, cmdline
, NULL
, NULL
, TRUE
, 0L, NULL
, NULL
, &startup
, &info
), "CreateProcess\n");
2313 ret
= WaitForSingleObject(ready_event
, 10000);
2314 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
2316 ok(CloseHandle(info
.hThread
), "CloseHandle\n");
2317 ok(CloseHandle(ready_event
), "CloseHandle\n");
2318 return info
.hProcess
;
2321 static void run_server(HANDLE ready_event
)
2323 static unsigned char np
[] = "ncacn_np";
2324 static unsigned char pipe
[] = PIPE
"term_test";
2328 status
= RpcServerUseProtseqEpA(np
, 0, pipe
, NULL
);
2329 ok(status
== RPC_S_OK
, "RpcServerUseProtseqEp(ncacn_np) failed with status %d\n", status
);
2331 status
= RpcServerRegisterIf(s_IMixedServer_v0_0_s_ifspec
, NULL
, NULL
);
2332 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed with status %d\n", status
);
2334 test_is_server_listening(NULL
, RPC_S_NOT_LISTENING
);
2335 status
= RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, TRUE
);
2336 ok(status
== RPC_S_OK
, "RpcServerListen failed with status %d\n", status
);
2338 stop_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2339 ok(stop_event
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2341 ret
= SetEvent(ready_event
);
2342 ok(ret
, "SetEvent failed: %u\n", GetLastError());
2344 ret
= WaitForSingleObject(stop_event
, 5000);
2345 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
2347 status
= RpcMgmtWaitServerListen();
2348 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListening failed with status %d\n", status
);
2350 CloseHandle(stop_event
);
2354 static DWORD WINAPI
basic_tests_thread(void *arg
)
2360 static void test_reconnect(void)
2362 static unsigned char np
[] = "ncacn_np";
2363 static unsigned char address_np
[] = "\\\\.";
2364 static unsigned char pipe
[] = PIPE
"term_test";
2365 unsigned char *binding
;
2367 HANDLE server_process
;
2371 server_process
= create_server_process();
2373 ok(RPC_S_OK
== RpcStringBindingComposeA(NULL
, np
, address_np
, pipe
, NULL
, &binding
), "RpcStringBindingCompose\n");
2374 ok(RPC_S_OK
== RpcBindingFromStringBindingA(binding
, &IMixedServer_IfHandle
), "RpcBindingFromStringBinding\n");
2376 for (i
= 0; i
< ARRAY_SIZE(threads
); i
++)
2378 threads
[i
] = CreateThread(NULL
, 0, basic_tests_thread
, 0, 0, NULL
);
2379 ok(threads
[i
] != NULL
, "CreateThread failed: %u\n", GetLastError());
2382 for (i
= 0; i
< ARRAY_SIZE(threads
); i
++)
2384 ret
= WaitForSingleObject(threads
[i
], 10000);
2385 ok(WAIT_OBJECT_0
== ret
, "WaitForSingleObject\n");
2386 CloseHandle(threads
[i
]);
2391 wait_child_process(server_process
);
2392 ok(CloseHandle(server_process
), "CloseHandle\n");
2394 /* create new server, rpcrt4 will connect to it once sending to existing connection fails
2395 * that current connection is broken. */
2396 server_process
= create_server_process();
2400 wait_child_process(server_process
);
2401 ok(CloseHandle(server_process
), "CloseHandle\n");
2403 ok(RPC_S_OK
== RpcStringFreeA(&binding
), "RpcStringFree\n");
2404 ok(RPC_S_OK
== RpcBindingFree(&IMixedServer_IfHandle
), "RpcBindingFree\n");
2407 static BOOL
is_process_elevated(void)
2410 if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY
, &token
))
2412 TOKEN_ELEVATION_TYPE type
;
2416 ret
= GetTokenInformation( token
, TokenElevationType
, &type
, sizeof(type
), &size
);
2417 CloseHandle( token
);
2418 return (ret
&& type
== TokenElevationTypeFull
);
2423 static BOOL
is_firewall_enabled(void)
2426 INetFwMgr
*mgr
= NULL
;
2427 INetFwPolicy
*policy
= NULL
;
2428 INetFwProfile
*profile
= NULL
;
2429 VARIANT_BOOL enabled
= VARIANT_FALSE
;
2431 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
2433 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
2435 ok( hr
== S_OK
, "got %08x\n", hr
);
2436 if (hr
!= S_OK
) goto done
;
2438 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
2439 ok( hr
== S_OK
, "got %08x\n", hr
);
2440 if (hr
!= S_OK
) goto done
;
2442 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
2443 if (hr
!= S_OK
) goto done
;
2445 hr
= INetFwProfile_get_FirewallEnabled( profile
, &enabled
);
2446 ok( hr
== S_OK
, "got %08x\n", hr
);
2449 if (policy
) INetFwPolicy_Release( policy
);
2450 if (profile
) INetFwProfile_Release( profile
);
2451 if (mgr
) INetFwMgr_Release( mgr
);
2452 if (SUCCEEDED( init
)) CoUninitialize();
2453 return (enabled
== VARIANT_TRUE
);
2462 static HRESULT
set_firewall( enum firewall_op op
)
2465 INetFwMgr
*mgr
= NULL
;
2466 INetFwPolicy
*policy
= NULL
;
2467 INetFwProfile
*profile
= NULL
;
2468 INetFwAuthorizedApplication
*app
= NULL
;
2469 INetFwAuthorizedApplications
*apps
= NULL
;
2470 BSTR name
, image
= SysAllocStringLen( NULL
, MAX_PATH
);
2472 if (!GetModuleFileNameW( NULL
, image
, MAX_PATH
))
2474 SysFreeString( image
);
2477 init
= CoInitializeEx( 0, COINIT_APARTMENTTHREADED
);
2479 hr
= CoCreateInstance( &CLSID_NetFwMgr
, NULL
, CLSCTX_INPROC_SERVER
, &IID_INetFwMgr
,
2481 ok( hr
== S_OK
, "got %08x\n", hr
);
2482 if (hr
!= S_OK
) goto done
;
2484 hr
= INetFwMgr_get_LocalPolicy( mgr
, &policy
);
2485 ok( hr
== S_OK
, "got %08x\n", hr
);
2486 if (hr
!= S_OK
) goto done
;
2488 hr
= INetFwPolicy_get_CurrentProfile( policy
, &profile
);
2489 if (hr
!= S_OK
) goto done
;
2491 hr
= INetFwProfile_get_AuthorizedApplications( profile
, &apps
);
2492 ok( hr
== S_OK
, "got %08x\n", hr
);
2493 if (hr
!= S_OK
) goto done
;
2495 hr
= CoCreateInstance( &CLSID_NetFwAuthorizedApplication
, NULL
, CLSCTX_INPROC_SERVER
,
2496 &IID_INetFwAuthorizedApplication
, (void **)&app
);
2497 ok( hr
== S_OK
, "got %08x\n", hr
);
2498 if (hr
!= S_OK
) goto done
;
2500 hr
= INetFwAuthorizedApplication_put_ProcessImageFileName( app
, image
);
2501 if (hr
!= S_OK
) goto done
;
2503 name
= SysAllocString( L
"rpcrt4_test" );
2504 hr
= INetFwAuthorizedApplication_put_Name( app
, name
);
2505 SysFreeString( name
);
2506 ok( hr
== S_OK
, "got %08x\n", hr
);
2507 if (hr
!= S_OK
) goto done
;
2510 hr
= INetFwAuthorizedApplications_Add( apps
, app
);
2511 else if (op
== APP_REMOVE
)
2512 hr
= INetFwAuthorizedApplications_Remove( apps
, image
);
2517 if (app
) INetFwAuthorizedApplication_Release( app
);
2518 if (apps
) INetFwAuthorizedApplications_Release( apps
);
2519 if (policy
) INetFwPolicy_Release( policy
);
2520 if (profile
) INetFwProfile_Release( profile
);
2521 if (mgr
) INetFwMgr_Release( mgr
);
2522 if (SUCCEEDED( init
)) CoUninitialize();
2523 SysFreeString( image
);
2532 BOOL firewall_enabled
= is_firewall_enabled(), firewall_disabled
= FALSE
;
2534 InitFunctionPointers();
2535 set_mixed_interface();
2537 ok(!GetUserNameExA(NameSamCompatible
, NULL
, &size
), "GetUserNameExA\n");
2538 domain_and_user
= HeapAlloc(GetProcessHeap(), 0, size
);
2539 ok(GetUserNameExA(NameSamCompatible
, domain_and_user
, &size
), "GetUserNameExA\n");
2541 argc
= winetest_get_mainargs(&argv
);
2552 trace("Exception %d\n", RpcExceptionCode());
2558 if (!strcmp(argv
[3], "listen"))
2560 test_server_listening();
2562 else if(!strcmp(argv
[2], "run"))
2565 sscanf(argv
[3], "%lx", &event
);
2566 run_server((HANDLE
)event
);
2571 if (firewall_enabled
)
2573 if (is_process_elevated())
2575 HRESULT hr
= set_firewall(APP_ADD
);
2578 firewall_enabled
= FALSE
;
2579 firewall_disabled
= TRUE
;
2583 skip("can't authorize app in firewall %08x\n", hr
);
2588 trace("no privileges, skipping tests to avoid firewall dialog\n");
2592 if (!firewall_enabled
) server();
2594 /* Those tests cause occasional crashes on winxp and win2k3 */
2595 if (GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "RpcExceptionFilter"))
2598 win_skip("Skipping reconnect tests on too old Windows version\n");
2600 run_client("test listen");
2601 if (firewall_disabled
) set_firewall(APP_REMOVE
);
2604 HeapFree(GetProcessHeap(), 0, domain_and_user
);