2 * Copyright 2015 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
21 #include "webservices.h"
22 #include "wine/test.h"
26 static inline float __port_infinity(void)
28 static const unsigned __inf_bytes
= 0x7f800000;
29 return *(const float *)&__inf_bytes
;
31 #define INFINITY __port_infinity()
35 static inline float __port_nan(void)
37 static const unsigned __nan_bytes
= 0x7fc00000;
38 return *(const float *)&__nan_bytes
;
40 #define NAN __port_nan()
43 static HRESULT
set_output( WS_XML_WRITER
*writer
)
45 WS_XML_WRITER_TEXT_ENCODING text
= { {WS_XML_WRITER_ENCODING_TYPE_TEXT
}, WS_CHARSET_UTF8
};
46 WS_XML_WRITER_BUFFER_OUTPUT buf
= { {WS_XML_WRITER_OUTPUT_TYPE_BUFFER
} };
47 return WsSetOutput( writer
, &text
.encoding
, &buf
.output
, NULL
, 0, NULL
);
50 static void test_WsCreateWriter(void)
53 WS_XML_WRITER
*writer
;
54 WS_XML_WRITER_PROPERTY prop
;
55 ULONG size
, max_depth
, max_attrs
, indent
, trim_size
, max_size
, max_ns
;
56 BOOL allow_fragment
, write_decl
, in_attr
;
61 hr
= WsCreateWriter( NULL
, 0, NULL
, NULL
);
62 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
65 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
66 ok( hr
== S_OK
, "got %08x\n", hr
);
67 ok( writer
!= NULL
, "writer not set\n" );
69 /* can't retrieve properties before output is set */
70 max_depth
= 0xdeadbeef;
71 size
= sizeof(max_depth
);
72 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_DEPTH
, &max_depth
, size
, NULL
);
73 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
74 ok( max_depth
== 0xdeadbeef, "max_depth set\n" );
76 hr
= set_output( writer
);
77 ok( hr
== S_OK
, "got %08x\n", hr
);
79 /* check some defaults */
80 max_depth
= 0xdeadbeef;
81 size
= sizeof(max_depth
);
82 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_DEPTH
, &max_depth
, size
, NULL
);
83 ok( hr
== S_OK
, "got %08x\n", hr
);
84 ok( max_depth
== 32, "got %u\n", max_depth
);
86 allow_fragment
= TRUE
;
87 size
= sizeof(allow_fragment
);
88 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_ALLOW_FRAGMENT
, &allow_fragment
, size
, NULL
);
89 ok( hr
== S_OK
, "got %08x\n", hr
);
90 ok( !allow_fragment
, "got %d\n", allow_fragment
);
92 max_attrs
= 0xdeadbeef;
93 size
= sizeof(max_attrs
);
94 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_ATTRIBUTES
, &max_attrs
, size
, NULL
);
95 ok( hr
== S_OK
, "got %08x\n", hr
);
96 ok( max_attrs
== 128, "got %u\n", max_attrs
);
99 size
= sizeof(write_decl
);
100 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_WRITE_DECLARATION
, &write_decl
, size
, NULL
);
101 ok( hr
== S_OK
, "got %08x\n", hr
);
102 ok( !write_decl
, "got %d\n", write_decl
);
105 size
= sizeof(indent
);
106 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_INDENT
, &indent
, size
, NULL
);
107 ok( hr
== S_OK
, "got %08x\n", hr
);
108 ok( !indent
, "got %u\n", indent
);
110 trim_size
= 0xdeadbeef;
111 size
= sizeof(trim_size
);
112 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BUFFER_TRIM_SIZE
, &trim_size
, size
, NULL
);
113 ok( hr
== S_OK
, "got %08x\n", hr
);
114 ok( trim_size
== 4096, "got %u\n", trim_size
);
116 charset
= 0xdeadbeef;
117 size
= sizeof(charset
);
118 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_CHARSET
, &charset
, size
, NULL
);
119 ok( hr
== S_OK
, "got %08x\n", hr
);
120 ok( charset
== WS_CHARSET_UTF8
, "got %u\n", charset
);
122 buffers
.bufferCount
= 0xdeadbeef;
123 buffers
.buffers
= (WS_BYTES
*)0xdeadbeef;
124 size
= sizeof(buffers
);
125 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BUFFERS
, &buffers
, size
, NULL
);
126 ok( hr
== S_OK
, "got %08x\n", hr
);
127 ok( !buffers
.bufferCount
, "got %u\n", buffers
.bufferCount
);
128 ok( !buffers
.buffers
, "got %p\n", buffers
.buffers
);
130 max_size
= 0xdeadbeef;
131 size
= sizeof(max_size
);
132 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE
, &max_size
, size
, NULL
);
133 ok( hr
== S_OK
, "got %08x\n", hr
);
134 ok( max_size
== 65536, "got %u\n", max_size
);
136 bytes
.length
= 0xdeadbeef;
137 bytes
.bytes
= (BYTE
*)0xdeadbeef;
138 size
= sizeof(buffers
);
139 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BYTES
, &bytes
, size
, NULL
);
140 ok( hr
== S_OK
, "got %08x\n", hr
);
141 ok( !bytes
.length
, "got %u\n", bytes
.length
);
142 ok( bytes
.bytes
!= NULL
, "got %p\n", bytes
.bytes
);
144 max_size
= 0xdeadbeef;
145 size
= sizeof(max_size
);
146 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_MIME_PARTS_BUFFER_SIZE
, &max_size
, size
, NULL
);
147 ok( hr
== S_OK
, "got %08x\n", hr
);
148 ok( max_size
== 65536, "got %u\n", max_size
);
150 bytes
.length
= 0xdeadbeef;
151 bytes
.bytes
= (BYTE
*)0xdeadbeef;
152 size
= sizeof(bytes
);
153 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_INITIAL_BUFFER
, &bytes
, size
, NULL
);
154 ok( hr
== S_OK
, "got %08x\n", hr
);
155 ok( !bytes
.length
, "got %u\n", bytes
.length
);
156 ok( !bytes
.bytes
, "got %p\n", bytes
.bytes
);
159 size
= sizeof(max_ns
);
160 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_NAMESPACES
, &max_ns
, size
, NULL
);
161 ok( hr
== S_OK
, "got %08x\n", hr
);
162 ok( max_ns
== 32, "got %u\n", max_ns
);
163 WsFreeWriter( writer
);
165 /* change a property */
167 prop
.id
= WS_XML_WRITER_PROPERTY_MAX_DEPTH
;
168 prop
.value
= &max_depth
;
169 prop
.valueSize
= sizeof(max_depth
);
170 hr
= WsCreateWriter( &prop
, 1, &writer
, NULL
);
171 ok( hr
== S_OK
, "got %08x\n", hr
);
173 hr
= set_output( writer
);
174 ok( hr
== S_OK
, "got %08x\n", hr
);
176 max_depth
= 0xdeadbeef;
177 size
= sizeof(max_depth
);
178 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_DEPTH
, &max_depth
, size
, NULL
);
179 ok( hr
== S_OK
, "got %08x\n", hr
);
180 ok( max_depth
== 16, "got %u\n", max_depth
);
181 WsFreeWriter( writer
);
183 /* show that some properties are read-only */
185 prop
.id
= WS_XML_WRITER_PROPERTY_IN_ATTRIBUTE
;
186 prop
.value
= &in_attr
;
187 prop
.valueSize
= sizeof(in_attr
);
188 hr
= WsCreateWriter( &prop
, 1, &writer
, NULL
);
189 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
192 prop
.id
= WS_XML_WRITER_PROPERTY_BYTES_WRITTEN
;
194 prop
.valueSize
= sizeof(size
);
195 hr
= WsCreateWriter( &prop
, 1, &writer
, NULL
);
196 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
199 prop
.id
= WS_XML_WRITER_PROPERTY_BYTES_TO_CLOSE
;
201 prop
.valueSize
= sizeof(size
);
202 hr
= WsCreateWriter( &prop
, 1, &writer
, NULL
);
203 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
206 static void test_WsCreateXmlBuffer(void)
210 WS_XML_WRITER
*writer
;
211 WS_XML_BUFFER
*buffer
;
215 hr
= WsCreateXmlBuffer( NULL
, NULL
, 0, NULL
, NULL
);
216 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
218 hr
= WsCreateXmlBuffer( NULL
, NULL
, 0, &buffer
, NULL
);
219 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
221 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
222 ok( hr
== S_OK
, "got %08x\n", hr
);
224 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, NULL
, NULL
);
225 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
228 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
229 ok( hr
== S_OK
, "got %08x\n", hr
);
230 ok( buffer
!= NULL
, "buffer not set\n" );
232 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
233 ok( hr
== S_OK
, "got %08x\n", hr
);
235 size
= sizeof(bytes
);
236 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BYTES
, &bytes
, size
, NULL
);
237 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
239 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
240 ok( hr
== S_OK
, "got %08x\n", hr
);
242 size
= sizeof(bytes
);
243 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BYTES
, &bytes
, size
, NULL
);
244 todo_wine
ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
246 WsFreeWriter( writer
);
250 static void test_WsSetOutput(void)
253 WS_XML_WRITER
*writer
;
254 WS_XML_WRITER_PROPERTY prop
;
255 WS_XML_WRITER_TEXT_ENCODING encoding
;
256 WS_XML_WRITER_BUFFER_OUTPUT output
;
257 ULONG size
, max_depth
;
259 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
260 ok( hr
== S_OK
, "got %08x\n", hr
);
262 hr
= WsSetOutput( NULL
, NULL
, NULL
, NULL
, 0, NULL
);
263 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
265 encoding
.encoding
.encodingType
= WS_XML_WRITER_ENCODING_TYPE_TEXT
;
266 encoding
.charSet
= WS_CHARSET_UTF8
;
268 output
.output
.outputType
= WS_XML_WRITER_OUTPUT_TYPE_BUFFER
;
270 hr
= WsSetOutput( writer
, &encoding
.encoding
, &output
.output
, NULL
, 0, NULL
);
271 ok( hr
== S_OK
, "got %08x\n", hr
);
273 /* multiple calls are allowed */
274 hr
= WsSetOutput( writer
, &encoding
.encoding
, &output
.output
, NULL
, 0, NULL
);
275 ok( hr
== S_OK
, "got %08x\n", hr
);
277 /* writer properties can be set with WsSetOutput */
279 prop
.id
= WS_XML_WRITER_PROPERTY_MAX_DEPTH
;
280 prop
.value
= &max_depth
;
281 prop
.valueSize
= sizeof(max_depth
);
282 hr
= WsSetOutput( writer
, &encoding
.encoding
, &output
.output
, &prop
, 1, NULL
);
283 ok( hr
== S_OK
, "got %08x\n", hr
);
285 max_depth
= 0xdeadbeef;
286 size
= sizeof(max_depth
);
287 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_DEPTH
, &max_depth
, size
, NULL
);
288 ok( hr
== S_OK
, "got %08x\n", hr
);
289 ok( max_depth
== 16, "got %u\n", max_depth
);
290 WsFreeWriter( writer
);
293 static void test_WsSetOutputToBuffer(void)
297 WS_XML_BUFFER
*buffer
;
298 WS_XML_WRITER
*writer
;
299 WS_XML_WRITER_PROPERTY prop
;
300 ULONG size
, max_depth
;
302 hr
= WsSetOutputToBuffer( NULL
, NULL
, NULL
, 0, NULL
);
303 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
305 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
306 ok( hr
== S_OK
, "got %08x\n", hr
);
308 hr
= WsSetOutputToBuffer( writer
, NULL
, NULL
, 0, NULL
);
309 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
311 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
312 ok( hr
== S_OK
, "got %08x\n", hr
);
314 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
315 ok( hr
== S_OK
, "got %08x\n", hr
);
317 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
318 ok( hr
== S_OK
, "got %08x\n", hr
);
320 /* multiple calls are allowed */
321 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
322 ok( hr
== S_OK
, "got %08x\n", hr
);
324 /* writer properties can be set with WsSetOutputToBuffer */
326 prop
.id
= WS_XML_WRITER_PROPERTY_MAX_DEPTH
;
327 prop
.value
= &max_depth
;
328 prop
.valueSize
= sizeof(max_depth
);
329 hr
= WsSetOutputToBuffer( writer
, buffer
, &prop
, 1, NULL
);
330 ok( hr
== S_OK
, "got %08x\n", hr
);
332 max_depth
= 0xdeadbeef;
333 size
= sizeof(max_depth
);
334 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_MAX_DEPTH
, &max_depth
, size
, NULL
);
335 ok( hr
== S_OK
, "got %08x\n", hr
);
336 ok( max_depth
== 16, "got %u\n", max_depth
);
338 WsFreeWriter( writer
);
342 static void check_output( WS_XML_WRITER
*writer
, const char *expected
, unsigned int line
)
345 ULONG size
= sizeof(bytes
);
346 int len
= strlen( expected
);
349 memset( &bytes
, 0, sizeof(bytes
) );
350 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BYTES
, &bytes
, size
, NULL
);
351 ok( hr
== S_OK
, "%u: got %08x\n", line
, hr
);
352 ok( bytes
.length
== len
, "%u: got %u expected %u\n", line
, bytes
.length
, len
);
353 if (bytes
.length
!= len
) return;
354 ok( !memcmp( bytes
.bytes
, expected
, len
), "%u: got %s expected %s\n", line
, bytes
.bytes
, expected
);
357 static void test_WsWriteStartElement(void)
360 WS_XML_WRITER
*writer
;
361 WS_XML_STRING prefix
= {1, (BYTE
*)"p"}, ns
= {2, (BYTE
*)"ns"}, ns2
= {3, (BYTE
*)"ns2"};
362 WS_XML_STRING localname
= {1, (BYTE
*)"a"}, localname2
= {1, (BYTE
*)"b"};
364 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
365 ok( hr
== S_OK
, "got %08x\n", hr
);
367 hr
= set_output( writer
);
368 ok( hr
== S_OK
, "got %08x\n", hr
);
370 hr
= WsWriteStartElement( NULL
, &prefix
, &localname
, &ns
, NULL
);
371 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
373 /* first call to WsWriteStartElement doesn't output anything */
374 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
375 ok( hr
== S_OK
, "got %08x\n", hr
);
376 check_output( writer
, "", __LINE__
);
378 /* two ways to close an element */
379 hr
= WsWriteEndStartElement( writer
, NULL
);
380 ok( hr
== S_OK
, "got %08x\n", hr
);
381 check_output( writer
, "<p:a xmlns:p=\"ns\">", __LINE__
);
383 hr
= WsWriteEndElement( writer
, NULL
);
384 ok( hr
== S_OK
, "got %08x\n", hr
);
385 check_output( writer
, "<p:a xmlns:p=\"ns\"></p:a>", __LINE__
);
387 hr
= set_output( writer
);
388 ok( hr
== S_OK
, "got %08x\n", hr
);
390 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
391 ok( hr
== S_OK
, "got %08x\n", hr
);
393 hr
= WsWriteEndElement( writer
, NULL
);
394 ok( hr
== S_OK
, "got %08x\n", hr
);
395 check_output( writer
, "<p:a xmlns:p=\"ns\"/>", __LINE__
);
397 /* nested elements */
398 hr
= set_output( writer
);
399 ok( hr
== S_OK
, "got %08x\n", hr
);
401 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
402 ok( hr
== S_OK
, "got %08x\n", hr
);
403 check_output( writer
, "", __LINE__
);
405 hr
= WsWriteStartElement( writer
, NULL
, &localname2
, &ns
, NULL
);
406 ok( hr
== S_OK
, "got %08x\n", hr
);
407 check_output( writer
, "<p:a xmlns:p=\"ns\">", __LINE__
);
409 hr
= WsWriteEndElement( writer
, NULL
);
410 ok( hr
== S_OK
, "got %08x\n", hr
);
411 check_output( writer
, "<p:a xmlns:p=\"ns\"><p:b/>", __LINE__
);
413 hr
= WsWriteEndElement( writer
, NULL
);
414 ok( hr
== S_OK
, "got %08x\n", hr
);
415 check_output( writer
, "<p:a xmlns:p=\"ns\"><p:b/></p:a>", __LINE__
);
417 hr
= set_output( writer
);
418 ok( hr
== S_OK
, "got %08x\n", hr
);
420 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
421 ok( hr
== S_OK
, "got %08x\n", hr
);
422 check_output( writer
, "", __LINE__
);
424 hr
= WsWriteStartElement( writer
, NULL
, &localname2
, &ns2
, NULL
);
425 ok( hr
== S_OK
, "got %08x\n", hr
);
426 check_output( writer
, "<p:a xmlns:p=\"ns\">", __LINE__
);
428 hr
= WsWriteEndElement( writer
, NULL
);
429 ok( hr
== S_OK
, "got %08x\n", hr
);
430 check_output( writer
, "<p:a xmlns:p=\"ns\"><b xmlns=\"ns2\"/>", __LINE__
);
432 hr
= WsWriteEndElement( writer
, NULL
);
433 ok( hr
== S_OK
, "got %08x\n", hr
);
434 check_output( writer
, "<p:a xmlns:p=\"ns\"><b xmlns=\"ns2\"/></p:a>", __LINE__
);
436 WsFreeWriter( writer
);
439 static void test_WsWriteStartAttribute(void)
442 WS_XML_WRITER
*writer
;
443 WS_XML_STRING prefix
= {1, (BYTE
*)"p"}, localname
= {3, (BYTE
*)"str"}, ns
= {2, (BYTE
*)"ns"};
444 WS_XML_UTF8_TEXT text
;
446 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
447 ok( hr
== S_OK
, "got %08x\n", hr
);
449 hr
= set_output( writer
);
450 ok( hr
== S_OK
, "got %08x\n", hr
);
452 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
453 ok( hr
== S_OK
, "got %08x\n", hr
);
455 hr
= WsWriteStartAttribute( NULL
, &prefix
, &localname
, &ns
, FALSE
, NULL
);
456 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
458 /* WsWriteStartAttribute doesn't output anything */
459 localname
.length
= 3;
460 localname
.bytes
= (BYTE
*)"len";
461 hr
= WsWriteStartAttribute( writer
, &prefix
, &localname
, &ns
, FALSE
, NULL
);
462 ok( hr
== S_OK
, "got %08x\n", hr
);
463 check_output( writer
, "", __LINE__
);
465 text
.text
.textType
= WS_XML_TEXT_TYPE_UTF8
;
466 text
.value
.length
= 1;
467 text
.value
.bytes
= (BYTE
*)"0";
468 hr
= WsWriteText( writer
, &text
.text
, NULL
);
469 ok( hr
== S_OK
, "got %08x\n", hr
);
470 check_output( writer
, "", __LINE__
);
472 /* WsWriteEndAttribute doesn't output anything */
473 hr
= WsWriteEndAttribute( writer
, NULL
);
474 ok( hr
== S_OK
, "got %08x\n", hr
);
475 check_output( writer
, "", __LINE__
);
477 hr
= WsWriteEndElement( writer
, NULL
);
478 ok( hr
== S_OK
, "got %08x\n", hr
);
479 check_output( writer
, "<p:str p:len=\"0\" xmlns:p=\"ns\"/>", __LINE__
);
481 WsFreeWriter( writer
);
484 static void test_WsWriteType(void)
486 static const WCHAR testW
[] = {'t','e','s','t',0};
488 WS_XML_WRITER
*writer
;
489 WS_XML_STRING prefix
= {1, (BYTE
*)"p"}, localname
= {3, (BYTE
*)"str"}, ns
= {2, (BYTE
*)"ns"};
490 const WCHAR
*val_str
;
492 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
493 ok( hr
== S_OK
, "got %08x\n", hr
);
495 hr
= set_output( writer
);
496 ok( hr
== S_OK
, "got %08x\n", hr
);
499 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
500 WS_WRITE_REQUIRED_POINTER
, &val_str
, sizeof(val_str
), NULL
);
501 ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
503 hr
= set_output( writer
);
504 ok( hr
== S_OK
, "got %08x\n", hr
);
506 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
507 ok( hr
== S_OK
, "got %08x\n", hr
);
510 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
511 WS_WRITE_REQUIRED_VALUE
, NULL
, sizeof(testW
), NULL
);
512 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
514 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
515 WS_WRITE_REQUIRED_VALUE
, testW
, sizeof(testW
), NULL
);
516 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
518 /* required pointer */
519 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
520 WS_WRITE_REQUIRED_POINTER
, NULL
, sizeof(val_str
), NULL
);
521 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
523 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
524 WS_WRITE_REQUIRED_VALUE
, testW
, sizeof(testW
), NULL
);
525 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
527 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
528 WS_WRITE_REQUIRED_POINTER
, &val_str
, sizeof(WCHAR
**), NULL
);
529 ok( hr
== S_OK
, "got %08x\n", hr
);
530 check_output( writer
, "<p:str xmlns:p=\"ns\">test", __LINE__
);
532 hr
= WsWriteEndElement( writer
, NULL
);
533 ok( hr
== S_OK
, "got %08x\n", hr
);
534 check_output( writer
, "<p:str xmlns:p=\"ns\">test</p:str>", __LINE__
);
536 hr
= set_output( writer
);
537 ok( hr
== S_OK
, "got %08x\n", hr
);
539 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
540 ok( hr
== S_OK
, "got %08x\n", hr
);
542 hr
= WsWriteStartAttribute( writer
, NULL
, &localname
, &ns
, FALSE
, NULL
);
543 ok( hr
== S_OK
, "got %08x\n", hr
);
546 hr
= WsWriteType( writer
, WS_ATTRIBUTE_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
547 WS_WRITE_REQUIRED_POINTER
, &val_str
, sizeof(val_str
), NULL
);
548 ok( hr
== S_OK
, "got %08x\n", hr
);
549 check_output( writer
, "", __LINE__
);
551 hr
= WsWriteEndAttribute( writer
, NULL
);
552 ok( hr
== S_OK
, "got %08x\n", hr
);
553 check_output( writer
, "", __LINE__
);
555 hr
= WsWriteEndElement( writer
, NULL
);
556 ok( hr
== S_OK
, "got %08x\n", hr
);
557 check_output( writer
, "<p:str p:str=\"test\" xmlns:p=\"ns\"/>", __LINE__
);
559 hr
= set_output( writer
);
560 ok( hr
== S_OK
, "got %08x\n", hr
);
562 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
563 ok( hr
== S_OK
, "got %08x\n", hr
);
566 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, WS_WSZ_TYPE
, NULL
,
567 WS_WRITE_REQUIRED_POINTER
, &val_str
, sizeof(val_str
), NULL
);
568 ok( hr
== S_OK
, "got %08x\n", hr
);
569 check_output( writer
, "<p:str xmlns:p=\"ns\">test", __LINE__
);
571 hr
= WsWriteEndElement( writer
, NULL
);
572 ok( hr
== S_OK
, "got %08x\n", hr
);
573 check_output( writer
, "<p:str xmlns:p=\"ns\">test</p:str>", __LINE__
);
575 WsFreeWriter( writer
);
578 static void test_basic_type(void)
581 WS_XML_WRITER
*writer
;
582 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
594 { WS_BOOL_TYPE
, TRUE
, sizeof(BOOL
), "<t>true</t>", "<t t=\"true\"/>" },
595 { WS_BOOL_TYPE
, FALSE
, sizeof(BOOL
), "<t>false</t>", "<t t=\"false\"/>" },
596 { WS_INT8_TYPE
, -128, sizeof(INT8
), "<t>-128</t>", "<t t=\"-128\"/>" },
597 { WS_INT16_TYPE
, -32768, sizeof(INT16
), "<t>-32768</t>", "<t t=\"-32768\"/>" },
598 { WS_INT32_TYPE
, -2147483647 - 1, sizeof(INT32
), "<t>-2147483648</t>",
599 "<t t=\"-2147483648\"/>" },
600 { WS_INT64_TYPE
, -9223372036854775807 - 1, sizeof(INT64
), "<t>-9223372036854775808</t>",
601 "<t t=\"-9223372036854775808\"/>" },
602 { WS_UINT8_TYPE
, 255, sizeof(UINT8
), "<t>255</t>", "<t t=\"255\"/>" },
603 { WS_UINT16_TYPE
, 65535, sizeof(UINT16
), "<t>65535</t>", "<t t=\"65535\"/>" },
604 { WS_UINT32_TYPE
, ~0u, sizeof(UINT32
), "<t>4294967295</t>", "<t t=\"4294967295\"/>" },
605 { WS_UINT64_TYPE
, ~0, sizeof(UINT64
), "<t>18446744073709551615</t>",
606 "<t t=\"18446744073709551615\"/>" },
609 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
610 ok( hr
== S_OK
, "got %08x\n", hr
);
612 /* element content type mapping */
613 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
615 hr
= set_output( writer
);
616 ok( hr
== S_OK
, "got %08x\n", hr
);
618 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
619 ok( hr
== S_OK
, "got %08x\n", hr
);
621 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, tests
[i
].type
, NULL
,
622 WS_WRITE_REQUIRED_VALUE
, &tests
[i
].val
, tests
[i
].size
, NULL
);
623 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
625 hr
= WsWriteEndElement( writer
, NULL
);
626 ok( hr
== S_OK
, "got %08x\n", hr
);
627 check_output( writer
, tests
[i
].result
, __LINE__
);
630 /* element type mapping is the same as element content type mapping for basic types */
631 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
633 const INT64
*ptr
= &tests
[i
].val
;
635 hr
= set_output( writer
);
636 ok( hr
== S_OK
, "got %08x\n", hr
);
638 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
639 ok( hr
== S_OK
, "got %08x\n", hr
);
641 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, tests
[i
].type
, NULL
,
642 WS_WRITE_REQUIRED_POINTER
, &ptr
, sizeof(ptr
), NULL
);
643 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
645 hr
= WsWriteEndElement( writer
, NULL
);
646 ok( hr
== S_OK
, "got %08x\n", hr
);
647 check_output( writer
, tests
[i
].result
, __LINE__
);
650 /* attribute type mapping */
651 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
653 hr
= set_output( writer
);
654 ok( hr
== S_OK
, "got %08x\n", hr
);
656 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
657 ok( hr
== S_OK
, "got %08x\n", hr
);
659 hr
= WsWriteStartAttribute( writer
, NULL
, &localname
, &ns
, FALSE
, NULL
);
660 ok( hr
== S_OK
, "got %08x\n", hr
);
662 hr
= WsWriteType( writer
, WS_ATTRIBUTE_TYPE_MAPPING
, tests
[i
].type
, NULL
,
663 WS_WRITE_REQUIRED_VALUE
, &tests
[i
].val
, tests
[i
].size
, NULL
);
664 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
666 hr
= WsWriteEndAttribute( writer
, NULL
);
667 ok( hr
== S_OK
, "got %08x\n", hr
);
669 hr
= WsWriteEndElement( writer
, NULL
);
670 ok( hr
== S_OK
, "got %08x\n", hr
);
671 check_output( writer
, tests
[i
].result2
, __LINE__
);
674 WsFreeWriter( writer
);
677 static void test_simple_struct_type(void)
679 static const WCHAR valueW
[] = {'v','a','l','u','e',0};
681 WS_XML_WRITER
*writer
;
682 WS_STRUCT_DESCRIPTION s
;
683 WS_FIELD_DESCRIPTION f
, *fields
[1];
684 WS_XML_STRING localname
= {6, (BYTE
*)"struct"}, ns
= {0, NULL
};
690 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
691 ok( hr
== S_OK
, "got %08x\n", hr
);
693 hr
= set_output( writer
);
694 ok( hr
== S_OK
, "got %08x\n", hr
);
696 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
697 ok( hr
== S_OK
, "got %08x\n", hr
);
699 memset( &f
, 0, sizeof(f
) );
700 f
.mapping
= WS_TEXT_FIELD_MAPPING
;
701 f
.type
= WS_WSZ_TYPE
;
704 memset( &s
, 0, sizeof(s
) );
705 s
.size
= sizeof(struct test
);
706 s
.alignment
= TYPE_ALIGNMENT(struct test
);
710 test
= HeapAlloc( GetProcessHeap(), 0, sizeof(*test
) );
711 test
->field
= valueW
;
712 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, WS_STRUCT_TYPE
, NULL
,
713 WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
714 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
716 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, WS_STRUCT_TYPE
, NULL
,
717 WS_WRITE_REQUIRED_VALUE
, test
, sizeof(*test
), NULL
);
718 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
720 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, WS_STRUCT_TYPE
, &s
,
721 WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
722 ok( hr
== S_OK
, "got %08x\n", hr
);
724 hr
= WsWriteEndElement( writer
, NULL
);
725 ok( hr
== S_OK
, "got %08x\n", hr
);
726 check_output( writer
, "<struct>value</struct>", __LINE__
);
728 hr
= set_output( writer
);
729 ok( hr
== S_OK
, "got %08x\n", hr
);
731 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
732 ok( hr
== S_OK
, "got %08x\n", hr
);
734 hr
= WsWriteType( writer
, WS_ELEMENT_TYPE_MAPPING
, WS_STRUCT_TYPE
, &s
,
735 WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
736 ok( hr
== S_OK
, "got %08x\n", hr
);
738 hr
= WsWriteEndElement( writer
, NULL
);
739 ok( hr
== S_OK
, "got %08x\n", hr
);
740 check_output( writer
, "<struct>value</struct>", __LINE__
);
742 hr
= set_output( writer
);
743 ok( hr
== S_OK
, "got %08x\n", hr
);
745 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
746 ok( hr
== S_OK
, "got %08x\n", hr
);
748 hr
= WsWriteStartAttribute( writer
, NULL
, &localname
, &ns
, FALSE
, NULL
);
749 ok( hr
== S_OK
, "got %08x\n", hr
);
751 hr
= WsWriteType( writer
, WS_ATTRIBUTE_TYPE_MAPPING
, WS_STRUCT_TYPE
, &s
,
752 WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
753 ok( hr
== S_OK
, "got %08x\n", hr
);
755 hr
= WsWriteEndAttribute( writer
, NULL
);
756 ok( hr
== S_OK
, "got %08x\n", hr
);
758 hr
= WsWriteEndElement( writer
, NULL
);
759 ok( hr
== S_OK
, "got %08x\n", hr
);
760 check_output( writer
, "<struct struct=\"value\"/>", __LINE__
);
762 HeapFree( GetProcessHeap(), 0, test
);
763 WsFreeWriter( writer
);
766 static void test_WsWriteElement(void)
768 static const WCHAR testW
[] = {'t','e','s','t',0};
770 WS_XML_WRITER
*writer
;
771 WS_STRUCT_DESCRIPTION s
;
772 WS_FIELD_DESCRIPTION f
, *fields
[1];
773 WS_ELEMENT_DESCRIPTION desc
;
774 WS_XML_STRING localname
= {3, (BYTE
*)"str"}, ns
= {0, NULL
};
775 struct test
{ const WCHAR
*str
; } *test
;
777 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
778 ok( hr
== S_OK
, "got %08x\n", hr
);
780 hr
= set_output( writer
);
781 ok( hr
== S_OK
, "got %08x\n", hr
);
783 /* text field mapping */
784 memset( &f
, 0, sizeof(f
) );
785 f
.mapping
= WS_TEXT_FIELD_MAPPING
;
786 f
.type
= WS_WSZ_TYPE
;
789 memset( &s
, 0, sizeof(s
) );
790 s
.size
= sizeof(struct test
);
791 s
.alignment
= TYPE_ALIGNMENT(struct test
);
795 desc
.elementLocalName
= &localname
;
796 desc
.elementNs
= &ns
;
797 desc
.type
= WS_STRUCT_TYPE
;
798 desc
.typeDescription
= &s
;
800 test
= HeapAlloc( GetProcessHeap(), 0, sizeof(*test
) );
802 hr
= WsWriteElement( NULL
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
803 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
805 hr
= WsWriteElement( writer
, NULL
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
806 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
808 hr
= WsWriteElement( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, NULL
, 0, NULL
);
809 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
811 hr
= WsWriteElement( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
812 ok( hr
== S_OK
, "got %08x\n", hr
);
813 check_output( writer
, "<str>test</str>", __LINE__
);
815 hr
= set_output( writer
);
816 ok( hr
== S_OK
, "got %08x\n", hr
);
818 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
819 ok( hr
== S_OK
, "got %08x\n", hr
);
821 hr
= WsWriteElement( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
822 ok( hr
== S_OK
, "got %08x\n", hr
);
823 check_output( writer
, "<str><str>test</str>", __LINE__
);
825 hr
= set_output( writer
);
826 ok( hr
== S_OK
, "got %08x\n", hr
);
828 /* attribute field mapping */
829 f
.mapping
= WS_ATTRIBUTE_FIELD_MAPPING
;
831 /* requires localName and ns to be set */
832 hr
= WsWriteElement( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
833 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
835 hr
= set_output( writer
);
836 ok( hr
== S_OK
, "got %08x\n", hr
);
838 f
.localName
= &localname
;
840 hr
= WsWriteElement( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
841 ok( hr
== S_OK
, "got %08x\n", hr
);
842 check_output( writer
, "<str str=\"test\"/>", __LINE__
);
844 HeapFree( GetProcessHeap(), 0, test
);
845 WsFreeWriter( writer
);
848 static void test_WsWriteValue(void)
851 WS_XML_WRITER
*writer
;
852 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
864 { WS_BOOL_VALUE_TYPE
, ~0, sizeof(BOOL
), "<t>true</t>", "<t t=\"true\"/>" },
865 { WS_BOOL_VALUE_TYPE
, FALSE
, sizeof(BOOL
), "<t>false</t>", "<t t=\"false\"/>" },
866 { WS_INT8_VALUE_TYPE
, -128, sizeof(INT8
), "<t>-128</t>", "<t t=\"-128\"/>" },
867 { WS_INT16_VALUE_TYPE
, -32768, sizeof(INT16
), "<t>-32768</t>", "<t t=\"-32768\"/>" },
868 { WS_INT32_VALUE_TYPE
, -2147483647 - 1, sizeof(INT32
), "<t>-2147483648</t>",
869 "<t t=\"-2147483648\"/>" },
870 { WS_INT64_VALUE_TYPE
, -9223372036854775807 - 1, sizeof(INT64
), "<t>-9223372036854775808</t>",
871 "<t t=\"-9223372036854775808\"/>" },
872 { WS_UINT8_VALUE_TYPE
, 255, sizeof(UINT8
), "<t>255</t>", "<t t=\"255\"/>" },
873 { WS_UINT16_VALUE_TYPE
, 65535, sizeof(UINT16
), "<t>65535</t>", "<t t=\"65535\"/>" },
874 { WS_UINT32_VALUE_TYPE
, ~0u, sizeof(UINT32
), "<t>4294967295</t>", "<t t=\"4294967295\"/>" },
875 { WS_UINT64_VALUE_TYPE
, ~0, sizeof(UINT64
), "<t>18446744073709551615</t>",
876 "<t t=\"18446744073709551615\"/>" },
879 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
880 ok( hr
== S_OK
, "got %08x\n", hr
);
882 hr
= set_output( writer
);
883 ok( hr
== S_OK
, "got %08x\n", hr
);
885 hr
= WsWriteValue( NULL
, tests
[0].type
, &tests
[0].val
, tests
[0].size
, NULL
);
886 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
888 hr
= WsWriteValue( writer
, tests
[0].type
, &tests
[0].val
, tests
[0].size
, NULL
);
889 ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
891 hr
= set_output( writer
);
892 ok( hr
== S_OK
, "got %08x\n", hr
);
894 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
895 ok( hr
== S_OK
, "got %08x\n", hr
);
898 hr
= WsWriteValue( writer
, tests
[0].type
, &tests
[0].val
, 0, NULL
);
899 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
901 hr
= set_output( writer
);
902 ok( hr
== S_OK
, "got %08x\n", hr
);
904 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
905 ok( hr
== S_OK
, "got %08x\n", hr
);
908 hr
= WsWriteValue( writer
, tests
[0].type
, NULL
, 0, NULL
);
909 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
911 /* element type mapping */
912 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
914 hr
= set_output( writer
);
915 ok( hr
== S_OK
, "got %08x\n", hr
);
917 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
918 ok( hr
== S_OK
, "got %08x\n", hr
);
920 hr
= WsWriteValue( writer
, tests
[i
].type
, &tests
[i
].val
, tests
[i
].size
, NULL
);
921 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
923 hr
= WsWriteEndElement( writer
, NULL
);
924 ok( hr
== S_OK
, "got %08x\n", hr
);
925 check_output( writer
, tests
[i
].result
, __LINE__
);
928 /* attribute type mapping */
929 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
931 hr
= set_output( writer
);
932 ok( hr
== S_OK
, "got %08x\n", hr
);
934 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
935 ok( hr
== S_OK
, "got %08x\n", hr
);
937 hr
= WsWriteStartAttribute( writer
, NULL
, &localname
, &ns
, FALSE
, NULL
);
938 ok( hr
== S_OK
, "got %08x\n", hr
);
940 hr
= WsWriteValue( writer
, tests
[i
].type
, &tests
[i
].val
, tests
[i
].size
, NULL
);
941 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
943 hr
= WsWriteEndAttribute( writer
, NULL
);
944 ok( hr
== S_OK
, "got %08x\n", hr
);
946 hr
= WsWriteEndElement( writer
, NULL
);
947 ok( hr
== S_OK
, "got %08x\n", hr
);
948 check_output( writer
, tests
[i
].result2
, __LINE__
);
951 WsFreeWriter( writer
);
954 static void test_WsWriteAttribute(void)
956 static const WCHAR testW
[] = {'t','e','s','t',0};
958 WS_XML_WRITER
*writer
;
959 WS_STRUCT_DESCRIPTION s
;
960 WS_FIELD_DESCRIPTION f
, *fields
[1];
961 WS_ATTRIBUTE_DESCRIPTION desc
;
962 WS_XML_STRING localname
= {3, (BYTE
*)"str"}, ns
= {0, NULL
};
963 struct test
{ const WCHAR
*str
; } *test
;
965 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
966 ok( hr
== S_OK
, "got %08x\n", hr
);
968 hr
= set_output( writer
);
969 ok( hr
== S_OK
, "got %08x\n", hr
);
971 /* text field mapping */
972 memset( &f
, 0, sizeof(f
) );
973 f
.mapping
= WS_TEXT_FIELD_MAPPING
;
974 f
.type
= WS_WSZ_TYPE
;
977 memset( &s
, 0, sizeof(s
) );
978 s
.size
= sizeof(struct test
);
979 s
.alignment
= TYPE_ALIGNMENT(struct test
);
983 desc
.attributeLocalName
= &localname
;
984 desc
.attributeNs
= &ns
;
985 desc
.type
= WS_STRUCT_TYPE
;
986 desc
.typeDescription
= &s
;
988 test
= HeapAlloc( GetProcessHeap(), 0, sizeof(*test
) );
990 hr
= WsWriteAttribute( NULL
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
991 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
993 hr
= WsWriteAttribute( writer
, NULL
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
994 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
996 hr
= WsWriteAttribute( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, NULL
, 0, NULL
);
997 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
999 hr
= WsWriteAttribute( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
1000 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1002 hr
= set_output( writer
);
1003 ok( hr
== S_OK
, "got %08x\n", hr
);
1005 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1006 ok( hr
== S_OK
, "got %08x\n", hr
);
1008 hr
= WsWriteAttribute( writer
, &desc
, WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
1009 ok( hr
== S_OK
, "got %08x\n", hr
);
1011 hr
= WsWriteEndElement( writer
, NULL
);
1012 ok( hr
== S_OK
, "got %08x\n", hr
);
1013 check_output( writer
, "<str str=\"test\"/>", __LINE__
);
1015 HeapFree( GetProcessHeap(), 0, test
);
1016 WsFreeWriter( writer
);
1019 static void test_WsWriteStartCData(void)
1022 WS_XML_WRITER
*writer
;
1023 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
1024 WS_XML_UTF8_TEXT text
;
1026 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1027 ok( hr
== S_OK
, "got %08x\n", hr
);
1029 hr
= set_output( writer
);
1030 ok( hr
== S_OK
, "got %08x\n", hr
);
1032 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1033 ok( hr
== S_OK
, "got %08x\n", hr
);
1035 hr
= WsWriteEndCData( writer
, NULL
);
1036 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1038 hr
= set_output( writer
);
1039 ok( hr
== S_OK
, "got %08x\n", hr
);
1041 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1042 ok( hr
== S_OK
, "got %08x\n", hr
);
1043 check_output( writer
, "", __LINE__
);
1045 hr
= WsWriteStartCData( writer
, NULL
);
1046 ok( hr
== S_OK
, "got %08x\n", hr
);
1047 check_output( writer
, "<t><![CDATA[", __LINE__
);
1049 text
.text
.textType
= WS_XML_TEXT_TYPE_UTF8
;
1050 text
.value
.bytes
= (BYTE
*)"<data>";
1051 text
.value
.length
= 6;
1052 hr
= WsWriteText( writer
, &text
.text
, NULL
);
1053 ok( hr
== S_OK
, "got %08x\n", hr
);
1054 check_output( writer
, "<t><![CDATA[<data>", __LINE__
);
1056 hr
= WsWriteEndCData( writer
, NULL
);
1057 ok( hr
== S_OK
, "got %08x\n", hr
);
1058 check_output( writer
, "<t><![CDATA[<data>]]>", __LINE__
);
1060 hr
= WsWriteEndElement( writer
, NULL
);
1061 ok( hr
== S_OK
, "got %08x\n", hr
);
1062 check_output( writer
, "<t><![CDATA[<data>]]></t>", __LINE__
);
1064 WsFreeWriter( writer
);
1067 static void check_output_buffer( WS_XML_BUFFER
*buffer
, const char *expected
, unsigned int line
)
1069 WS_XML_WRITER
*writer
;
1071 ULONG size
= sizeof(bytes
);
1072 int len
= strlen(expected
);
1075 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1076 ok( hr
== S_OK
, "got %08x\n", hr
);
1078 hr
= set_output( writer
);
1079 ok( hr
== S_OK
, "got %08x\n", hr
);
1081 hr
= WsWriteXmlBuffer( writer
, buffer
, NULL
);
1082 ok( hr
== S_OK
, "got %08x\n", hr
);
1084 memset( &bytes
, 0, sizeof(bytes
) );
1085 hr
= WsGetWriterProperty( writer
, WS_XML_WRITER_PROPERTY_BYTES
, &bytes
, size
, NULL
);
1086 ok( hr
== S_OK
, "%u: got %08x\n", line
, hr
);
1087 ok( bytes
.length
== len
, "%u: got %u expected %u\n", line
, bytes
.length
, len
);
1088 if (bytes
.length
!= len
) return;
1089 ok( !memcmp( bytes
.bytes
, expected
, len
), "%u: got %s expected %s\n", line
, bytes
.bytes
, expected
);
1091 WsFreeWriter( writer
);
1094 static void prepare_xmlns_test( WS_XML_WRITER
*writer
, WS_HEAP
**heap
, WS_XML_BUFFER
**buffer
)
1096 WS_XML_STRING prefix
= {6, (BYTE
*)"prefix"}, localname
= {1, (BYTE
*)"t"}, ns
= {2, (BYTE
*)"ns"};
1099 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, heap
, NULL
);
1100 ok( hr
== S_OK
, "got %08x\n", hr
);
1102 hr
= WsCreateXmlBuffer( *heap
, NULL
, 0, buffer
, NULL
);
1103 ok( hr
== S_OK
, "got %08x\n", hr
);
1105 hr
= WsSetOutputToBuffer( writer
, *buffer
, NULL
, 0, NULL
);
1106 ok( hr
== S_OK
, "got %08x\n", hr
);
1108 hr
= WsWriteStartElement( writer
, &prefix
, &localname
, &ns
, NULL
);
1109 ok( hr
== S_OK
, "got %08x\n", hr
);
1112 static void test_WsWriteXmlnsAttribute(void)
1114 WS_XML_STRING ns
= {2, (BYTE
*)"ns"}, ns2
= {3, (BYTE
*)"ns2"};
1115 WS_XML_STRING prefix
= {6, (BYTE
*)"prefix"}, prefix2
= {7, (BYTE
*)"prefix2"};
1116 WS_XML_STRING xmlns
= {6, (BYTE
*)"xmlns"}, attr
= {4, (BYTE
*)"attr"};
1117 WS_XML_STRING localname
= {1, (BYTE
*)"u"};
1119 WS_XML_BUFFER
*buffer
;
1120 WS_XML_WRITER
*writer
;
1123 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1124 ok( hr
== S_OK
, "got %08x\n", hr
);
1126 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1127 ok( hr
== S_OK
, "got %08x\n", hr
);
1129 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1130 ok( hr
== S_OK
, "got %08x\n", hr
);
1132 hr
= WsWriteXmlnsAttribute( NULL
, NULL
, NULL
, FALSE
, NULL
);
1133 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1136 prepare_xmlns_test( writer
, &heap
, &buffer
);
1137 hr
= WsWriteXmlnsAttribute( writer
, NULL
, NULL
, FALSE
, NULL
);
1138 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1141 prepare_xmlns_test( writer
, &heap
, &buffer
);
1142 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, NULL
, FALSE
, NULL
);
1143 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1145 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1146 ok( hr
== S_OK
, "got %08x\n", hr
);
1147 hr
= WsWriteXmlnsAttribute( writer
, NULL
, &ns
, FALSE
, NULL
);
1148 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1152 prepare_xmlns_test( writer
, &heap
, &buffer
);
1153 hr
= WsWriteXmlnsAttribute( writer
, NULL
, &ns2
, FALSE
, NULL
);
1154 ok( hr
== S_OK
, "got %08x\n", hr
);
1155 hr
= WsWriteEndElement( writer
, NULL
);
1156 ok( hr
== S_OK
, "got %08x\n", hr
);
1157 check_output_buffer( buffer
, "<prefix:t xmlns:prefix=\"ns\" xmlns=\"ns2\"/>", __LINE__
);
1161 prepare_xmlns_test( writer
, &heap
, &buffer
);
1162 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns2
, FALSE
, NULL
);
1163 ok( hr
== S_OK
, "got %08x\n", hr
);
1164 hr
= WsWriteEndElement( writer
, NULL
);
1165 ok( hr
== S_OK
, "got %08x\n", hr
);
1166 check_output_buffer( buffer
, "<prefix:t xmlns:prefix2=\"ns2\" xmlns:prefix=\"ns\"/>", __LINE__
);
1169 /* implicitly set element prefix namespace */
1170 prepare_xmlns_test( writer
, &heap
, &buffer
);
1171 hr
= WsWriteEndElement( writer
, NULL
);
1172 ok( hr
== S_OK
, "got %08x\n", hr
);
1173 check_output_buffer( buffer
, "<prefix:t xmlns:prefix=\"ns\"/>", __LINE__
);
1176 /* explicitly set element prefix namespace */
1177 prepare_xmlns_test( writer
, &heap
, &buffer
);
1178 hr
= WsWriteXmlnsAttribute( writer
, &prefix
, &ns
, TRUE
, NULL
);
1179 ok( hr
== S_OK
, "got %08x\n", hr
);
1180 hr
= WsWriteEndElement( writer
, NULL
);
1181 ok( hr
== S_OK
, "got %08x\n", hr
);
1182 check_output_buffer( buffer
, "<prefix:t xmlns:prefix='ns'/>", __LINE__
);
1185 /* repeated calls, same namespace */
1186 prepare_xmlns_test( writer
, &heap
, &buffer
);
1187 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns
, FALSE
, NULL
);
1188 ok( hr
== S_OK
, "got %08x\n", hr
);
1189 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns
, FALSE
, NULL
);
1190 ok( hr
== S_OK
, "got %08x\n", hr
);
1191 hr
= WsWriteEndElement( writer
, NULL
);
1192 ok( hr
== S_OK
, "got %08x\n", hr
);
1193 check_output_buffer( buffer
, "<prefix:t xmlns:prefix2=\"ns\" xmlns:prefix=\"ns\"/>", __LINE__
);
1196 /* repeated calls, different namespace */
1197 prepare_xmlns_test( writer
, &heap
, &buffer
);
1198 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns
, FALSE
, NULL
);
1199 ok( hr
== S_OK
, "got %08x\n", hr
);
1200 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns2
, FALSE
, NULL
);
1201 ok( hr
== S_OK
, "got %08x\n", hr
);
1202 hr
= WsWriteEndElement( writer
, NULL
);
1203 todo_wine
ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1207 prepare_xmlns_test( writer
, &heap
, &buffer
);
1208 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns
, TRUE
, NULL
);
1209 ok( hr
== S_OK
, "got %08x\n", hr
);
1210 hr
= WsWriteEndElement( writer
, NULL
);
1211 ok( hr
== S_OK
, "got %08x\n", hr
);
1212 check_output_buffer( buffer
, "<prefix:t xmlns:prefix2='ns' xmlns:prefix=\"ns\"/>", __LINE__
);
1215 /* different namespace, different prefix */
1216 prepare_xmlns_test( writer
, &heap
, &buffer
);
1217 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns2
, TRUE
, NULL
);
1218 ok( hr
== S_OK
, "got %08x\n", hr
);
1219 hr
= WsWriteEndElement( writer
, NULL
);
1220 ok( hr
== S_OK
, "got %08x\n", hr
);
1221 check_output_buffer( buffer
, "<prefix:t xmlns:prefix2='ns2' xmlns:prefix=\"ns\"/>", __LINE__
);
1224 /* different namespace, same prefix */
1225 prepare_xmlns_test( writer
, &heap
, &buffer
);
1226 hr
= WsWriteXmlnsAttribute( writer
, &prefix
, &ns2
, TRUE
, NULL
);
1227 ok( hr
== S_OK
, "got %08x\n", hr
);
1228 hr
= WsWriteEndElement( writer
, NULL
);
1229 todo_wine
ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1232 /* regular attribute */
1233 prepare_xmlns_test( writer
, &heap
, &buffer
);
1234 hr
= WsWriteStartAttribute( writer
, &xmlns
, &prefix2
, &ns2
, TRUE
, NULL
);
1235 ok( hr
== S_OK
, "got %08x\n", hr
);
1236 hr
= WsWriteEndAttribute( writer
, NULL
);
1237 ok( hr
== S_OK
, "got %08x\n", hr
);
1238 hr
= WsWriteEndElement( writer
, NULL
);
1239 todo_wine
ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1242 /* attribute order */
1243 prepare_xmlns_test( writer
, &heap
, &buffer
);
1244 hr
= WsWriteXmlnsAttribute( writer
, &prefix
, &ns
, TRUE
, NULL
);
1245 ok( hr
== S_OK
, "got %08x\n", hr
);
1246 hr
= WsWriteStartAttribute( writer
, &prefix
, &attr
, &ns
, TRUE
, NULL
);
1247 ok( hr
== S_OK
, "got %08x\n", hr
);
1248 hr
= WsWriteEndAttribute( writer
, NULL
);
1249 ok( hr
== S_OK
, "got %08x\n", hr
);
1250 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns2
, TRUE
, NULL
);
1251 ok( hr
== S_OK
, "got %08x\n", hr
);
1252 hr
= WsWriteEndElement( writer
, NULL
);
1253 ok( hr
== S_OK
, "got %08x\n", hr
);
1254 check_output_buffer( buffer
, "<prefix:t prefix:attr='' xmlns:prefix='ns' xmlns:prefix2='ns2'/>", __LINE__
);
1258 prepare_xmlns_test( writer
, &heap
, &buffer
);
1259 hr
= WsWriteXmlnsAttribute( writer
, &prefix2
, &ns2
, TRUE
, NULL
);
1260 ok( hr
== S_OK
, "got %08x\n", hr
);
1261 hr
= WsWriteStartElement( writer
, &prefix2
, &localname
, &ns2
, NULL
);
1262 ok( hr
== S_OK
, "got %08x\n", hr
);
1263 hr
= WsWriteEndElement( writer
, NULL
);
1264 ok( hr
== S_OK
, "got %08x\n", hr
);
1265 hr
= WsWriteEndElement( writer
, NULL
);
1266 ok( hr
== S_OK
, "got %08x\n", hr
);
1267 check_output_buffer( buffer
, "<prefix:t xmlns:prefix2='ns2' xmlns:prefix=\"ns\"><prefix2:u/></prefix:t>",
1271 WsFreeWriter( writer
);
1274 static void prepare_prefix_test( WS_XML_WRITER
*writer
)
1276 const WS_XML_STRING p
= {1, (BYTE
*)"p"}, localname
= {1, (BYTE
*)"t"}, ns
= {2, (BYTE
*)"ns"};
1279 hr
= set_output( writer
);
1280 ok( hr
== S_OK
, "got %08x\n", hr
);
1281 hr
= WsWriteStartElement( writer
, &p
, &localname
, &ns
, NULL
);
1282 ok( hr
== S_OK
, "got %08x\n", hr
);
1283 hr
= WsWriteEndStartElement( writer
, NULL
);
1284 ok( hr
== S_OK
, "got %08x\n", hr
);
1287 static void test_WsGetPrefixFromNamespace(void)
1289 const WS_XML_STRING p
= {1, (BYTE
*)"p"}, localname
= {1, (BYTE
*)"t"}, *prefix
;
1290 const WS_XML_STRING ns
= {2, (BYTE
*)"ns"}, ns2
= {3, (BYTE
*)"ns2"};
1291 WS_XML_WRITER
*writer
;
1294 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1295 ok( hr
== S_OK
, "got %08x\n", hr
);
1297 hr
= set_output( writer
);
1298 ok( hr
== S_OK
, "got %08x\n", hr
);
1299 hr
= WsWriteStartElement( writer
, &p
, &localname
, &ns
, NULL
);
1300 ok( hr
== S_OK
, "got %08x\n", hr
);
1302 hr
= WsGetPrefixFromNamespace( NULL
, NULL
, FALSE
, NULL
, NULL
);
1303 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1305 hr
= WsGetPrefixFromNamespace( NULL
, NULL
, FALSE
, &prefix
, NULL
);
1306 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1308 hr
= WsGetPrefixFromNamespace( writer
, NULL
, FALSE
, &prefix
, NULL
);
1309 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1311 /* element must be committed */
1312 hr
= set_output( writer
);
1313 ok( hr
== S_OK
, "got %08x\n", hr
);
1314 hr
= WsWriteStartElement( writer
, &p
, &localname
, &ns
, NULL
);
1315 ok( hr
== S_OK
, "got %08x\n", hr
);
1316 hr
= WsGetPrefixFromNamespace( writer
, &ns
, TRUE
, &prefix
, NULL
);
1317 ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1319 /* but writer can't be positioned on end element node */
1320 hr
= set_output( writer
);
1321 ok( hr
== S_OK
, "got %08x\n", hr
);
1322 hr
= WsWriteStartElement( writer
, &p
, &localname
, &ns
, NULL
);
1323 ok( hr
== S_OK
, "got %08x\n", hr
);
1324 hr
= WsWriteEndElement( writer
, NULL
);
1325 ok( hr
== S_OK
, "got %08x\n", hr
);
1326 hr
= WsGetPrefixFromNamespace( writer
, &ns
, TRUE
, &prefix
, NULL
);
1327 ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1329 /* required = TRUE */
1331 prepare_prefix_test( writer
);
1332 hr
= WsGetPrefixFromNamespace( writer
, &ns
, TRUE
, &prefix
, NULL
);
1333 ok( hr
== S_OK
, "got %08x\n", hr
);
1334 ok( prefix
!= NULL
, "prefix not set\n" );
1337 ok( prefix
->length
== 1, "got %u\n", prefix
->length
);
1338 ok( !memcmp( prefix
->bytes
, "p", 1 ), "wrong prefix\n" );
1341 prefix
= (const WS_XML_STRING
*)0xdeadbeef;
1342 hr
= WsGetPrefixFromNamespace( writer
, &ns2
, TRUE
, &prefix
, NULL
);
1343 ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1344 ok( prefix
== (const WS_XML_STRING
*)0xdeadbeef, "prefix set\n" );
1346 /* required = FALSE */
1348 prepare_prefix_test( writer
);
1349 hr
= WsGetPrefixFromNamespace( writer
, &ns
, FALSE
, &prefix
, NULL
);
1350 ok( hr
== S_OK
, "got %08x\n", hr
);
1351 ok( prefix
!= NULL
, "prefix not set\n" );
1354 ok( prefix
->length
== 1, "got %u\n", prefix
->length
);
1355 ok( !memcmp( prefix
->bytes
, "p", 1 ), "wrong prefix\n" );
1358 prefix
= (const WS_XML_STRING
*)0xdeadbeef;
1359 hr
= WsGetPrefixFromNamespace( writer
, &ns2
, FALSE
, &prefix
, NULL
);
1360 ok( hr
== S_FALSE
, "got %08x\n", hr
);
1361 ok( prefix
== NULL
, "prefix not set\n" );
1363 WsFreeWriter( writer
);
1366 static void test_complex_struct_type(void)
1368 static const char expected
[] =
1369 "<o:OfficeConfig xmlns:o=\"urn:schemas-microsoft-com:office:office\">"
1370 "<o:services o:GenerationTime=\"2015-09-03T18:47:54\"/>"
1371 "</o:OfficeConfig>";
1372 static const WCHAR timestampW
[] =
1373 {'2','0','1','5','-','0','9','-','0','3','T','1','8',':','4','7',':','5','4',0};
1374 WS_XML_STRING str_officeconfig
= {12, (BYTE
*)"OfficeConfig"};
1375 WS_XML_STRING str_services
= {8, (BYTE
*)"services"};
1376 WS_XML_STRING str_generationtime
= {14, (BYTE
*)"GenerationTime"};
1377 WS_XML_STRING ns
= {39, (BYTE
*)"urn:schemas-microsoft-com:office:office"};
1378 WS_XML_STRING prefix
= {1, (BYTE
*)"o"};
1382 WS_XML_BUFFER
*buffer
;
1383 WS_XML_WRITER
*writer
;
1384 WS_STRUCT_DESCRIPTION s
, s2
;
1385 WS_FIELD_DESCRIPTION f
, f2
, *fields
[1], *fields2
[1];
1388 const WCHAR
*generationtime
;
1392 struct services
*services
;
1395 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1396 ok( hr
== S_OK
, "got %08x\n", hr
);
1398 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1399 ok( hr
== S_OK
, "got %08x\n", hr
);
1401 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1402 ok( hr
== S_OK
, "got %08x\n", hr
);
1404 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1405 ok( hr
== S_OK
, "got %08x\n", hr
);
1407 hr
= WsWriteStartElement( writer
, &prefix
, &str_officeconfig
, &ns
, NULL
);
1408 ok( hr
== S_OK
, "got %08x\n", hr
);
1410 memset( &f2
, 0, sizeof(f2
) );
1411 f2
.mapping
= WS_ATTRIBUTE_FIELD_MAPPING
;
1412 f2
.localName
= &str_generationtime
;
1414 f2
.type
= WS_WSZ_TYPE
;
1415 f2
.options
= WS_FIELD_OPTIONAL
;
1418 memset( &s2
, 0, sizeof(s2
) );
1419 s2
.size
= sizeof(*test
->services
);
1421 s2
.fields
= fields2
;
1423 s2
.typeLocalName
= &str_services
;
1426 memset( &f
, 0, sizeof(f
) );
1427 f
.mapping
= WS_ELEMENT_FIELD_MAPPING
;
1428 f
.localName
= &str_services
;
1430 f
.type
= WS_STRUCT_TYPE
;
1431 f
.typeDescription
= &s2
;
1432 f
.options
= WS_FIELD_POINTER
;
1435 memset( &s
, 0, sizeof(s
) );
1436 s
.size
= sizeof(*test
);
1440 s
.typeLocalName
= &str_officeconfig
;
1443 size
= sizeof(struct officeconfig
) + sizeof(struct services
);
1444 test
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1445 test
->services
= (struct services
*)(test
+ 1);
1446 test
->services
->generationtime
= timestampW
;
1447 hr
= WsWriteType( writer
, WS_ELEMENT_CONTENT_TYPE_MAPPING
, WS_STRUCT_TYPE
, &s
,
1448 WS_WRITE_REQUIRED_POINTER
, &test
, sizeof(test
), NULL
);
1449 ok( hr
== S_OK
, "got %08x\n", hr
);
1451 hr
= WsWriteEndElement( writer
, NULL
);
1452 ok( hr
== S_OK
, "got %08x\n", hr
);
1453 check_output_buffer( buffer
, expected
, __LINE__
);
1455 HeapFree( GetProcessHeap(), 0, test
);
1456 WsFreeWriter( writer
);
1460 static void test_WsMoveWriter(void)
1462 WS_XML_STRING localname
= {1, (BYTE
*)"a"}, localname2
= {1, (BYTE
*)"b"}, ns
= {0, NULL
};
1464 WS_XML_WRITER
*writer
;
1465 WS_XML_BUFFER
*buffer
;
1468 hr
= WsMoveWriter( NULL
, WS_MOVE_TO_EOF
, NULL
, NULL
);
1469 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1471 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1472 ok( hr
== S_OK
, "got %08x\n", hr
);
1474 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1475 ok( hr
== S_OK
, "got %08x\n", hr
);
1477 hr
= set_output( writer
);
1478 ok( hr
== S_OK
, "got %08x\n", hr
);
1480 /* writer must be set to an XML buffer */
1481 hr
= WsMoveWriter( writer
, WS_MOVE_TO_EOF
, NULL
, NULL
);
1482 todo_wine
ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1484 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1485 ok( hr
== S_OK
, "got %08x\n", hr
);
1487 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1488 ok( hr
== S_OK
, "got %08x\n", hr
);
1490 hr
= WsMoveWriter( writer
, WS_MOVE_TO_EOF
, NULL
, NULL
);
1491 ok( hr
== S_OK
, "got %08x\n", hr
);
1494 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1495 ok( hr
== S_OK
, "got %08x\n", hr
);
1497 hr
= WsWriteStartElement( writer
, NULL
, &localname2
, &ns
, NULL
);
1498 ok( hr
== S_OK
, "got %08x\n", hr
);
1500 hr
= WsWriteEndElement( writer
, NULL
);
1501 ok( hr
== S_OK
, "got %08x\n", hr
);
1503 hr
= WsWriteEndElement( writer
, NULL
);
1504 ok( hr
== S_OK
, "got %08x\n", hr
);
1506 hr
= WsMoveWriter( writer
, WS_MOVE_TO_EOF
, NULL
, NULL
);
1507 ok( hr
== S_OK
, "got %08x\n", hr
);
1509 hr
= WsMoveWriter( writer
, WS_MOVE_TO_ROOT_ELEMENT
, NULL
, NULL
);
1510 ok( hr
== S_OK
, "got %08x\n", hr
);
1512 hr
= WsMoveWriter( writer
, WS_MOVE_TO_CHILD_ELEMENT
, NULL
, NULL
);
1513 ok( hr
== S_OK
, "got %08x\n", hr
);
1515 hr
= WsMoveWriter( writer
, WS_MOVE_TO_END_ELEMENT
, NULL
, NULL
);
1516 ok( hr
== S_OK
, "got %08x\n", hr
);
1518 hr
= WsMoveWriter( writer
, WS_MOVE_TO_PARENT_ELEMENT
, NULL
, NULL
);
1519 ok( hr
== S_OK
, "got %08x\n", hr
);
1521 hr
= WsMoveWriter( writer
, WS_MOVE_TO_END_ELEMENT
, NULL
, NULL
);
1522 ok( hr
== S_OK
, "got %08x\n", hr
);
1524 hr
= WsMoveWriter( writer
, WS_MOVE_TO_BOF
, NULL
, NULL
);
1525 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1527 WsFreeWriter( writer
);
1531 static void test_WsGetWriterPosition(void)
1534 WS_XML_WRITER
*writer
;
1535 WS_XML_BUFFER
*buffer
;
1536 WS_XML_NODE_POSITION pos
;
1539 hr
= WsGetWriterPosition( NULL
, NULL
, NULL
);
1540 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1542 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1543 ok( hr
== S_OK
, "got %08x\n", hr
);
1545 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1546 ok( hr
== S_OK
, "got %08x\n", hr
);
1548 hr
= WsGetWriterPosition( writer
, &pos
, NULL
);
1549 ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1551 hr
= set_output( writer
);
1552 ok( hr
== S_OK
, "got %08x\n", hr
);
1554 /* writer must be set to an XML buffer */
1555 hr
= WsGetWriterPosition( writer
, &pos
, NULL
);
1556 todo_wine
ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1558 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1559 ok( hr
== S_OK
, "got %08x\n", hr
);
1561 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1562 ok( hr
== S_OK
, "got %08x\n", hr
);
1564 hr
= WsGetWriterPosition( writer
, NULL
, NULL
);
1565 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1567 pos
.buffer
= pos
.node
= NULL
;
1568 hr
= WsGetWriterPosition( writer
, &pos
, NULL
);
1569 ok( hr
== S_OK
, "got %08x\n", hr
);
1570 ok( pos
.buffer
!= NULL
, "buffer not set\n" );
1571 ok( pos
.node
!= NULL
, "node not set\n" );
1573 WsFreeWriter( writer
);
1577 static void test_WsSetWriterPosition(void)
1580 WS_XML_WRITER
*writer
;
1581 WS_XML_BUFFER
*buf1
, *buf2
;
1582 WS_XML_NODE_POSITION pos
;
1585 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1586 ok( hr
== S_OK
, "got %08x\n", hr
);
1588 hr
= WsSetWriterPosition( NULL
, NULL
, NULL
);
1589 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1591 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1592 ok( hr
== S_OK
, "got %08x\n", hr
);
1594 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buf1
, NULL
);
1595 ok( hr
== S_OK
, "got %08x\n", hr
);
1597 hr
= WsSetOutputToBuffer( writer
, buf1
, NULL
, 0, NULL
);
1598 ok( hr
== S_OK
, "got %08x\n", hr
);
1600 hr
= WsSetWriterPosition( writer
, NULL
, NULL
);
1601 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1603 pos
.buffer
= pos
.node
= NULL
;
1604 hr
= WsGetWriterPosition( writer
, &pos
, NULL
);
1605 ok( hr
== S_OK
, "got %08x\n", hr
);
1606 ok( pos
.buffer
== buf1
, "wrong buffer\n" );
1607 ok( pos
.node
!= NULL
, "node not set\n" );
1609 hr
= WsSetWriterPosition( writer
, &pos
, NULL
);
1610 ok( hr
== S_OK
, "got %08x\n", hr
);
1612 /* different buffer */
1613 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buf2
, NULL
);
1614 ok( hr
== S_OK
, "got %08x\n", hr
);
1617 hr
= WsSetWriterPosition( writer
, &pos
, NULL
);
1618 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1620 WsFreeWriter( writer
);
1624 static void test_WsWriteXmlBuffer(void)
1626 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
1627 WS_XML_WRITER
*writer1
, *writer2
;
1628 WS_XML_BUFFER
*buffer1
, *buffer2
;
1632 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1633 ok( hr
== S_OK
, "got %08x\n", hr
);
1635 hr
= WsCreateXmlBuffer( NULL
, NULL
, 0, NULL
, NULL
);
1636 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1638 hr
= WsCreateWriter( NULL
, 0, &writer1
, NULL
);
1639 ok( hr
== S_OK
, "got %08x\n", hr
);
1641 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, NULL
, NULL
);
1642 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1644 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer1
, NULL
);
1645 ok( hr
== S_OK
, "got %08x\n", hr
);
1647 hr
= WsSetOutputToBuffer( writer1
, buffer1
, NULL
, 0, NULL
);
1648 ok( hr
== S_OK
, "got %08x\n", hr
);
1650 hr
= WsWriteStartElement( writer1
, NULL
, &localname
, &ns
, NULL
);
1651 ok( hr
== S_OK
, "got %08x\n", hr
);
1653 hr
= WsWriteEndElement( writer1
, NULL
);
1654 ok( hr
== S_OK
, "got %08x\n", hr
);
1655 check_output_buffer( buffer1
, "<t/>", __LINE__
);
1657 hr
= WsCreateWriter( NULL
, 0, &writer2
, NULL
);
1658 ok( hr
== S_OK
, "got %08x\n", hr
);
1660 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer2
, NULL
);
1661 ok( hr
== S_OK
, "got %08x\n", hr
);
1663 hr
= WsSetOutputToBuffer( writer2
, buffer2
, NULL
, 0, NULL
);
1664 ok( hr
== S_OK
, "got %08x\n", hr
);
1666 hr
= WsWriteXmlBuffer( writer2
, buffer1
, NULL
);
1667 ok( hr
== S_OK
, "got %08x\n", hr
);
1668 check_output_buffer( buffer2
, "<t/>", __LINE__
);
1670 hr
= WsMoveWriter( writer2
, WS_MOVE_TO_PREVIOUS_ELEMENT
, NULL
, NULL
);
1671 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
1673 hr
= WsWriteXmlBuffer( writer2
, buffer1
, NULL
);
1674 todo_wine
ok( hr
== WS_E_INVALID_FORMAT
, "got %08x\n", hr
);
1676 WsFreeWriter( writer1
);
1677 WsFreeWriter( writer2
);
1681 static void test_WsWriteNode(void)
1683 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, localname2
= {4, (BYTE
*)"attr"}, ns
= {0, NULL
};
1684 WS_XML_WRITER
*writer
;
1685 WS_XML_BUFFER
*buffer
;
1686 WS_XML_UTF8_TEXT utf8
;
1687 WS_XML_ATTRIBUTE attr
, *attrs
[1];
1688 WS_XML_ELEMENT_NODE elem
;
1689 WS_XML_COMMENT_NODE comment
;
1691 WS_XML_TEXT_NODE text
;
1695 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1696 ok( hr
== S_OK
, "got %08x\n", hr
);
1698 hr
= WsWriteNode( NULL
, NULL
, NULL
);
1699 ok( hr
== E_INVALIDARG
, "got %08x\n", hr
);
1701 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1702 ok( hr
== S_OK
, "got %08x\n", hr
);
1704 hr
= WsWriteNode( writer
, NULL
, NULL
);
1705 todo_wine
ok( hr
== WS_E_INVALID_OPERATION
, "got %08x\n", hr
);
1707 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1708 ok( hr
== S_OK
, "got %08x\n", hr
);
1710 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1711 ok( hr
== S_OK
, "got %08x\n", hr
);
1713 utf8
.text
.textType
= WS_XML_TEXT_TYPE_UTF8
;
1714 utf8
.value
.bytes
= (BYTE
*)"value";
1715 utf8
.value
.length
= sizeof("value") - 1;
1717 attr
.singleQuote
= TRUE
;
1718 attr
.isXmlNs
= FALSE
;
1720 attr
.localName
= &localname2
;
1722 attr
.value
= &utf8
.text
;
1725 elem
.node
.nodeType
= WS_XML_NODE_TYPE_ELEMENT
;
1727 elem
.localName
= &localname
;
1729 elem
.attributeCount
= 1;
1730 elem
.attributes
= attrs
;
1731 elem
.isEmpty
= FALSE
;
1732 hr
= WsWriteNode( writer
, (const WS_XML_NODE
*)&elem
, NULL
);
1733 ok( hr
== S_OK
, "got %08x\n", hr
);
1735 comment
.node
.nodeType
= WS_XML_NODE_TYPE_COMMENT
;
1736 comment
.value
.bytes
= (BYTE
*)"comment";
1737 comment
.value
.length
= sizeof("comment") - 1;
1738 hr
= WsWriteNode( writer
, (const WS_XML_NODE
*)&comment
, NULL
);
1739 ok( hr
== S_OK
, "got %08x\n", hr
);
1741 node
.nodeType
= WS_XML_NODE_TYPE_EOF
;
1742 hr
= WsWriteNode( writer
, &node
, NULL
);
1743 ok( hr
== S_OK
, "got %08x\n", hr
);
1745 node
.nodeType
= WS_XML_NODE_TYPE_BOF
;
1746 hr
= WsWriteNode( writer
, &node
, NULL
);
1747 ok( hr
== S_OK
, "got %08x\n", hr
);
1749 node
.nodeType
= WS_XML_NODE_TYPE_CDATA
;
1750 hr
= WsWriteNode( writer
, &node
, NULL
);
1751 ok( hr
== S_OK
, "got %08x\n", hr
);
1753 utf8
.value
.bytes
= (BYTE
*)"cdata";
1754 utf8
.value
.length
= sizeof("cdata") - 1;
1755 text
.node
.nodeType
= WS_XML_NODE_TYPE_TEXT
;
1756 text
.text
= &utf8
.text
;
1757 hr
= WsWriteNode( writer
, (const WS_XML_NODE
*)&text
, NULL
);
1758 ok( hr
== S_OK
, "got %08x\n", hr
);
1760 node
.nodeType
= WS_XML_NODE_TYPE_END_CDATA
;
1761 hr
= WsWriteNode( writer
, &node
, NULL
);
1762 ok( hr
== S_OK
, "got %08x\n", hr
);
1764 utf8
.value
.bytes
= (BYTE
*)"text";
1765 utf8
.value
.length
= sizeof("text") - 1;
1766 hr
= WsWriteNode( writer
, (const WS_XML_NODE
*)&text
, NULL
);
1767 ok( hr
== S_OK
, "got %08x\n", hr
);
1769 node
.nodeType
= WS_XML_NODE_TYPE_END_ELEMENT
;
1770 hr
= WsWriteNode( writer
, &node
, NULL
);
1771 ok( hr
== S_OK
, "got %08x\n", hr
);
1772 check_output_buffer( buffer
, "<t attr='value'><!--comment--><![CDATA[cdata]]>text</t>", __LINE__
);
1774 WsFreeWriter( writer
);
1778 static HRESULT
set_input( WS_XML_READER
*reader
, const char *data
, ULONG size
)
1780 WS_XML_READER_TEXT_ENCODING enc
;
1781 WS_XML_READER_BUFFER_INPUT input
;
1783 enc
.encoding
.encodingType
= WS_XML_READER_ENCODING_TYPE_TEXT
;
1784 enc
.charSet
= WS_CHARSET_AUTO
;
1786 input
.input
.inputType
= WS_XML_READER_INPUT_TYPE_BUFFER
;
1787 input
.encodedData
= (void *)data
;
1788 input
.encodedDataSize
= size
;
1790 return WsSetInput( reader
, &enc
.encoding
, &input
.input
, NULL
, 0, NULL
);
1793 static void test_WsCopyNode(void)
1795 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, localname2
= {1, (BYTE
*)"u"}, ns
= {0, NULL
};
1796 WS_XML_NODE_POSITION pos
, pos2
;
1797 WS_XML_WRITER
*writer
;
1798 WS_XML_READER
*reader
;
1799 WS_XML_BUFFER
*buffer
;
1803 hr
= WsCreateHeap( 1 << 16, 0, NULL
, 0, &heap
, NULL
);
1804 ok( hr
== S_OK
, "got %08x\n", hr
);
1806 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1807 ok( hr
== S_OK
, "got %08x\n", hr
);
1809 hr
= WsCreateXmlBuffer( heap
, NULL
, 0, &buffer
, NULL
);
1810 ok( hr
== S_OK
, "got %08x\n", hr
);
1812 hr
= WsSetOutputToBuffer( writer
, buffer
, NULL
, 0, NULL
);
1813 ok( hr
== S_OK
, "got %08x\n", hr
);
1815 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1816 ok( hr
== S_OK
, "got %08x\n", hr
);
1818 hr
= WsWriteStartElement( writer
, NULL
, &localname2
, &ns
, NULL
);
1819 ok( hr
== S_OK
, "got %08x\n", hr
);
1821 hr
= WsWriteEndElement( writer
, NULL
);
1822 ok( hr
== S_OK
, "got %08x\n", hr
);
1824 hr
= WsGetWriterPosition( writer
, &pos
, NULL
);
1825 ok( hr
== S_OK
, "got %08x\n", hr
);
1827 hr
= WsWriteEndElement( writer
, NULL
);
1828 ok( hr
== S_OK
, "got %08x\n", hr
);
1829 check_output_buffer( buffer
, "<t><u/></t>", __LINE__
);
1831 hr
= WsCreateReader( NULL
, 0, &reader
, NULL
);
1832 ok( hr
== S_OK
, "got %08x\n", hr
);
1834 hr
= set_input( reader
, "<v/>", sizeof("<v/>") - 1 );
1835 ok( hr
== S_OK
, "got %08x\n", hr
);
1837 hr
= WsFillReader( reader
, sizeof("<v/>") - 1, NULL
, NULL
);
1838 ok( hr
== S_OK
, "got %08x\n", hr
);
1840 hr
= WsReadToStartElement( reader
, NULL
, NULL
, NULL
, NULL
);
1841 ok( hr
== S_OK
, "got %08x\n", hr
);
1843 hr
= WsSetWriterPosition( writer
, &pos
, NULL
);
1844 ok( hr
== S_OK
, "got %08x\n", hr
);
1846 hr
= WsCopyNode( writer
, reader
, NULL
);
1847 ok( hr
== S_OK
, "got %08x\n", hr
);
1848 check_output_buffer( buffer
, "<t><u/><v/></t>", __LINE__
);
1850 hr
= WsGetWriterPosition( writer
, &pos2
, NULL
);
1851 ok( hr
== S_OK
, "got %08x\n", hr
);
1852 ok( pos2
.buffer
== pos
.buffer
, "wrong buffer\n" );
1853 ok( pos2
.node
== pos
.node
, "wrong node\n" );
1855 WsFreeReader( reader
);
1856 WsFreeWriter( writer
);
1860 static void test_text_types(void)
1862 static const WCHAR utf16W
[] = {'u','t','f','1','6'};
1863 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
1864 WS_XML_WRITER
*writer
;
1865 static const WS_XML_UTF8_TEXT val_utf8
= { {WS_XML_TEXT_TYPE_UTF8
}, {4, (BYTE
*)"utf8"} };
1866 static WS_XML_UTF16_TEXT val_utf16
= { {WS_XML_TEXT_TYPE_UTF16
} };
1867 static const WS_XML_GUID_TEXT val_guid
= { {WS_XML_TEXT_TYPE_GUID
} };
1868 static const WS_XML_UNIQUE_ID_TEXT val_urn
= { {WS_XML_TEXT_TYPE_UNIQUE_ID
} };
1869 static const WS_XML_BOOL_TEXT val_bool
= { {WS_XML_TEXT_TYPE_BOOL
}, TRUE
};
1870 static const WS_XML_INT32_TEXT val_int32
= { {WS_XML_TEXT_TYPE_INT32
}, -2147483647 - 1 };
1871 static const WS_XML_INT64_TEXT val_int64
= { {WS_XML_TEXT_TYPE_INT64
}, -9223372036854775807 - 1 };
1872 static const WS_XML_UINT64_TEXT val_uint64
= { {WS_XML_TEXT_TYPE_UINT64
}, ~0 };
1875 const WS_XML_TEXT
*text
;
1880 { &val_utf8
.text
, "<t>utf8</t>" },
1881 { &val_utf16
.text
, "<t>utf16</t>" },
1882 { &val_guid
.text
, "<t>00000000-0000-0000-0000-000000000000</t>" },
1883 { &val_urn
.text
, "<t>urn:uuid:00000000-0000-0000-0000-000000000000</t>" },
1884 { &val_bool
.text
, "<t>true</t>" },
1885 { &val_int32
.text
, "<t>-2147483648</t>" },
1886 { &val_int64
.text
, "<t>-9223372036854775808</t>" },
1887 { &val_uint64
.text
, "<t>18446744073709551615</t>" },
1892 val_utf16
.bytes
= (BYTE
*)utf16W
;
1893 val_utf16
.byteCount
= sizeof(utf16W
);
1895 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
);
1896 ok( hr
== S_OK
, "got %08x\n", hr
);
1898 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
1900 hr
= set_output( writer
);
1901 ok( hr
== S_OK
, "got %08x\n", hr
);
1902 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1903 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1905 hr
= WsWriteText( writer
, tests
[i
].text
, NULL
);
1906 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1908 hr
= WsWriteEndElement( writer
, NULL
);
1909 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1910 check_output( writer
, tests
[i
].result
, __LINE__
);
1913 WsFreeWriter( writer
);
1916 static void test_double(void)
1918 WS_XML_STRING localname
= {1, (BYTE
*)"t"}, ns
= {0, NULL
};
1928 {-1.0, "<t>-1</t>"},
1929 {1.0000000000000001, "<t>1</t>"},
1930 {1.0000000000000002, "<t>1.0000000000000002</t>"},
1931 {1.0000000000000003, "<t>1.0000000000000002</t>"},
1932 {1.0000000000000004, "<t>1.0000000000000004</t>"},
1933 {100000000000000, "<t>100000000000000</t>"},
1934 {1000000000000000, "<t>1E+15</t>"},
1935 {0.1, "<t>0.1</t>"},
1936 {0.01, "<t>1E-2</t>"},
1937 {-0.1, "<t>-0.1</t>"},
1938 {-0.01, "<t>-1E-2</t>"},
1939 {1.7976931348623158e308
, "<t>1.7976931348623157E+308</t>"},
1940 {-1.7976931348623158e308
, "<t>-1.7976931348623157E+308</t>"},
1943 WS_XML_WRITER
*writer
;
1944 WS_XML_DOUBLE_TEXT text
;
1947 hr
= WsCreateWriter( NULL
, 0, &writer
, NULL
) ;
1948 ok( hr
== S_OK
, "got %08x\n", hr
);
1950 text
.text
.textType
= WS_XML_TEXT_TYPE_DOUBLE
;
1951 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
1953 hr
= set_output( writer
);
1954 ok( hr
== S_OK
, "got %08x\n", hr
);
1955 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1956 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1958 text
.value
= tests
[i
].val
;
1959 hr
= WsWriteText( writer
, &text
.text
, NULL
);
1960 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1962 hr
= WsWriteEndElement( writer
, NULL
);
1963 ok( hr
== S_OK
, "%u: got %08x\n", i
, hr
);
1964 check_output( writer
, tests
[i
].result
, __LINE__
);
1967 hr
= set_output( writer
);
1968 ok( hr
== S_OK
, "got %08x\n", hr
);
1969 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1970 ok( hr
== S_OK
, "got %08x\n", hr
);
1973 hr
= WsWriteText( writer
, &text
.text
, NULL
);
1974 ok( hr
== S_OK
, "got %08x\n", hr
);
1976 hr
= WsWriteEndElement( writer
, NULL
);
1977 ok( hr
== S_OK
, "got %08x\n", hr
);
1978 check_output( writer
, "<t>NaN</t>", __LINE__
);
1980 hr
= set_output( writer
);
1981 ok( hr
== S_OK
, "got %08x\n", hr
);
1982 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1983 ok( hr
== S_OK
, "got %08x\n", hr
);
1985 text
.value
= INFINITY
;
1986 hr
= WsWriteText( writer
, &text
.text
, NULL
);
1987 ok( hr
== S_OK
, "got %08x\n", hr
);
1989 hr
= WsWriteEndElement( writer
, NULL
);
1990 ok( hr
== S_OK
, "got %08x\n", hr
);
1991 check_output( writer
, "<t>INF</t>", __LINE__
);
1993 hr
= set_output( writer
);
1994 ok( hr
== S_OK
, "got %08x\n", hr
);
1995 hr
= WsWriteStartElement( writer
, NULL
, &localname
, &ns
, NULL
);
1996 ok( hr
== S_OK
, "got %08x\n", hr
);
1998 text
.value
= -INFINITY
;
1999 hr
= WsWriteText( writer
, &text
.text
, NULL
);
2000 ok( hr
== S_OK
, "got %08x\n", hr
);
2002 hr
= WsWriteEndElement( writer
, NULL
);
2003 ok( hr
== S_OK
, "got %08x\n", hr
);
2004 check_output( writer
, "<t>-INF</t>", __LINE__
);
2006 WsFreeWriter( writer
);
2011 test_WsCreateWriter();
2012 test_WsCreateXmlBuffer();
2014 test_WsSetOutputToBuffer();
2015 test_WsWriteStartElement();
2016 test_WsWriteStartAttribute();
2019 test_simple_struct_type();
2020 test_WsWriteElement();
2021 test_WsWriteValue();
2022 test_WsWriteAttribute();
2023 test_WsWriteStartCData();
2024 test_WsWriteXmlnsAttribute();
2025 test_WsGetPrefixFromNamespace();
2026 test_complex_struct_type();
2027 test_WsMoveWriter();
2028 test_WsGetWriterPosition();
2029 test_WsSetWriterPosition();
2030 test_WsWriteXmlBuffer();