iostreams.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/streams/iostreams.cpp
  3. // Purpose: unit test for input/output streams
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-06-15
  6. ///////////////////////////////////////////////////////////////////////////////
  7. // ----------------------------------------------------------------------------
  8. // headers
  9. // ----------------------------------------------------------------------------
  10. #include "testprec.h"
  11. #ifdef __BORLANDC__
  12. #pragma hdrstop
  13. #endif
  14. #if wxUSE_STREAMS
  15. #include "wx/filename.h"
  16. #include "wx/wfstream.h"
  17. // --------------------------------------------------------------------------
  18. // test class
  19. // --------------------------------------------------------------------------
  20. class IOStreamsTestCase : public CppUnit::TestCase
  21. {
  22. public:
  23. IOStreamsTestCase() { }
  24. virtual void tearDown()
  25. {
  26. if ( !m_fnTemp.empty() )
  27. {
  28. wxRemoveFile(m_fnTemp);
  29. m_fnTemp.clear();
  30. }
  31. }
  32. private:
  33. CPPUNIT_TEST_SUITE( IOStreamsTestCase );
  34. CPPUNIT_TEST( FStream );
  35. CPPUNIT_TEST( FFStream );
  36. CPPUNIT_TEST_SUITE_END();
  37. void FStream() { wxFileStream s(GetTempFName()); DoTest(s); }
  38. void FFStream() { wxFFileStream s(GetTempFName()); DoTest(s); }
  39. wxString GetTempFName()
  40. {
  41. m_fnTemp = wxFileName::CreateTempFileName("wxtest");
  42. return m_fnTemp;
  43. }
  44. template <class Stream>
  45. void DoTest(Stream& s)
  46. {
  47. s.PutC('x');
  48. CPPUNIT_ASSERT_EQUAL( 1, s.LastWrite() );
  49. s.SeekI(0);
  50. CPPUNIT_ASSERT_EQUAL( int('x'), s.GetC() );
  51. }
  52. wxString m_fnTemp;
  53. DECLARE_NO_COPY_CLASS(IOStreamsTestCase)
  54. };
  55. // register in the unnamed registry so that these tests are run by default
  56. CPPUNIT_TEST_SUITE_REGISTRATION( IOStreamsTestCase );
  57. // also include in its own registry so that these tests can be run alone
  58. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IOStreamsTestCase, "IOStreamsTestCase" );
  59. #endif // wxUSE_STREAMS