mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 14:39:53 +01:00
#2908 tests
This commit is contained in:
parent
888d8e6fb9
commit
76012717b0
@ -176,14 +176,14 @@ bool ProcessImpl::mustEscapeArg(const std::string& arg)
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
}
|
||||
return result && !inQuotes;
|
||||
return result || inQuotes;
|
||||
}
|
||||
|
||||
|
||||
// Based on code from https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
|
||||
std::string ProcessImpl::escapeArg(const std::string& arg)
|
||||
{
|
||||
if (mostEscapeArg(arg))
|
||||
if (mustEscapeArg(arg))
|
||||
{
|
||||
std::string quotedArg("\"");
|
||||
for (std::string::const_iterator it = arg.begin(); ; ++it)
|
||||
@ -214,10 +214,7 @@ std::string ProcessImpl::escapeArg(const std::string& arg)
|
||||
quotedArg.push_back('"');
|
||||
return quotedArg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
else return arg;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "Poco/PipeStream.h"
|
||||
|
||||
|
||||
using namespace std::string_literals;
|
||||
using Poco::Process;
|
||||
using Poco::ProcessHandle;
|
||||
using Poco::Pipe;
|
||||
@ -33,6 +34,24 @@ ProcessTest::~ProcessTest()
|
||||
}
|
||||
|
||||
|
||||
void ProcessTest::testEscapeArgs()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
assertTrue (Poco::ProcessImpl::mustEscapeArg("a b"));
|
||||
assertFalse (Poco::ProcessImpl::mustEscapeArg("abc"));
|
||||
assertFalse (Poco::ProcessImpl::mustEscapeArg("\"a b \""));
|
||||
assertFalse (Poco::ProcessImpl::mustEscapeArg("\"abc\""));
|
||||
assertTrue (Poco::ProcessImpl::mustEscapeArg("\"a b "));
|
||||
assertFalse (Poco::ProcessImpl::mustEscapeArg("/arg=\"a b c\""));
|
||||
|
||||
assertEquals ("abc"s, Poco::ProcessImpl::escapeArg("abc"));
|
||||
assertEquals ("\"a b c\""s, Poco::ProcessImpl::escapeArg("a b c"));
|
||||
assertEquals ("\"a b \\\" c\""s, Poco::ProcessImpl::escapeArg("a b \" c"));
|
||||
assertEquals ("/arg=\"a b c\""s, Poco::ProcessImpl::escapeArg("/arg=\"a b c\""));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void ProcessTest::testLaunch()
|
||||
{
|
||||
std::string name("TestApp");
|
||||
@ -253,6 +272,7 @@ CppUnit::Test* ProcessTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ProcessTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ProcessTest, testEscapeArgs);
|
||||
CppUnit_addTest(pSuite, ProcessTest, testLaunch);
|
||||
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectIn);
|
||||
CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectOut);
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
ProcessTest(const std::string& name);
|
||||
~ProcessTest();
|
||||
|
||||
void testEscapeArgs();
|
||||
void testLaunch();
|
||||
void testLaunchRedirectIn();
|
||||
void testLaunchRedirectOut();
|
||||
|
Loading…
x
Reference in New Issue
Block a user