2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-03-22 10:58:47 +01:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/utility.hpp"
|
2016-09-07 08:20:51 +02:00
|
|
|
#include <BoostTestTargetConfig.h>
|
2013-03-22 10:58:47 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(base_shellescape)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(escape_basic)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("%PATH%") == "^%PATH^%");
|
2013-11-13 09:08:17 +01:00
|
|
|
#else /* _WIN32 */
|
2013-03-22 10:58:47 +01:00
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("$PATH") == "\\$PATH");
|
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("\\$PATH") == "\\\\\\$PATH");
|
2013-11-13 09:08:17 +01:00
|
|
|
#endif /* _WIN32 */
|
2013-03-22 10:58:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(escape_quoted)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2013-11-13 09:08:17 +01:00
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("'hello'") == "^'hello^'");
|
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("\"hello\"") == "^\"hello^\"");
|
2013-03-22 10:58:47 +01:00
|
|
|
#else /* _WIN32 */
|
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("'hello'") == "'hello'");
|
|
|
|
BOOST_CHECK(Utility::EscapeShellCmd("'hello") == "\\'hello");
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|