]> granicus.if.org Git - icinga2/blob - test/base-shellescape.cpp
Merge pull request #6999 from Icinga/bugfix/compiler-warnings
[icinga2] / test / base-shellescape.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/utility.hpp"
4 #include <BoostTestTargetConfig.h>
5 #include <iostream>
6
7 using namespace icinga;
8
9 BOOST_AUTO_TEST_SUITE(base_shellescape)
10
11 BOOST_AUTO_TEST_CASE(escape_basic)
12 {
13 #ifdef _WIN32
14         BOOST_CHECK(Utility::EscapeShellCmd("%PATH%") == "^%PATH^%");
15 #else /* _WIN32 */
16         BOOST_CHECK(Utility::EscapeShellCmd("$PATH") == "\\$PATH");
17         BOOST_CHECK(Utility::EscapeShellCmd("\\$PATH") == "\\\\\\$PATH");
18 #endif /* _WIN32 */
19 }
20
21 BOOST_AUTO_TEST_CASE(escape_quoted)
22 {
23 #ifdef _WIN32
24         BOOST_CHECK(Utility::EscapeShellCmd("'hello'") == "^'hello^'");
25         BOOST_CHECK(Utility::EscapeShellCmd("\"hello\"") == "^\"hello^\"");
26 #else /* _WIN32 */
27         BOOST_CHECK(Utility::EscapeShellCmd("'hello'") == "'hello'");
28         BOOST_CHECK(Utility::EscapeShellCmd("'hello") == "\\'hello");
29 #endif /* _WIN32 */
30 }
31
32 BOOST_AUTO_TEST_SUITE_END()