]>
git.saurik.com Git - wxWidgets.git/blob - tests/strings/vararg.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/vararg.cpp
3 // Purpose: Test for wx vararg look-alike macros
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
25 #include "wx/string.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class VarArgTestCase
: public CppUnit::TestCase
37 CPPUNIT_TEST_SUITE( VarArgTestCase
);
38 CPPUNIT_TEST( StringPrintf
);
40 CPPUNIT_TEST( StdString
);
42 CPPUNIT_TEST_SUITE_END();
49 DECLARE_NO_COPY_CLASS(VarArgTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( VarArgTestCase
);
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VarArgTestCase
, "VarArgTestCase" );
58 void VarArgTestCase::StringPrintf()
62 // test passing literals:
63 s
.Printf("%s %i", "foo", 42);
64 CPPUNIT_ASSERT( s
== "foo 42" );
65 s
.Printf("%s %s %i", _T("bar"), "=", 11);
67 // test passing c_str():
68 CPPUNIT_ASSERT( s
== "bar = 11" );
69 s2
.Printf("(%s)", s
.c_str());
70 CPPUNIT_ASSERT( s2
== "(bar = 11)" );
71 s2
.Printf(_T("[%s](%s)"), s
.c_str(), "str");
72 CPPUNIT_ASSERT( s2
== "[bar = 11](str)" );
74 // test passing wxString directly:
75 s2
.Printf(_T("[%s](%s)"), s
, "str");
76 CPPUNIT_ASSERT( s2
== "[bar = 11](str)" );
78 // test passing wxCharBufferType<T>:
80 s2
.Printf(_T("(%s)"), s
.mb_str());
81 CPPUNIT_ASSERT( s2
== "(FooBar)" );
82 s2
.Printf(_T("value=%s;"), s
.wc_str());
83 CPPUNIT_ASSERT( s2
== "value=FooBar;" );
85 // this tests correct passing of wxCStrData constructed from string
88 s2
.Printf(_T("foo %s"), !cond
? s
.c_str() : _T("bar"));
93 void VarArgTestCase::StdString()
95 // test passing std::[w]string
98 std::string
mb("multi-byte");
99 std::string
wc("widechar");
101 s
.Printf("string %s(%i).", mb
, 1);
102 CPPUNIT_ASSERT( s
== "string multi-byte(1)." );
104 s
.Printf("string %s(%i).", wc
, 2);
105 CPPUNIT_ASSERT( s
== "string widechar(2)." );
107 #endif // wxUSE_STD_STRING