diff options
author | KWSys Upstream <kwrobot@kitware.com> | 2016-12-02 14:36:32 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-12-05 14:55:32 (GMT) |
commit | 1b50bd3f5c1f608a84df89c2f5e187a53f0be31d (patch) | |
tree | e7e50180cf0126ec7b7a83baf2a4ce2a23352fac /testConsoleBuf.cxx | |
parent | cd5cff13370f6953497484f6e4b04f957fe9c9a7 (diff) | |
download | CMake-1b50bd3f5c1f608a84df89c2f5e187a53f0be31d.zip CMake-1b50bd3f5c1f608a84df89c2f5e187a53f0be31d.tar.gz CMake-1b50bd3f5c1f608a84df89c2f5e187a53f0be31d.tar.bz2 |
KWSys 2016-12-02 (4967ccc0)
Code extracted from:
http://public.kitware.com/KWSys.git
at commit 4967ccc054d268c430e73445f3a103e737c5f5f7 (master).
Upstream Shortlog
-----------------
Chuck Atkins (2):
f1afce25 DynamicLoader: Re-organize preprocessor checks to use if, elif, else
d94f92f7 DynamicLoader: Expand noop implementation to more platforms
Dāvis Mosāns (2):
f069db91 Encoding: Fix conversion of strings that contain null bytes
4967ccc0 ConsoleBuf: Fix output for strings that contain null byte
Diffstat (limited to 'testConsoleBuf.cxx')
-rw-r--r-- | testConsoleBuf.cxx | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/testConsoleBuf.cxx b/testConsoleBuf.cxx index bd58fb6..3b8cdab 100644 --- a/testConsoleBuf.cxx +++ b/testConsoleBuf.cxx @@ -18,6 +18,7 @@ #if defined(_WIN32) +#include <algorithm> #include <iomanip> #include <iostream> #include <stdexcept> @@ -318,6 +319,7 @@ static int testPipe() bytesRead == 0) { throw std::runtime_error("ReadFile#1 failed!"); } + buffer[bytesRead] = 0; if ((bytesRead < encodedTestString.size() + 1 + encodedInputTestString.size() && !ReadFile(outPipeRead, buffer + bytesRead, @@ -336,8 +338,12 @@ static int testPipe() bytesRead == 0) { throw std::runtime_error("ReadFile#3 failed!"); } - buffer2[bytesRead - 1] = 0; - didFail = encodedTestString.compare(buffer2) == 0 ? 0 : 1; + buffer2[bytesRead] = 0; + didFail = + encodedTestString.compare(0, encodedTestString.npos, buffer2, + encodedTestString.size()) == 0 + ? 0 + : 1; } if (didFail != 0) { std::cerr << "Pipe's output didn't match expected output!" @@ -423,23 +429,28 @@ static int testFile() bytesRead == 0) { throw std::runtime_error("ReadFile#1 failed!"); } - buffer[bytesRead - 1] = 0; + buffer[bytesRead] = 0; if (memcmp(buffer, encodedTestString.c_str(), encodedTestString.size()) == 0 && memcmp(buffer + encodedTestString.size() + 1, encodedInputTestString.c_str(), - encodedInputTestString.size() - 1) == 0) { + encodedInputTestString.size()) == 0) { bytesRead = 0; if (SetFilePointer(errFile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { throw std::runtime_error("SetFilePointer#2 failed!"); } + if (!ReadFile(errFile, buffer2, sizeof(buffer2), &bytesRead, NULL) || bytesRead == 0) { throw std::runtime_error("ReadFile#2 failed!"); } - buffer2[bytesRead - 1] = 0; - didFail = encodedTestString.compare(buffer2) == 0 ? 0 : 1; + buffer2[bytesRead] = 0; + didFail = + encodedTestString.compare(0, encodedTestString.npos, buffer2, + encodedTestString.size()) == 0 + ? 0 + : 1; } if (didFail != 0) { std::cerr << "File's output didn't match expected output!" @@ -448,7 +459,7 @@ static int testFile() encodedTestString.size()); dumpBuffers<char>(encodedInputTestString.c_str(), buffer + encodedTestString.size() + 1, - encodedInputTestString.size() - 1); + encodedInputTestString.size()); dumpBuffers<char>(encodedTestString.c_str(), buffer2, encodedTestString.size()); } @@ -685,6 +696,7 @@ static int testConsole() throw std::runtime_error("ReadConsoleOutputCharacter failed!"); } std::wstring wideTestString = kwsys::Encoding::ToWide(encodedTestString); + std::replace(wideTestString.begin(), wideTestString.end(), '\0', ' '); std::wstring wideInputTestString = kwsys::Encoding::ToWide(encodedInputTestString); if (memcmp(outputBuffer, wideTestString.c_str(), @@ -757,8 +769,11 @@ int testConsoleBuf(int, char* []) return 1; } - encodedTestString = kwsys::Encoding::ToNarrow(UnicodeTestString); - encodedInputTestString = kwsys::Encoding::ToNarrow(UnicodeInputTestString); + encodedTestString = kwsys::Encoding::ToNarrow(std::wstring( + UnicodeTestString, sizeof(UnicodeTestString) / sizeof(wchar_t) - 1)); + encodedInputTestString = kwsys::Encoding::ToNarrow( + std::wstring(UnicodeInputTestString, + sizeof(UnicodeInputTestString) / sizeof(wchar_t) - 1)); encodedInputTestString += "\n"; ret |= testPipe(); |