void CmdLineTestCase::ConvertStringTestCase()
{
- #define WX_ASSERT_ARGS_EQUAL(s, args) \
+ #define WX_ASSERT_DOS_ARGS_EQUAL(s, args) \
+ { \
+ const wxArrayString \
+ argsDOS(wxCmdLineParser::ConvertStringToArgs(args, \
+ wxCMD_LINE_SPLIT_DOS)); \
+ WX_ASSERT_STRARRAY_EQUAL(s, argsDOS); \
+ }
+
+ #define WX_ASSERT_UNIX_ARGS_EQUAL(s, args) \
{ \
- const wxArrayString a(wxCmdLineParser::ConvertStringToArgs(args));\
- WX_ASSERT_STRARRAY_EQUAL(s, a); \
+ const wxArrayString \
+ argsUnix(wxCmdLineParser::ConvertStringToArgs(args, \
+ wxCMD_LINE_SPLIT_UNIX)); \
+ WX_ASSERT_STRARRAY_EQUAL(s, argsUnix); \
}
+ #define WX_ASSERT_ARGS_EQUAL(s, args) \
+ WX_ASSERT_DOS_ARGS_EQUAL(s, args) \
+ WX_ASSERT_UNIX_ARGS_EQUAL(s, args)
+
// normal cases
WX_ASSERT_ARGS_EQUAL( "foo", "foo" )
WX_ASSERT_ARGS_EQUAL( "foo bar", "\"foo bar\"" )
WX_ASSERT_ARGS_EQUAL( "foo", "foo \t " )
WX_ASSERT_ARGS_EQUAL( "foo|bar", "foo bar " )
WX_ASSERT_ARGS_EQUAL( "foo|bar|", "foo bar \"" )
- WX_ASSERT_ARGS_EQUAL( "foo|bar|\\", "foo bar \\" )
+ WX_ASSERT_DOS_ARGS_EQUAL( "foo|bar|\\", "foo bar \\" )
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo|bar|", "foo bar \\" )
- // check for (broken) Windows semantics: backslash doesn't escape spaces
- WX_ASSERT_ARGS_EQUAL( "foo|bar\\|baz", "foo bar\\ baz" );
- WX_ASSERT_ARGS_EQUAL( "foo|bar\\\"baz", "foo \"bar\\\"baz\"" );
+ WX_ASSERT_ARGS_EQUAL( "12 34", "1\"2 3\"4" );
+ WX_ASSERT_ARGS_EQUAL( "1|2 34", "1 \"2 3\"4" );
+ WX_ASSERT_ARGS_EQUAL( "1|2 3|4", "1 \"2 3\" 4" );
+ // check for (broken) Windows semantics: backslash doesn't escape spaces
+ WX_ASSERT_DOS_ARGS_EQUAL( "\\\\foo\\\\|/bar", "\"\\\\foo\\\\\" /bar" );
+ WX_ASSERT_DOS_ARGS_EQUAL( "foo|bar\\|baz", "foo bar\\ baz" );
+ WX_ASSERT_DOS_ARGS_EQUAL( "foo|bar\\\"baz", "foo \"bar\\\"baz\"" );
+
+ // check for more sane Unix semantics: backslash does escape spaces and
+ // quotes
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo|bar baz", "foo bar\\ baz" );
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo|bar\"baz", "foo \"bar\\\"baz\"" );
+
+ // check that single quotes work too with Unix semantics
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo bar", "'foo bar'" )
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo|bar baz", "foo 'bar baz'" )
+ WX_ASSERT_UNIX_ARGS_EQUAL( "foo|bar baz", "foo 'bar baz'" )
+ WX_ASSERT_UNIX_ARGS_EQUAL( "O'Henry", "\"O'Henry\"" )
+ WX_ASSERT_UNIX_ARGS_EQUAL( "O'Henry", "O\\'Henry" )
+
+ #undef WX_ASSERT_DOS_ARGS_EQUAL
+ #undef WX_ASSERT_UNIX_ARGS_EQUAL
#undef WX_ASSERT_ARGS_EQUAL
}
Line_Max
};
- WX_ASSERT_SIZET_EQUAL( Line_Max, usageLines.size() );
- WX_ASSERT_STR_EQUAL("Verbosity options", usageLines[Line_Text_Verbosity]);
- WX_ASSERT_STR_EQUAL("", usageLines[Line_Text_Dummy1]);
- WX_ASSERT_STR_EQUAL("Even more usage text", usageLines[Line_Text_Dummy2]);
- WX_ASSERT_STR_EQUAL("", usageLines[Line_Last]);
+ CPPUNIT_ASSERT_EQUAL(Line_Max, usageLines.size());
+ CPPUNIT_ASSERT_EQUAL("Verbosity options", usageLines[Line_Text_Verbosity]);
+ CPPUNIT_ASSERT_EQUAL("", usageLines[Line_Text_Dummy1]);
+ CPPUNIT_ASSERT_EQUAL("Even more usage text", usageLines[Line_Text_Dummy2]);
+ CPPUNIT_ASSERT_EQUAL("", usageLines[Line_Last]);
}