Merge pull request #8712 from Icinga/feature/avoid-windows-atl-dependency

Avoid dependency on Visual C++ ATL in tests on Windows
This commit is contained in:
Julian Brost 2021-04-12 09:37:57 +02:00 committed by GitHub
commit 8dc069dc24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -7,7 +7,6 @@
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
# include <shellapi.h> # include <shellapi.h>
# include <atlstr.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
using namespace icinga; using namespace icinga;
@ -84,6 +83,8 @@ BOOST_AUTO_TEST_CASE(validateutf8)
BOOST_AUTO_TEST_CASE(EscapeCreateProcessArg) BOOST_AUTO_TEST_CASE(EscapeCreateProcessArg)
{ {
#ifdef _WIN32 #ifdef _WIN32
using convert = std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>, wchar_t>;
std::vector<std::string> testdata = { std::vector<std::string> testdata = {
R"(foobar)", R"(foobar)",
R"(foo bar)", R"(foo bar)",
@ -98,11 +99,11 @@ BOOST_AUTO_TEST_CASE(EscapeCreateProcessArg)
// Prepend some fake exec name as the first argument is handled differently. // Prepend some fake exec name as the first argument is handled differently.
std::string escaped = "some.exe " + Utility::EscapeCreateProcessArg(t); std::string escaped = "some.exe " + Utility::EscapeCreateProcessArg(t);
int argc; int argc;
std::shared_ptr<LPWSTR> argv(CommandLineToArgvW(CA2W(escaped.c_str()), &argc), LocalFree); std::shared_ptr<LPWSTR> argv(CommandLineToArgvW(convert{}.from_bytes(escaped.c_str()).data(), &argc), LocalFree);
BOOST_CHECK_MESSAGE(argv != nullptr, "CommandLineToArgvW() should not return nullptr for " << t); BOOST_CHECK_MESSAGE(argv != nullptr, "CommandLineToArgvW() should not return nullptr for " << t);
BOOST_CHECK_MESSAGE(argc == 2, "CommandLineToArgvW() should find 2 arguments for " << t); BOOST_CHECK_MESSAGE(argc == 2, "CommandLineToArgvW() should find 2 arguments for " << t);
if (argc >= 2) { if (argc >= 2) {
std::string unescaped = CW2A(argv.get()[1]); std::string unescaped = convert{}.to_bytes(argv.get()[1]);
BOOST_CHECK_MESSAGE(unescaped == t, BOOST_CHECK_MESSAGE(unescaped == t,
"CommandLineToArgvW() should return original value for " << t << " (got: " << unescaped << ")"); "CommandLineToArgvW() should return original value for " << t << " (got: " << unescaped << ")");
} }