]>
git.saurik.com Git - wxWidgets.git/blob - tests/streams/tempfile.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/streams/tempfile.cpp
3 // Purpose: Test wxTempFileOutputStream
4 // Author: Mike Wetherell
5 // Copyright: (c) 2005 Mike Wetherell
6 // Licence: wxWindows licence
7 ///////////////////////////////////////////////////////////////////////////////
15 // for all others, include the necessary headers
20 #include "wx/wfstream.h"
21 #include "wx/filename.h"
24 #if wxUSE_STREAMS && wxUSE_FILE
28 ///////////////////////////////////////////////////////////////////////////////
31 class tempStream
: public CppUnit::TestCase
33 CPPUNIT_TEST_SUITE(tempStream
);
34 CPPUNIT_TEST(DoNothing
);
37 CPPUNIT_TEST(Discard
);
38 CPPUNIT_TEST_SUITE_END();
40 void DoNothing() { DoTest(DONOTHING
, false); }
41 void Close() { DoTest(CLOSE
, true); }
42 void Commit() { DoTest(COMMIT
, true); }
43 void Discard() { DoTest(DISCARD
, false); }
45 enum Action
{ DONOTHING
, CLOSE
, COMMIT
, DISCARD
};
46 void DoTest(Action action
, bool shouldHaveCommited
);
49 // the common test code
51 void tempStream::DoTest(Action action
, bool shouldHaveCommited
)
56 wxTempFileOutputStream
out(temp
.GetName());
57 out
.Write("Affer", 5);
58 CPPUNIT_ASSERT(out
.SeekO(2) == 2);
60 CPPUNIT_ASSERT(out
.IsSeekable());
61 CPPUNIT_ASSERT(out
.GetLength() == 5);
62 CPPUNIT_ASSERT(out
.TellO() == 3);
65 case DONOTHING
: break;
66 case COMMIT
: out
.Commit(); break;
67 case DISCARD
: out
.Discard(); break;
68 case CLOSE
: out
.Close();
72 wxFileInputStream
in(temp
.GetName());
74 in
.Read(buf
, sizeof(buf
));
75 buf
[in
.LastRead()] = 0;
76 CPPUNIT_ASSERT(strcmp(buf
, shouldHaveCommited
? "After" : "Before") == 0);
80 // Register the stream sub suite, by using some stream helper macro.
81 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
82 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(tempStream
)
84 #endif // wxUSE_STREAMS && wxUSE_FILE