]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/vararg.cpp
compilation fix after last commit: make wxAppConsole a class, not typedef, under...
[wxWidgets.git] / tests / strings / vararg.cpp
CommitLineData
c9f78968
VS
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/strings/vararg.cpp
3// Purpose: Test for wx vararg look-alike macros
4// Author: Vaclav Slavik
5// Created: 2007-02-20
6// RCS-ID: $Id$
7// Copyright: (c) 2007 REA Elektronik GmbH
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ----------------------------------------------------------------------------
12// headers
13// ----------------------------------------------------------------------------
14
15#include "testprec.h"
16
17#ifdef __BORLANDC__
18 #pragma hdrstop
19#endif
20
21#ifndef WX_PRECOMP
22 #include "wx/wx.h"
23#endif // WX_PRECOMP
24
25#include "wx/string.h"
26
27// ----------------------------------------------------------------------------
28// test class
29// ----------------------------------------------------------------------------
30
31class VarArgTestCase : public CppUnit::TestCase
32{
33public:
34 VarArgTestCase() {}
35
36private:
37 CPPUNIT_TEST_SUITE( VarArgTestCase );
38 CPPUNIT_TEST( StringPrintf );
76fc401a
VS
39#if wxUSE_STD_STRING
40 CPPUNIT_TEST( StdString );
41#endif
c9f78968
VS
42 CPPUNIT_TEST_SUITE_END();
43
44 void StringPrintf();
76fc401a
VS
45#if wxUSE_STD_STRING
46 void StdString();
47#endif
c9f78968
VS
48
49 DECLARE_NO_COPY_CLASS(VarArgTestCase)
50};
51
52// register in the unnamed registry so that these tests are run by default
53CPPUNIT_TEST_SUITE_REGISTRATION( VarArgTestCase );
54
55// also include in it's own registry so that these tests can be run alone
56CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VarArgTestCase, "VarArgTestCase" );
57
58void VarArgTestCase::StringPrintf()
59{
60 wxString s, s2;
61
359bd4d1 62 // test passing literals:
c9f78968
VS
63 s.Printf("%s %i", "foo", 42);
64 CPPUNIT_ASSERT( s == "foo 42" );
65 s.Printf("%s %s %i", _T("bar"), "=", 11);
359bd4d1
VS
66
67 // test passing c_str():
c9f78968
VS
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)" );
73
0dc8d224
VS
74 s2.Printf("%s mailbox", wxString("Opening").c_str());
75 CPPUNIT_ASSERT( s2 == "Opening mailbox" );
76
359bd4d1 77 // test passing wxString directly:
c9f78968
VS
78 s2.Printf(_T("[%s](%s)"), s, "str");
79 CPPUNIT_ASSERT( s2 == "[bar = 11](str)" );
359bd4d1
VS
80
81 // test passing wxCharBufferType<T>:
82 s = "FooBar";
83 s2.Printf(_T("(%s)"), s.mb_str());
84 CPPUNIT_ASSERT( s2 == "(FooBar)" );
85 s2.Printf(_T("value=%s;"), s.wc_str());
86 CPPUNIT_ASSERT( s2 == "value=FooBar;" );
baf3d1dc
VS
87
88 // this tests correct passing of wxCStrData constructed from string
89 // literal:
90 bool cond = true;
91 s2.Printf(_T("foo %s"), !cond ? s.c_str() : _T("bar"));
76fc401a
VS
92
93}
94
95#if wxUSE_STD_STRING
96void VarArgTestCase::StdString()
97{
98 // test passing std::[w]string
99 wxString s;
100
101 std::string mb("multi-byte");
102 std::string wc("widechar");
103
104 s.Printf("string %s(%i).", mb, 1);
105 CPPUNIT_ASSERT( s == "string multi-byte(1)." );
106
107 s.Printf("string %s(%i).", wc, 2);
108 CPPUNIT_ASSERT( s == "string widechar(2)." );
c9f78968 109}
76fc401a 110#endif // wxUSE_STD_STRING