if ( !buf )
return false;
- const size_t size = strlen(buf); // FIXME: use buf.length() when available
+ const size_t size = buf.length();
return Write(buf, size) == size;
}
test_evthandler.o \
test_timertest.o \
test_exec.o \
+ test_filetest.o \
test_filekind.o \
test_filenametest.o \
test_filesystest.o \
test_exec.o: $(srcdir)/exec/exec.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/exec/exec.cpp
+test_filetest.o: $(srcdir)/file/filetest.cpp $(TEST_ODEP)
+ $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/file/filetest.cpp
+
test_filekind.o: $(srcdir)/filekind/filekind.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/filekind/filekind.cpp
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/file/filetest.cpp
+// Purpose: wxFile unit test
+// Author: Vadim Zeitlin
+// Created: 2009-09-12
+// RCS-ID: $Id$
+// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#if wxUSE_FILE
+
+#include "wx/file.h"
+
+#include "testfile.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class FileTestCase : public CppUnit::TestCase
+{
+public:
+ FileTestCase() { }
+
+private:
+ CPPUNIT_TEST_SUITE( FileTestCase );
+ CPPUNIT_TEST( RoundTripUTF8 );
+ CPPUNIT_TEST( RoundTripUTF16 );
+ CPPUNIT_TEST( RoundTripUTF32 );
+ CPPUNIT_TEST_SUITE_END();
+
+ void RoundTripUTF8() { DoRoundTripTest(wxConvUTF8); }
+ void RoundTripUTF16() { DoRoundTripTest(wxMBConvUTF16()); }
+ void RoundTripUTF32() { DoRoundTripTest(wxMBConvUTF32()); }
+
+ void DoRoundTripTest(const wxMBConv& conv);
+
+ wxDECLARE_NO_COPY_CLASS(FileTestCase);
+};
+
+// ----------------------------------------------------------------------------
+// CppUnit macros
+// ----------------------------------------------------------------------------
+
+CPPUNIT_TEST_SUITE_REGISTRATION( FileTestCase );
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileTestCase, "FileTestCase" );
+
+// ----------------------------------------------------------------------------
+// tests implementation
+// ----------------------------------------------------------------------------
+
+void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
+{
+ TestFile tf;
+
+ const wxString data = "Hello\0UTF";
+
+ {
+ wxFile fout(tf.GetName(), wxFile::write);
+ CPPUNIT_ASSERT( fout.IsOpened() );
+
+ CPPUNIT_ASSERT( fout.Write(data, conv) );
+ }
+
+ {
+ wxFile fin(tf.GetName(), wxFile::read);
+ CPPUNIT_ASSERT( fin.IsOpened() );
+
+ const wxFileOffset len = fin.Length();
+ wxCharBuffer buf(len);
+ CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );
+
+ wxWCharBuffer wbuf(conv.cMB2WC(buf));
+#if wxUSE_UNICODE
+ CPPUNIT_ASSERT_EQUAL( data, wbuf );
+#else // !wxUSE_UNICODE
+ CPPUNIT_ASSERT
+ (
+ memcmp(wbuf, L"Hello\0UTF", data.length()*sizeof(wchar_t)) == 0
+ );
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+ }
+}
+
+#endif // wxUSE_FILE
$(OBJS)\test_evthandler.obj \
$(OBJS)\test_timertest.obj \
$(OBJS)\test_exec.obj \
+ $(OBJS)\test_filetest.obj \
$(OBJS)\test_filekind.obj \
$(OBJS)\test_filenametest.obj \
$(OBJS)\test_filesystest.obj \
$(OBJS)\test_exec.obj: .\exec\exec.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\exec\exec.cpp
+$(OBJS)\test_filetest.obj: .\file\filetest.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\file\filetest.cpp
+
$(OBJS)\test_filekind.obj: .\filekind\filekind.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\filekind\filekind.cpp
$(OBJS)\test_evthandler.o \
$(OBJS)\test_timertest.o \
$(OBJS)\test_exec.o \
+ $(OBJS)\test_filetest.o \
$(OBJS)\test_filekind.o \
$(OBJS)\test_filenametest.o \
$(OBJS)\test_filesystest.o \
$(OBJS)\test_exec.o: ./exec/exec.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_filetest.o: ./file/filetest.cpp
+ $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\test_filekind.o: ./filekind/filekind.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_evthandler.obj \
$(OBJS)\test_timertest.obj \
$(OBJS)\test_exec.obj \
+ $(OBJS)\test_filetest.obj \
$(OBJS)\test_filekind.obj \
$(OBJS)\test_filenametest.obj \
$(OBJS)\test_filesystest.obj \
$(OBJS)\test_exec.obj: .\exec\exec.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\exec\exec.cpp
+$(OBJS)\test_filetest.obj: .\file\filetest.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\file\filetest.cpp
+
$(OBJS)\test_filekind.obj: .\filekind\filekind.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\filekind\filekind.cpp
$(OBJS)\test_evthandler.obj &
$(OBJS)\test_timertest.obj &
$(OBJS)\test_exec.obj &
+ $(OBJS)\test_filetest.obj &
$(OBJS)\test_filekind.obj &
$(OBJS)\test_filenametest.obj &
$(OBJS)\test_filesystest.obj &
$(OBJS)\test_exec.obj : .AUTODEPEND .\exec\exec.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+$(OBJS)\test_filetest.obj : .AUTODEPEND .\file\filetest.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
$(OBJS)\test_filekind.obj : .AUTODEPEND .\filekind\filekind.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
events/evthandler.cpp
events/timertest.cpp
exec/exec.cpp
+ file/filetest.cpp
filekind/filekind.cpp
filename/filenametest.cpp
filesys/filesystest.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\file\filetest.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\fontmap\fontmaptest.cpp\r
# End Source File\r
# Begin Source File\r
<File\r
RelativePath=".\filesys\filesystest.cpp">\r
</File>\r
+ <File\r
+ RelativePath=".\file\filetest.cpp">\r
+ </File>\r
<File\r
RelativePath=".\fontmap\fontmaptest.cpp">\r
</File>\r
RelativePath=".\filesys\filesystest.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\file\filetest.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\fontmap\fontmaptest.cpp"\r
>\r
RelativePath=".\filesys\filesystest.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\file\filetest.cpp"\r
+ >\r
+ </File>\r
<File\r
RelativePath=".\fontmap\fontmaptest.cpp"\r
>\r