2 * RPC Protocol Sequence Server Tests
4 * Copyright 2008-2009 Robert Shearman
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
24 #include "wine/test.h"
33 static void test_RpcServerUseProtseq(void)
36 RPC_BINDING_VECTOR *bindings;
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";
46 status = RpcServerInqBindings(&bindings);
47 if (status == RPC_S_NO_BINDINGS)
48 binding_count_before = 0;
51 binding_count_before = bindings->Count;
52 ok(status == RPC_S_OK, "RpcServerInqBindings failed with status %d\n", status);
53 RpcBindingVectorFree(&bindings);
56 /* show that RpcServerUseProtseqEp(..., NULL, ...) is the same as
57 * RpcServerUseProtseq(...) */
58 status = RpcServerUseProtseqEp(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",
63 /* register protocol sequences without explicit endpoints */
64 status = RpcServerUseProtseq(np, 0, NULL);
65 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
66 win_skip("ncacn_np not supported\n");
68 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
69 if (status == RPC_S_OK) endpoints_registered++;
71 status = RpcServerUseProtseq(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++;
75 status = RpcServerUseProtseq(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++;
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++)
88 status = RpcBindingToStringBinding(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 RpcStringFree(&str_bind);
93 RpcBindingVectorFree(&bindings);
95 /* re-register - endpoints should be reused */
96 status = RpcServerUseProtseq(np, 0, NULL);
97 if (status == RPC_S_PROTSEQ_NOT_SUPPORTED)
98 win_skip("ncacn_np not supported\n");
100 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_np) failed with status %d\n", status);
102 status = RpcServerUseProtseq(iptcp, 0, NULL);
103 ok(status == RPC_S_OK, "RpcServerUseProtseq(ncacn_ip_tcp) failed with status %d\n", status);
105 status = RpcServerUseProtseq(ncalrpc, 0, NULL);
106 ok(status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", status);
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);
117 static RPC_DISPATCH_FUNCTION IFoo_table[] =
122 static RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable =
128 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface =
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,
141 static RPC_IF_HANDLE IFoo_v0_0_s_ifspec = (RPC_IF_HANDLE)& IFoo___RpcServerInterface;
143 static void test_endpoint_mapper(RPC_CSTR protseq, RPC_CSTR address)
145 static unsigned char annotation[] = "Test annotation string.";
147 RPC_BINDING_VECTOR *binding_vector;
149 unsigned char *binding;
151 status = RpcServerRegisterIf(IFoo_v0_0_s_ifspec, NULL, NULL);
152 ok(status == RPC_S_OK, "%s: RpcServerRegisterIf failed (%u)\n", protseq, status);
154 status = RpcServerInqBindings(&binding_vector);
155 ok(status == RPC_S_OK, "%s: RpcServerInqBindings failed with error %u\n", protseq, status);
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);
161 status = RpcStringBindingCompose(NULL, protseq, address,
162 NULL, NULL, &binding);
163 ok(status == RPC_S_OK, "%s: RpcStringBindingCompose failed (%u)\n", protseq, status);
165 status = RpcBindingFromStringBinding(binding, &handle);
166 ok(status == RPC_S_OK, "%s: RpcBindingFromStringBinding failed (%u)\n", protseq, status);
168 RpcStringFree(&binding);
170 status = RpcBindingReset(handle);
171 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
173 RpcStringFree(&binding);
175 status = RpcEpResolveBinding(handle, IFoo_v0_0_s_ifspec);
176 ok(status == RPC_S_OK || broken(status == RPC_S_SERVER_UNAVAILABLE), /* win9x */
177 "%s: RpcEpResolveBinding failed with error %u\n", protseq, status);
179 status = RpcBindingReset(handle);
180 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
182 status = RpcBindingFree(&handle);
183 ok(status == RPC_S_OK, "%s: RpcBindingFree failed with error %u\n", protseq, status);
185 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
186 ok(status == RPC_S_OK, "%s: RpcServerUnregisterIf failed (%u)\n", protseq, status);
188 status = RpcEpUnregister(IFoo_v0_0_s_ifspec, binding_vector, NULL);
189 ok(status == RPC_S_OK, "%s: RpcEpUnregisterA failed with error %u\n", protseq, status);
191 status = RpcBindingVectorFree(&binding_vector);
192 ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %u\n", protseq, status);
195 START_TEST( rpc_protseq )
197 static unsigned char ncacn_np[] = "ncacn_np";
198 static unsigned char ncalrpc[] = "ncalrpc";
199 static unsigned char np_address[] = ".";
201 test_RpcServerUseProtseq();
202 test_endpoint_mapper(ncacn_np, np_address);
203 test_endpoint_mapper(ncalrpc, NULL);