]>
git.saurik.com Git - wxWidgets.git/blob - tests/file/filetest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/file/filetest.cpp
3 // Purpose: wxFile unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class FileTestCase
: public CppUnit::TestCase
36 CPPUNIT_TEST_SUITE( FileTestCase
);
37 CPPUNIT_TEST( RoundTripUTF8
);
38 CPPUNIT_TEST( RoundTripUTF16
);
39 CPPUNIT_TEST( RoundTripUTF32
);
40 CPPUNIT_TEST_SUITE_END();
42 void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8
); }
43 void RoundTripUTF16() { DoRoundTripTest(wxMBConvUTF16()); }
44 void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
46 void DoRoundTripTest(const wxMBConv
& conv
);
48 wxDECLARE_NO_COPY_CLASS(FileTestCase
);
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 CPPUNIT_TEST_SUITE_REGISTRATION( FileTestCase
);
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileTestCase
, "FileTestCase" );
58 // ----------------------------------------------------------------------------
59 // tests implementation
60 // ----------------------------------------------------------------------------
62 void FileTestCase::DoRoundTripTest(const wxMBConv
& conv
)
66 const wxString data
= "Hello\0UTF";
69 wxFile
fout(tf
.GetName(), wxFile::write
);
70 CPPUNIT_ASSERT( fout
.IsOpened() );
72 CPPUNIT_ASSERT( fout
.Write(data
, conv
) );
76 wxFile
fin(tf
.GetName(), wxFile::read
);
77 CPPUNIT_ASSERT( fin
.IsOpened() );
79 const ssize_t len
= fin
.Length();
80 wxCharBuffer
buf(len
);
81 CPPUNIT_ASSERT_EQUAL( len
, fin
.Read(buf
.data(), len
) );
83 wxWCharBuffer
wbuf(conv
.cMB2WC(buf
));
85 CPPUNIT_ASSERT_EQUAL( data
, wbuf
);
86 #else // !wxUSE_UNICODE
89 memcmp(wbuf
, L
"Hello\0UTF", data
.length()*sizeof(wchar_t)) == 0
91 #endif // wxUSE_UNICODE/!wxUSE_UNICODE