Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
5f4ed88e
Commit
5f4ed88e
authored
Jul 23, 2017
by
Nikolay Sivov
Committed by
Alexandre Julliard
Jul 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xmllite/writer: Fix empty element and state handling in WriteElementString().
Signed-off-by:
Nikolay Sivov
<
nsivov@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
4a463fae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
44 deletions
+64
-44
writer.c
dlls/xmllite/tests/writer.c
+50
-32
writer.c
dlls/xmllite/writer.c
+14
-12
No files found.
dlls/xmllite/tests/writer.c
View file @
5f4ed88e
...
@@ -67,6 +67,14 @@ static void check_output(IStream *stream, const char *expected, BOOL todo, int l
...
@@ -67,6 +67,14 @@ static void check_output(IStream *stream, const char *expected, BOOL todo, int l
#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, FALSE, __LINE__)
#define CHECK_OUTPUT(stream, expected) check_output(stream, expected, FALSE, __LINE__)
#define CHECK_OUTPUT_TODO(stream, expected) check_output(stream, expected, TRUE, __LINE__)
#define CHECK_OUTPUT_TODO(stream, expected) check_output(stream, expected, TRUE, __LINE__)
static
void
writer_set_property
(
IXmlWriter
*
writer
,
XmlWriterProperty
property
)
{
HRESULT
hr
;
hr
=
IXmlWriter_SetProperty
(
writer
,
property
,
TRUE
);
ok
(
hr
==
S_OK
,
"Failed to set writer property, hr %#x.
\n
"
,
hr
);
}
/* used to test all Write* methods for consistent error state */
/* used to test all Write* methods for consistent error state */
static
void
check_writer_state
(
IXmlWriter
*
writer
,
HRESULT
exp_hr
)
static
void
check_writer_state
(
IXmlWriter
*
writer
,
HRESULT
exp_hr
)
{
{
...
@@ -475,8 +483,7 @@ static void test_omitxmldeclaration(void)
...
@@ -475,8 +483,7 @@ static void test_omitxmldeclaration(void)
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Yes
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Yes
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -557,8 +564,7 @@ static void test_bom(void)
...
@@ -557,8 +564,7 @@ static void test_bom(void)
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_SetOutput
(
writer
,
output
);
hr
=
IXmlWriter_SetOutput
(
writer
,
output
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -664,7 +670,6 @@ static void test_bom(void)
...
@@ -664,7 +670,6 @@ static void test_bom(void)
static
void
test_writestartelement
(
void
)
static
void
test_writestartelement
(
void
)
{
{
static
const
WCHAR
valueW
[]
=
{
'v'
,
'a'
,
'l'
,
'u'
,
'e'
,
0
};
static
const
WCHAR
valueW
[]
=
{
'v'
,
'a'
,
'l'
,
'u'
,
'e'
,
0
};
static
const
char
*
str
=
"<a><b>value</b>"
;
static
const
WCHAR
aW
[]
=
{
'a'
,
0
};
static
const
WCHAR
aW
[]
=
{
'a'
,
0
};
static
const
WCHAR
bW
[]
=
{
'b'
,
0
};
static
const
WCHAR
bW
[]
=
{
'b'
,
0
};
IXmlWriter
*
writer
;
IXmlWriter
*
writer
;
...
@@ -726,10 +731,14 @@ static void test_writestartelement(void)
...
@@ -726,10 +731,14 @@ static void test_writestartelement(void)
hr
=
IXmlWriter_WriteElementString
(
writer
,
NULL
,
bW
,
NULL
,
valueW
);
hr
=
IXmlWriter_WriteElementString
(
writer
,
NULL
,
bW
,
NULL
,
valueW
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteElementString
(
writer
,
NULL
,
bW
,
NULL
,
NULL
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_Flush
(
writer
);
hr
=
IXmlWriter_Flush
(
writer
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
CHECK_OUTPUT
(
stream
,
str
);
CHECK_OUTPUT
(
stream
,
"<a><b>value</b><b />"
);
IStream_Release
(
stream
);
IStream_Release
(
stream
);
IXmlWriter_Release
(
writer
);
IXmlWriter_Release
(
writer
);
...
@@ -840,8 +849,7 @@ static void test_WriteComment(void)
...
@@ -840,8 +849,7 @@ static void test_WriteComment(void)
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteComment
(
writer
,
aW
);
hr
=
IXmlWriter_WriteComment
(
writer
,
aW
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -888,8 +896,7 @@ static void test_WriteCData(void)
...
@@ -888,8 +896,7 @@ static void test_WriteCData(void)
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteCData
(
writer
,
aW
);
hr
=
IXmlWriter_WriteCData
(
writer
,
aW
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1087,11 +1094,8 @@ static void test_indentation(void)
...
@@ -1087,11 +1094,8 @@ static void test_indentation(void)
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
writer_set_property
(
writer
,
XmlWriterProperty_Indent
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_Indent
,
TRUE
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1117,8 +1121,31 @@ static void test_indentation(void)
...
@@ -1117,8 +1121,31 @@ static void test_indentation(void)
" <b />
\r\n
"
" <b />
\r\n
"
"</a>"
);
"</a>"
);
IXmlWriter_Release
(
writer
);
IStream_Release
(
stream
);
IStream_Release
(
stream
);
/* WriteElementString */
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_WriteStartElement
(
writer
,
NULL
,
aW
,
NULL
);
ok
(
hr
==
S_OK
,
"Unexpected hr %#x.
\n
"
,
hr
);
hr
=
IXmlWriter_WriteElementString
(
writer
,
NULL
,
bW
,
NULL
,
NULL
);
ok
(
hr
==
S_OK
,
"Unexpected hr %#x.
\n
"
,
hr
);
hr
=
IXmlWriter_WriteEndElement
(
writer
);
ok
(
hr
==
S_OK
,
"Unexpected hr %#x.
\n
"
,
hr
);
hr
=
IXmlWriter_Flush
(
writer
);
ok
(
hr
==
S_OK
,
"Unexpected hr %#x.
\n
"
,
hr
);
CHECK_OUTPUT_TODO
(
stream
,
"<a>
\r\n
"
" <b />
\r\n
"
"</a>"
);
IStream_Release
(
stream
);
IXmlWriter_Release
(
writer
);
}
}
static
void
test_WriteAttributeString
(
void
)
static
void
test_WriteAttributeString
(
void
)
...
@@ -1139,8 +1166,7 @@ static void test_WriteAttributeString(void)
...
@@ -1139,8 +1166,7 @@ static void test_WriteAttributeString(void)
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1219,11 +1245,8 @@ static void test_WriteFullEndElement(void)
...
@@ -1219,11 +1245,8 @@ static void test_WriteFullEndElement(void)
/* standalone element */
/* standalone element */
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
writer_set_property
(
writer
,
XmlWriterProperty_Indent
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_Indent
,
TRUE
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1247,11 +1270,8 @@ static void test_WriteFullEndElement(void)
...
@@ -1247,11 +1270,8 @@ static void test_WriteFullEndElement(void)
/* nested elements */
/* nested elements */
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
writer_set_property
(
writer
,
XmlWriterProperty_Indent
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_Indent
,
TRUE
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1293,8 +1313,7 @@ static void test_WriteCharEntity(void)
...
@@ -1293,8 +1313,7 @@ static void test_WriteCharEntity(void)
/* without indentation */
/* without indentation */
stream
=
writer_set_output
(
writer
);
stream
=
writer_set_output
(
writer
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
hr
=
IXmlWriter_WriteStartDocument
(
writer
,
XmlStandalone_Omit
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
...
@@ -1334,8 +1353,7 @@ static void test_WriteString(void)
...
@@ -1334,8 +1353,7 @@ static void test_WriteString(void)
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
hr
=
CreateXmlWriter
(
&
IID_IXmlWriter
,
(
void
**
)
&
writer
,
NULL
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
ok
(
hr
==
S_OK
,
"Expected S_OK, got %08x
\n
"
,
hr
);
hr
=
IXmlWriter_SetProperty
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
,
TRUE
);
writer_set_property
(
writer
,
XmlWriterProperty_OmitXmlDeclaration
);
ok
(
hr
==
S_OK
,
"got 0x%08x
\n
"
,
hr
);
hr
=
IXmlWriter_WriteString
(
writer
,
aW
);
hr
=
IXmlWriter_WriteString
(
writer
,
aW
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
ok
(
hr
==
E_UNEXPECTED
,
"got 0x%08x
\n
"
,
hr
);
...
...
dlls/xmllite/writer.c
View file @
5f4ed88e
...
@@ -40,6 +40,7 @@ DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d,
...
@@ -40,6 +40,7 @@ DEFINE_GUID(IID_IXmlWriterOutput, 0xc1131708, 0x0f59, 0x477f, 0x93, 0x59, 0x7d,
#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
static
const
WCHAR
closeelementW
[]
=
{
'<'
,
'/'
};
static
const
WCHAR
closeelementW
[]
=
{
'<'
,
'/'
};
static
const
WCHAR
closetagW
[]
=
{
' '
,
'/'
,
'>'
};
static
const
WCHAR
closepiW
[]
=
{
'?'
,
'>'
};
static
const
WCHAR
closepiW
[]
=
{
'?'
,
'>'
};
static
const
WCHAR
ltW
[]
=
{
'<'
};
static
const
WCHAR
ltW
[]
=
{
'<'
};
static
const
WCHAR
gtW
[]
=
{
'>'
};
static
const
WCHAR
gtW
[]
=
{
'>'
};
...
@@ -835,26 +836,27 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
...
@@ -835,26 +836,27 @@ static HRESULT WINAPI xmlwriter_WriteElementString(IXmlWriter *iface, LPCWSTR pr
case
XmlWriterState_ElemStarted
:
case
XmlWriterState_ElemStarted
:
writer_close_starttag
(
This
);
writer_close_starttag
(
This
);
break
;
break
;
case
XmlWriterState_Ready
:
case
XmlWriterState_DocClosed
:
case
XmlWriterState_DocStarted
:
case
XmlWriterState_PIDocStarted
:
break
;
default:
This
->
state
=
XmlWriterState_DocClosed
;
return
WR_E_INVALIDACTION
;
return
WR_E_INVALIDACTION
;
default:
;
}
}
write_encoding_bom
(
This
);
write_encoding_bom
(
This
);
write_output_buffer
(
This
->
output
,
ltW
,
ARRAY_SIZE
(
ltW
));
write_output_buffer
(
This
->
output
,
ltW
,
ARRAY_SIZE
(
ltW
));
write_output_qname
(
This
->
output
,
prefix
,
local_name
);
write_output_qname
(
This
->
output
,
prefix
,
local_name
);
write_output_buffer
(
This
->
output
,
gtW
,
ARRAY_SIZE
(
gtW
));
if
(
value
)
if
(
value
)
{
write_output_buffer
(
This
->
output
,
gtW
,
ARRAY_SIZE
(
gtW
));
write_output_buffer
(
This
->
output
,
value
,
-
1
);
write_output_buffer
(
This
->
output
,
value
,
-
1
);
write_output_buffer
(
This
->
output
,
closeelementW
,
ARRAY_SIZE
(
closeelementW
));
write_output_qname
(
This
->
output
,
prefix
,
local_name
);
write_output_buffer
(
This
->
output
,
gtW
,
ARRAY_SIZE
(
gtW
));
}
else
write_output_buffer
(
This
->
output
,
closetagW
,
ARRAY_SIZE
(
closetagW
));
write_output_buffer
(
This
->
output
,
closeelementW
,
ARRAY_SIZE
(
closeelementW
));
write_output_qname
(
This
->
output
,
prefix
,
local_name
);
write_output_buffer
(
This
->
output
,
gtW
,
ARRAY_SIZE
(
gtW
));
This
->
state
=
XmlWriterState_Content
;
This
->
state
=
XmlWriterState_Content
;
return
S_OK
;
return
S_OK
;
...
@@ -911,8 +913,8 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
...
@@ -911,8 +913,8 @@ static HRESULT WINAPI xmlwriter_WriteEndElement(IXmlWriter *iface)
writer_dec_indent
(
This
);
writer_dec_indent
(
This
);
if
(
This
->
starttagopen
)
{
if
(
This
->
starttagopen
)
static
WCHAR
closetagW
[]
=
{
' '
,
'/'
,
'>'
};
{
write_output_buffer
(
This
->
output
,
closetagW
,
ARRAY_SIZE
(
closetagW
));
write_output_buffer
(
This
->
output
,
closetagW
,
ARRAY_SIZE
(
closetagW
));
This
->
starttagopen
=
FALSE
;
This
->
starttagopen
=
FALSE
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment