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 void test_rpc_ncacn_ip_tcp(void)
181 static unsigned char foo[] = "foo";
182 static unsigned char ncacn_ip_tcp[] = "ncacn_ip_tcp";
184 status = RpcNetworkIsProtseqValid(foo);
185 ok(status == RPC_S_INVALID_RPC_PROTSEQ, "return wrong\n");
187 status = RpcNetworkIsProtseqValid(ncacn_ip_tcp);
188 ok(status == RPC_S_OK, "return wrong\n");
191 /* this is what's generated with MS/RPC - it includes an extra 2
192 * bytes in the protocol floor */
193 static const unsigned char tower_data_tcp_ip1[] =
195 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
196 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
197 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
198 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
199 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
200 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
201 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x02,
202 0x00,0x00,0x00,0x01,0x00,0x07,0x02,0x00,
203 0x00,0x87,0x01,0x00,0x09,0x04,0x00,0x0a,
206 /* this is the optimal data that i think should be generated */
207 static const unsigned char tower_data_tcp_ip2[] =
209 0x05,0x00,0x13,0x00,0x0d,0x00,0xdb,0xf1,
210 0xa4,0x47,0xca,0x67,0x10,0xb3,0x1f,0x00,
211 0xdd,0x01,0x06,0x62,0xda,0x00,0x00,0x02,
212 0x00,0x00,0x00,0x13,0x00,0x0d,0x04,0x5d,
213 0x88,0x8a,0xeb,0x1c,0xc9,0x11,0x9f,0xe8,
214 0x08,0x00,0x2b,0x10,0x48,0x60,0x02,0x00,
215 0x02,0x00,0x00,0x00,0x01,0x00,0x0b,0x00,
216 0x00,0x01,0x00,0x07,0x02,0x00,0x00,0x87,
217 0x01,0x00,0x09,0x04,0x00,0x0a,0x00,0x00,
221 static void test_towers(void)
225 static const RPC_SYNTAX_IDENTIFIER mapi_if_id = { { 0xa4f1db00, 0xca47, 0x1067, { 0xb3, 0x1f, 0x00, 0xdd, 0x01, 0x06, 0x62, 0xda } }, { 0, 0 } };
226 static const RPC_SYNTAX_IDENTIFIER ndr_syntax = { { 0x8a885d04, 0x1ceb, 0x11c9, { 0x9f, 0xe8, 0x08, 0x00, 0x2b, 0x10, 0x48, 0x60 } }, { 2, 0 } };
227 RPC_SYNTAX_IDENTIFIER object, syntax;
228 char *protseq, *endpoint, *address;
231 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "10.0.0.1", &tower);
232 ok(ret == RPC_S_OK, "TowerConstruct failed with error %ld\n", ret);
234 /* first check we have the right amount of data */
235 ok(tower->tower_length == sizeof(tower_data_tcp_ip1) ||
236 tower->tower_length == sizeof(tower_data_tcp_ip2),
237 "Wrong size of tower %d\n", tower->tower_length);
239 /* then do a byte-by-byte comparison */
240 same = ((tower->tower_length == sizeof(tower_data_tcp_ip1)) &&
241 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip1, sizeof(tower_data_tcp_ip1))) ||
242 ((tower->tower_length == sizeof(tower_data_tcp_ip2)) &&
243 !memcmp(&tower->tower_octet_string, tower_data_tcp_ip2, sizeof(tower_data_tcp_ip2)));
245 ok(same, "Tower data differs\n");
249 for (i = 0; i < tower->tower_length; i++)
251 if (i % 8 == 0) printf(" ");
252 printf("0x%02x,", tower->tower_octet_string[i]);
253 if (i % 8 == 7) printf("\n");
258 ret = TowerExplode(tower, &object, &syntax, &protseq, &endpoint, &address);
259 ok(ret == RPC_S_OK, "TowerExplode failed with error %ld\n", ret);
260 ok(!memcmp(&object, &mapi_if_id, sizeof(mapi_if_id)), "object id didn't match\n");
261 ok(!memcmp(&syntax, &ndr_syntax, sizeof(syntax)), "syntax id didn't match\n");
262 ok(!strcmp(protseq, "ncacn_ip_tcp"), "protseq was \"%s\" instead of \"ncacn_ip_tcp\"\n", protseq);
263 ok(!strcmp(endpoint, "135"), "endpoint was \"%s\" instead of \"135\"\n", endpoint);
264 ok(!strcmp(address, "10.0.0.1"), "address was \"%s\" instead of \"10.0.0.1\"\n", address);
270 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, NULL);
271 ok(ret == RPC_S_OK, "TowerExplode failed with error %ld\n", ret);
275 /* test the behaviour for ip_tcp with name instead of dotted IP notation */
276 ret = TowerConstruct(&mapi_if_id, &ndr_syntax, "ncacn_ip_tcp", "135", "localhost", &tower);
277 ok(ret == RPC_S_OK, "TowerConstruct failed with error %ld\n", ret);
278 ret = TowerExplode(tower, NULL, NULL, NULL, NULL, &address);
279 ok(ret == RPC_S_OK, "TowerExplode failed with error %ld\n", ret);
280 ok(!strcmp(address, "0.0.0.0"), "address was \"%s\" instead of \"0.0.0.0\"\n", address);
288 trace ( " ** Uuid Conversion and Comparison Tests **\n" );
289 UuidConversionAndComparison();
290 trace ( " ** DceErrorInqText **\n");
291 TestDceErrorInqText();
292 test_rpc_ncacn_ip_tcp();