2 * Unit test suite for rpc functions
4 * Copyright 2002 Greg Turner
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 typedef unsigned int unsigned32
;
36 unsigned32 tower_length
;
37 /* [size_is] */ byte tower_octet_string
[ 1 ];
40 RPC_STATUS WINAPI
TowerExplode(const twr_t
*tower
, RPC_SYNTAX_IDENTIFIER
*object
, RPC_SYNTAX_IDENTIFIER
*syntax
, char **protseq
, char **endpoint
, char **address
);
41 RPC_STATUS WINAPI
TowerConstruct(const RPC_SYNTAX_IDENTIFIER
*object
, const RPC_SYNTAX_IDENTIFIER
*syntax
, const char *protseq
, const char *endpoint
, const char *address
, twr_t
**tower
);
43 static UUID Uuid_Table
[10] = {
44 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 0 (null) */
45 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8a} }, /* 1 */
46 { 0xabadfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 2 */
47 { 0x93da375c, 0x1324, 0x1355, {0x87, 0xff, 0x49, 0x44, 0x34, 0x44, 0x22, 0x19} }, /* 3 */
48 { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8b} }, /* 4 (~1) */
49 { 0x9badfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 5 (~2) */
50 { 0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 6 (~0) */
51 { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} }, /* 7 (~0) */
52 { 0x12312312, 0x1231, 0x1231, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff} }, /* 8 */
53 { 0x11111111, 0x1111, 0x1111, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} } /* 9 */
56 /* index of "10" means "NULL" */
57 static BOOL Uuid_Comparison_Grid
[11][11] = {
58 { TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
},
59 { FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
},
60 { FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
},
61 { FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
},
62 { FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
},
63 { FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
},
64 { FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
, FALSE
},
65 { FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, FALSE
},
66 { FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
},
67 { FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
, FALSE
},
68 { TRUE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, FALSE
, TRUE
}
71 static void UuidConversionAndComparison(void) {
77 UUID Uuid1
, Uuid2
, *PUuid1
, *PUuid2
;
83 for (i1
= 0; i1
< 11; i1
++)
84 for (i2
= 0; i2
< 11; i2
++) {
86 Uuid1
= Uuid_Table
[i1
];
92 Uuid2
= Uuid_Table
[i2
];
97 ok( (UuidEqual(PUuid1
, PUuid2
, &rslt
) == Uuid_Comparison_Grid
[i1
][i2
]), "UUID Equality\n" );
100 /* Uuid to String to Uuid (char) */
101 for (i1
= 0; i1
< 10; i1
++) {
102 Uuid1
= Uuid_Table
[i1
];
103 ok( (UuidToStringA(&Uuid1
, (unsigned char**)&str
) == RPC_S_OK
), "Simple UUID->String copy\n" );
104 ok( (UuidFromStringA((unsigned char*)str
, &Uuid2
) == RPC_S_OK
), "Simple String->UUID copy from generated UUID String\n" );
105 ok( UuidEqual(&Uuid1
, &Uuid2
, &rslt
), "Uuid -> String -> Uuid transform\n" );
106 /* invalid uuid tests -- size of valid UUID string=36 */
107 for (i2
= 0; i2
< 36; i2
++) {
109 str
[i2
] = 'g'; /* whatever, but "g" is a good boundary condition */
110 ok( (UuidFromStringA((unsigned char*)str
, &Uuid1
) == RPC_S_INVALID_STRING_UUID
), "Invalid UUID String\n" );
111 str
[i2
] = x
; /* change it back so remaining tests are interesting. */
115 /* Uuid to String to Uuid (wchar) */
116 for (i1
= 0; i1
< 10; i1
++) {
117 Uuid1
= Uuid_Table
[i1
];
118 rslt
=UuidToStringW(&Uuid1
, &wstr
);
119 if (rslt
==RPC_S_CANNOT_SUPPORT
) {
120 /* Must be Win9x (no Unicode support), skip the tests */
123 ok( (rslt
== RPC_S_OK
), "Simple UUID->WString copy\n" );
124 ok( (UuidFromStringW(wstr
, &Uuid2
) == RPC_S_OK
), "Simple WString->UUID copy from generated UUID String\n" );
125 ok( UuidEqual(&Uuid1
, &Uuid2
, &rslt
), "Uuid -> WString -> Uuid transform\n" );
126 /* invalid uuid tests -- size of valid UUID string=36 */
127 for (i2
= 0; i2
< 36; i2
++) {
129 wstr
[i2
] = 'g'; /* whatever, but "g" is a good boundary condition */
130 ok( (UuidFromStringW(wstr
, &Uuid1
) == RPC_S_INVALID_STRING_UUID
), "Invalid UUID WString\n" );
131 wstr
[i2
] = wx
; /* change it back so remaining tests are interesting. */
136 static void TestDceErrorInqText (void)
138 char bufferInvalid
[1024];
139 char buffer
[1024]; /* The required size is not documented but would
144 dwCount
= FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM
|
145 FORMAT_MESSAGE_IGNORE_INSERTS
,
146 NULL
, RPC_S_NOT_RPC_ERROR
, 0, bufferInvalid
,
147 sizeof(bufferInvalid
)/sizeof(bufferInvalid
[0]), NULL
);
149 /* A random sample of DceErrorInqText */
151 ok ((DceErrorInqTextA (0, (unsigned char*)buffer
) == RPC_S_OK
),
152 "DceErrorInqTextA(0...)\n");
153 /* A real RPC_S error */
154 ok ((DceErrorInqTextA (RPC_S_INVALID_STRING_UUID
, (unsigned char*)buffer
) == RPC_S_OK
),
155 "DceErrorInqTextA(valid...)\n");
159 /* A message for which FormatMessage should fail
160 * which should return RPC_S_OK and the
161 * fixed "not valid" message
163 ok ((DceErrorInqTextA (35, (unsigned char*)buffer
) == RPC_S_OK
&&
164 strcmp (buffer
, bufferInvalid
) == 0),
165 "DceErrorInqTextA(unformattable...)\n");
166 /* One for which FormatMessage should succeed but
167 * DceErrorInqText should "fail"
168 * 3814 is generally quite a long message
170 ok ((DceErrorInqTextA (3814, (unsigned char*)buffer
) == RPC_S_OK
&&
171 strcmp (buffer
, bufferInvalid
) == 0),
172 "DceErrorInqTextA(deviation...)\n");
175 ok (0, "Cannot set up for DceErrorInqText\n");
178 static RPC_DISPATCH_FUNCTION IFoo_table
[] =
183 RPC_DISPATCH_TABLE IFoo_v0_0_DispatchTable
=
189 static const RPC_SERVER_INTERFACE IFoo___RpcServerInterface
=
191 sizeof(RPC_SERVER_INTERFACE
),
192 {{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x34}},{0,0}},
193 {{0x8a885d04,0x1ceb,0x11c9,{0x9f,0xe8,0x08,0x00,0x2b,0x10,0x48,0x60}},{2,0}},
194 &IFoo_v0_0_DispatchTable
,
202 RPC_IF_HANDLE IFoo_v0_0_s_ifspec
= (RPC_IF_HANDLE
)& IFoo___RpcServerInterface
;
204 static void test_rpc_ncacn_ip_tcp(void)
207 unsigned char *binding
;
208 handle_t IFoo_IfHandle
;
209 static unsigned char foo
[] = "foo";
210 static unsigned char ncacn_ip_tcp
[] = "ncacn_ip_tcp";
211 static unsigned char address
[] = "127.0.0.1";
212 static unsigned char endpoint
[] = "4114";
214 status
= RpcNetworkIsProtseqValid(foo
);
215 ok(status
== RPC_S_INVALID_RPC_PROTSEQ
, "return wrong\n");
217 status
= RpcNetworkIsProtseqValid(ncacn_ip_tcp
);
218 ok(status
== RPC_S_OK
, "return wrong\n");
220 status
= RpcMgmtStopServerListening(NULL
);
222 ok(status
== RPC_S_NOT_LISTENING
,
223 "wrong RpcMgmtStopServerListening error (%lu)\n", status
);
226 status
= RpcMgmtWaitServerListen();
227 ok(status
== RPC_S_NOT_LISTENING
,
228 "wrong RpcMgmtWaitServerListen error status (%lu)\n", status
);
230 status
= RpcServerListen(1, 20, FALSE
);
231 ok(status
== RPC_S_NO_PROTSEQS_REGISTERED
,
232 "wrong RpcServerListen error (%lu)\n", status
);
234 status
= RpcServerUseProtseqEp(ncacn_ip_tcp
, 20, endpoint
, NULL
);
235 ok(status
== RPC_S_OK
, "RpcServerUseProtseqEp failed (%lu)\n", status
);
237 status
= RpcServerRegisterIf(IFoo_v0_0_s_ifspec
, NULL
, NULL
);
238 ok(status
== RPC_S_OK
, "RpcServerRegisterIf failed (%lu)\n", status
);
240 status
= RpcServerListen(1, 20, TRUE
);
242 ok(status
== RPC_S_OK
, "RpcServerListen failed (%lu)\n", status
);
245 status
= RpcServerListen(1, 20, TRUE
);
247 ok(status
== RPC_S_ALREADY_LISTENING
,
248 "wrong RpcServerListen error (%lu)\n", status
);
251 status
= RpcStringBindingCompose(NULL
, ncacn_ip_tcp
, address
,
252 endpoint
, NULL
, &binding
);
253 ok(status
== RPC_S_OK
, "RpcStringBindingCompose failed (%lu)\n", status
);
255 status
= RpcBindingFromStringBinding(binding
, &IFoo_IfHandle
);
256 ok(status
== RPC_S_OK
, "RpcBindingFromStringBinding failed (%lu)\n",
259 status
= RpcMgmtStopServerListening(NULL
);
260 ok(status
== RPC_S_OK
, "RpcMgmtStopServerListening failed (%lu)\n",
263 status
= RpcMgmtStopServerListening(NULL
);
264 ok(status
== RPC_S_OK
, "RpcMgmtStopServerListening failed (%lu)\n",
267 status
= RpcServerUnregisterIf(NULL
, NULL
, FALSE
);
268 ok(status
== RPC_S_OK
, "RpcServerUnregisterIf failed (%lu)\n", status
);
270 status
= RpcMgmtWaitServerListen();
272 ok(status
== RPC_S_OK
, "RpcMgmtWaitServerListen failed (%lu)\n", status
);
275 status
= RpcStringFree(&binding
);
276 ok(status
== RPC_S_OK
, "RpcStringFree failed (%lu)\n", status
);
278 status
= RpcBindingFree(&IFoo_IfHandle
);
279 ok(status
== RPC_S_OK
, "RpcBindingFree failed (%lu)\n", status
);
282 /* this is what's generated with MS/RPC - it includes an extra 2
283 * bytes in the protocol floor */
284 static const unsigned char tower_data_tcp_ip1
[] =
286 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
287 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
288 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
289 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
290 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
291 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
292 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x02,
293 0x00,0x00,0x00,0x01,0x00,0x07,0x02,0x00,
294 0x00,0x87,0x01,0x00,0x09,0x04,0x00,0x0a,
297 /* this is the optimal data that i think should be generated */
298 static const unsigned char tower_data_tcp_ip2
[] =
300 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
301 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
302 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
303 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
304 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
305 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
306 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x00,
307 0x00,0x01,0x00,0x07,0x02,0x00,0x00,0x87,
308 0x01,0x00,0x09,0x04,0x00,0x0a,0x00,0x00,
312 static void test_towers(void)
316 static const RPC_SYNTAX_IDENTIFIER mapi_if_id
= { { 0xa4f1db00, 0xca47, 0x1067, { 0xb3, 0x1f, 0x00, 0xdd, 0x01, 0x06, 0x62, 0xda } }, { 0, 0 } };
317 static const RPC_SYNTAX_IDENTIFIER ndr_syntax
= { { 0x8a885d04, 0x1ceb, 0x11c9, { 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60 } }, { 2, 0 } };
318 RPC_SYNTAX_IDENTIFIER object
, syntax
;
319 char *protseq
, *endpoint
, *address
;
322 ret
= TowerConstruct(&mapi_if_id
, &ndr_syntax
, "ncacn_ip_tcp", "135", "10.0.0.1", &tower
);
323 ok(ret
== RPC_S_OK
, "TowerConstruct failed with error %ld\n", ret
);
325 /* first check we have the right amount of data */
326 ok(tower
->tower_length
== sizeof(tower_data_tcp_ip1
) ||
327 tower
->tower_length
== sizeof(tower_data_tcp_ip2
),
328 "Wrong size of tower %d\n", tower
->tower_length
);
330 /* then do a byte-by-byte comparison */
331 same
= ((tower
->tower_length
== sizeof(tower_data_tcp_ip1
)) &&
332 !memcmp(&tower
->tower_octet_string
, tower_data_tcp_ip1
, sizeof(tower_data_tcp_ip1
))) ||
333 ((tower
->tower_length
== sizeof(tower_data_tcp_ip2
)) &&
334 !memcmp(&tower
->tower_octet_string
, tower_data_tcp_ip2
, sizeof(tower_data_tcp_ip2
)));
336 ok(same
, "Tower data differs\n");
340 for (i
= 0; i
< tower
->tower_length
; i
++)
342 if (i
% 8 == 0) printf(" ");
343 printf("0x%02x,", tower
->tower_octet_string
[i
]);
344 if (i
% 8 == 7) printf("\n");
349 ret
= TowerExplode(tower
, &object
, &syntax
, &protseq
, &endpoint
, &address
);
350 ok(ret
== RPC_S_OK
, "TowerExplode failed with error %ld\n", ret
);
351 ok(!memcmp(&object
, &mapi_if_id
, sizeof(mapi_if_id
)), "object id didn't match\n");
352 ok(!memcmp(&syntax
, &ndr_syntax
, sizeof(syntax
)), "syntax id didn't match\n");
353 ok(!strcmp(protseq
, "ncacn_ip_tcp"), "protseq was \"%s\" instead of \"ncacn_ip_tcp\"\n", protseq
);
354 ok(!strcmp(endpoint
, "135"), "endpoint was \"%s\" instead of \"135\"\n", endpoint
);
355 ok(!strcmp(address
, "10.0.0.1"), "address was \"%s\" instead of \"10.0.0.1\"\n", address
);
361 ret
= TowerExplode(tower
, NULL
, NULL
, NULL
, NULL
, NULL
);
362 ok(ret
== RPC_S_OK
, "TowerExplode failed with error %ld\n", ret
);
366 /* test the behaviour for ip_tcp with name instead of dotted IP notation */
367 ret
= TowerConstruct(&mapi_if_id
, &ndr_syntax
, "ncacn_ip_tcp", "135", "localhost", &tower
);
368 ok(ret
== RPC_S_OK
, "TowerConstruct failed with error %ld\n", ret
);
369 ret
= TowerExplode(tower
, NULL
, NULL
, NULL
, NULL
, &address
);
370 ok(ret
== RPC_S_OK
, "TowerExplode failed with error %ld\n", ret
);
371 ok(!strcmp(address
, "0.0.0.0"), "address was \"%s\" instead of \"0.0.0.0\"\n", address
);
379 trace ( " ** Uuid Conversion and Comparison Tests **\n" );
380 UuidConversionAndComparison();
381 trace ( " ** DceErrorInqText **\n");
382 TestDceErrorInqText();
383 test_rpc_ncacn_ip_tcp();