fix bugs introduced in wxCmdLineParser::ConvertStringToArgs() during Unicode transiti...
[wxWidgets.git] / tests / cmdline / cmdlinetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/cmdline/cmdlinetest.cpp
3 // Purpose: wxCmdLineParser unit test
4 // Author: Vadim Zeitlin
5 // Created: 2008-04-12
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #endif // WX_PRECOMP
22
23 #include "wx/cmdline.h"
24
25 // --------------------------------------------------------------------------
26 // test class
27 // --------------------------------------------------------------------------
28
29 class CmdLineTestCase : public CppUnit::TestCase
30 {
31 public:
32 CmdLineTestCase() {}
33
34 private:
35 CPPUNIT_TEST_SUITE( CmdLineTestCase );
36 CPPUNIT_TEST( ConvertStringTestCase );
37 CPPUNIT_TEST_SUITE_END();
38
39 void ConvertStringTestCase();
40
41 DECLARE_NO_COPY_CLASS(CmdLineTestCase)
42 };
43
44 // register in the unnamed registry so that these tests are run by default
45 CPPUNIT_TEST_SUITE_REGISTRATION( CmdLineTestCase );
46
47 // also include in it's own registry so that these tests can be run alone
48 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CmdLineTestCase, "CmdLineTestCase" );
49
50 // ============================================================================
51 // implementation
52 // ============================================================================
53
54 void CmdLineTestCase::ConvertStringTestCase()
55 {
56 #define WX_ASSERT_ARGS_EQUAL(s, args) \
57 { \
58 const wxArrayString a(wxCmdLineParser::ConvertStringToArgs(args));\
59 WX_ASSERT_STRARRAY_EQUAL(s, a); \
60 }
61
62 // normal cases
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\"" )
68
69 // special cases
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 \\" )
76
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\"" );
80
81 #undef WX_ASSERT_ARGS_EQUAL
82 }