From da030566e7de8b5c8cd99985598c04f72a54f646 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Tue, 23 May 2017 12:03:50 +0200 Subject: [PATCH] webservices: Implement WsSkipNode. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/reader.c | 46 ++++++++++++++++++++++++++++++ dlls/webservices/tests/reader.c | 60 +++++++++++++++++++++++++++++++++++++++ dlls/webservices/webservices.spec | 2 +- 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c index 1d85f00cfb3..befe8db7946 100644 --- a/dlls/webservices/reader.c +++ b/dlls/webservices/reader.c @@ -1739,6 +1739,52 @@ HRESULT WINAPI WsReadNode( WS_XML_READER *handle, WS_ERROR *error ) return hr; } +static HRESULT skip_node( struct reader *reader ) +{ + const struct node *parent; + HRESULT hr; + + if (node_type( reader->current ) == WS_XML_NODE_TYPE_EOF) return WS_E_INVALID_OPERATION; + if (node_type( reader->current ) == WS_XML_NODE_TYPE_ELEMENT) parent = reader->current; + else parent = NULL; + + for (;;) + { + if ((hr = read_node( reader ) != S_OK) || !parent) break; + if (node_type( reader->current ) != WS_XML_NODE_TYPE_END_ELEMENT) continue; + if (reader->current->parent == parent) return read_node( reader ); + } + + return hr; +} + +/************************************************************************** + * WsSkipNode [webservices.@] + */ +HRESULT WINAPI WsSkipNode( WS_XML_READER *handle, WS_ERROR *error ) +{ + struct reader *reader = (struct reader *)handle; + HRESULT hr; + + TRACE( "%p %p\n", handle, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!reader) return E_INVALIDARG; + + EnterCriticalSection( &reader->cs ); + + if (reader->magic != READER_MAGIC) + { + LeaveCriticalSection( &reader->cs ); + return E_INVALIDARG; + } + + hr = skip_node( reader ); + + LeaveCriticalSection( &reader->cs ); + return hr; +} + /************************************************************************** * WsReadStartElement [webservices.@] */ diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c index 1598cb25508..93b7ed5f267 100644 --- a/dlls/webservices/tests/reader.c +++ b/dlls/webservices/tests/reader.c @@ -4403,6 +4403,65 @@ static void test_WsReadAttribute(void) WsFreeReader( reader ); } +static void test_WsSkipNode(void) +{ + const WS_XML_NODE *node; + WS_XML_READER *reader; + HRESULT hr; + + hr = WsSkipNode( NULL, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = WsCreateReader( NULL, 0, &reader, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsSkipNode( reader, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = set_input( reader, "", sizeof("") - 1 ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsGetReaderNode( reader, &node, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( node->nodeType == WS_XML_NODE_TYPE_BOF, "got %u\n", node->nodeType ); + + /* BOF */ + hr = WsSkipNode( reader, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + hr = WsGetReaderNode( reader, &node, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType ); + + /* element */ + hr = WsSkipNode( reader, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + hr = WsGetReaderNode( reader, &node, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( node->nodeType == WS_XML_NODE_TYPE_EOF, "got %u\n", node->nodeType ); + + /* EOF */ + hr = WsSkipNode( reader, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = set_input( reader, "", sizeof("") - 1 ); + ok( hr == S_OK, "got %08x\n", hr ); + + /* non-element */ + hr = WsSkipNode( reader, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + hr = WsGetReaderNode( reader, &node, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( node->nodeType == WS_XML_NODE_TYPE_COMMENT, "got %u\n", node->nodeType ); + + hr = WsSkipNode( reader, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + hr = WsGetReaderNode( reader, &node, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( node->nodeType == WS_XML_NODE_TYPE_ELEMENT, "got %u\n", node->nodeType ); + + WsFreeReader( reader ); +} + START_TEST(reader) { test_WsCreateError(); @@ -4444,4 +4503,5 @@ START_TEST(reader) test_WsReadCharsUtf8(); test_WsReadQualifiedName(); test_WsReadAttribute(); + test_WsSkipNode(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index a6b84521110..1f98aa34589 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -159,7 +159,7 @@ @ stdcall WsSetReaderPosition(ptr ptr ptr) @ stdcall WsSetWriterPosition(ptr ptr ptr) @ stub WsShutdownSessionChannel -@ stub WsSkipNode +@ stdcall WsSkipNode(ptr ptr) @ stub WsStartReaderCanonicalization @ stub WsStartWriterCanonicalization @ stub WsTrimXmlWhitespace -- 2.11.4.GIT