cbfb7afe3c562237d05d99588990c214df2af969
[reactos.git] / rostests / winetests / rpcrt4 / rpc_protseq.c
1 /*
2 * RPC Protocol Sequence Server Tests
3 *
4 * Copyright 2008-2009 Robert Shearman
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winnt.h>
28 #include <winerror.h>
29
30 #include "rpc.h"
31 #include "rpcdce.h"
32
33 static void test_RpcServerUseProtseq(void)
34 {
35 RPC_STATUS status;
36 RPC_BINDING_VECTOR *bindings;
37 ULONG i;
38 ULONG binding_count_before;
39 ULONG binding_count_after1;
40 ULONG binding_count_after2;
41 ULONG endpoints_registered = 0;
42 static unsigned char iptcp[] = "ncacn_ip_tcp";
43 static unsigned char np[] = "ncacn_np";
44 static unsigned char ncalrpc[] = "ncalrpc";
45
46 status = RpcServerInqBindings(&bindings);
47 if (status == RPC_S_NO_BINDINGS)
48 binding_count_before = 0;
49 else
50 {
51 binding_count_before = bindings->Count;
52 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
53 RpcBindingVectorFree(&bindings);
54 }
55
56 /* show that RpcServerUseProtseqEp(..., NULL, ...) is the same as
57 * RpcServerUseProtseq(...) */
58 status = RpcServerUseProtseqEpA(ncalrpc, 0, NULL, NULL);
59 ok(status == RPC_S_OK || broken(status == RPC_S_INVALID_ENDPOINT_FORMAT),
60 "RpcServerUseProtseqEp with NULL endpoint failed with status %d\n",
61 status);
62
63 /* register protocol sequences without explicit endpoints */
64 status = RpcServerUseProtseqA(np, 0, NULL);
65 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
66 win_skip("ncacn_np not supported\n");
67 else
68 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
69 if (status == RPC_S_OK) endpoints_registered++;
70
71 status = RpcServerUseProtseqA(iptcp, 0, NULL);
72 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
73 if (status == RPC_S_OK) endpoints_registered++;
74
75 status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
76 ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
77 if (status == RPC_S_OK) endpoints_registered++;
78
79 status = RpcServerInqBindings(&bindings);
80 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
81 binding_count_after1 = bindings->Count;
82 ok(binding_count_after1 == binding_count_before + endpoints_registered,
83 "wrong binding count - before: %u, after %u, endpoints registered %u\n",
84 binding_count_before, binding_count_after1, endpoints_registered);
85 for (i = 0; i < bindings->Count; i++)
86 {
87 RPC_CSTR str_bind;
88 status = RpcBindingToStringBindingA(bindings->BindingH[i], &str_bind);
89 ok(status == RPC_S_OK, "RpcBindingToStringBinding failed with status %d\n", status);
90 trace("string binding: %s\n", str_bind);
91 RpcStringFreeA(&str_bind);
92 }
93 RpcBindingVectorFree(&bindings);
94
95 /* re-register - endpoints should be reused */
96 status = RpcServerUseProtseqA(np, 0, NULL);
97 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
98 win_skip("ncacn_np not supported\n");
99 else
100 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
101
102 status = RpcServerUseProtseqA(iptcp, 0, NULL);
103 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
104
105 status = RpcServerUseProtseqA(ncalrpc, 0, NULL);
106 ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
107
108 status = RpcServerInqBindings(&bindings);
109 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
110 binding_count_after2 = bindings->Count;
111 ok(binding_count_after2 == binding_count_after1,
112 "bindings should have been re-used - after1: %u after2: %u\n",
113 binding_count_after1, binding_count_after2);
114 RpcBindingVectorFree(&bindings);
115 }
116
117 static RPC_DISPATCH_FUNCTION IFoo_table[] =
118 {
119 0
120 };
121
122 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable =
123 {
124 0,
125 IFoo_table
126 };
127
128 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface =
129 {
130 sizeof(RPC_SERVER_INTERFACE),
131 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
132 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
133 &IFoo_v0_0_DispatchTable,
134 0,
135 0,
136 0,
137 0,
138 0,
139 };
140
141 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec = (RPC_IF_HANDLE)& IFoo___RpcServerInterface;
142
143 static void test_endpoint_mapper(RPC_CSTR protseq, RPC_CSTR address)
144 {
145 static unsigned char annotation[] = "Test annotation string.";
146 RPC_STATUS status;
147 RPC_BINDING_VECTOR *binding_vector;
148 handle_t handle;
149 unsigned char *binding;
150
151 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
152 ok(status == RPC_S_OK, "%s: RpcServerRegisterIf failed (%u)\n", protseq, status);
153
154 status = RpcServerInqBindings(&binding_vector);
155 ok(status == RPC_S_OK, "%s: RpcServerInqBindings failed with error %u\n", protseq, status);
156
157 /* register endpoints created in test_RpcServerUseProtseq */
158 status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, annotation);
159 ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status);
160 /* reregister the same endpoint with no annotation */
161 status = RpcEpRegisterA(IFoo_v0_0_s_ifspec, binding_vector, NULL, NULL);
162 ok(status == RPC_S_OK, "%s: RpcEpRegisterA failed with error %u\n", protseq, status);
163
164 status = RpcStringBindingComposeA(NULL, protseq, address,
165 NULL, NULL, &binding);
166 ok(status == RPC_S_OK, "%s: RpcStringBindingCompose failed (%u)\n", protseq, status);
167
168 status = RpcBindingFromStringBindingA(binding, &handle);
169 ok(status == RPC_S_OK, "%s: RpcBindingFromStringBinding failed (%u)\n", protseq, status);
170
171 RpcStringFreeA(&binding);
172
173 status = RpcBindingReset(handle);
174 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
175
176 status = RpcEpResolveBinding(handle, IFoo_v0_0_s_ifspec);
177 ok(status == RPC_S_OK || broken(status == RPC_S_SERVER_UNAVAILABLE), /* win9x */
178 "%s: RpcEpResolveBinding failed with error %u\n", protseq, status);
179
180 status = RpcBindingReset(handle);
181 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
182
183 status = RpcBindingFree(&handle);
184 ok(status == RPC_S_OK, "%s: RpcBindingFree failed with error %u\n", protseq, status);
185
186 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
187 ok(status == RPC_S_OK, "%s: RpcServerUnregisterIf failed (%u)\n", protseq, status);
188
189 status = RpcEpUnregister(IFoo_v0_0_s_ifspec, binding_vector, NULL);
190 ok(status == RPC_S_OK, "%s: RpcEpUnregisterA failed with error %u\n", protseq, status);
191
192 status = RpcBindingVectorFree(&binding_vector);
193 ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %u\n", protseq, status);
194 }
195
196 START_TEST( rpc_protseq )
197 {
198 static unsigned char ncacn_np[] = "ncacn_np";
199 static unsigned char ncalrpc[] = "ncalrpc";
200 static unsigned char np_address[] = ".";
201
202 test_RpcServerUseProtseq();
203 test_endpoint_mapper(ncacn_np, np_address);
204 test_endpoint_mapper(ncalrpc, NULL);
205 }