summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testEncoding.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-12-05 14:55:34 (GMT)
committerBrad King <brad.king@kitware.com>2016-12-05 14:55:34 (GMT)
commit7f307d9ea6e77ee6fd7081d464314a64cbf64f32 (patch)
treea165c1c500907a74c6046dbbebcbbd68d4fda078 /Source/kwsys/testEncoding.cxx
parentd59010e47fa953afb7f638fbab1a65195478d3fa (diff)
parent1b50bd3f5c1f608a84df89c2f5e187a53f0be31d (diff)
downloadCMake-7f307d9ea6e77ee6fd7081d464314a64cbf64f32.zip
CMake-7f307d9ea6e77ee6fd7081d464314a64cbf64f32.tar.gz
CMake-7f307d9ea6e77ee6fd7081d464314a64cbf64f32.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys: KWSys 2016-12-02 (4967ccc0)
Diffstat (limited to 'Source/kwsys/testEncoding.cxx')
-rw-r--r--Source/kwsys/testEncoding.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/Source/kwsys/testEncoding.cxx b/Source/kwsys/testEncoding.cxx
index 996976f..03f2ec9 100644
--- a/Source/kwsys/testEncoding.cxx
+++ b/Source/kwsys/testEncoding.cxx
@@ -9,6 +9,7 @@
#include KWSYS_HEADER(Encoding.hxx)
#include KWSYS_HEADER(Encoding.h)
+#include <algorithm>
#include <iostream>
#include <locale.h>
#include <stdlib.h>
@@ -124,6 +125,35 @@ static int testRobustEncoding()
return ret;
}
+static int testWithNulls()
+{
+ int ret = 0;
+ std::vector<std::string> strings;
+ strings.push_back(std::string("ab") + '\0' + 'c');
+ strings.push_back(std::string("d") + '\0' + '\0' + 'e');
+ strings.push_back(std::string() + '\0' + 'f');
+ strings.push_back(std::string() + '\0' + '\0' + "gh");
+ strings.push_back(std::string("ij") + '\0');
+ strings.push_back(std::string("k") + '\0' + '\0');
+ strings.push_back(std::string("\0\0\0\0", 4) + "lmn" +
+ std::string("\0\0\0\0", 4));
+ for (std::vector<std::string>::iterator it = strings.begin();
+ it != strings.end(); ++it) {
+ std::wstring wstr = kwsys::Encoding::ToWide(*it);
+ std::string str = kwsys::Encoding::ToNarrow(wstr);
+ std::string s(*it);
+ std::replace(s.begin(), s.end(), '\0', ' ');
+ std::cout << "'" << s << "' (" << it->size() << ")" << std::endl;
+ if (str != *it) {
+ std::replace(str.begin(), str.end(), '\0', ' ');
+ std::cout << "string with null was different: '" << str << "' ("
+ << str.size() << ")" << std::endl;
+ ret++;
+ }
+ }
+ return ret;
+}
+
static int testCommandLineArguments()
{
int status = 0;
@@ -165,6 +195,7 @@ int testEncoding(int, char* [])
ret |= testHelloWorldEncoding();
ret |= testRobustEncoding();
ret |= testCommandLineArguments();
+ ret |= testWithNulls();
return ret;
}