]>
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
6 // Copyright: (c) 2005 Mike Wetherell
7 // Licence: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
16 // for all others, include the necessary headers
21 #include "wx/wfstream.h"
22 #include "wx/filename.h"
25 #if wxUSE_STREAMS && wxUSE_FILE
29 ///////////////////////////////////////////////////////////////////////////////
32 class tempStream
: public CppUnit::TestCase
34 CPPUNIT_TEST_SUITE(tempStream
);
35 CPPUNIT_TEST(DoNothing
);
38 CPPUNIT_TEST(Discard
);
39 CPPUNIT_TEST_SUITE_END();
41 void DoNothing() { DoTest(DONOTHING
, false); }
42 void Close() { DoTest(CLOSE
, true); }
43 void Commit() { DoTest(COMMIT
, true); }
44 void Discard() { DoTest(DISCARD
, false); }
46 enum Action
{ DONOTHING
, CLOSE
, COMMIT
, DISCARD
};
47 void DoTest(Action action
, bool shouldHaveCommited
);
50 // the common test code
52 void tempStream::DoTest(Action action
, bool shouldHaveCommited
)
57 wxTempFileOutputStream
out(temp
.GetName());
58 out
.Write("Affer", 5);
59 CPPUNIT_ASSERT(out
.SeekO(2) == 2);
61 CPPUNIT_ASSERT(out
.IsSeekable());
62 CPPUNIT_ASSERT(out
.GetLength() == 5);
63 CPPUNIT_ASSERT(out
.TellO() == 3);
66 case DONOTHING
: break;
67 case COMMIT
: out
.Commit(); break;
68 case DISCARD
: out
.Discard(); break;
69 case CLOSE
: out
.Close();
73 wxFileInputStream
in(temp
.GetName());
75 in
.Read(buf
, sizeof(buf
));
76 buf
[in
.LastRead()] = 0;
77 CPPUNIT_ASSERT(strcmp(buf
, shouldHaveCommited
? "After" : "Before") == 0);
81 // Register the stream sub suite, by using some stream helper macro.
82 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
83 STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(tempStream
)
85 #endif // wxUSE_STREAMS && wxUSE_FILE