iostream.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
  7. ///////////////////////////////////////////////////////////////////////////////
  8. // ----------------------------------------------------------------------------
  9. // headers
  10. // ----------------------------------------------------------------------------
  11. #include "testprec.h"
  12. #ifdef __BORLANDC__
  13. #pragma hdrstop
  14. #endif
  15. #ifndef WX_PRECOMP
  16. #include "wx/string.h"
  17. #endif // WX_PRECOMP
  18. #if wxUSE_STD_IOSTREAM
  19. #include <sstream>
  20. #define ASSERT_OSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::string(p), s.str())
  21. #define ASSERT_WOSTREAM_EQUAL(p, s) CPPUNIT_ASSERT_EQUAL(std::wstring(p), s.str())
  22. // ----------------------------------------------------------------------------
  23. // test class
  24. // ----------------------------------------------------------------------------
  25. class StringIostreamTestCase : public CppUnit::TestCase
  26. {
  27. public:
  28. StringIostreamTestCase() { }
  29. private:
  30. CPPUNIT_TEST_SUITE( StringIostreamTestCase );
  31. CPPUNIT_TEST( Out );
  32. CPPUNIT_TEST_SUITE_END();
  33. void Out();
  34. };
  35. CPPUNIT_TEST_SUITE_REGISTRATION( StringIostreamTestCase );
  36. // also include in its own registry so that these tests can be run alone
  37. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringIostreamTestCase, "StringIostream" );
  38. void StringIostreamTestCase::Out()
  39. {
  40. std::ostringstream s;
  41. s << wxString("hello");
  42. ASSERT_OSTREAM_EQUAL("hello", s);
  43. #if wxUSE_UNICODE && defined(HAVE_WOSTREAM)
  44. std::wostringstream ws;
  45. ws << wxString("bye");
  46. ASSERT_WOSTREAM_EQUAL(L"bye", ws);
  47. #endif
  48. }
  49. #endif // wxUSE_STD_IOSTREAM