From d6e59cd56f196eb40cbec3223531ee8d98e8ac8f Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 23 Jul 2015 18:45:31 +0100 Subject: [PATCH] Fixed Xml encoding - don't encode apostrophes - only encode quotes in attributes - encode control characters (as in PR #465) --- include/internal/catch_xmlwriter.hpp | 95 +- .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 126 ++- .../SelfTest/Baselines/junit.sw.approved.txt | 10 +- .../SelfTest/Baselines/xml.sw.approved.txt | 943 ++++++++++-------- projects/SelfTest/MiscTests.cpp | 37 + 6 files changed, 762 insertions(+), 453 deletions(-) diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp index 3355f4d3..5f2e87e5 100644 --- a/include/internal/catch_xmlwriter.hpp +++ b/include/internal/catch_xmlwriter.hpp @@ -14,9 +14,65 @@ #include #include #include +#include namespace Catch { + class XmlEncode { + public: + enum ForWhat { ForTextNodes, ForAttributes }; + + XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ) + : m_str( str ), + m_forWhat( forWhat ) + {} + + void encodeTo( std::ostream& os ) const { + + // Apostrophe escaping not necessary if we always use " to write attributes + // (see: http://www.w3.org/TR/xml/#syntax) + + for( std::size_t i = 0; i < m_str.size(); ++ i ) { + char c = m_str[i]; + switch( c ) { + case '<': os << "<"; break; + case '&': os << "&"; break; + + case '>': + // See: http://www.w3.org/TR/xml/#syntax + if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' ) + os << ">"; + else + os << c; + break; + + case '\"': + if( m_forWhat == ForAttributes ) + os << """; + else + os << c; + break; + + default: + // Escape control chars - based on contribution by @espenalb in PR #465 + if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) + os << "&#x" << std::uppercase << std::hex << static_cast( c ); + else + os << c; + } + } + } + + friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { + xmlEncode.encodeTo( os ); + return os; + } + + private: + std::string m_str; + ForWhat m_forWhat; + }; + class XmlWriter { public: @@ -99,11 +155,8 @@ namespace Catch { } XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { - if( !name.empty() && !attribute.empty() ) { - stream() << " " << name << "=\""; - writeEncodedText( attribute ); - stream() << "\""; - } + if( !name.empty() && !attribute.empty() ) + stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\""; return *this; } @@ -114,9 +167,9 @@ namespace Catch { template XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { - if( !name.empty() ) - stream() << " " << name << "=\"" << attribute << "\""; - return *this; + std::ostringstream oss; + oss << attribute; + return writeAttribute( name, oss.str() ); } XmlWriter& writeText( std::string const& text, bool indent = true ) { @@ -125,7 +178,7 @@ namespace Catch { ensureTagClosed(); if( tagWasOpen && indent ) stream() << m_indent; - writeEncodedText( text ); + stream() << XmlEncode( text ); m_needsNewline = true; } return *this; @@ -170,30 +223,6 @@ namespace Catch { } } - void writeEncodedText( std::string const& text ) { - static const char* charsToEncode = "<&\""; - std::string mtext = text; - std::string::size_type pos = mtext.find_first_of( charsToEncode ); - while( pos != std::string::npos ) { - stream() << mtext.substr( 0, pos ); - - switch( mtext[pos] ) { - case '<': - stream() << "<"; - break; - case '&': - stream() << "&"; - break; - case '\"': - stream() << """; - break; - } - mtext = mtext.substr( pos+1 ); - pos = mtext.find_first_of( charsToEncode ); - } - stream() << mtext; - } - bool m_tagIsOpen; bool m_needsNewline; std::vector m_tags; diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 67fb8437..3aa3ae86 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -797,6 +797,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 157 | 117 passed | 39 failed | 1 failed as expected -assertions: 773 | 680 passed | 80 failed | 13 failed as expected +test cases: 158 | 118 passed | 39 failed | 1 failed as expected +assertions: 783 | 690 passed | 80 failed | 13 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 7d41c5a7..238450b0 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -3762,6 +3762,128 @@ PASSED: with expansion: ""wide load"" == ""wide load"" +------------------------------------------------------------------------------- +XmlEncode + normal string +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "normal string" ) == "normal string" ) +with expansion: + "normal string" == "normal string" + +------------------------------------------------------------------------------- +XmlEncode + empty string +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "" ) == "" ) +with expansion: + "" == "" + +------------------------------------------------------------------------------- +XmlEncode + string with ampersand +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "smith & jones" ) == "smith & jones" ) +with expansion: + "smith & jones" == "smith & jones" + +------------------------------------------------------------------------------- +XmlEncode + string with less-than +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "smith < jones" ) == "smith < jones" ) +with expansion: + "smith < jones" == "smith < jones" + +------------------------------------------------------------------------------- +XmlEncode + string with greater-than +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "smith > jones" ) == "smith > jones" ) +with expansion: + "smith > jones" == "smith > jones" + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "smith ]]> jones" ) == "smith ]]> jones" ) +with expansion: + "smith ]]> jones" + == + "smith ]]> jones" + +------------------------------------------------------------------------------- +XmlEncode + string with quotes +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( stringWithQuotes ) == stringWithQuotes ) +with expansion: + "don't "quote" me on that" + == + "don't "quote" me on that" + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't "quote" me on that" ) +with expansion: + "don't "quote" me on that" + == + "don't "quote" me on that" + +------------------------------------------------------------------------------- +XmlEncode + string with control char (1) +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "[\x01]" ) == "[]" ) +with expansion: + "[]" == "[]" + +------------------------------------------------------------------------------- +XmlEncode + string with control char (x7F) +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: +PASSED: + REQUIRE( encode( "[\x7F]" ) == "[]" ) +with expansion: + "[]" == "[]" + ------------------------------------------------------------------------------- Process can be configured on command line default - no arguments @@ -8004,6 +8126,6 @@ with expansion: true =============================================================================== -test cases: 157 | 101 passed | 55 failed | 1 failed as expected -assertions: 793 | 680 passed | 100 failed | 13 failed as expected +test cases: 158 | 102 passed | 55 failed | 1 failed as expected +assertions: 803 | 690 passed | 100 failed | 13 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index cd978bfb..deae7529 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,5 +1,5 @@ - + @@ -463,6 +463,14 @@ MiscTests.cpp: + + + + + + + + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 654061f2..10b826c2 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -3,18 +3,18 @@ - Catch::toString(e0) == "0" + Catch::toString(e0) == "0" - "0" == "0" + "0" == "0" - Catch::toString(e1) == "1" + Catch::toString(e1) == "1" - "1" == "1" + "1" == "1" @@ -22,18 +22,18 @@ - Catch::toString(e0) == "E2{0}" + Catch::toString(e0) == "E2{0}" - "E2{0}" == "E2{0}" + "E2{0}" == "E2{0}" - Catch::toString(e1) == "E2{1}" + Catch::toString(e1) == "E2{1}" - "E2{1}" == "E2{1}" + "E2{1}" == "E2{1}" @@ -41,18 +41,18 @@ - Catch::toString(e0) == "0" + Catch::toString(e0) == "0" - "0" == "0" + "0" == "0" - Catch::toString(e1) == "1" + Catch::toString(e1) == "1" - "1" == "1" + "1" == "1" @@ -60,28 +60,28 @@ - Catch::toString(e0) == "E2/V0" + Catch::toString(e0) == "E2/V0" - "E2/V0" == "E2/V0" + "E2/V0" == "E2/V0" - Catch::toString(e1) == "E2/V1" + Catch::toString(e1) == "E2/V1" - "E2/V1" == "E2/V1" + "E2/V1" == "E2/V1" - Catch::toString(e3) == "Unknown enum value 10" + Catch::toString(e3) == "Unknown enum value 10" - "Unknown enum value 10" + "Unknown enum value 10" == -"Unknown enum value 10" +"Unknown enum value 10" @@ -326,10 +326,10 @@ - s == "hello" + s == "hello" - "hello" == "hello" + "hello" == "hello" @@ -337,10 +337,10 @@ - s == "world" + s == "world" - "hello" == "world" + "hello" == "world" @@ -394,18 +394,18 @@ - data.str_hello == "hello" + data.str_hello == "hello" - "hello" == "hello" + "hello" == "hello" - "hello" == data.str_hello + "hello" == data.str_hello - "hello" == "hello" + "hello" == "hello" @@ -493,26 +493,26 @@ - data.str_hello == "goodbye" + data.str_hello == "goodbye" - "hello" == "goodbye" + "hello" == "goodbye" - data.str_hello == "hell" + data.str_hello == "hell" - "hello" == "hell" + "hello" == "hell" - data.str_hello == "hello1" + data.str_hello == "hello1" - "hello" == "hello1" + "hello" == "hello1" @@ -592,26 +592,26 @@ - data.str_hello != "goodbye" + data.str_hello != "goodbye" - "hello" != "goodbye" + "hello" != "goodbye" - data.str_hello != "hell" + data.str_hello != "hell" - "hello" != "hell" + "hello" != "hell" - data.str_hello != "hello1" + data.str_hello != "hello1" - "hello" != "hello1" + "hello" != "hello1" @@ -651,10 +651,10 @@ - data.str_hello != "hello" + data.str_hello != "hello" - "hello" != "hello" + "hello" != "hello" @@ -758,50 +758,50 @@ - data.str_hello <= "hello" + data.str_hello <= "hello" - "hello" <= "hello" + "hello" <= "hello" - data.str_hello >= "hello" + data.str_hello >= "hello" - "hello" >= "hello" + "hello" >= "hello" - data.str_hello < "hellp" + data.str_hello < "hellp" - "hello" < "hellp" + "hello" < "hellp" - data.str_hello < "zebra" + data.str_hello < "zebra" - "hello" < "zebra" + "hello" < "zebra" - data.str_hello > "hellm" + data.str_hello > "hellm" - "hello" > "hellm" + "hello" > "hellm" - data.str_hello > "a" + data.str_hello > "a" - "hello" > "a" + "hello" > "a" @@ -897,66 +897,66 @@ - data.str_hello > "hello" + data.str_hello > "hello" - "hello" > "hello" + "hello" > "hello" - data.str_hello < "hello" + data.str_hello < "hello" - "hello" < "hello" + "hello" < "hello" - data.str_hello > "hellp" + data.str_hello > "hellp" - "hello" > "hellp" + "hello" > "hellp" - data.str_hello > "z" + data.str_hello > "z" - "hello" > "z" + "hello" > "z" - data.str_hello < "hellm" + data.str_hello < "hellm" - "hello" < "hellm" + "hello" < "hellm" - data.str_hello < "a" + data.str_hello < "a" - "hello" < "a" + "hello" < "a" - data.str_hello >= "z" + data.str_hello >= "z" - "hello" >= "z" + "hello" >= "z" - data.str_hello <= "a" + data.str_hello <= "a" - "hello" <= "a" + "hello" <= "a" @@ -1600,10 +1600,10 @@
- thisThrows(), "expected exception" + thisThrows(), "expected exception" - thisThrows(), "expected exception" + thisThrows(), "expected exception" @@ -1611,10 +1611,10 @@
- thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) + thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) - thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) + thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) @@ -1622,34 +1622,34 @@
- thisThrows(), StartsWith( "expected" ) + thisThrows(), StartsWith( "expected" ) - thisThrows(), StartsWith( "expected" ) + thisThrows(), StartsWith( "expected" ) - thisThrows(), EndsWith( "exception" ) + thisThrows(), EndsWith( "exception" ) - thisThrows(), EndsWith( "exception" ) + thisThrows(), EndsWith( "exception" ) - thisThrows(), Contains( "except" ) + thisThrows(), Contains( "except" ) - thisThrows(), Contains( "except" ) + thisThrows(), Contains( "except" ) - thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) + thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) - thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) + thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) @@ -1659,15 +1659,15 @@ - thisThrows(), "expected exception" + thisThrows(), "expected exception" - thisThrows(), "expected exception" + thisThrows(), "expected exception" - thisThrows(), "should fail" + thisThrows(), "should fail" expected exception @@ -3308,7 +3308,7 @@ makeString( false ) != static_cast<char*>(nullptr) - "valid string" != {null string} + "valid string" != {null string} @@ -3434,34 +3434,34 @@ - testStringForMatching() Contains( "string" ) + testStringForMatching() Contains( "string" ) - "this string contains 'abc' as a substring" contains: "string" + "this string contains 'abc' as a substring" contains: "string" - testStringForMatching() Contains( "abc" ) + testStringForMatching() Contains( "abc" ) - "this string contains 'abc' as a substring" contains: "abc" + "this string contains 'abc' as a substring" contains: "abc" - testStringForMatching() StartsWith( "this" ) + testStringForMatching() StartsWith( "this" ) - "this string contains 'abc' as a substring" starts with: "this" + "this string contains 'abc' as a substring" starts with: "this" - testStringForMatching() EndsWith( "substring" ) + testStringForMatching() EndsWith( "substring" ) - "this string contains 'abc' as a substring" ends with: "substring" + "this string contains 'abc' as a substring" ends with: "substring" @@ -3469,10 +3469,10 @@ - testStringForMatching() Contains( "not there" ) + testStringForMatching() Contains( "not there" ) - "this string contains 'abc' as a substring" contains: "not there" + "this string contains 'abc' as a substring" contains: "not there" @@ -3480,10 +3480,10 @@ - testStringForMatching() StartsWith( "string" ) + testStringForMatching() StartsWith( "string" ) - "this string contains 'abc' as a substring" starts with: "string" + "this string contains 'abc' as a substring" starts with: "string" @@ -3491,10 +3491,10 @@ - testStringForMatching() EndsWith( "this" ) + testStringForMatching() EndsWith( "this" ) - "this string contains 'abc' as a substring" ends with: "this" + "this string contains 'abc' as a substring" ends with: "this" @@ -3502,10 +3502,10 @@ - testStringForMatching() Equals( "something else" ) + testStringForMatching() Equals( "something else" ) - "this string contains 'abc' as a substring" equals: "something else" + "this string contains 'abc' as a substring" equals: "something else" @@ -3513,10 +3513,10 @@ - "" Equals(nullptr) + "" Equals(nullptr) - "" equals: "" + "" equals: "" @@ -3524,10 +3524,10 @@ - testStringForMatching() AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) + testStringForMatching() AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) - "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" ) + "this string contains 'abc' as a substring" ( contains: "string" and contains: "abc" ) @@ -3535,18 +3535,18 @@ - testStringForMatching() AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) + testStringForMatching() AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) - "this string contains 'abc' as a substring" ( contains: "string" or contains: "not there" ) + "this string contains 'abc' as a substring" ( contains: "string" or contains: "not there" ) - testStringForMatching() AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) + testStringForMatching() AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) - "this string contains 'abc' as a substring" ( contains: "not there" or contains: "string" ) + "this string contains 'abc' as a substring" ( contains: "not there" or contains: "string" ) @@ -3554,10 +3554,10 @@ - testStringForMatching() Equals( "this string contains 'abc' as a substring" ) + testStringForMatching() Equals( "this string contains 'abc' as a substring" ) - "this string contains 'abc' as a substring" equals: "this string contains 'abc' as a substring" + "this string contains 'abc' as a substring" equals: "this string contains 'abc' as a substring" @@ -3795,14 +3795,14 @@ s1 == s2 - "if ($b == 10) { + "if ($b == 10) { $a = 20; -}" +}" == -"if ($b == 10) { +"if ($b == 10) { $a = 20; } -" +" @@ -3810,10 +3810,10 @@ - result == "\"wide load\"" + result == "\"wide load\"" - ""wide load"" == ""wide load"" + ""wide load"" == ""wide load"" @@ -3821,10 +3821,10 @@ - result == "\"wide load\"" + result == "\"wide load\"" - ""wide load"" == ""wide load"" + ""wide load"" == ""wide load"" @@ -3832,10 +3832,10 @@ - result == "\"wide load\"" + result == "\"wide load\"" - ""wide load"" == ""wide load"" + ""wide load"" == ""wide load"" @@ -3843,14 +3843,127 @@ - result == "\"wide load\"" + result == "\"wide load\"" - ""wide load"" == ""wide load"" + ""wide load"" == ""wide load"" + +
+ + + encode( "normal string" ) == "normal string" + + + "normal string" == "normal string" + + + +
+
+ + + encode( "" ) == "" + + + "" == "" + + + +
+
+ + + encode( "smith & jones" ) == "smith &amp; jones" + + + "smith &amp; jones" == "smith &amp; jones" + + + +
+
+ + + encode( "smith < jones" ) == "smith &lt; jones" + + + "smith &lt; jones" == "smith &lt; jones" + + + +
+
+ + + encode( "smith > jones" ) == "smith > jones" + + + "smith > jones" == "smith > jones" + + + + + encode( "smith ]]> jones" ) == "smith ]]&gt; jones" + + + "smith ]]&gt; jones" +== +"smith ]]&gt; jones" + + + +
+
+ + + encode( stringWithQuotes ) == stringWithQuotes + + + "don't "quote" me on that" +== +"don't "quote" me on that" + + + + + encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't &quot;quote&quot; me on that" + + + "don't &quot;quote&quot; me on that" +== +"don't &quot;quote&quot; me on that" + + + +
+
+ + + encode( "[\x01]" ) == "[&#x1]" + + + "[&#x1]" == "[&#x1]" + + + +
+
+ + + encode( "[\x7F]" ) == "[&#x7F]" + + + "[&#x7F]" == "[&#x7F]" + + + +
+ +
@@ -3907,7 +4020,7 @@ - cfg.testSpec().matches( fakeTestCase( "notIncluded" ) ) == false + cfg.testSpec().matches( fakeTestCase( "notIncluded" ) ) == false false == false @@ -3915,7 +4028,7 @@ - cfg.testSpec().matches( fakeTestCase( "test1" ) ) + cfg.testSpec().matches( fakeTestCase( "test1" ) ) true @@ -3937,7 +4050,7 @@ - cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false + cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false false == false @@ -3945,7 +4058,7 @@ - cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) + cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) true @@ -3967,7 +4080,7 @@ - cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false + cfg.testSpec().matches( fakeTestCase( "test1" ) ) == false false == false @@ -3975,7 +4088,7 @@ - cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) + cfg.testSpec().matches( fakeTestCase( "alwaysIncluded" ) ) true @@ -3997,10 +4110,10 @@ - config.reporterName == "console" + config.reporterName == "console" - "console" == "console" + "console" == "console" @@ -4019,10 +4132,10 @@ - config.reporterName == "xml" + config.reporterName == "xml" - "xml" == "xml" + "xml" == "xml" @@ -4041,10 +4154,10 @@ - config.reporterName == "junit" + config.reporterName == "junit" - "junit" == "junit" + "junit" == "junit" @@ -4143,11 +4256,11 @@
- parseIntoConfigAndReturnError( argv, config ) Contains( "greater than zero" ) + parseIntoConfigAndReturnError( argv, config ) Contains( "greater than zero" ) - "Value after -x or --abortAfter must be greater than zero -- while parsing: (-x, --abortx <no. failures>)" contains: "greater than zero" + "Value after -x or --abortAfter must be greater than zero +- while parsing: (-x, --abortx <no. failures>)" contains: "greater than zero" @@ -4158,11 +4271,11 @@
- parseIntoConfigAndReturnError( argv, config ) Contains( "-x" ) + parseIntoConfigAndReturnError( argv, config ) Contains( "-x" ) - "Unable to convert oops to destination type -- while parsing: (-x, --abortx <no. failures>)" contains: "-x" + "Unable to convert oops to destination type +- while parsing: (-x, --abortx <no. failures>)" contains: "-x" @@ -4225,10 +4338,10 @@ - config.outputFilename == "filename.ext" + config.outputFilename == "filename.ext" - "filename.ext" == "filename.ext" + "filename.ext" == "filename.ext" @@ -4247,10 +4360,10 @@ - config.outputFilename == "filename.ext" + config.outputFilename == "filename.ext" - "filename.ext" == "filename.ext" + "filename.ext" == "filename.ext" @@ -4349,9 +4462,9 @@ Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString - "one two three four" + "one two three four" == -"one two three four" +"one two three four" @@ -4359,9 +4472,9 @@ Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString - "one two three four" + "one two three four" == -"one two three four" +"one two three four" @@ -4372,62 +4485,62 @@
- Text( testString, TextAttributes().setWidth( 17 ) ).toString() == "one two three\nfour" + Text( testString, TextAttributes().setWidth( 17 ) ).toString() == "one two three\nfour" - "one two three -four" + "one two three +four" == -"one two three -four" +"one two three +four" - Text( testString, TextAttributes().setWidth( 16 ) ).toString() == "one two three\nfour" + Text( testString, TextAttributes().setWidth( 16 ) ).toString() == "one two three\nfour" - "one two three -four" + "one two three +four" == -"one two three -four" +"one two three +four" - Text( testString, TextAttributes().setWidth( 14 ) ).toString() == "one two three\nfour" + Text( testString, TextAttributes().setWidth( 14 ) ).toString() == "one two three\nfour" - "one two three -four" + "one two three +four" == -"one two three -four" +"one two three +four" - Text( testString, TextAttributes().setWidth( 13 ) ).toString() == "one two three\nfour" + Text( testString, TextAttributes().setWidth( 13 ) ).toString() == "one two three\nfour" - "one two three -four" + "one two three +four" == -"one two three -four" +"one two three +four" - Text( testString, TextAttributes().setWidth( 12 ) ).toString() == "one two\nthree four" + Text( testString, TextAttributes().setWidth( 12 ) ).toString() == "one two\nthree four" - "one two -three four" + "one two +three four" == -"one two -three four" +"one two +three four" @@ -4438,44 +4551,44 @@ three four"
- Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" - Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" - Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" @@ -4486,34 +4599,34 @@ four"
- Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" + Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" - "one + "one two three -four" +four" == -"one +"one two three -four" +four" - Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one\ntwo\nthree\nfour" + Text( testString, TextAttributes().setWidth( 5 ) ).toString() == "one\ntwo\nthree\nfour" - "one + "one two three -four" +four" == -"one +"one two three -four" +four" @@ -4524,78 +4637,78 @@ four"
- Text( "abcdef", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef" + Text( "abcdef", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef" - "abc- -def" + "abc- +def" == -"abc- -def" +"abc- +def" - Text( "abcdefg", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndefg" + Text( "abcdefg", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndefg" - "abc- -defg" + "abc- +defg" == -"abc- -defg" +"abc- +defg" - Text( "abcdefgh", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef-\ngh" + Text( "abcdefgh", TextAttributes().setWidth( 4 ) ).toString() == "abc-\ndef-\ngh" - "abc- + "abc- def- -gh" +gh" == -"abc- +"abc- def- -gh" +gh" - Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one\ntwo\nthr-\nee\nfour" + Text( testString, TextAttributes().setWidth( 4 ) ).toString() == "one\ntwo\nthr-\nee\nfour" - "one + "one two thr- ee -four" +four" == -"one +"one two thr- ee -four" +four" - Text( testString, TextAttributes().setWidth( 3 ) ).toString() == "one\ntwo\nth-\nree\nfo-\nur" + Text( testString, TextAttributes().setWidth( 3 ) ).toString() == "one\ntwo\nth-\nree\nfo-\nur" - "one + "one two th- ree fo- -ur" +ur" == -"one +"one two th- ree fo- -ur" +ur" @@ -4614,34 +4727,34 @@ ur" - text[0] == "one" + text[0] == "one" - "one" == "one" + "one" == "one" - text[1] == "two" + text[1] == "two" - "two" == "two" + "two" == "two" - text[2] == "three" + text[2] == "three" - "three" == "three" + "three" == "three" - text[3] == "four" + text[3] == "four" - "four" == "four" + "four" == "four" @@ -4652,16 +4765,16 @@ ur"
- text.toString() == " one two\n three\n four" + text.toString() == " one two\n three\n four" - " one two + " one two three - four" + four" == -" one two +" one two three - four" + four" @@ -4675,11 +4788,11 @@ ur" Text( testString, TextAttributes().setWidth( 80 ) ).toString() == testString - "one two -three four" + "one two +three four" == -"one two -three four" +"one two +three four" @@ -4687,11 +4800,11 @@ three four" Text( testString, TextAttributes().setWidth( 18 ) ).toString() == testString - "one two -three four" + "one two +three four" == -"one two -three four" +"one two +three four" @@ -4699,11 +4812,11 @@ three four" Text( testString, TextAttributes().setWidth( 10 ) ).toString() == testString - "one two -three four" + "one two +three four" == -"one two -three four" +"one two +three four" @@ -4714,34 +4827,34 @@ three four"
- Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" + Text( "abcdef\n", TextAttributes().setWidth( 10 ) ).toString() == "abcdef\n" - "abcdef -" + "abcdef +" == -"abcdef -" +"abcdef +" - Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" + Text( "abcdef", TextAttributes().setWidth( 6 ) ).toString() == "abcdef" - "abcdef" == "abcdef" + "abcdef" == "abcdef" - Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" + Text( "abcdef\n", TextAttributes().setWidth( 6 ) ).toString() == "abcdef\n" - "abcdef -" + "abcdef +" == -"abcdef -" +"abcdef +" @@ -4752,44 +4865,44 @@ three four"
- Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 9 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" - Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 8 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" - Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" + Text( testString, TextAttributes().setWidth( 7 ) ).toString() == "one two\nthree\nfour" - "one two + "one two three -four" +four" == -"one two +"one two three -four" +four" @@ -4800,18 +4913,18 @@ four"
- Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" + Text( testString, TextAttributes().setWidth( 6 ) ).toString() == "one\ntwo\nthree\nfour" - "one + "one two three -four" +four" == -"one +"one two three -four" +four" @@ -4821,18 +4934,18 @@ four"
- Text( testString, TextAttributes().setWidth( 15 ) ).toString() == "one two three\n four\n five\n six" + Text( testString, TextAttributes().setWidth( 15 ) ).toString() == "one two three\n four\n five\n six" - "one two three + "one two three four five - six" + six" == -"one two three +"one two three four five - six" + six" @@ -4843,7 +4956,7 @@ four"
- replaceInPlace( letters, "b", "z" ) + replaceInPlace( letters, "b", "z" ) true @@ -4851,10 +4964,10 @@ four" - letters == "azcdefcg" + letters == "azcdefcg" - "azcdefcg" == "azcdefcg" + "azcdefcg" == "azcdefcg" @@ -4862,7 +4975,7 @@ four"
- replaceInPlace( letters, "c", "z" ) + replaceInPlace( letters, "c", "z" ) true @@ -4870,10 +4983,10 @@ four" - letters == "abzdefzg" + letters == "abzdefzg" - "abzdefzg" == "abzdefzg" + "abzdefzg" == "abzdefzg" @@ -4881,7 +4994,7 @@ four"
- replaceInPlace( letters, "a", "z" ) + replaceInPlace( letters, "a", "z" ) true @@ -4889,10 +5002,10 @@ four" - letters == "zbcdefcg" + letters == "zbcdefcg" - "zbcdefcg" == "zbcdefcg" + "zbcdefcg" == "zbcdefcg" @@ -4900,7 +5013,7 @@ four"
- replaceInPlace( letters, "g", "z" ) + replaceInPlace( letters, "g", "z" ) true @@ -4908,10 +5021,10 @@ four" - letters == "abcdefcz" + letters == "abcdefcz" - "abcdefcz" == "abcdefcz" + "abcdefcz" == "abcdefcz" @@ -4919,7 +5032,7 @@ four"
- replaceInPlace( letters, letters, "replaced" ) + replaceInPlace( letters, letters, "replaced" ) true @@ -4927,10 +5040,10 @@ four" - letters == "replaced" + letters == "replaced" - "replaced" == "replaced" + "replaced" == "replaced" @@ -4938,7 +5051,7 @@ four"
- !replaceInPlace( letters, "x", "z" ) + !replaceInPlace( letters, "x", "z" ) !false @@ -4949,7 +5062,7 @@ four" letters == letters - "abcdefcg" == "abcdefcg" + "abcdefcg" == "abcdefcg" @@ -4957,7 +5070,7 @@ four"
- replaceInPlace( s, "'", "|'" ) + replaceInPlace( s, "'", "|'" ) true @@ -4965,10 +5078,10 @@ four" - s == "didn|'t" + s == "didn|'t" - "didn|'t" == "didn|'t" + "didn|'t" == "didn|'t" @@ -4981,22 +5094,22 @@ four" - Text( "hi there" ).toString() == "hi there" + Text( "hi there" ).toString() == "hi there" - "hi there" == "hi there" + "hi there" == "hi there" - Text( "hi there", narrow ).toString() == "hi\nthere" + Text( "hi there", narrow ).toString() == "hi\nthere" - "hi -there" + "hi +there" == -"hi -there" +"hi +there" @@ -5004,10 +5117,10 @@ there" - t.toString() EndsWith( "... message truncated due to excessive size" ) + t.toString() EndsWith( "... message truncated due to excessive size" ) - "******************************************************************************- + "******************************************************************************- ******************************************************************************- ************************ ******************************************************************************- @@ -6007,7 +6120,7 @@ there" ******************************************************************************- ************************ ******************************************************************************- -... message truncated due to excessive size" ends with: "... message truncated due to excessive size" +... message truncated due to excessive size" ends with: "... message truncated due to excessive size" @@ -6057,10 +6170,10 @@ there" - std::string( "first" ) == "second" + std::string( "first" ) == "second" - "first" == "second" + "first" == "second" @@ -6303,10 +6416,10 @@ there" - s == "7" + s == "7" - "7" == "7" + "7" == "7" @@ -6380,12 +6493,12 @@ there" - Catch::toString( item ) == "toString( has_toString )" + Catch::toString( item ) == "toString( has_toString )" - "toString( has_toString )" + "toString( has_toString )" == -"toString( has_toString )" +"toString( has_toString )" @@ -6393,12 +6506,12 @@ there" - Catch::toString( item ) == "StringMaker<has_maker>" + Catch::toString( item ) == "StringMaker<has_maker>" - "StringMaker<has_maker>" + "StringMaker<has_maker>" == -"StringMaker<has_maker>" +"StringMaker<has_maker>" @@ -6406,12 +6519,12 @@ there" - Catch::toString( item ) == "toString( has_maker_and_toString )" + Catch::toString( item ) == "toString( has_maker_and_toString )" - "toString( has_maker_and_toString )" + "toString( has_maker_and_toString )" == -"toString( has_maker_and_toString )" +"toString( has_maker_and_toString )" @@ -6419,10 +6532,10 @@ there" - Catch::toString( v ) == "{ {?} }" + Catch::toString( v ) == "{ {?} }" - "{ {?} }" == "{ {?} }" + "{ {?} }" == "{ {?} }" @@ -6430,12 +6543,12 @@ there" - Catch::toString( v ) == "{ StringMaker<has_maker> }" + Catch::toString( v ) == "{ StringMaker<has_maker> }" - "{ StringMaker<has_maker> }" + "{ StringMaker<has_maker> }" == -"{ StringMaker<has_maker> }" +"{ StringMaker<has_maker> }" @@ -6443,12 +6556,12 @@ there" - Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" + Catch::toString( v ) == "{ StringMaker<has_maker_and_toString> }" - "{ StringMaker<has_maker_and_toString> }" + "{ StringMaker<has_maker_and_toString> }" == -"{ StringMaker<has_maker_and_toString> }" +"{ StringMaker<has_maker_and_toString> }" @@ -6456,10 +6569,10 @@ there" - Catch::toString( value ) == "{ 34, \"xyzzy\" }" + Catch::toString( value ) == "{ 34, \"xyzzy\" }" - "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" + "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" @@ -6467,10 +6580,10 @@ there" - Catch::toString(value) == "{ 34, \"xyzzy\" }" + Catch::toString(value) == "{ 34, \"xyzzy\" }" - "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" + "{ 34, "xyzzy" }" == "{ 34, "xyzzy" }" @@ -6478,12 +6591,12 @@ there" - Catch::toString( pr ) == "{ { \"green\", 55 } }" + Catch::toString( pr ) == "{ { \"green\", 55 } }" - "{ { "green", 55 } }" + "{ { "green", 55 } }" == -"{ { "green", 55 } }" +"{ { "green", 55 } }" @@ -6491,12 +6604,12 @@ there" - Catch::toString( pair ) == "{ { 42, \"Arthur\" }, { \"Ford\", 24 } }" + Catch::toString( pair ) == "{ { 42, \"Arthur\" }, { \"Ford\", 24 } }" - "{ { 42, "Arthur" }, { "Ford", 24 } }" + "{ { 42, "Arthur" }, { "Ford", 24 } }" == -"{ { 42, "Arthur" }, { "Ford", 24 } }" +"{ { 42, "Arthur" }, { "Ford", 24 } }" @@ -6504,26 +6617,26 @@ there" - Catch::toString(vv) == "{ }" + Catch::toString(vv) == "{ }" - "{ }" == "{ }" + "{ }" == "{ }" - Catch::toString(vv) == "{ 42 }" + Catch::toString(vv) == "{ 42 }" - "{ 42 }" == "{ 42 }" + "{ 42 }" == "{ 42 }" - Catch::toString(vv) == "{ 42, 250 }" + Catch::toString(vv) == "{ 42, 250 }" - "{ 42, 250 }" == "{ 42, 250 }" + "{ 42, 250 }" == "{ 42, 250 }" @@ -6531,28 +6644,28 @@ there" - Catch::toString(vv) == "{ }" + Catch::toString(vv) == "{ }" - "{ }" == "{ }" + "{ }" == "{ }" - Catch::toString(vv) == "{ \"hello\" }" + Catch::toString(vv) == "{ \"hello\" }" - "{ "hello" }" == "{ "hello" }" + "{ "hello" }" == "{ "hello" }" - Catch::toString(vv) == "{ \"hello\", \"world\" }" + Catch::toString(vv) == "{ \"hello\", \"world\" }" - "{ "hello", "world" }" + "{ "hello", "world" }" == -"{ "hello", "world" }" +"{ "hello", "world" }" @@ -6560,26 +6673,26 @@ there" - Catch::toString(vv) == "{ }" + Catch::toString(vv) == "{ }" - "{ }" == "{ }" + "{ }" == "{ }" - Catch::toString(vv) == "{ 42 }" + Catch::toString(vv) == "{ 42 }" - "{ 42 }" == "{ 42 }" + "{ 42 }" == "{ 42 }" - Catch::toString(vv) == "{ 42, 250 }" + Catch::toString(vv) == "{ 42, 250 }" - "{ 42, 250 }" == "{ 42, 250 }" + "{ 42, 250 }" == "{ 42, 250 }" @@ -6587,20 +6700,20 @@ there" - Catch::toString(v) == "{ }" + Catch::toString(v) == "{ }" - "{ }" == "{ }" + "{ }" == "{ }" - Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" + Catch::toString(v) == "{ { \"hello\" }, { \"world\" } }" - "{ { "hello" }, { "world" } }" + "{ { "hello" }, { "world" } }" == -"{ { "hello" }, { "world" } }" +"{ { "hello" }, { "world" } }" @@ -6819,7 +6932,7 @@ there" - parseTestSpec( "*a" ).matches( tcA ) == true + parseTestSpec( "*a" ).matches( tcA ) == true true == true @@ -6870,7 +6983,7 @@ there" - parseTestSpec( "a*" ).matches( tcA ) == true + parseTestSpec( "a*" ).matches( tcA ) == true true == true @@ -6921,7 +7034,7 @@ there" - parseTestSpec( "*a*" ).matches( tcA ) == true + parseTestSpec( "*a*" ).matches( tcA ) == true true == true @@ -7784,18 +7897,18 @@ there" - "{ }" == Catch::toString(type{}) + "{ }" == Catch::toString(type{}) - "{ }" == "{ }" + "{ }" == "{ }" - "{ }" == Catch::toString(value) + "{ }" == Catch::toString(value) - "{ }" == "{ }" + "{ }" == "{ }" @@ -7803,10 +7916,10 @@ there" - "{ 0 }" == Catch::toString(type{0}) + "{ 0 }" == Catch::toString(type{0}) - "{ 0 }" == "{ 0 }" + "{ 0 }" == "{ 0 }" @@ -7814,18 +7927,18 @@ there" - "1.2f" == Catch::toString(float(1.2)) + "1.2f" == Catch::toString(float(1.2)) - "1.2f" == "1.2f" + "1.2f" == "1.2f" - "{ 1.2f, 0 }" == Catch::toString(type{1.2,0}) + "{ 1.2f, 0 }" == Catch::toString(type{1.2,0}) - "{ 1.2f, 0 }" == "{ 1.2f, 0 }" + "{ 1.2f, 0 }" == "{ 1.2f, 0 }" @@ -7833,12 +7946,12 @@ there" - "{ \"hello\", \"world\" }" == Catch::toString(type{"hello","world"}) + "{ \"hello\", \"world\" }" == Catch::toString(type{"hello","world"}) - "{ "hello", "world" }" + "{ "hello", "world" }" == -"{ "hello", "world" }" +"{ "hello", "world" }" @@ -7846,12 +7959,12 @@ there" - "{ { 42 }, { }, 1.2f }" == Catch::toString(value) + "{ { 42 }, { }, 1.2f }" == Catch::toString(value) - "{ { 42 }, { }, 1.2f }" + "{ { 42 }, { }, 1.2f }" == -"{ { 42 }, { }, 1.2f }" +"{ { 42 }, { }, 1.2f }" @@ -7859,12 +7972,12 @@ there" - "{ nullptr, 42, \"Catch me\" }" == Catch::toString(value) + "{ nullptr, 42, \"Catch me\" }" == Catch::toString(value) - "{ nullptr, 42, "Catch me" }" + "{ nullptr, 42, "Catch me" }" == -"{ nullptr, 42, "Catch me" }" +"{ nullptr, 42, "Catch me" }" @@ -7873,42 +7986,42 @@ there"
- what Contains( "[@zzz]" ) + what Contains( "[@zzz]" ) - "error: tag alias, "[@zzz]" already registered. + "error: tag alias, "[@zzz]" already registered. First seen at file:2 - Redefined at file:10" contains: "[@zzz]" + Redefined at file:10" contains: "[@zzz]" - what Contains( "file" ) + what Contains( "file" ) - "error: tag alias, "[@zzz]" already registered. + "error: tag alias, "[@zzz]" already registered. First seen at file:2 - Redefined at file:10" contains: "file" + Redefined at file:10" contains: "file" - what Contains( "2" ) + what Contains( "2" ) - "error: tag alias, "[@zzz]" already registered. + "error: tag alias, "[@zzz]" already registered. First seen at file:2 - Redefined at file:10" contains: "2" + Redefined at file:10" contains: "2" - what Contains( "10" ) + what Contains( "10" ) - "error: tag alias, "[@zzz]" already registered. + "error: tag alias, "[@zzz]" already registered. First seen at file:2 - Redefined at file:10" contains: "10" + Redefined at file:10" contains: "10" @@ -7916,34 +8029,34 @@ there"
- registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[no ampersat]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[the @ is not at the start]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "@no square bracket at start]", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) - registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) + registry.add( "[@no square bracket at end", "", Catch::SourceLineInfo( "file", 3 ) ) @@ -8299,7 +8412,7 @@ there"
- + - + diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index d91db944..04b86c81 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -7,6 +7,7 @@ */ #include "catch.hpp" +#include "catch_xmlwriter.hpp" #include @@ -381,6 +382,42 @@ TEST_CASE( "toString on wchar_t returns the string contents", "[toString]" ) { CHECK( result == "\"wide load\"" ); } +inline std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) { + std::ostringstream oss; + oss << Catch::XmlEncode( str, forWhat ); + return oss.str(); +} + +TEST_CASE( "XmlEncode" ) { + SECTION( "normal string" ) { + REQUIRE( encode( "normal string" ) == "normal string" ); + } + SECTION( "empty string" ) { + REQUIRE( encode( "" ) == "" ); + } + SECTION( "string with ampersand" ) { + REQUIRE( encode( "smith & jones" ) == "smith & jones" ); + } + SECTION( "string with less-than" ) { + REQUIRE( encode( "smith < jones" ) == "smith < jones" ); + } + SECTION( "string with greater-than" ) { + REQUIRE( encode( "smith > jones" ) == "smith > jones" ); + REQUIRE( encode( "smith ]]> jones" ) == "smith ]]> jones" ); + } + SECTION( "string with quotes" ) { + std::string stringWithQuotes = "don't \"quote\" me on that"; + REQUIRE( encode( stringWithQuotes ) == stringWithQuotes ); + REQUIRE( encode( stringWithQuotes, Catch::XmlEncode::ForAttributes ) == "don't "quote" me on that" ); + } + SECTION( "string with control char (1)" ) { + REQUIRE( encode( "[\x01]" ) == "[]" ); + } + SECTION( "string with control char (x7F)" ) { + REQUIRE( encode( "[\x7F]" ) == "[]" ); + } +} + //TEST_CASE( "Divide by Zero signal handler", "[.][sig]" ) { // int i = 0; // int x = 10/i; // This should cause the signal to fire