class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
{
public:
- wxFFileOutputStream(const wxString& fileName, const wxString& mode = "w+b");
+ wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
wxFFileOutputStream(wxFFile& file);
wxFFileOutputStream(FILE *file);
virtual ~wxFFileOutputStream();
public wxFFileOutputStream
{
public:
- wxFFileStream(const wxString& fileName);
+ wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
virtual bool IsOk() const;
private:
Initializes a file stream in write-only mode using the file descriptor @e fp.
*/
wxFFileOutputStream(const wxString& filename,
- const wxString& mode = "w+b");
+ const wxString& mode = "wb");
wxFFileOutputStream(wxFFile& file);
wxFFileOutputStream(FILE* fp);
//@}
Initializes a new file stream in read-write mode using the specified
@e iofilename name.
*/
- wxFFileStream(const wxString& iofileName);
+ wxFFileStream(const wxString& iofileName, const wxString& mode = "w+b");
};
// ----------------------------------------------------------------------------
wxFileStream::wxFileStream(const wxString& fileName)
- : wxFileInputStream(fileName)
+ : wxFileInputStream(),
+ wxFileOutputStream()
{
- wxFileOutputStream::m_file = wxFileInputStream::m_file;
+ wxFileOutputStream::m_file =
+ wxFileInputStream::m_file = new wxFile(fileName, wxFile::read_write);
+
+ // this is a bit ugly as streams are symmetric but we still have to delete
+ // the file we created above exactly once so we decide to (arbitrarily) do
+ // it in wxFileInputStream
+ wxFileInputStream::m_file_destroy = true;
}
bool wxFileStream::IsOk() const
// wxFFileStream
// ----------------------------------------------------------------------------
-wxFFileStream::wxFFileStream(const wxString& fileName)
- : wxFFileInputStream(fileName)
+wxFFileStream::wxFFileStream(const wxString& fileName, const wxString& mode)
+ : wxFFileInputStream(),
+ wxFFileOutputStream()
{
- wxFFileOutputStream::m_file = wxFFileInputStream::m_file;
+ wxASSERT_MSG( mode.find_first_of('+') != wxString::npos,
+ "must be opened in read-write mode for this class to work" );
+
+ wxFFileOutputStream::m_file =
+ wxFFileInputStream::m_file = new wxFFile(fileName, mode);
+
+ // see comment in wxFileStream ctor
+ wxFFileInputStream::m_file_destroy = true;
}
bool wxFFileStream::IsOk() const
test_ffilestream.o \
test_fileback.o \
test_filestream.o \
+ test_iostream.o \
test_largefile.o \
test_memstream.o \
test_sstream.o \
test_scopeguardtest.o: $(srcdir)/scopeguard/scopeguardtest.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/scopeguard/scopeguardtest.cpp
-test_iostream.o: $(srcdir)/strings/iostream.cpp $(TEST_ODEP)
- $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/iostream.cpp
-
test_strings.o: $(srcdir)/strings/strings.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/strings.cpp
test_xmltest.o: $(srcdir)/xml/xmltest.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/xml/xmltest.cpp
+test_iostream.o: $(srcdir)/strings/iostream.cpp $(TEST_ODEP)
+ $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/strings/iostream.cpp
+
+test_iostream.o: $(srcdir)/streams/iostream.cpp $(TEST_ODEP)
+ $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/iostream.cpp
+
test_gui_sample_rc.o: $(srcdir)/../samples/sample.rc $(TEST_GUI_ODEP)
$(WINDRES) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_5) $(__EXCEPTIONS_DEFINE_p_5) $(__RTTI_DEFINE_p_5) $(__THREAD_DEFINE_p_5) --include-dir $(srcdir) $(__DLLFLAG_p_5) --include-dir $(srcdir)/../samples $(__RCDEFDIR_p_1) --include-dir $(top_srcdir)/include
$(CXXC) -c -o $@ $(PRINTFBENCH_CXXFLAGS) $(srcdir)/benchmarks/printfbench.cpp
+$(srcdir)/include/wx/stc/stc.h: \
+$(srcdir)/src/stc/scintilla/include/Scintilla.iface \
+$(srcdir)/src/stc/stc.cpp.in \
+$(srcdir)/src/stc/stc.h.in \
+$(srcdir)/src/stc/gen_iface.py
+ cd $(srcdir)/src/stc && ./gen_iface.py
+monolib_stc.o monodll_stc.o stcdll_stc.o stclib_stc.o: \
+$(srcdir)/include/wx/stc/stc.h
+
# Include dependency info, if present:
@IF_GNU_MAKE@-include .deps/*.d
$(OBJS)\test_ffilestream.obj \
$(OBJS)\test_fileback.obj \
$(OBJS)\test_filestream.obj \
+ $(OBJS)\test_iostream.obj \
$(OBJS)\test_largefile.obj \
$(OBJS)\test_memstream.obj \
$(OBJS)\test_sstream.obj \
$(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\scopeguard\scopeguardtest.cpp
-$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
- $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
-
$(OBJS)\test_strings.obj: .\strings\strings.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\strings.cpp
$(OBJS)\test_xmltest.obj: .\xml\xmltest.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\xml\xmltest.cpp
+$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
+
+$(OBJS)\test_iostream.obj: .\streams\iostream.cpp
+ $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\iostream.cpp
+
$(OBJS)\test_gui_sample.res: .\..\samples\sample.rc
brcc32 -32 -r -fo$@ -i$(BCCDIR)\include -d__WXMSW__ $(__WXUNIV_DEFINE_p_3) $(__DEBUG_DEFINE_p_3) $(__EXCEPTIONS_DEFINE_p_3) $(__RTTI_DEFINE_p_3) $(__THREAD_DEFINE_p_3) $(__UNICODE_DEFINE_p_3) $(__MSLU_DEFINE_p_3) $(__GFXCTX_DEFINE_p_3) -i$(SETUPHDIR) -i.\..\include -i. $(__DLLFLAG_p_3) -i.\..\samples -dNOPCH .\..\samples\sample.rc
$(OBJS)\test_ffilestream.o \
$(OBJS)\test_fileback.o \
$(OBJS)\test_filestream.o \
+ $(OBJS)\test_iostream.o \
$(OBJS)\test_largefile.o \
$(OBJS)\test_memstream.o \
$(OBJS)\test_sstream.o \
$(OBJS)\test_scopeguardtest.o: ./scopeguard/scopeguardtest.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
-$(OBJS)\test_iostream.o: ./strings/iostream.cpp
- $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
-
$(OBJS)\test_strings.o: ./strings/strings.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_xmltest.o: ./xml/xmltest.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+$(OBJS)\test_iostream.o: ./strings/iostream.cpp
+ $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
+$(OBJS)\test_iostream.o: ./streams/iostream.cpp
+ $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
$(OBJS)\test_gui_sample_rc.o: ./../samples/sample.rc
windres --use-temp-file -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_3) $(__DEBUG_DEFINE_p_3) $(__EXCEPTIONS_DEFINE_p_3) $(__RTTI_DEFINE_p_3) $(__THREAD_DEFINE_p_3) $(__UNICODE_DEFINE_p_3) $(__MSLU_DEFINE_p_3) $(__GFXCTX_DEFINE_p_3) --include-dir $(SETUPHDIR) --include-dir ./../include --include-dir . $(__DLLFLAG_p_3) --include-dir ./../samples --define NOPCH
$(OBJS)\test_ffilestream.obj \
$(OBJS)\test_fileback.obj \
$(OBJS)\test_filestream.obj \
+ $(OBJS)\test_iostream.obj \
$(OBJS)\test_largefile.obj \
$(OBJS)\test_memstream.obj \
$(OBJS)\test_sstream.obj \
$(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\scopeguard\scopeguardtest.cpp
-$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
- $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
-
$(OBJS)\test_strings.obj: .\strings\strings.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\strings.cpp
$(OBJS)\test_xmltest.obj: .\xml\xmltest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\xml\xmltest.cpp
+$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
+
+$(OBJS)\test_iostream.obj: .\streams\iostream.cpp
+ $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\iostream.cpp
+
$(OBJS)\test_gui_dummy.obj: .\dummy.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) /Yctestprec.h .\dummy.cpp
$(OBJS)\test_ffilestream.obj &
$(OBJS)\test_fileback.obj &
$(OBJS)\test_filestream.obj &
+ $(OBJS)\test_iostream.obj &
$(OBJS)\test_largefile.obj &
$(OBJS)\test_memstream.obj &
$(OBJS)\test_sstream.obj &
$(OBJS)\test_scopeguardtest.obj : .AUTODEPEND .\scopeguard\scopeguardtest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
-$(OBJS)\test_iostream.obj : .AUTODEPEND .\strings\iostream.cpp
- $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
-
$(OBJS)\test_strings.obj : .AUTODEPEND .\strings\strings.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
$(OBJS)\test_xmltest.obj : .AUTODEPEND .\xml\xmltest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+$(OBJS)\test_iostream.obj : .AUTODEPEND .\strings\iostream.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
+$(OBJS)\test_iostream.obj : .AUTODEPEND .\streams\iostream.cpp
+ $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
$(OBJS)\test_gui_sample.res : .AUTODEPEND .\..\samples\sample.rc
wrc -q -ad -bt=nt -r -fo=$^@ -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) $(__GFXCTX_DEFINE_p) -i=$(SETUPHDIR) -i=.\..\include -i=. $(__DLLFLAG_p) -i=.\..\samples -dNOPCH $<
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/streams/iostreams.cpp
+// Purpose: unit test for input/output streams
+// Author: Vadim Zeitlin
+// Created: 2008-06-15
+// RCS-ID: $Id$
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#if wxUSE_STREAMS
+
+#include "wx/filename.h"
+#include "wx/wfstream.h"
+
+// --------------------------------------------------------------------------
+// test class
+// --------------------------------------------------------------------------
+
+class IOStreamsTestCase : public CppUnit::TestCase
+{
+public:
+ IOStreamsTestCase() { }
+
+ virtual void tearDown()
+ {
+ if ( !m_fnTemp.empty() )
+ {
+ wxRemoveFile(m_fnTemp);
+ m_fnTemp.clear();
+ }
+ }
+
+private:
+ CPPUNIT_TEST_SUITE( IOStreamsTestCase );
+ CPPUNIT_TEST( FStream );
+ CPPUNIT_TEST( FFStream );
+ CPPUNIT_TEST_SUITE_END();
+
+ void FStream() { wxFileStream s(GetTempFName()); DoTest(s); }
+ void FFStream() { wxFFileStream s(GetTempFName()); DoTest(s); }
+
+ wxString GetTempFName()
+ {
+ m_fnTemp = wxFileName::CreateTempFileName("wxtest");
+ return m_fnTemp;
+ }
+
+ template <class Stream>
+ void DoTest(Stream& s)
+ {
+ s.PutC('x');
+ WX_ASSERT_SIZET_EQUAL( 1, s.LastWrite() );
+
+ s.SeekI(0);
+ CPPUNIT_ASSERT_EQUAL( int('x'), s.GetC() );
+ }
+
+ wxString m_fnTemp;
+
+ DECLARE_NO_COPY_CLASS(IOStreamsTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( IOStreamsTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IOStreamsTestCase, "IOStreamsTestCase" );
+
+#endif // wxUSE_STREAMS
streams/ffilestream.cpp
streams/fileback.cpp
streams/filestream.cpp
+ streams/iostreams.cpp
streams/largefile.cpp
streams/memstream.cpp
streams/sstream.cpp
# End Source File\r
# Begin Source File\r
\r
+SOURCE=.\streams\iostream.cpp\r
+# End Source File\r
+# Begin Source File\r
+\r
SOURCE=.\streams\largefile.cpp\r
# End Source File\r
# Begin Source File\r
RelativePath=".\intl\intltest.cpp"/>\r
<File\r
RelativePath=".\strings\iostream.cpp"/>\r
+ <File\r
+ RelativePath=".\streams\iostream.cpp"/>\r
<File\r
RelativePath=".\streams\largefile.cpp"/>\r
<File\r
<File\r
RelativePath=".\strings\iostream.cpp"\r
/>\r
+ <File\r
+ RelativePath=".\streams\iostream.cpp"\r
+ />\r
<File\r
RelativePath=".\streams\largefile.cpp"\r
/>\r