]>
git.saurik.com Git - wxWidgets.git/blob - tests/cmdline/cmdlinetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/cmdline/cmdlinetest.cpp
3 // Purpose: wxCmdLineParser unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
23 #include "wx/cmdline.h"
25 // --------------------------------------------------------------------------
27 // --------------------------------------------------------------------------
29 class CmdLineTestCase
: public CppUnit::TestCase
35 CPPUNIT_TEST_SUITE( CmdLineTestCase
);
36 CPPUNIT_TEST( ConvertStringTestCase
);
37 CPPUNIT_TEST_SUITE_END();
39 void ConvertStringTestCase();
41 DECLARE_NO_COPY_CLASS(CmdLineTestCase
)
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( CmdLineTestCase
);
47 // also include in it's own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CmdLineTestCase
, "CmdLineTestCase" );
50 // ============================================================================
52 // ============================================================================
54 void CmdLineTestCase::ConvertStringTestCase()
56 #define WX_ASSERT_ARGS_EQUAL(s, args) \
58 const wxArrayString a(wxCmdLineParser::ConvertStringToArgs(args));\
59 WX_ASSERT_STRARRAY_EQUAL(s, a); \
63 WX_ASSERT_ARGS_EQUAL( "foo", "foo" )
64 WX_ASSERT_ARGS_EQUAL( "foo bar", "\"foo bar\"" )
65 WX_ASSERT_ARGS_EQUAL( "foo|bar", "foo bar" )
66 WX_ASSERT_ARGS_EQUAL( "foo|bar|baz", "foo bar baz" )
67 WX_ASSERT_ARGS_EQUAL( "foo|bar baz", "foo \"bar baz\"" )
70 WX_ASSERT_ARGS_EQUAL( "", "" )
71 WX_ASSERT_ARGS_EQUAL( "foo", "foo " )
72 WX_ASSERT_ARGS_EQUAL( "foo", "foo \t " )
73 WX_ASSERT_ARGS_EQUAL( "foo|bar", "foo bar " )
74 WX_ASSERT_ARGS_EQUAL( "foo|bar|", "foo bar \"" )
75 WX_ASSERT_ARGS_EQUAL( "foo|bar|\\", "foo bar \\" )
77 // check for (broken) Windows semantics: backslash doesn't escape spaces
78 WX_ASSERT_ARGS_EQUAL( "foo|bar\\|baz", "foo bar\\ baz" );
79 WX_ASSERT_ARGS_EQUAL( "foo|bar\\\"baz", "foo \"bar\\\"baz\"" );
81 #undef WX_ASSERT_ARGS_EQUAL