]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/cmdline/cmdlinetest.cpp
implement wxTreeCtrl::GetFocusedItem() for wxMSW too (see #10859)
[wxWidgets.git] / tests / cmdline / cmdlinetest.cpp
index 388166ffaf4377fc2a8346f71e8c7d6ca0887735..04e5c2ac8364192d2e064355eea1dfb77622584d 100644 (file)
@@ -55,12 +55,26 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CmdLineTestCase, "CmdLineTestCase" );
 
 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\"" )
@@ -74,12 +88,32 @@ void CmdLineTestCase::ConvertStringTestCase()
     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
 }
 
@@ -125,9 +159,9 @@ void CmdLineTestCase::Usage()
         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]);
 }