Add explicit test for serialization of boolean attributes in XML

This commit is contained in:
Martin Hořeňovský 2021-05-30 20:02:02 +02:00
parent 0e2895934c
commit 5741de9ccd
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
10 changed files with 65 additions and 10 deletions

View File

@ -269,6 +269,7 @@ Message from section two
:test-result: PASS X/level/1/a
:test-result: PASS X/level/1/b
:test-result: PASS XmlEncode
:test-result: PASS XmlWriter writes boolean attributes as true/false
:test-result: PASS analyse no analysis
:test-result: PASS array<int, N> -> toString
:test-result: PASS atomic if

View File

@ -1982,6 +1982,9 @@ Xml.tests.cpp:<line number>: passed: encode( stringWithQuotes, Catch::XmlEncode:
"don't &quot;quote&quot; me on that"
Xml.tests.cpp:<line number>: passed: encode( "[\x01]" ) == "[\\x01]" for: "[\x01]" == "[\x01]"
Xml.tests.cpp:<line number>: passed: encode( "[\x7F]" ) == "[\\x7F]" for: "[\x7F]" == "[\x7F]"
Xml.tests.cpp:<line number>: passed: stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") for: "<?xml version="1.0" encoding="UTF-8"?>
<Element1 attr1="true" attr2="false"/>
" ( contains: "attr1="true"" and contains: "attr2="false"" )
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.point.count() == 23 for: 23.0 == 23
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.lower_bound.count() == 23 for: 23.0 == 23
InternalBenchmark.tests.cpp:<line number>: passed: analysis.mean.upper_bound.count() == 23 for: 23.0 == 23

View File

@ -1386,6 +1386,6 @@ due to unexpected exception with message:
Why would you throw a std::string?
===============================================================================
test cases: 363 | 287 passed | 70 failed | 6 failed as expected
assertions: 2090 | 1938 passed | 129 failed | 23 failed as expected
test cases: 364 | 288 passed | 70 failed | 6 failed as expected
assertions: 2091 | 1939 passed | 129 failed | 23 failed as expected

View File

@ -14068,6 +14068,19 @@ Xml.tests.cpp:<line number>: PASSED:
with expansion:
"[\x7F]" == "[\x7F]"
-------------------------------------------------------------------------------
XmlWriter writes boolean attributes as true/false
-------------------------------------------------------------------------------
Xml.tests.cpp:<line number>
...............................................................................
Xml.tests.cpp:<line number>: PASSED:
REQUIRE_THAT( stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") )
with expansion:
"<?xml version="1.0" encoding="UTF-8"?>
<Element1 attr1="true" attr2="false"/>
" ( contains: "attr1="true"" and contains: "attr2="false"" )
-------------------------------------------------------------------------------
analyse no analysis
-------------------------------------------------------------------------------
@ -16830,6 +16843,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED:
===============================================================================
test cases: 363 | 271 passed | 86 failed | 6 failed as expected
assertions: 2107 | 1938 passed | 146 failed | 23 failed as expected
test cases: 364 | 272 passed | 86 failed | 6 failed as expected
assertions: 2108 | 1939 passed | 146 failed | 23 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="130" tests="2108" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="130" tests="2109" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/>
@ -1513,6 +1513,7 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="XmlEncode/string with quotes" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (1)" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="XmlEncode/string with control char (x7F)" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="XmlWriter writes boolean attributes as true/false" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="analyse no analysis" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="array&lt;int, N> -> toString" time="{duration}" status="run"/>
<testcase classname="<exe-name>.global" name="atomic if" time="{duration}" status="run"/>

View File

@ -253,6 +253,7 @@
<testCase name="XmlEncode/string with quotes" duration="{duration}"/>
<testCase name="XmlEncode/string with control char (1)" duration="{duration}"/>
<testCase name="XmlEncode/string with control char (x7F)" duration="{duration}"/>
<testCase name="XmlWriter writes boolean attributes as true/false" duration="{duration}"/>
</file>
<file path="tests/<exe-name>/UsageTests/Approx.tests.cpp">
<testCase name="A comparison that uses literals instead of the normal constructor" duration="{duration}"/>

View File

@ -3541,6 +3541,8 @@ ok {test-number} - encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) =
ok {test-number} - encode( "[\x01]" ) == "[\\x01]" for: "[\x01]" == "[\x01]"
# XmlEncode
ok {test-number} - encode( "[\x7F]" ) == "[\\x7F]" for: "[\x7F]" == "[\x7F]"
# XmlWriter writes boolean attributes as true/false
ok {test-number} - stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") for: "<?xml version="1.0" encoding="UTF-8"?> <Element1 attr1="true" attr2="false"/> " ( contains: "attr1="true"" and contains: "attr2="false"" )
# analyse no analysis
ok {test-number} - analysis.mean.point.count() == 23 for: 23.0 == 23
# analyse no analysis
@ -4216,5 +4218,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2107
1..2108

View File

@ -662,6 +662,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "unexpe
##teamcity[testFinished name='X/level/1/b' duration="{duration}"]
##teamcity[testStarted name='XmlEncode']
##teamcity[testFinished name='XmlEncode' duration="{duration}"]
##teamcity[testStarted name='XmlWriter writes boolean attributes as true/false']
##teamcity[testFinished name='XmlWriter writes boolean attributes as true/false' duration="{duration}"]
##teamcity[testStarted name='analyse no analysis']
##teamcity[testFinished name='analyse no analysis' duration="{duration}"]
##teamcity[testStarted name='array<int, N> -> toString']

View File

@ -16544,6 +16544,19 @@ There is no extra whitespace here
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="XmlWriter writes boolean attributes as true/false" tags="[XML][XmlWriter]" filename="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp" >
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp" >
<Original>
stream.str(), Contains(R"(attr1="true")") &amp;&amp; Contains(R"(attr2="false")")
</Original>
<Expanded>
"&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;Element1 attr1="true" attr2="false"/>
" ( contains: "attr1="true"" and contains: "attr2="false"" )
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="analyse no analysis" tags="[benchmark]" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Original>
@ -19802,9 +19815,9 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="1938" failures="147" expectedFailures="23"/>
<OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
<OverallResults successes="1939" failures="147" expectedFailures="23"/>
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
</Group>
<OverallResults successes="1938" failures="146" expectedFailures="23"/>
<OverallResultsCases successes="271" failures="86" expectedFailures="6"/>
<OverallResults successes="1939" failures="146" expectedFailures="23"/>
<OverallResultsCases successes="272" failures="86" expectedFailures="6"/>
</Catch>

View File

@ -2,6 +2,9 @@
#include <catch2/internal/catch_xmlwriter.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
#include <sstream>
static std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) {
Catch::ReusableStringStream oss;
@ -112,3 +115,19 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
}
#undef ESC
}
TEST_CASE("XmlWriter writes boolean attributes as true/false", "[XML][XmlWriter]") {
using Catch::Matchers::Contains;
std::stringstream stream;
{
Catch::XmlWriter xml(stream);
xml.scopedElement("Element1")
.writeAttribute("attr1", true)
.writeAttribute("attr2", false);
}
REQUIRE_THAT( stream.str(),
Contains(R"(attr1="true")") &&
Contains(R"(attr2="false")") );
}