Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/MiscTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2015-07-23 18:45:31 +0100
committerPhil Nash2015-07-23 18:45:31 +0100
commitd6e59cd56f196eb40cbec3223531ee8d98e8ac8f (patch)
treee6bafb739dcc4b21dd0aed347d050312cb6379b0 /projects/SelfTest/MiscTests.cpp
parent6de135c63aad8986cb28a88b988661de7fddf003 (diff)
downloadcatch3-d6e59cd56f196eb40cbec3223531ee8d98e8ac8f.tar.gz
Fixed Xml encoding
- don't encode apostrophes - only encode quotes in attributes - encode control characters (as in PR #465)
Diffstat (limited to 'projects/SelfTest/MiscTests.cpp')
-rw-r--r--projects/SelfTest/MiscTests.cpp37
1 files changed, 37 insertions, 0 deletions
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 <iostream>
@@ -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 &amp; jones" );
+ }
+ SECTION( "string with less-than" ) {
+ REQUIRE( encode( "smith < jones" ) == "smith &lt; jones" );
+ }
+ SECTION( "string with greater-than" ) {
+ REQUIRE( encode( "smith > jones" ) == "smith > jones" );
+ REQUIRE( encode( "smith ]]> jones" ) == "smith ]]&gt; 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 &quot;quote&quot; me on that" );
+ }
+ SECTION( "string with control char (1)" ) {
+ REQUIRE( encode( "[\x01]" ) == "[&#x1]" );
+ }
+ SECTION( "string with control char (x7F)" ) {
+ REQUIRE( encode( "[\x7F]" ) == "[&#x7F]" );
+ }
+}
+
//TEST_CASE( "Divide by Zero signal handler", "[.][sig]" ) {
// int i = 0;
// int x = 10/i; // This should cause the signal to fire