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