]>
Commit | Line | Data |
---|---|---|
1 | ////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: tests/strings/iostream.cpp | |
3 | // Purpose: unit test of wxString interaction with std::[io]stream | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2007-10-09 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 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 | #include "wx/string.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | #if wxUSE_STD_IOSTREAM | |
25 | ||
26 | #include <sstream> | |
27 | ||
28 | #define ASSERT_OSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::string(p), s.str()) | |
29 | #define ASSERT_WOSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::wstring(p), s.str()) | |
30 | ||
31 | // ---------------------------------------------------------------------------- | |
32 | // test class | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
35 | class StringIostreamTestCase : public CppUnit::TestCase | |
36 | { | |
37 | public: | |
38 | StringIostreamTestCase() { } | |
39 | ||
40 | private: | |
41 | CPPUNIT_TEST_SUITE( StringIostreamTestCase ); | |
42 | CPPUNIT_TEST( Out ); | |
43 | CPPUNIT_TEST_SUITE_END(); | |
44 | ||
45 | void Out(); | |
46 | }; | |
47 | ||
48 | CPPUNIT_TEST_SUITE_REGISTRATION( StringIostreamTestCase ); | |
49 | ||
50 | // also include in it's own registry so that these tests can be run alone | |
51 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringIostreamTestCase, "StringIostream" ); | |
52 | ||
53 | void StringIostreamTestCase::Out() | |
54 | { | |
55 | std::ostringstream s; | |
56 | s << wxString("hello"); | |
57 | ASSERT_OSTREAM_EQUAL("hello", s); | |
58 | ||
59 | #if wxUSE_UNICODE && defined(HAVE_WOSTREAM) | |
60 | std::wostringstream ws; | |
61 | ws << wxString("bye"); | |
62 | ASSERT_WOSTREAM_EQUAL(L"bye", ws); | |
63 | #endif | |
64 | } | |
65 | ||
66 | #endif // wxUSE_STD_IOSTREAM |