Release 1.6-rc2.
[wine/testsucceed.git] / dlls / rpcrt4 / tests / rpc_protseq.c
blob36aea30bf88a62546d917deea4f8371736ae4e82
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "wine/test.h"
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winnt.h>
28 #include <winerror.h>
30 #include "rpc.h"
31 #include "rpcdce.h"
33 static void test_RpcServerUseProtseq(void)
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";
46 status = RpcServerInqBindings(&bindings);
47 if (status == RPC_S_NO_BINDINGS)
48 binding_count_before = 0;
49 else
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",
61 status);
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");
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++;
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++)
87 RPC_CSTR str_bind;
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");
99 else
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 =
125 IFoo_table
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.";
146 RPC_STATUS status;
147 RPC_BINDING_VECTOR *binding_vector;
148 handle_t handle;
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);
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);
164 status = RpcStringBindingCompose(NULL, protseq, address,
165 NULL, NULL, &binding);
166 ok(status == RPC_S_OK, "%s: RpcStringBindingCompose failed (%u)\n", protseq, status);
168 status = RpcBindingFromStringBinding(binding, &handle);
169 ok(status == RPC_S_OK, "%s: RpcBindingFromStringBinding failed (%u)\n", protseq, status);
171 RpcStringFree(&binding);
173 status = RpcBindingReset(handle);
174 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
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);
180 status = RpcBindingReset(handle);
181 ok(status == RPC_S_OK, "%s: RpcBindingReset failed with error %u\n", protseq, status);
183 status = RpcBindingFree(&handle);
184 ok(status == RPC_S_OK, "%s: RpcBindingFree failed with error %u\n", protseq, status);
186 status = RpcServerUnregisterIf(NULL, NULL, FALSE);
187 ok(status == RPC_S_OK, "%s: RpcServerUnregisterIf failed (%u)\n", protseq, status);
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);
192 status = RpcBindingVectorFree(&binding_vector);
193 ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %u\n", protseq, status);
196 START_TEST( rpc_protseq )
198 static unsigned char ncacn_np[] = "ncacn_np";
199 static unsigned char ncalrpc[] = "ncalrpc";
200 static unsigned char np_address[] = ".";
202 test_RpcServerUseProtseq();
203 test_endpoint_mapper(ncacn_np, np_address);
204 test_endpoint_mapper(ncalrpc, NULL);