From 5741de9ccdca3f41131c377394b4e3db0f11686c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 30 May 2021 20:02:02 +0200 Subject: [PATCH] Add explicit test for serialization of boolean attributes in XML --- .../Baselines/automake.sw.approved.txt | 1 + .../Baselines/compact.sw.approved.txt | 3 +++ .../Baselines/console.std.approved.txt | 4 ++-- .../Baselines/console.sw.approved.txt | 17 +++++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../Baselines/sonarqube.sw.approved.txt | 1 + tests/SelfTest/Baselines/tap.sw.approved.txt | 4 +++- .../Baselines/teamcity.sw.approved.txt | 2 ++ tests/SelfTest/Baselines/xml.sw.approved.txt | 21 +++++++++++++++---- .../SelfTest/IntrospectiveTests/Xml.tests.cpp | 19 +++++++++++++++++ 10 files changed, 65 insertions(+), 10 deletions(-) diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 7cf2f2c8..d6ffeee7 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -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 -> toString :test-result: PASS atomic if diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 41e6dc96..c41b3b34 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1982,6 +1982,9 @@ Xml.tests.cpp:: passed: encode( stringWithQuotes, Catch::XmlEncode: "don't "quote" me on that" Xml.tests.cpp:: passed: encode( "[\x01]" ) == "[\\x01]" for: "[\x01]" == "[\x01]" Xml.tests.cpp:: passed: encode( "[\x7F]" ) == "[\\x7F]" for: "[\x7F]" == "[\x7F]" +Xml.tests.cpp:: passed: stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") for: " + +" ( contains: "attr1="true"" and contains: "attr2="false"" ) InternalBenchmark.tests.cpp:: passed: analysis.mean.point.count() == 23 for: 23.0 == 23 InternalBenchmark.tests.cpp:: passed: analysis.mean.lower_bound.count() == 23 for: 23.0 == 23 InternalBenchmark.tests.cpp:: passed: analysis.mean.upper_bound.count() == 23 for: 23.0 == 23 diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 1d928cf9..a65f658c 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -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 diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 98394d06..b5045fe1 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -14068,6 +14068,19 @@ Xml.tests.cpp:: PASSED: with expansion: "[\x7F]" == "[\x7F]" +------------------------------------------------------------------------------- +XmlWriter writes boolean attributes as true/false +------------------------------------------------------------------------------- +Xml.tests.cpp: +............................................................................... + +Xml.tests.cpp:: PASSED: + REQUIRE_THAT( stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") ) +with expansion: + " + + " ( contains: "attr1="true"" and contains: "attr2="false"" ) + ------------------------------------------------------------------------------- analyse no analysis ------------------------------------------------------------------------------- @@ -16830,6 +16843,6 @@ Misc.tests.cpp: Misc.tests.cpp:: 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 diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 7c3e2f1f..811dab96 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1513,6 +1513,7 @@ Exception.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 10d00b02..143ed10c 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -253,6 +253,7 @@ + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 1977fa8f..17ddd242 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -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: " " ( 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 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index e0794baf..1dee018b 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -662,6 +662,8 @@ Exception.tests.cpp:|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 -> toString'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index ebfca6dc..c8f413e5 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -16544,6 +16544,19 @@ There is no extra whitespace here + + + + stream.str(), Contains(R"(attr1="true")") && Contains(R"(attr2="false")") + + + "<?xml version="1.0" encoding="UTF-8"?> +<Element1 attr1="true" attr2="false"/> +" ( contains: "attr1="true"" and contains: "attr2="false"" ) + + + + @@ -19802,9 +19815,9 @@ loose text artifact - - + + - - + + diff --git a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp index 2d375a22..c98d66ef 100644 --- a/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp @@ -2,6 +2,9 @@ #include #include +#include + +#include 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")") ); +}