makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / webservices / tests / msg.c
blobed399db6364bac497f0d98652f9646480b7c3d8b
1 /*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
20 #include "windows.h"
21 #include "webservices.h"
22 #include "wine/test.h"
24 static void test_WsCreateMessage(void)
26 HRESULT hr;
27 WS_MESSAGE *msg;
28 WS_MESSAGE_STATE state;
29 WS_ENVELOPE_VERSION env_version;
30 WS_ADDRESSING_VERSION addr_version;
31 WS_MESSAGE_PROPERTY prop;
33 hr = WsCreateMessage( 0, 0, NULL, 0, NULL, NULL );
34 ok( hr == E_INVALIDARG, "got %08x\n", hr );
36 hr = WsCreateMessage( 0, 0, NULL, 0, &msg, NULL );
37 ok( hr == E_INVALIDARG, "got %08x\n", hr );
39 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, 0, NULL, 0, &msg, NULL );
40 ok( hr == E_INVALIDARG, "got %08x\n", hr );
42 hr = WsCreateMessage( 0, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg, NULL );
43 ok( hr == E_INVALIDARG, "got %08x\n", hr );
45 env_version = WS_ENVELOPE_VERSION_SOAP_1_1;
46 prop.id = WS_MESSAGE_PROPERTY_ENVELOPE_VERSION;
47 prop.value = &env_version;
48 prop.valueSize = sizeof(env_version);
49 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, &prop,
50 1, &msg, NULL );
51 ok( hr == E_INVALIDARG, "got %08x\n", hr );
53 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL,
54 0, &msg, NULL );
55 ok( hr == S_OK, "got %08x\n", hr );
57 state = 0xdeadbeef;
58 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
59 ok( hr == S_OK, "got %08x\n", hr );
60 ok( state == WS_MESSAGE_STATE_EMPTY, "got %u\n", state );
62 env_version = 0xdeadbeef;
63 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
64 sizeof(env_version), NULL );
65 ok( hr == S_OK, "got %08x\n", hr );
66 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_1, "got %u\n", env_version );
68 addr_version = 0xdeadbeef;
69 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
70 sizeof(addr_version), NULL );
71 ok( hr == S_OK, "got %08x\n", hr );
72 ok( addr_version == WS_ADDRESSING_VERSION_0_9, "got %u\n", addr_version );
74 state = WS_MESSAGE_STATE_EMPTY;
75 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
76 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
78 env_version = WS_ENVELOPE_VERSION_SOAP_1_1;
79 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
80 sizeof(env_version), NULL );
81 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
83 addr_version = WS_ADDRESSING_VERSION_0_9;
84 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
85 sizeof(addr_version), NULL );
86 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
87 WsFreeMessage( msg );
90 static void test_WsCreateMessageForChannel(void)
92 HRESULT hr;
93 WS_CHANNEL *channel;
94 WS_MESSAGE *msg;
95 WS_MESSAGE_STATE state;
96 WS_ENVELOPE_VERSION env_version;
97 WS_ADDRESSING_VERSION addr_version;
98 WS_CHANNEL_PROPERTY prop;
99 BOOL addressed;
101 hr = WsCreateMessageForChannel( NULL, NULL, 0, NULL, NULL );
102 ok( hr == E_INVALIDARG, "got %08x\n", hr );
104 hr = WsCreateMessageForChannel( NULL, NULL, 0, &msg, NULL );
105 ok( hr == E_INVALIDARG, "got %08x\n", hr );
107 /* HTTP */
108 hr = WsCreateChannel( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, NULL, 0, NULL,
109 &channel, NULL );
110 ok( hr == S_OK, "got %08x\n", hr );
112 hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
113 ok( hr == S_OK, "got %08x\n", hr );
115 state = 0xdeadbeef;
116 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
117 ok( hr == S_OK, "got %08x\n", hr );
118 ok( state == WS_MESSAGE_STATE_EMPTY, "got %u\n", state );
120 env_version = 0xdeadbeef;
121 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
122 sizeof(env_version), NULL );
123 ok( hr == S_OK, "got %08x\n", hr );
124 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_2, "got %u\n", env_version );
126 addr_version = 0xdeadbeef;
127 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
128 sizeof(addr_version), NULL );
129 ok( hr == S_OK, "got %08x\n", hr );
130 ok( addr_version == WS_ADDRESSING_VERSION_1_0, "got %u\n", addr_version );
132 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
133 NULL );
134 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
136 WsFreeChannel( channel );
137 WsFreeMessage( msg );
139 env_version = WS_ENVELOPE_VERSION_SOAP_1_1;
140 prop.id = WS_CHANNEL_PROPERTY_ENVELOPE_VERSION;
141 prop.value = &env_version;
142 prop.valueSize = sizeof(env_version);
143 hr = WsCreateChannel( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &prop, 1, NULL,
144 &channel, NULL );
145 ok( hr == S_OK, "got %08x\n", hr );
147 hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
148 ok( hr == S_OK, "got %08x\n", hr );
150 env_version = 0xdeadbeef;
151 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
152 sizeof(env_version), NULL );
153 ok( hr == S_OK, "got %08x\n", hr );
154 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_1, "got %u\n", env_version );
156 WsFreeChannel( channel );
157 WsFreeMessage( msg );
159 /* TCP */
160 hr = WsCreateChannel( WS_CHANNEL_TYPE_DUPLEX_SESSION, WS_TCP_CHANNEL_BINDING, NULL, 0, NULL,
161 &channel, NULL );
162 ok( hr == S_OK, "got %08x\n", hr );
164 hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
165 ok( hr == S_OK, "got %08x\n", hr );
167 env_version = 0xdeadbeef;
168 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
169 sizeof(env_version), NULL );
170 ok( hr == S_OK, "got %08x\n", hr );
171 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_2, "got %u\n", env_version );
173 addr_version = 0xdeadbeef;
174 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
175 sizeof(addr_version), NULL );
176 ok( hr == S_OK, "got %08x\n", hr );
177 ok( addr_version == WS_ADDRESSING_VERSION_1_0, "got %u\n", addr_version );
179 WsFreeChannel( channel );
180 WsFreeMessage( msg );
182 /* UDP */
183 hr = WsCreateChannel( WS_CHANNEL_TYPE_DUPLEX, WS_UDP_CHANNEL_BINDING, NULL, 0, NULL,
184 &channel, NULL );
185 ok( hr == S_OK, "got %08x\n", hr );
187 hr = WsCreateMessageForChannel( channel, NULL, 0, &msg, NULL );
188 ok( hr == S_OK, "got %08x\n", hr );
190 env_version = 0xdeadbeef;
191 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
192 sizeof(env_version), NULL );
193 ok( hr == S_OK, "got %08x\n", hr );
194 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_2, "got %u\n", env_version );
196 addr_version = 0xdeadbeef;
197 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
198 sizeof(addr_version), NULL );
199 ok( hr == S_OK, "got %08x\n", hr );
200 ok( addr_version == WS_ADDRESSING_VERSION_1_0, "got %u\n", addr_version );
202 WsFreeChannel( channel );
203 WsFreeMessage( msg );
206 static void test_WsInitializeMessage(void)
208 HRESULT hr;
209 WS_MESSAGE *msg;
210 WS_MESSAGE_STATE state;
211 WS_ENVELOPE_VERSION env_version;
212 WS_ADDRESSING_VERSION addr_version;
213 BOOL addressed;
215 hr = WsInitializeMessage( NULL, WS_REQUEST_MESSAGE, NULL, NULL );
216 ok( hr == E_INVALIDARG, "got %08x\n", hr );
218 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL,
219 0, &msg, NULL );
220 ok( hr == S_OK, "got %08x\n", hr );
222 hr = WsInitializeMessage( msg, 0xdeadbeef, NULL, NULL );
223 ok( hr == E_INVALIDARG, "got %08x\n", hr );
225 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
226 ok( hr == S_OK, "got %08x\n", hr );
228 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
229 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
231 state = 0xdeadbeef;
232 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
233 ok( hr == S_OK, "got %08x\n", hr );
234 ok( state == WS_MESSAGE_STATE_INITIALIZED, "got %u\n", state );
236 addressed = -1;
237 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
238 NULL );
239 ok( hr == S_OK, "got %08x\n", hr );
240 ok( !addressed, "unexpected value %d\n", addressed );
242 state = WS_MESSAGE_STATE_EMPTY;
243 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
244 ok( hr == E_INVALIDARG, "got %08x\n", hr );
246 env_version = WS_ENVELOPE_VERSION_SOAP_1_1;
247 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
248 sizeof(env_version), NULL );
249 ok( hr == E_INVALIDARG, "got %08x\n", hr );
251 addr_version = WS_ADDRESSING_VERSION_0_9;
252 hr = WsSetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
253 sizeof(addr_version), NULL );
254 ok( hr == E_INVALIDARG, "got %08x\n", hr );
255 WsFreeMessage( msg );
258 static void test_WsAddressMessage(void)
260 HRESULT hr;
261 WS_MESSAGE *msg;
262 WS_ENDPOINT_ADDRESS endpoint;
263 BOOL addressed;
265 hr = WsAddressMessage( NULL, NULL, NULL );
266 ok( hr == E_INVALIDARG, "got %08x\n", hr );
268 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL,
269 0, &msg, NULL );
270 ok( hr == S_OK, "got %08x\n", hr );
272 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
273 NULL );
274 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
276 hr = WsAddressMessage( msg, NULL, NULL );
277 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
279 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
280 ok( hr == S_OK, "got %08x\n", hr );
282 addressed = -1;
283 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
284 NULL );
285 ok( hr == S_OK, "got %08x\n", hr );
286 ok( !addressed, "unexpected value %d\n", addressed );
288 hr = WsAddressMessage( msg, NULL, NULL );
289 ok( hr == S_OK, "got %08x\n", hr );
291 addressed = -1;
292 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
293 NULL );
294 ok( hr == S_OK, "got %08x\n", hr );
295 ok( addressed == TRUE, "unexpected value %d\n", addressed );
296 WsFreeMessage( msg );
298 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL,
299 0, &msg, NULL );
300 ok( hr == S_OK, "got %08x\n", hr );
302 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
303 ok( hr == S_OK, "got %08x\n", hr );
305 memset( &endpoint, 0, sizeof(endpoint) );
306 endpoint.url.chars = (WCHAR *)L"http://localhost/";
307 endpoint.url.length = ARRAY_SIZE( L"http://localhost/" ) - 1;
308 hr = WsAddressMessage( msg, &endpoint, NULL );
309 ok( hr == S_OK, "got %08x\n", hr );
311 addressed = -1;
312 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_IS_ADDRESSED, &addressed, sizeof(addressed),
313 NULL );
314 ok( hr == S_OK, "got %08x\n", hr );
315 ok( addressed == TRUE, "unexpected value %d\n", addressed );
316 WsFreeMessage( msg );
319 static HRESULT set_output( WS_XML_WRITER *writer )
321 WS_XML_WRITER_TEXT_ENCODING text = { {WS_XML_WRITER_ENCODING_TYPE_TEXT}, WS_CHARSET_UTF8 };
322 WS_XML_WRITER_BUFFER_OUTPUT buf = { {WS_XML_WRITER_OUTPUT_TYPE_BUFFER} };
323 return WsSetOutput( writer, &text.encoding, &buf.output, NULL, 0, NULL );
326 static void check_output( WS_XML_WRITER *writer, const char *expected, int len, unsigned int skip_start,
327 unsigned int skip_len, unsigned int line )
329 WS_BYTES bytes;
330 HRESULT hr;
332 if (len == -1) len = strlen( expected );
333 memset( &bytes, 0, sizeof(bytes) );
334 hr = WsGetWriterProperty( writer, WS_XML_WRITER_PROPERTY_BYTES, &bytes, sizeof(bytes), NULL );
335 ok( hr == S_OK, "%u: got %08x\n", line, hr );
336 ok( bytes.length == len, "%u: got %u expected %u\n", line, bytes.length, len );
337 if (bytes.length != len) return;
338 if (skip_start)
340 ok( !memcmp( bytes.bytes, expected, skip_start ), "%u: got %s expected %s\n", line,
341 bytes.bytes, expected );
342 ok( !memcmp( bytes.bytes + skip_start + skip_len, expected + skip_start + skip_len,
343 len - skip_start - skip_len), "%u: got %s expected %s\n", line, bytes.bytes, expected );
345 else
346 ok( !memcmp( bytes.bytes, expected, len ), "%u: got %s expected %s\n", line, bytes.bytes,
347 expected );
350 static void check_output_header( WS_MESSAGE *msg, const char *expected, int len, unsigned int skip_start,
351 unsigned int skip_len, unsigned int line )
353 WS_XML_WRITER *writer;
354 WS_XML_BUFFER *buf;
355 HRESULT hr;
357 hr = WsCreateWriter( NULL, 0, &writer, NULL );
358 ok( hr == S_OK, "got %08x\n", hr );
360 hr = set_output( writer );
361 ok( hr == S_OK, "got %08x\n", hr );
363 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_HEADER_BUFFER, &buf, sizeof(buf), NULL );
364 ok( hr == S_OK, "got %08x\n", hr );
366 hr = WsWriteXmlBuffer( writer, buf, NULL );
367 ok( hr == S_OK, "got %08x\n", hr );
369 check_output( writer, expected, len, skip_start, skip_len, line );
370 WsFreeWriter( writer );
373 static void test_WsWriteEnvelopeStart(void)
375 static const char expected[] =
376 "<s:Envelope xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" "
377 "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header>"
378 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
379 "<a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>"
380 "</a:ReplyTo></s:Header>";
381 static const char expected2[] =
382 "<s:Envelope xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" "
383 "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header>"
384 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
385 "<a:ReplyTo><a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>"
386 "</a:ReplyTo></s:Header><s:Body/></s:Envelope>";
387 static const char expected3[] =
388 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header/><s:Body/></s:Envelope>";
389 static const char expected4[] =
390 "<Envelope><Header/><Body/></Envelope>";
391 static const char expected5[] =
392 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
393 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
394 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
395 "</s:Header><s:Body/></s:Envelope>";
396 HRESULT hr;
397 WS_MESSAGE *msg;
398 WS_XML_WRITER *writer;
399 WS_MESSAGE_STATE state;
401 hr = WsWriteEnvelopeStart( NULL, NULL, NULL, NULL, NULL );
402 ok( hr == E_INVALIDARG, "got %08x\n", hr );
404 hr = WsCreateWriter( NULL, 0, &writer, NULL );
405 ok( hr == S_OK, "got %08x\n", hr );
407 hr = WsWriteEnvelopeStart( NULL, writer, NULL, NULL, NULL );
408 ok( hr == E_INVALIDARG, "got %08x\n", hr );
410 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg,
411 NULL );
412 ok( hr == S_OK, "got %08x\n", hr );
414 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
415 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
417 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
418 ok( hr == S_OK, "got %08x\n", hr );
419 hr = set_output( writer );
420 ok( hr == S_OK, "got %08x\n", hr );
421 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
422 ok( hr == S_OK, "got %08x\n", hr );
423 check_output( writer, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
424 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
426 state = 0xdeadbeef;
427 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
428 ok( hr == S_OK, "got %08x\n", hr );
429 ok( state == WS_MESSAGE_STATE_WRITING, "got %u\n", state );
430 WsFreeMessage( msg );
432 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_TRANSPORT, NULL, 0, &msg,
433 NULL );
434 ok( hr == S_OK, "got %08x\n", hr );
435 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
436 ok( hr == S_OK, "got %08x\n", hr );
437 hr = set_output( writer );
438 ok( hr == S_OK, "got %08x\n", hr );
439 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
440 ok( hr == S_OK, "got %08x\n", hr );
441 check_output_header( msg, expected3, -1, 0, 0, __LINE__ );
442 WsFreeMessage( msg );
444 hr = WsCreateMessage( WS_ENVELOPE_VERSION_NONE, WS_ADDRESSING_VERSION_TRANSPORT, NULL, 0, &msg,
445 NULL );
446 ok( hr == S_OK, "got %08x\n", hr );
447 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
448 ok( hr == S_OK, "got %08x\n", hr );
449 hr = set_output( writer );
450 ok( hr == S_OK, "got %08x\n", hr );
451 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
452 ok( hr == S_OK, "got %08x\n", hr );
453 check_output_header( msg, expected4, -1, 0, 0, __LINE__ );
454 WsFreeMessage( msg );
456 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
457 NULL );
458 ok( hr == S_OK, "got %08x\n", hr );
459 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
460 ok( hr == S_OK, "got %08x\n", hr );
461 hr = set_output( writer );
462 ok( hr == S_OK, "got %08x\n", hr );
463 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
464 ok( hr == S_OK, "got %08x\n", hr );
465 check_output_header( msg, expected5, -1, strstr(expected5, "urn:uuid:") - expected5, 46, __LINE__ );
466 WsFreeMessage( msg );
468 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
469 NULL );
470 ok( hr == S_OK, "got %08x\n", hr );
471 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
472 ok( hr == S_OK, "got %08x\n", hr );
473 WsFreeMessage( msg );
475 hr = WsCreateMessage( WS_ENVELOPE_VERSION_NONE, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg,
476 NULL );
477 ok( hr == E_INVALIDARG, "got %08x\n", hr );
478 hr = WsCreateMessage( WS_ENVELOPE_VERSION_NONE, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
479 NULL );
480 ok( hr == E_INVALIDARG, "got %08x\n", hr );
481 WsFreeWriter( writer );
484 static void test_WsWriteEnvelopeEnd(void)
486 static const char expected[] =
487 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
488 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
489 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
490 "</s:Header><s:Body/></s:Envelope>";
491 HRESULT hr;
492 WS_MESSAGE *msg;
493 WS_XML_WRITER *writer;
494 WS_MESSAGE_STATE state;
496 hr = WsWriteEnvelopeEnd( NULL, NULL );
497 ok( hr == E_INVALIDARG, "got %08x\n", hr );
499 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
500 NULL );
501 ok( hr == S_OK, "got %08x\n", hr );
503 hr = WsWriteEnvelopeEnd( msg, NULL );
504 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
506 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
507 ok( hr == S_OK, "got %08x\n", hr );
509 hr = WsWriteEnvelopeEnd( msg, NULL );
510 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
512 hr = WsCreateWriter( NULL, 0, &writer, NULL );
513 ok( hr == S_OK, "got %08x\n", hr );
515 hr = set_output( writer );
516 ok( hr == S_OK, "got %08x\n", hr );
518 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
519 ok( hr == S_OK, "got %08x\n", hr );
521 hr = WsWriteEnvelopeEnd( msg, NULL );
522 ok( hr == S_OK, "got %08x\n", hr );
523 check_output( writer, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
524 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
526 state = 0xdeadbeef;
527 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
528 ok( hr == S_OK, "got %08x\n", hr );
529 ok( state == WS_MESSAGE_STATE_DONE, "got %u\n", state );
531 WsFreeMessage( msg );
532 WsFreeWriter( writer );
535 static void test_WsWriteBody(void)
537 static char expected[] =
538 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
539 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
540 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
541 "</s:Header><s:Body><u xmlns=\"ns\"><val>1</val></u></s:Body></s:Envelope>";
542 static char expected2[] =
543 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
544 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
545 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
546 "</s:Header><s:Body/></s:Envelope>";
547 WS_XML_STRING localname = {1, (BYTE *)"t"}, localname2 = {1, (BYTE *)"u"};
548 WS_XML_STRING val = {3, (BYTE *)"val"}, ns = {2, (BYTE *)"ns"};
549 HRESULT hr;
550 WS_MESSAGE *msg;
551 WS_XML_WRITER *writer;
552 WS_MESSAGE_STATE state;
553 WS_ELEMENT_DESCRIPTION desc;
554 WS_STRUCT_DESCRIPTION s;
555 WS_FIELD_DESCRIPTION f, *fields[1];
556 struct test
558 UINT32 val;
559 } test, *ptr;
561 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
562 NULL );
563 ok( hr == S_OK, "got %08x\n", hr );
565 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
566 ok( hr == S_OK, "got %08x\n", hr );
568 hr = WsCreateWriter( NULL, 0, &writer, NULL );
569 ok( hr == S_OK, "got %08x\n", hr );
571 hr = set_output( writer );
572 ok( hr == S_OK, "got %08x\n", hr );
574 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
575 ok( hr == S_OK, "got %08x\n", hr );
577 hr = WsWriteBody( NULL, NULL, 0, NULL, 0, NULL );
578 ok( hr == E_INVALIDARG, "got %08x\n", hr );
580 hr = WsWriteBody( msg, NULL, 0, NULL, 0, NULL );
581 ok( hr == E_INVALIDARG, "got %08x\n", hr );
583 memset( &f, 0, sizeof(f) );
584 f.mapping = WS_ELEMENT_FIELD_MAPPING;
585 f.localName = &val;
586 f.ns = &ns;
587 f.type = WS_UINT32_TYPE;
588 fields[0] = &f;
590 memset( &s, 0, sizeof(s) );
591 s.size = sizeof(struct test);
592 s.alignment = TYPE_ALIGNMENT(struct test);
593 s.fields = fields;
594 s.fieldCount = 1;
595 s.typeLocalName = &localname;
596 s.typeNs = &ns;
598 desc.elementLocalName = &localname2;
599 desc.elementNs = &ns;
600 desc.type = WS_STRUCT_TYPE;
601 desc.typeDescription = &s;
603 ptr = &test;
604 test.val = 1;
605 hr = WsWriteBody( msg, &desc, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
606 ok( hr == S_OK, "got %08x\n", hr );
607 check_output( writer, expected, 240, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
608 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
610 state = 0xdeadbeef;
611 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
612 ok( hr == S_OK, "got %08x\n", hr );
613 ok( state == WS_MESSAGE_STATE_WRITING, "got %u\n", state );
615 hr = WsWriteEnvelopeEnd( msg, NULL );
616 ok( hr == S_OK, "got %08x\n", hr );
617 check_output( writer, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
618 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
620 hr = WsWriteBody( msg, &desc, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
621 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
623 WsFreeMessage( msg );
624 WsFreeWriter( writer );
627 static void test_WsSetHeader(void)
629 static const char expected[] =
630 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
631 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
632 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
633 "<a:Action s:mustUnderstand=\"1\">action</a:Action></s:Header>"
634 "<s:Body/></s:Envelope>";
635 static const char expected2[] =
636 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
637 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
638 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
639 "<a:Action s:mustUnderstand=\"1\">action2</a:Action></s:Header>"
640 "<s:Body/></s:Envelope>";
641 static const WS_XML_STRING action2 = {7, (BYTE *)"action2"};
642 HRESULT hr;
643 WS_MESSAGE *msg;
644 WS_XML_WRITER *writer;
645 const WCHAR *ptr = L"action";
647 hr = WsSetHeader( NULL, 0, 0, 0, NULL, 0, NULL );
648 ok( hr == E_INVALIDARG, "got %08x\n", hr );
650 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
651 NULL );
652 ok( hr == S_OK, "got %08x\n", hr );
654 hr = WsSetHeader( msg, 0, 0, 0, NULL, 0, NULL );
655 ok( hr == E_INVALIDARG, "got %08x\n", hr );
657 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr,
658 sizeof(ptr), NULL );
659 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
661 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
662 ok( hr == S_OK, "got %08x\n", hr );
664 hr = WsSetHeader( msg, 0, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
665 ok( hr == E_INVALIDARG, "got %08x\n", hr );
667 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr,
668 sizeof(ptr), NULL );
669 ok( hr == S_OK, "got %08x\n", hr );
670 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
672 hr = WsCreateWriter( NULL, 0, &writer, NULL );
673 ok( hr == S_OK, "got %08x\n", hr );
675 hr = set_output( writer );
676 ok( hr == S_OK, "got %08x\n", hr );
678 hr = WsWriteEnvelopeStart( msg, writer, NULL, NULL, NULL );
679 ok( hr == S_OK, "got %08x\n", hr );
680 check_output( writer, expected, 250, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
681 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
683 /* called after WsWriteEnvelopeStart */
684 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, &action2,
685 sizeof(action2), NULL );
686 ok( hr == S_OK, "got %08x\n", hr );
687 check_output( writer, expected, 250, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
688 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
690 WsFreeMessage( msg );
691 WsFreeWriter( writer );
694 static void test_WsRemoveHeader(void)
696 static const char expected[] =
697 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
698 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
699 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
700 "<a:Action s:mustUnderstand=\"1\">action</a:Action></s:Header>"
701 "<s:Body/></s:Envelope>";
702 static const char expected2[] =
703 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
704 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
705 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
706 "</s:Header><s:Body/></s:Envelope>";
707 static const WS_XML_STRING action = {6, (BYTE *)"action"};
708 HRESULT hr;
709 WS_MESSAGE *msg;
711 hr = WsSetHeader( NULL, 0, 0, 0, NULL, 0, NULL );
712 ok( hr == E_INVALIDARG, "got %08x\n", hr );
714 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg,
715 NULL );
716 ok( hr == S_OK, "got %08x\n", hr );
718 hr = WsRemoveHeader( NULL, 0, NULL );
719 ok( hr == E_INVALIDARG, "got %08x\n", hr );
721 hr = WsRemoveHeader( msg, 0, NULL );
722 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
724 hr = WsRemoveHeader( msg, WS_ACTION_HEADER, NULL );
725 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
727 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
728 ok( hr == S_OK, "got %08x\n", hr );
729 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
731 hr = WsRemoveHeader( msg, 0, NULL );
732 ok( hr == E_INVALIDARG, "got %08x\n", hr );
734 hr = WsRemoveHeader( msg, WS_ACTION_HEADER, NULL );
735 ok( hr == S_OK, "got %08x\n", hr );
736 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
738 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, &action,
739 sizeof(action), NULL );
740 ok( hr == S_OK, "got %08x\n", hr );
741 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
743 hr = WsRemoveHeader( msg, WS_ACTION_HEADER, NULL );
744 ok( hr == S_OK, "got %08x\n", hr );
745 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
747 /* again */
748 hr = WsRemoveHeader( msg, WS_ACTION_HEADER, NULL );
749 ok( hr == S_OK, "got %08x\n", hr );
750 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
752 WsFreeMessage( msg );
755 static void test_WsAddMappedHeader(void)
757 static const WS_XML_STRING header = {6, (BYTE *)"Header"}, value = {5, (BYTE *)"value"};
758 WS_MESSAGE *msg;
759 HRESULT hr;
761 hr = WsAddMappedHeader( NULL, NULL, 0, 0, NULL, 0, NULL );
762 ok( hr == E_INVALIDARG, "got %08x\n", hr );
764 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg, NULL );
765 ok( hr == S_OK, "got %08x\n", hr );
767 hr = WsAddMappedHeader( msg, NULL, 0, 0, NULL, 0, NULL );
768 ok( hr == E_INVALIDARG, "got %08x\n", hr );
770 hr = WsAddMappedHeader( msg, &header, 0, 0, NULL, 0, NULL );
771 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
773 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
774 ok( hr == S_OK, "got %08x\n", hr );
776 hr = WsAddMappedHeader( msg, &header, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, NULL, 0, NULL );
777 ok( hr == E_INVALIDARG, "got %08x\n", hr );
779 hr = WsAddMappedHeader( msg, &header, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, &value, sizeof(value), NULL );
780 ok( hr == S_OK, "got %08x\n", hr );
782 /* again */
783 hr = WsAddMappedHeader( msg, &header, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, &value, sizeof(value), NULL );
784 ok( hr == S_OK, "got %08x\n", hr );
786 WsFreeMessage( msg );
789 static void test_WsRemoveMappedHeader(void)
791 static const WS_XML_STRING header = {6, (BYTE *)"Header"}, value = {5, (BYTE *)"value"};
792 WS_MESSAGE *msg;
793 HRESULT hr;
795 hr = WsRemoveMappedHeader( NULL, NULL, NULL );
796 ok( hr == E_INVALIDARG, "got %08x\n", hr );
798 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg, NULL );
799 ok( hr == S_OK, "got %08x\n", hr );
801 hr = WsRemoveMappedHeader( msg, NULL, NULL );
802 ok( hr == E_INVALIDARG, "got %08x\n", hr );
804 hr = WsRemoveMappedHeader( msg, &header, NULL );
805 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
807 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
808 ok( hr == S_OK, "got %08x\n", hr );
810 hr = WsAddMappedHeader( msg, &header, WS_XML_STRING_TYPE, WS_WRITE_REQUIRED_VALUE, &value, sizeof(value), NULL );
811 ok( hr == S_OK, "got %08x\n", hr );
813 hr = WsRemoveMappedHeader( msg, &header, NULL );
814 ok( hr == S_OK, "got %08x\n", hr );
816 /* again */
817 hr = WsRemoveMappedHeader( msg, &header, NULL );
818 ok( hr == S_OK, "got %08x\n", hr );
820 WsFreeMessage( msg );
823 static void test_WsAddCustomHeader(void)
825 static const char expected[] =
826 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
827 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
828 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
829 "<header xmlns=\"ns\">value</header></s:Header><s:Body/></s:Envelope>";
830 static const char expected2[] =
831 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
832 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
833 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
834 "</s:Header><s:Body/></s:Envelope>";
835 static const char expected3[] =
836 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
837 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
838 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
839 "<header xmlns=\"ns\">value</header><header xmlns=\"ns\">value2</header>"
840 "</s:Header><s:Body/></s:Envelope>";
841 static const char expected4[] =
842 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
843 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
844 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
845 "<header xmlns=\"ns\">value</header><header xmlns=\"ns\">value2</header>"
846 "<header2 xmlns=\"ns\">value2</header2></s:Header><s:Body/></s:Envelope>";
847 static WS_XML_STRING header = {6, (BYTE *)"header"}, ns = {2, (BYTE *)"ns"};
848 static WS_XML_STRING header2 = {7, (BYTE *)"header2"};
849 HRESULT hr;
850 WS_MESSAGE *msg;
851 WS_ELEMENT_DESCRIPTION desc;
852 WS_STRUCT_DESCRIPTION s;
853 WS_FIELD_DESCRIPTION f, *fields[1];
854 struct header
856 const WCHAR *value;
857 } test;
859 hr = WsAddCustomHeader( NULL, NULL, 0, NULL, 0, 0, NULL );
860 ok( hr == E_INVALIDARG, "got %08x\n", hr );
862 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg, NULL );
863 ok( hr == S_OK, "got %08x\n", hr );
865 hr = WsAddCustomHeader( msg, NULL, 0, NULL, 0, 0, NULL );
866 ok( hr == E_INVALIDARG, "got %08x\n", hr );
868 memset( &f, 0, sizeof(f) );
869 f.mapping = WS_TEXT_FIELD_MAPPING;
870 f.type = WS_WSZ_TYPE;
871 fields[0] = &f;
873 memset( &s, 0, sizeof(s) );
874 s.size = sizeof(struct header);
875 s.alignment = TYPE_ALIGNMENT(struct header);
876 s.fields = fields;
877 s.fieldCount = 1;
879 desc.elementLocalName = &header;
880 desc.elementNs = &ns;
881 desc.type = WS_STRUCT_TYPE;
882 desc.typeDescription = &s;
883 hr = WsAddCustomHeader( msg, &desc, 0, NULL, 0, 0, NULL );
884 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
886 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
887 ok( hr == S_OK, "got %08x\n", hr );
888 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
890 test.value = L"value";
891 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
892 ok( hr == S_OK, "got %08x\n", hr );
893 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
895 test.value = L"value2";
896 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
897 ok( hr == S_OK, "got %08x\n", hr );
898 check_output_header( msg, expected3, -1, strstr(expected3, "urn:uuid:") - expected3, 46, __LINE__ );
900 desc.elementLocalName = &header2;
901 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
902 ok( hr == S_OK, "got %08x\n", hr );
903 check_output_header( msg, expected4, -1, strstr(expected4, "urn:uuid:") - expected4, 46, __LINE__ );
905 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, NULL, 0, 0, NULL );
906 ok( hr == E_INVALIDARG, "got %08x\n", hr );
908 WsFreeMessage( msg );
911 static void test_WsRemoveCustomHeader(void)
913 static const char expected[] =
914 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
915 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
916 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
917 "<test xmlns=\"ns\">value</test></s:Header><s:Body/></s:Envelope>";
918 static const char expected2[] =
919 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
920 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
921 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
922 "</s:Header><s:Body/></s:Envelope>";
923 static const char expected3[] =
924 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
925 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
926 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
927 "<test xmlns=\"ns\">value</test><test xmlns=\"ns\">value2</test>"
928 "</s:Header><s:Body/></s:Envelope>";
929 static WS_XML_STRING localname = {4, (BYTE *)"test"}, ns = {2, (BYTE *)"ns"};
930 static const WS_XML_STRING value = {5, (BYTE *)"value"};
931 static const WS_XML_STRING value2 = {6, (BYTE *)"value2"};
932 HRESULT hr;
933 WS_MESSAGE *msg;
934 WS_ELEMENT_DESCRIPTION desc;
936 hr = WsRemoveCustomHeader( NULL, NULL, NULL, NULL );
937 ok( hr == E_INVALIDARG, "got %08x\n", hr );
939 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg, NULL );
940 ok( hr == S_OK, "got %08x\n", hr );
942 hr = WsRemoveCustomHeader( msg, &localname, &ns, NULL );
943 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
945 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
946 ok( hr == S_OK, "got %08x\n", hr );
947 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
949 desc.elementLocalName = &localname;
950 desc.elementNs = &ns;
951 desc.type = WS_XML_STRING_TYPE;
952 desc.typeDescription = NULL;
953 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &value, sizeof(value), 0, NULL );
954 ok( hr == S_OK, "got %08x\n", hr );
955 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
957 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &value2, sizeof(value2), 0, NULL );
958 ok( hr == S_OK, "got %08x\n", hr );
959 check_output_header( msg, expected3, -1, strstr(expected3, "urn:uuid:") - expected3, 46, __LINE__ );
961 hr = WsRemoveCustomHeader( msg, NULL, NULL, NULL );
962 ok( hr == E_INVALIDARG, "got %08x\n", hr );
964 hr = WsRemoveCustomHeader( msg, &localname, NULL, NULL );
965 ok( hr == E_INVALIDARG, "got %08x\n", hr );
967 hr = WsRemoveCustomHeader( msg, &localname, &ns, NULL );
968 ok( hr == S_OK, "got %08x\n", hr );
969 check_output_header( msg, expected2, -1, strstr(expected2, "urn:uuid:") - expected2, 46, __LINE__ );
971 /* again */
972 hr = WsRemoveCustomHeader( msg, &localname, &ns, NULL );
973 ok( hr == S_OK, "got %08x\n", hr );
975 WsFreeMessage( msg );
978 static HRESULT set_input( WS_XML_READER *reader, const char *data, ULONG size )
980 WS_XML_READER_TEXT_ENCODING text = {{WS_XML_READER_ENCODING_TYPE_TEXT}, WS_CHARSET_AUTO};
981 WS_XML_READER_BUFFER_INPUT buf;
983 buf.input.inputType = WS_XML_READER_INPUT_TYPE_BUFFER;
984 buf.encodedData = (void *)data;
985 buf.encodedDataSize = size;
986 return WsSetInput( reader, &text.encoding, &buf.input, NULL, 0, NULL );
989 static void test_WsReadEnvelopeStart(void)
991 static const char xml[] =
992 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body/></s:Envelope>";
993 WS_MESSAGE *msg, *msg2;
994 WS_XML_READER *reader;
995 WS_MESSAGE_STATE state;
996 const WS_XML_NODE *node;
997 HRESULT hr;
999 hr = WsReadEnvelopeStart( NULL, NULL, NULL, NULL, NULL );
1000 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1002 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg, NULL );
1003 ok( hr == S_OK, "got %08x\n", hr );
1005 hr = WsReadEnvelopeStart( msg, NULL, NULL, NULL, NULL );
1006 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1008 hr = WsCreateReader( NULL, 0, &reader, NULL );
1009 ok( hr == S_OK, "got %08x\n", hr );
1011 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1012 ok( hr == S_OK, "got %08x\n", hr );
1014 hr = WsReadEnvelopeStart( msg, reader, NULL, NULL, NULL );
1015 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
1017 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg2, NULL );
1018 ok( hr == S_OK, "got %08x\n", hr );
1020 hr = set_input( reader, xml, strlen(xml) );
1021 ok( hr == S_OK, "got %08x\n", hr );
1023 hr = WsReadEnvelopeStart( msg2, reader, NULL, NULL, NULL );
1024 ok( hr == S_OK, "got %08x\n", hr );
1026 state = 0xdeadbeef;
1027 hr = WsGetMessageProperty( msg2, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
1028 ok( hr == S_OK, "got %08x\n", hr );
1029 ok( state == WS_MESSAGE_STATE_READING, "got %u\n", state );
1031 hr = WsGetReaderNode( reader, &node, NULL );
1032 ok( hr == S_OK, "got %08x\n", hr );
1033 ok( node->nodeType == WS_XML_NODE_TYPE_END_ELEMENT, "got %u\n", node->nodeType );
1035 hr = WsReadEndElement( reader, NULL );
1036 ok( hr == S_OK, "got %08x\n", hr );
1038 hr = WsGetReaderNode( reader, &node, NULL );
1039 ok( hr == S_OK, "got %08x\n", hr );
1040 ok( node->nodeType == WS_XML_NODE_TYPE_END_ELEMENT, "got %u\n", node->nodeType );
1042 hr = WsReadEndElement( reader, NULL );
1043 ok( hr == S_OK, "got %08x\n", hr );
1045 hr = WsGetReaderNode( reader, &node, NULL );
1046 ok( hr == S_OK, "got %08x\n", hr );
1047 ok( node->nodeType == WS_XML_NODE_TYPE_EOF, "got %u\n", node->nodeType );
1049 WsFreeMessage( msg );
1050 WsFreeMessage( msg2 );
1051 WsFreeReader( reader );
1054 static void test_WsReadEnvelopeEnd(void)
1056 static const char xml[] =
1057 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body></s:Body></s:Envelope>";
1058 WS_MESSAGE *msg, *msg2;
1059 WS_XML_READER *reader;
1060 WS_MESSAGE_STATE state;
1061 HRESULT hr;
1063 hr = WsReadEnvelopeEnd( NULL, NULL );
1064 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1066 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg, NULL );
1067 ok( hr == S_OK, "got %08x\n", hr );
1069 hr = WsCreateReader( NULL, 0, &reader, NULL );
1070 ok( hr == S_OK, "got %08x\n", hr );
1072 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1073 ok( hr == S_OK, "got %08x\n", hr );
1075 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg2, NULL );
1076 ok( hr == S_OK, "got %08x\n", hr );
1078 hr = set_input( reader, xml, strlen(xml) );
1079 ok( hr == S_OK, "got %08x\n", hr );
1081 hr = WsReadEnvelopeEnd( msg2, NULL );
1082 ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr );
1084 hr = WsReadEnvelopeStart( msg2, reader, NULL, NULL, NULL );
1085 ok( hr == S_OK, "got %08x\n", hr );
1087 hr = WsReadEnvelopeEnd( msg2, NULL );
1088 ok( hr == S_OK, "got %08x\n", hr );
1090 state = 0xdeadbeef;
1091 hr = WsGetMessageProperty( msg2, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
1092 ok( hr == S_OK, "got %08x\n", hr );
1093 ok( state == WS_MESSAGE_STATE_DONE, "got %u\n", state );
1095 WsFreeMessage( msg );
1096 WsFreeMessage( msg2 );
1097 WsFreeReader( reader );
1100 static void test_WsReadBody(void)
1102 static const char xml[] =
1103 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>"
1104 "<u xmlns=\"ns\"><val>1</val></u></s:Body></s:Envelope>";
1105 WS_HEAP *heap;
1106 WS_MESSAGE *msg, *msg2;
1107 WS_XML_READER *reader;
1108 WS_MESSAGE_STATE state;
1109 WS_XML_STRING localname = {1, (BYTE *)"t"}, localname2 = {1, (BYTE *)"u"};
1110 WS_XML_STRING val = {3, (BYTE *)"val"}, ns = {2, (BYTE *)"ns"};
1111 WS_ELEMENT_DESCRIPTION desc;
1112 WS_STRUCT_DESCRIPTION s;
1113 WS_FIELD_DESCRIPTION f, *fields[1];
1114 struct test
1116 UINT32 val;
1117 } test;
1118 HRESULT hr;
1120 hr = WsCreateHeap( 1 << 16, 0, NULL, 0, &heap, NULL );
1121 ok( hr == S_OK, "got %08x\n", hr );
1123 hr = WsReadBody( NULL, NULL, 0, NULL, NULL, 0, NULL );
1124 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1126 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg, NULL );
1127 ok( hr == S_OK, "got %08x\n", hr );
1129 hr = WsCreateReader( NULL, 0, &reader, NULL );
1130 ok( hr == S_OK, "got %08x\n", hr );
1132 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1133 ok( hr == S_OK, "got %08x\n", hr );
1135 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg2, NULL );
1136 ok( hr == S_OK, "got %08x\n", hr );
1138 hr = WsReadBody( msg2, NULL, 0, NULL, NULL, 0, NULL );
1139 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1141 hr = set_input( reader, xml, strlen(xml) );
1142 ok( hr == S_OK, "got %08x\n", hr );
1144 hr = WsReadEnvelopeStart( msg2, reader, NULL, NULL, NULL );
1145 ok( hr == S_OK, "got %08x\n", hr );
1147 hr = WsReadBody( msg2, NULL, WS_READ_REQUIRED_VALUE, heap, &test, sizeof(test), NULL );
1148 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1150 memset( &f, 0, sizeof(f) );
1151 f.mapping = WS_ELEMENT_FIELD_MAPPING;
1152 f.localName = &val;
1153 f.ns = &ns;
1154 f.type = WS_UINT32_TYPE;
1155 fields[0] = &f;
1157 memset( &s, 0, sizeof(s) );
1158 s.size = sizeof(struct test);
1159 s.alignment = TYPE_ALIGNMENT(struct test);
1160 s.fields = fields;
1161 s.fieldCount = 1;
1162 s.typeLocalName = &localname;
1163 s.typeNs = &ns;
1165 desc.elementLocalName = &localname2;
1166 desc.elementNs = &ns;
1167 desc.type = WS_STRUCT_TYPE;
1168 desc.typeDescription = &s;
1170 memset( &test, 0, sizeof(test) );
1171 hr = WsReadBody( msg2, &desc, WS_READ_REQUIRED_VALUE, heap, &test, sizeof(test), NULL );
1172 ok( hr == S_OK, "got %08x\n", hr );
1173 ok( test.val == 1, "got %u\n", test.val );
1175 state = 0xdeadbeef;
1176 hr = WsGetMessageProperty( msg2, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
1177 ok( hr == S_OK, "got %08x\n", hr );
1178 ok( state == WS_MESSAGE_STATE_READING, "got %u\n", state );
1180 hr = WsReadEnvelopeEnd( msg2, NULL );
1181 ok( hr == S_OK, "got %08x\n", hr );
1183 WsFreeMessage( msg );
1184 WsFreeMessage( msg2 );
1185 WsFreeReader( reader );
1186 WsFreeHeap( heap );
1189 static void test_WsResetMessage(void)
1191 WS_MESSAGE *msg;
1192 WS_MESSAGE_STATE state;
1193 WS_ENVELOPE_VERSION env_version;
1194 WS_ADDRESSING_VERSION addr_version;
1195 HRESULT hr;
1197 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_1, WS_ADDRESSING_VERSION_0_9, NULL, 0, &msg, NULL );
1198 ok( hr == S_OK, "got %08x\n", hr );
1200 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1201 ok( hr == S_OK, "got %08x\n", hr );
1203 hr = WsResetMessage( msg, NULL );
1204 ok( hr == S_OK, "got %08x\n", hr );
1206 state = 0xdeadbeef;
1207 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_STATE, &state, sizeof(state), NULL );
1208 ok( hr == S_OK, "got %08x\n", hr );
1209 ok( state == WS_MESSAGE_STATE_EMPTY, "got %u\n", state );
1211 env_version = 0xdeadbeef;
1212 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ENVELOPE_VERSION, &env_version,
1213 sizeof(env_version), NULL );
1214 ok( hr == S_OK, "got %08x\n", hr );
1215 ok( env_version == WS_ENVELOPE_VERSION_SOAP_1_1, "got %u\n", env_version );
1217 addr_version = 0xdeadbeef;
1218 hr = WsGetMessageProperty( msg, WS_MESSAGE_PROPERTY_ADDRESSING_VERSION, &addr_version,
1219 sizeof(addr_version), NULL );
1220 ok( hr == S_OK, "got %08x\n", hr );
1221 ok( addr_version == WS_ADDRESSING_VERSION_0_9, "got %u\n", addr_version );
1223 WsFreeMessage( msg );
1226 static void test_WsGetHeader(void)
1228 static char expected[] =
1229 "<s:Envelope xmlns:a=\"http://www.w3.org/2005/08/addressing\" "
1230 "xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
1231 "<a:MessageID>urn:uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
1232 "<a:Action s:mustUnderstand=\"1\">action</a:Action></s:Header><s:Body/></s:Envelope>";
1233 static char expected2[] =
1234 "<Envelope><Header><Action mustUnderstand=\"1\" "
1235 "xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">action</Action>"
1236 "</Header><Body/></Envelope>";
1237 static char expected3[] =
1238 "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header>"
1239 "<Action s:mustUnderstand=\"1\" "
1240 "xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">action</Action>"
1241 "</s:Header><s:Body/></s:Envelope>";
1242 WS_MESSAGE *msg;
1243 const WCHAR *ptr;
1244 HRESULT hr;
1246 hr = WsGetHeader( NULL, 0, 0, 0, NULL, NULL, 0, NULL );
1247 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1249 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_1_0, NULL, 0, &msg, NULL );
1250 ok( hr == S_OK, "got %08x\n", hr );
1252 hr = WsGetHeader( msg, 0, 0, 0, NULL, NULL, 0, NULL );
1253 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1255 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1256 ok( hr == S_OK, "got %08x\n", hr );
1258 hr = WsGetHeader( msg, 0, 0, 0, NULL, NULL, 0, NULL );
1259 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1261 hr = WsGetHeader( msg, WS_ACTION_HEADER, 0, 0, NULL, NULL, 0, NULL );
1262 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1264 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, 0, NULL, NULL, 0, NULL );
1265 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1267 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_NILLABLE_POINTER, NULL, NULL, 0, NULL );
1268 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1270 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, NULL, 0, NULL );
1271 ok( hr == WS_E_INVALID_FORMAT, "got %08x\n", hr );
1273 ptr = L"action";
1274 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
1275 ok( hr == S_OK, "got %08x\n", hr );
1276 check_output_header( msg, expected, -1, strstr(expected, "urn:uuid:") - expected, 46, __LINE__ );
1278 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, NULL, 0, NULL );
1279 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1281 ptr = NULL;
1282 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, &ptr, 0, NULL );
1283 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1285 ptr = NULL;
1286 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, &ptr, sizeof(ptr), NULL );
1287 ok( hr == S_OK, "got %08x\n", hr );
1288 ok( ptr != NULL, "ptr not set\n" );
1289 ok( !memcmp( ptr, L"action", sizeof(L"action") ), "wrong data\n" );
1290 WsFreeMessage( msg );
1292 hr = WsCreateMessage( WS_ENVELOPE_VERSION_NONE, WS_ADDRESSING_VERSION_TRANSPORT, NULL, 0, &msg, NULL );
1293 ok( hr == S_OK, "got %08x\n", hr );
1295 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1296 ok( hr == S_OK, "got %08x\n", hr );
1298 ptr = L"action";
1299 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
1300 ok( hr == S_OK, "got %08x\n", hr );
1301 if (hr == S_OK) check_output_header( msg, expected2, -1, 0, 0, __LINE__ );
1303 ptr = NULL;
1304 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, &ptr, sizeof(ptr), NULL );
1305 ok( hr == S_OK, "got %08x\n", hr );
1306 ok( ptr != NULL, "ptr not set\n" );
1307 ok( !memcmp( ptr, L"action", sizeof(L"action") ), "wrong data\n" );
1308 WsFreeMessage( msg );
1310 hr = WsCreateMessage( WS_ENVELOPE_VERSION_SOAP_1_2, WS_ADDRESSING_VERSION_TRANSPORT, NULL, 0, &msg, NULL );
1311 ok( hr == S_OK, "got %08x\n", hr );
1313 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1314 ok( hr == S_OK, "got %08x\n", hr );
1316 ptr = L"action";
1317 hr = WsSetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_WRITE_REQUIRED_POINTER, &ptr, sizeof(ptr), NULL );
1318 ok( hr == S_OK, "got %08x\n", hr );
1319 if (hr == S_OK) check_output_header( msg, expected3, -1, 0, 0, __LINE__ );
1321 ptr = NULL;
1322 hr = WsGetHeader( msg, WS_ACTION_HEADER, WS_WSZ_TYPE, WS_READ_REQUIRED_POINTER, NULL, &ptr, sizeof(ptr), NULL );
1323 ok( hr == S_OK, "got %08x\n", hr );
1324 ok( ptr != NULL, "ptr not set\n" );
1325 ok( !memcmp( ptr, L"action", sizeof(L"action") ), "wrong data\n" );
1326 WsFreeMessage( msg );
1329 static void test_WsGetCustomHeader(void)
1331 static char expected[] =
1332 "<Envelope><Header><Custom xmlns=\"ns\">value</Custom></Header><Body/></Envelope>";
1333 static WS_XML_STRING custom = {6, (BYTE *)"Custom"}, ns = {2, (BYTE *)"ns"};
1334 WS_ELEMENT_DESCRIPTION desc;
1335 WS_STRUCT_DESCRIPTION s;
1336 WS_FIELD_DESCRIPTION f, *fields[1];
1337 WS_MESSAGE *msg;
1338 HRESULT hr;
1339 struct header
1341 const WCHAR *value;
1342 } test;
1344 hr = WsGetCustomHeader( NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL, NULL );
1345 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1347 hr = WsCreateMessage( WS_ENVELOPE_VERSION_NONE, WS_ADDRESSING_VERSION_TRANSPORT, NULL, 0, &msg, NULL );
1348 ok( hr == S_OK, "got %08x\n", hr );
1350 hr = WsGetCustomHeader( msg, NULL, 0, 0, 0, NULL, NULL, 0, NULL, NULL );
1351 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1353 hr = WsInitializeMessage( msg, WS_REQUEST_MESSAGE, NULL, NULL );
1354 ok( hr == S_OK, "got %08x\n", hr );
1356 memset( &f, 0, sizeof(f) );
1357 f.mapping = WS_TEXT_FIELD_MAPPING;
1358 f.type = WS_WSZ_TYPE;
1359 fields[0] = &f;
1361 memset( &s, 0, sizeof(s) );
1362 s.size = sizeof(struct header);
1363 s.alignment = TYPE_ALIGNMENT(struct header);
1364 s.fields = fields;
1365 s.fieldCount = 1;
1367 desc.elementLocalName = &custom;
1368 desc.elementNs = &ns;
1369 desc.type = WS_STRUCT_TYPE;
1370 desc.typeDescription = &s;
1372 test.value = L"value";
1373 hr = WsAddCustomHeader( msg, &desc, WS_WRITE_REQUIRED_VALUE, &test, sizeof(test), 0, NULL );
1374 ok( hr == S_OK, "got %08x\n", hr );
1375 check_output_header( msg, expected, -1, 0, 0, __LINE__ );
1377 hr = WsGetCustomHeader( msg, &desc, 0, 0, 0, NULL, NULL, 0, NULL, NULL );
1378 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1380 hr = WsGetCustomHeader( msg, &desc, WS_SINGLETON_HEADER, 1, 0, NULL, NULL, 0, NULL, NULL );
1381 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1383 hr = WsGetCustomHeader( msg, &desc, WS_SINGLETON_HEADER, 0, WS_READ_REQUIRED_VALUE, NULL, NULL, 0, NULL, NULL );
1384 ok( hr == E_INVALIDARG, "got %08x\n", hr );
1386 memset( &test, 0, sizeof(test) );
1387 hr = WsGetCustomHeader( msg, &desc, WS_SINGLETON_HEADER, 0, WS_READ_REQUIRED_VALUE, NULL, &test, sizeof(test),
1388 NULL, NULL );
1389 ok( hr == S_OK, "got %08x\n", hr );
1390 ok( test.value != NULL, "value not set\n" );
1391 ok( !memcmp( test.value, L"value", sizeof(L"value") ), "wrong value\n" );
1392 WsFreeMessage( msg );
1395 START_TEST(msg)
1397 test_WsCreateMessage();
1398 test_WsCreateMessageForChannel();
1399 test_WsInitializeMessage();
1400 test_WsAddressMessage();
1401 test_WsWriteEnvelopeStart();
1402 test_WsWriteEnvelopeEnd();
1403 test_WsWriteBody();
1404 test_WsSetHeader();
1405 test_WsRemoveHeader();
1406 test_WsAddMappedHeader();
1407 test_WsRemoveMappedHeader();
1408 test_WsAddCustomHeader();
1409 test_WsRemoveCustomHeader();
1410 test_WsReadEnvelopeStart();
1411 test_WsReadEnvelopeEnd();
1412 test_WsReadBody();
1413 test_WsResetMessage();
1414 test_WsGetHeader();
1415 test_WsGetCustomHeader();