]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxTempFileOutputStream
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Sun, 13 Mar 2005 16:20:51 +0000 (16:20 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Sun, 13 Mar 2005 16:20:51 +0000 (16:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32796 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
docs/latex/wx/category.tex
docs/latex/wx/classes.tex
docs/latex/wx/tempfile.tex
docs/latex/wx/tempfilestrm.tex [new file with mode: 0644]
include/wx/file.h
include/wx/wfstream.h
src/common/wfstream.cpp
tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/streams/bstream.cpp
tests/streams/tempfile.cpp [new file with mode: 0644]
tests/test.bkl
tests/test_test.dsp

index 0160e814465e0c89ea913401d5db47fa2c00c1fb..367f939a6f66291d32c9654a3be5d5602ef142dc 100644 (file)
@@ -493,6 +493,7 @@ libraries, and to provide enhanced functionality.
 \twocolitem{\helpref{wxFileOutputStream}{wxfileoutputstream}}{File output stream class}
 \twocolitem{\helpref{wxFFileInputStream}{wxffileinputstream}}{Another file input stream class}
 \twocolitem{\helpref{wxFFileOutputStream}{wxffileoutputstream}}{Another file output stream class}
+\twocolitem{\helpref{wxTempFileOutputStream}{wxtempfileoutputstream}}{Stream to safely replace an existing file}
 \twocolitem{\helpref{wxStringInputStream}{wxstringinputstream}}{String input stream class}
 \twocolitem{\helpref{wxStringOutputStream}{wxstringoutputstream}}{String output stream class}
 \twocolitem{\helpref{wxZlibInputStream}{wxzlibinputstream}}{Zlib (compression) input stream class}
index 4987765079f935f50279fd7cd90b819cba4ee175..10b9d36ec92e146267a53836b629fc77a73c8757 100644 (file)
 \input tcpconn.tex
 \input tcpservr.tex
 \input tempfile.tex
+\input tempfilestrm.tex
 \input text.tex
 \input txtdatob.tex
 \input txtdrptg.tex
index 06a03a0d1e60f62571fa5fbfd77e4c4d2ccbd1ae..e7c0c98f681a8aa142f55293de1fb18af67bdac0 100644 (file)
@@ -43,7 +43,8 @@ No base class
 
 \wxheading{See also:}
 
-\helpref{wxFile}{wxfile}
+\helpref{wxFile}{wxfile}\\
+\helpref{wxTempFileOutputStream}{wxtempfileoutputstream}
 
 \latexignore{\rtfignore{\wxheading{Members}}}
 
@@ -79,6 +80,25 @@ and the program should have write access to it for the function to succeed.
 
 Returns {\tt true} if the file was successfully opened.
 
+\membersection{wxTempFile::Length}\label{wxtempfilelength}
+
+\constfunc{wxFileOffset}{Length}{\void}
+
+Returns the length of the file.
+
+\membersection{wxTempFile::Seek}\label{wxtempfileseek}
+
+\func{wxFileOffset}{Seek}{\param{wxFileOffset }{ofs}, \param{wxSeekMode }{mode = wxFromStart}}
+
+Seeks to the specified position.
+
+\membersection{wxTempFile::Tell}\label{wxtempfiletell}
+
+\constfunc{wxFileOffset}{Tell}{\void}
+
+Returns the current position or wxInvalidOffset if file is not opened or if another
+error occurred.
+
 \membersection{wxTempFile::Write}\label{wxtempfilewrite}
 
 \func{bool}{Write}{\param{const void }{*p}, \param{size\_t }{n}}
diff --git a/docs/latex/wx/tempfilestrm.tex b/docs/latex/wx/tempfilestrm.tex
new file mode 100644 (file)
index 0000000..01fe896
--- /dev/null
@@ -0,0 +1,55 @@
+%
+% automatically generated by HelpGen $Revision$ from
+% wx/wfstream.h at 07/Mar/05 20:45:33
+%
+
+\section{\class{wxTempFileOutputStream}}\label{wxtempfileoutputstream}
+
+wxTempFileOutputStream is an output stream based on \helpref{wxTempFile}{wxtempfile}. It
+provides a relatively safe way to replace the contents of the
+existing file.
+
+\wxheading{Derived from}
+
+\helpref{wxOutputStream}{wxoutputstream}
+
+\wxheading{Include files}
+
+<wx/wfstream.h>
+
+\wxheading{See also}
+
+\helpref{wxTempFile}{wxtempfile}
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+
+\membersection{wxTempFileOutputStream::wxTempFileOutputStream}\label{wxtempfileoutputstreamwxtempfileoutputstream}
+
+\func{}{wxTempFileOutputStream}{\param{const wxString\& }{fileName}}
+
+Associates wxTempFileOutputStream with the file to be replaced and opens it. You should use 
+\helpref{IsOk}{wxstreambaseisok} to verify if the constructor succeeded.
+
+Call \helpref{Commit()}{wxtempfileoutputstreamcommit} or \helpref{Close()}{wxoutputstreamclose} to
+replace the old file and close this one. Calling \helpref{Discard()}{wxtempfileoutputstreamdiscard} 
+(or allowing the destructor to do it) will discard the changes.
+
+
+\membersection{wxTempFileOutputStream::Commit}\label{wxtempfileoutputstreamcommit}
+
+\func{bool}{Commit}{\void}
+
+Validate changes: deletes the old file of the given name and renames the new
+file to the old name. Returns {\tt true} if both actions succeeded. If {\tt false} is
+returned it may unfortunately mean two quite different things: either that
+either the old file couldn't be deleted or that the new file couldn't be renamed
+to the old name.
+
+
+\membersection{wxTempFileOutputStream::Discard}\label{wxtempfileoutputstreamdiscard}
+
+\func{void}{Discard}{\void}
+
+Discard changes: the old file contents are not changed, the temporary file is
+deleted.
index 3382610c571f261dbf943c2b5391d91174bd9bf5..abb427af66df28d34f2089ef8df6a1d8248f1725 100644 (file)
@@ -164,6 +164,13 @@ public:
 
   // is the file opened?
   bool IsOpened() const { return m_file.IsOpened(); }
+    // get current file length
+  wxFileOffset Length() const { return m_file.Length(); }
+    // move ptr ofs bytes related to start/current offset/end of file
+  wxFileOffset Seek(wxFileOffset ofs, wxSeekMode mode = wxFromStart)
+    { return m_file.Seek(ofs, mode); }
+    // get current offset
+  wxFileOffset Tell() const { return m_file.Tell(); }
 
   // I/O (both functions return true on success, false on failure)
   bool Write(const void *p, size_t n) { return m_file.Write(p, n) == n; }
index d0d50a608cc129c12dfc3d5cfa1b8f50d6ba1a43..79cdb866cf04a391a24b824d61501daefb6bfc39 100644 (file)
@@ -88,6 +88,31 @@ protected:
     DECLARE_NO_COPY_CLASS(wxFileOutputStream)
 };
 
+class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
+{
+public:
+    wxTempFileOutputStream(const wxString& fileName);
+    virtual ~wxTempFileOutputStream();
+
+    bool Close() { return Commit(); }
+    virtual bool Commit() { return m_file->Commit(); }
+    virtual void Discard() { m_file->Discard(); }
+
+    wxFileOffset GetLength() const { return m_file->Length(); }
+    bool IsSeekable() const { return true; }
+
+protected:
+    size_t OnSysWrite(const void *buffer, size_t size);
+    wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
+        { return m_file->Seek(pos, mode); }
+    wxFileOffset OnSysTell() const { return m_file->Tell(); }
+
+private:
+    wxTempFile *m_file;
+
+    DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
+};
+
 class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
                                       public wxFileOutputStream
 {
index 8370eebc6faac3f3332554139f29e37bfcee0aa8..9d15b4f9b65d501e7dd71a5bce998b04666b42fa 100644 (file)
@@ -183,6 +183,33 @@ wxFileOffset wxFileOutputStream::GetLength() const
     return m_file->Length();
 }
 
+// ----------------------------------------------------------------------------
+// wxTempFileOutputStream
+// ----------------------------------------------------------------------------
+
+wxTempFileOutputStream::wxTempFileOutputStream(const wxString& fileName)
+{
+    m_file = new wxTempFile(fileName);
+
+    if (!m_file->IsOpened())
+        m_lasterror = wxSTREAM_WRITE_ERROR;
+}
+
+wxTempFileOutputStream::~wxTempFileOutputStream()
+{
+    if (m_file->IsOpened())
+        Discard();
+    delete m_file;
+}
+
+size_t wxTempFileOutputStream::OnSysWrite(const void *buffer, size_t size)
+{
+    if (IsOk() && m_file->Write(buffer, size))
+        return size;
+    m_lasterror = wxSTREAM_WRITE_ERROR;
+    return 0;
+}
+
 // ----------------------------------------------------------------------------
 // wxFileStream
 // ----------------------------------------------------------------------------
index b53355ed4d27dc244c5193af0dd0574fb9c05d8c..06ca3197f11018d9b02ba2fd76631f2720cf69e5 100644 (file)
@@ -71,6 +71,7 @@ TEST_OBJECTS =  \
        test_largefile.o \
        test_memstream.o \
        test_sstream.o \
+       test_tempfile.o \
        test_textstreamtest.o \
        test_zlibstream.o \
        test_uris.o
@@ -321,6 +322,9 @@ test_memstream.o: $(srcdir)/streams/memstream.cpp $(TEST_ODEP)
 test_sstream.o: $(srcdir)/streams/sstream.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/sstream.cpp
 
+test_tempfile.o: $(srcdir)/streams/tempfile.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/tempfile.cpp
+
 test_textstreamtest.o: $(srcdir)/streams/textstreamtest.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/textstreamtest.cpp
 
index ab60059c57b6ef59a332907abe50213322d23e69..6ed5c2423d997c9ab68b5b000bc7f8cf79767a65 100644 (file)
@@ -1,6 +1,6 @@
 # =========================================================================
 #     This makefile was generated by
-#     Bakefile 0.1.6 (http://bakefile.sourceforge.net)
+#     Bakefile 0.1.7 (http://bakefile.sourceforge.net)
 #     Do not modify, all changes will be overwritten!
 # =========================================================================
 
@@ -28,10 +28,10 @@ LIBDIRNAME = .\..\lib\bcc_$(LIBTYPE_SUFFIX)$(CFG)
 SETUPHDIR = \
        $(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
 TEST_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
-       $(__OPTIMIZEFLAG) -tWM -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
-       $(__UNICODE_DEFINE_p) -I.\..\include -I$(SETUPHDIR) -I. $(__DLLFLAG_p) \
-       -DwxUSE_GUI=0 $(CPPUNIT_CFLAGS) -Hu -H=$(OBJS)\testprec_test.csm $(CPPFLAGS) \
-       $(CXXFLAGS)
+       $(__OPTIMIZEFLAG) $(__THREADSFLAG_0) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
+       $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) -I.\..\include -I$(SETUPHDIR) -I. \
+       $(__DLLFLAG_p) -DwxUSE_GUI=0 $(CPPUNIT_CFLAGS) -Hu \
+       -H=$(OBJS)\testprec_test.csm $(CPPFLAGS) $(CXXFLAGS)
 TEST_OBJECTS =  \
        $(OBJS)\test_dummy.obj \
        $(OBJS)\test_test.obj \
@@ -62,13 +62,14 @@ TEST_OBJECTS =  \
        $(OBJS)\test_largefile.obj \
        $(OBJS)\test_memstream.obj \
        $(OBJS)\test_sstream.obj \
+       $(OBJS)\test_tempfile.obj \
        $(OBJS)\test_textstreamtest.obj \
        $(OBJS)\test_zlibstream.obj \
        $(OBJS)\test_uris.obj
 TEST_GUI_CXXFLAGS = $(__RUNTIME_LIBS) -I$(BCCDIR)\include $(__DEBUGINFO) \
-       $(__OPTIMIZEFLAG) -tWM -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
-       $(__UNICODE_DEFINE_p) -I.\..\include -I$(SETUPHDIR) -I. $(__DLLFLAG_p) \
-       -I.\..\samples -DNOPCH $(CPPUNIT_CFLAGS) -Hu \
+       $(__OPTIMIZEFLAG) $(__THREADSFLAG_0) -D__WXMSW__ $(__WXUNIV_DEFINE_p) \
+       $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) -I.\..\include -I$(SETUPHDIR) -I. \
+       $(__DLLFLAG_p) -I.\..\samples -DNOPCH $(CPPUNIT_CFLAGS) -Hu \
        -H=$(OBJS)\testprec_test_gui.csm $(CPPFLAGS) $(CXXFLAGS)
 TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_dummy.obj \
@@ -144,6 +145,18 @@ __OPTIMIZEFLAG = -Od
 !if "$(BUILD)" == "release"
 __OPTIMIZEFLAG = -O2
 !endif
+!if "$(USE_THREADS)" == "0"
+__THREADSFLAG = 
+!endif
+!if "$(USE_THREADS)" == "1"
+__THREADSFLAG = mt
+!endif
+!if "$(USE_THREADS)" == "0"
+__THREADSFLAG_0 = 
+!endif
+!if "$(USE_THREADS)" == "1"
+__THREADSFLAG_0 = -tWM
+!endif
 !if "$(RUNTIME_LIBS)" == "dynamic"
 __RUNTIME_LIBS = -tWR
 !endif
@@ -232,13 +245,13 @@ clean:
 
 $(OBJS)\test.exe: $(OBJS)\test_dummy.obj  $(TEST_OBJECTS)
        ilink32 -Tpe -q $(LDFLAGS) -L$(BCCDIR)\lib -L$(BCCDIR)\lib\psdk $(__DEBUGINFO)  -L$(LIBDIRNAME) -ap $(CPPUNIT_LIBS) @&&|
-       c0x32.obj $(TEST_OBJECTS),$@,, $(__WXLIB_NET_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib odbc32.lib import32.lib cw32mt$(__RUNTIME_LIBS_0).lib,,
+       c0x32.obj $(TEST_OBJECTS),$@,, $(__WXLIB_NET_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib odbc32.lib import32.lib cw32$(__THREADSFLAG)$(__RUNTIME_LIBS_0).lib,,
 |
 
 !if "$(USE_GUI)" == "1"
 $(OBJS)\test_gui.exe: $(OBJS)\test_gui_dummy.obj  $(TEST_GUI_OBJECTS)  $(OBJS)\test_gui_sample.res
        ilink32 -Tpe -q $(LDFLAGS) -L$(BCCDIR)\lib -L$(BCCDIR)\lib\psdk $(__DEBUGINFO)  -L$(LIBDIRNAME) $(CPPUNIT_LIBS) -ap @&&|
-       c0x32.obj $(TEST_GUI_OBJECTS),$@,, $(__WXLIB_CORE_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib odbc32.lib  import32.lib cw32mt$(__RUNTIME_LIBS_0).lib,, $(OBJS)\test_gui_sample.res
+       c0x32.obj $(TEST_GUI_OBJECTS),$@,, $(__WXLIB_CORE_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib odbc32.lib  import32.lib cw32$(__THREADSFLAG)$(__RUNTIME_LIBS_0).lib,, $(OBJS)\test_gui_sample.res
 |
 !endif
 
@@ -333,6 +346,9 @@ $(OBJS)\test_memstream.obj: .\streams\memstream.cpp
 $(OBJS)\test_sstream.obj: .\streams\sstream.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_tempfile.obj: .\streams\tempfile.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_textstreamtest.obj: .\streams\textstreamtest.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
index 0ade361a4aa48d43235fe904c219747723ebcc10..e03845161f68b1ac588840dce7e6c246d3632e64 100644 (file)
@@ -1,6 +1,6 @@
 # =========================================================================
 #     This makefile was generated by
-#     Bakefile 0.1.6 (http://bakefile.sourceforge.net)
+#     Bakefile 0.1.7 (http://bakefile.sourceforge.net)
 #     Do not modify, all changes will be overwritten!
 # =========================================================================
 
@@ -21,8 +21,8 @@ SETUPHDIR = \
 TEST_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(GCCFLAGS) -DHAVE_W32API_H \
        -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) \
        -I.\..\include -I$(SETUPHDIR) -W -Wall -I. $(__DLLFLAG_p) -DwxUSE_GUI=0 \
-       $(CPPUNIT_CFLAGS) $(__EXCEPTIONSFLAG) $(__EXCEPTIONSFLAG_0) \
-       -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
+       $(CPPUNIT_CFLAGS) $(__RTTIFLAG) $(__EXCEPTIONSFLAG) -Wno-ctor-dtor-privacy \
+       $(CPPFLAGS) $(CXXFLAGS)
 TEST_OBJECTS =  \
        $(OBJS)\test_dummy.o \
        $(OBJS)\test_test.o \
@@ -53,14 +53,15 @@ TEST_OBJECTS =  \
        $(OBJS)\test_largefile.o \
        $(OBJS)\test_memstream.o \
        $(OBJS)\test_sstream.o \
+       $(OBJS)\test_tempfile.o \
        $(OBJS)\test_textstreamtest.o \
        $(OBJS)\test_zlibstream.o \
        $(OBJS)\test_uris.o
 TEST_GUI_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(GCCFLAGS) \
        -DHAVE_W32API_H -D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
        $(__UNICODE_DEFINE_p) -I.\..\include -I$(SETUPHDIR) -W -Wall -I. \
-       $(__DLLFLAG_p) -I.\..\samples -DNOPCH $(CPPUNIT_CFLAGS) $(__EXCEPTIONSFLAG) \
-       $(__EXCEPTIONSFLAG_0) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
+       $(__DLLFLAG_p) -I.\..\samples -DNOPCH $(CPPUNIT_CFLAGS) $(__RTTIFLAG) \
+       $(__EXCEPTIONSFLAG) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
 TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_sample_rc.o \
        $(OBJS)\test_gui_dummy.o \
@@ -143,17 +144,23 @@ endif
 ifeq ($(BUILD),release)
 __OPTIMIZEFLAG = -O2
 endif
-ifeq ($(USE_EXCEPTIONS),0)
-__EXCEPTIONSFLAG = -fno-rtti
+ifeq ($(USE_THREADS),0)
+__THREADSFLAG = 
 endif
-ifeq ($(USE_EXCEPTIONS),1)
-__EXCEPTIONSFLAG = 
+ifeq ($(USE_THREADS),1)
+__THREADSFLAG = -mthreads
+endif
+ifeq ($(USE_RTTI),0)
+__RTTIFLAG = -fno-rtti
+endif
+ifeq ($(USE_RTTI),1)
+__RTTIFLAG = 
 endif
 ifeq ($(USE_EXCEPTIONS),0)
-__EXCEPTIONSFLAG_0 = -fno-exceptions
+__EXCEPTIONSFLAG = -fno-exceptions
 endif
 ifeq ($(USE_EXCEPTIONS),1)
-__EXCEPTIONSFLAG_0 = 
+__EXCEPTIONSFLAG = 
 endif
 ifeq ($(WXUNIV),1)
 __WXUNIV_DEFINE_p = -D__WXUNIVERSAL__
@@ -224,11 +231,11 @@ clean:
        -if exist $(OBJS)\test_gui.exe del $(OBJS)\test_gui.exe
 
 $(OBJS)\test.exe: $(TEST_OBJECTS)
-       $(CXX) -o $@ $(TEST_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) -mthreads -L$(LIBDIRNAME)  $(CPPUNIT_LIBS)  $(__WXLIB_NET_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG)  -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
+       $(CXX) -o $@ $(TEST_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME)  $(CPPUNIT_LIBS)  $(__WXLIB_NET_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG)  -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
 
 ifeq ($(USE_GUI),1)
 $(OBJS)\test_gui.exe: $(TEST_GUI_OBJECTS) $(OBJS)\test_gui_sample_rc.o
-       $(CXX) -o $@ $(TEST_GUI_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) -mthreads -L$(LIBDIRNAME) $(CPPUNIT_LIBS)   $(__WXLIB_CORE_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG)  -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
+       $(CXX) -o $@ $(TEST_GUI_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) $(CPPUNIT_LIBS)   $(__WXLIB_CORE_p)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG)  -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
 endif
 
 data: 
@@ -322,6 +329,9 @@ $(OBJS)\test_memstream.o: ./streams/memstream.cpp
 $(OBJS)\test_sstream.o: ./streams/sstream.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_tempfile.o: ./streams/tempfile.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_textstreamtest.o: ./streams/textstreamtest.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
index 10d9f2fda25cd8fa9662264463d0f3d19053db72..cbb4b7b9b8c7a58cd3e385fe4134f0c20c0202f0 100644 (file)
@@ -1,6 +1,6 @@
 # =========================================================================
 #     This makefile was generated by
-#     Bakefile 0.1.6 (http://bakefile.sourceforge.net)
+#     Bakefile 0.1.7 (http://bakefile.sourceforge.net)
 #     Do not modify, all changes will be overwritten!
 # =========================================================================
 
@@ -18,12 +18,12 @@ OBJS = \
 LIBDIRNAME = .\..\lib\vc_$(LIBTYPE_SUFFIX)$(CFG)
 SETUPHDIR = \
        $(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
-TEST_CXXFLAGS = /M$(__RUNTIME_LIBS)$(__DEBUGRUNTIME_3) /DWIN32 $(__DEBUGINFO) \
-       /Fd$(OBJS)\test.pdb $(____DEBUGRUNTIME_2_p) $(__OPTIMIZEFLAG) \
-       $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
-       $(__UNICODE_DEFINE_p) /I.\..\include /I$(SETUPHDIR) /W4 /I. $(__DLLFLAG_p) \
-       /D_CONSOLE /DwxUSE_GUI=0 $(CPPUNIT_CFLAGS) $(__EXCEPTIONSFLAG) \
-       $(__EXCEPTIONSFLAG_0) /Yu"testprec.h" /Fp"$(OBJS)\testprec_test.pch" \
+TEST_CXXFLAGS = /M$(__RUNTIME_LIBS_7)$(__DEBUGRUNTIME_3) /DWIN32 \
+       $(__DEBUGINFO) /Fd$(OBJS)\test.pdb $(____DEBUGRUNTIME_2_p) \
+       $(__OPTIMIZEFLAG) $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) \
+       $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) /I.\..\include /I$(SETUPHDIR) /W4 \
+       /I. $(__DLLFLAG_p) /D_CONSOLE /DwxUSE_GUI=0 $(CPPUNIT_CFLAGS) $(__RTTIFLAG) \
+       $(__EXCEPTIONSFLAG) /Yu"testprec.h" /Fp"$(OBJS)\testprec_test.pch" \
        $(CPPFLAGS) $(CXXFLAGS)
 TEST_OBJECTS =  \
        $(OBJS)\test_dummy.obj \
@@ -55,15 +55,16 @@ TEST_OBJECTS =  \
        $(OBJS)\test_largefile.obj \
        $(OBJS)\test_memstream.obj \
        $(OBJS)\test_sstream.obj \
+       $(OBJS)\test_tempfile.obj \
        $(OBJS)\test_textstreamtest.obj \
        $(OBJS)\test_zlibstream.obj \
        $(OBJS)\test_uris.obj
-TEST_GUI_CXXFLAGS = /M$(__RUNTIME_LIBS)$(__DEBUGRUNTIME_17) /DWIN32 \
+TEST_GUI_CXXFLAGS = /M$(__RUNTIME_LIBS_21)$(__DEBUGRUNTIME_17) /DWIN32 \
        $(__DEBUGINFO) /Fd$(OBJS)\test_gui.pdb $(____DEBUGRUNTIME_16_p) \
        $(__OPTIMIZEFLAG) $(__NO_VC_CRTDBG_p) /D__WXMSW__ $(__WXUNIV_DEFINE_p) \
        $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) /I.\..\include /I$(SETUPHDIR) /W4 \
        /I. $(__DLLFLAG_p) /I.\..\samples /DNOPCH $(CPPUNIT_CFLAGS) /D_CONSOLE \
-       $(__EXCEPTIONSFLAG) $(__EXCEPTIONSFLAG_0) /Yu"testprec.h" \
+       $(__RTTIFLAG) $(__EXCEPTIONSFLAG) /Yu"testprec.h" \
        /Fp"$(OBJS)\testprec_test_gui.pch" $(CPPFLAGS) $(CXXFLAGS)
 TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_sample.res \
@@ -126,6 +127,12 @@ __DEBUGRUNTIME_3 = d
 !if "$(DEBUG_RUNTIME_LIBS)" == "default"
 __DEBUGRUNTIME_3 = $(__DEBUGINFO_2)
 !endif
+!if "$(RUNTIME_LIBS)" == "dynamic"
+__RUNTIME_LIBS_7 = D
+!endif
+!if "$(RUNTIME_LIBS)" == "static"
+__RUNTIME_LIBS_7 = $(__THREADSFLAG)
+!endif
 !if "$(MONOLITHIC)" == "0"
 __WXLIB_NET_p = \
        wxbase$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_net.lib
@@ -172,6 +179,12 @@ __DEBUGRUNTIME_17 = d
 !if "$(DEBUG_RUNTIME_LIBS)" == "default"
 __DEBUGRUNTIME_17 = $(__DEBUGINFO_2)
 !endif
+!if "$(RUNTIME_LIBS)" == "dynamic"
+__RUNTIME_LIBS_21 = D
+!endif
+!if "$(RUNTIME_LIBS)" == "static"
+__RUNTIME_LIBS_21 = $(__THREADSFLAG)
+!endif
 !if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "0"
 __NO_VC_CRTDBG_p_3 = /d __NO_VC_CRTDBG__
 !endif
@@ -251,23 +264,23 @@ __OPTIMIZEFLAG = /Od
 !if "$(BUILD)" == "release"
 __OPTIMIZEFLAG = /O2
 !endif
-!if "$(RUNTIME_LIBS)" == "dynamic"
-__RUNTIME_LIBS = D
+!if "$(USE_THREADS)" == "0"
+__THREADSFLAG = L
 !endif
-!if "$(RUNTIME_LIBS)" == "static"
-__RUNTIME_LIBS = T
+!if "$(USE_THREADS)" == "1"
+__THREADSFLAG = T
 !endif
-!if "$(USE_EXCEPTIONS)" == "0"
-__EXCEPTIONSFLAG = 
+!if "$(USE_RTTI)" == "0"
+__RTTIFLAG = 
 !endif
-!if "$(USE_EXCEPTIONS)" == "1"
-__EXCEPTIONSFLAG = /GR
+!if "$(USE_RTTI)" == "1"
+__RTTIFLAG = /GR
 !endif
 !if "$(USE_EXCEPTIONS)" == "0"
-__EXCEPTIONSFLAG_0 = 
+__EXCEPTIONSFLAG = 
 !endif
 !if "$(USE_EXCEPTIONS)" == "1"
-__EXCEPTIONSFLAG_0 = /GX
+__EXCEPTIONSFLAG = /GX
 !endif
 !if "$(BUILD)" == "debug" && "$(DEBUG_RUNTIME_LIBS)" == "0"
 __NO_VC_CRTDBG_p = /D__NO_VC_CRTDBG__
@@ -434,6 +447,9 @@ $(OBJS)\test_memstream.obj: .\streams\memstream.cpp
 $(OBJS)\test_sstream.obj: .\streams\sstream.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_tempfile.obj: .\streams\tempfile.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_textstreamtest.obj: .\streams\textstreamtest.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
index 2b5866d43c85b44c4bebaf80edd58969ee2f7738..ac72d15dd4c3c8de454be2e6e8b1b4f1f10cdca9 100644 (file)
@@ -1,6 +1,6 @@
 # =========================================================================
 #     This makefile was generated by
-#     Bakefile 0.1.6 (http://bakefile.sourceforge.net)
+#     Bakefile 0.1.7 (http://bakefile.sourceforge.net)
 #     Do not modify, all changes will be overwritten!
 # =========================================================================
 
@@ -124,6 +124,13 @@ __OPTIMIZEFLAG = -od
 !ifeq BUILD release
 __OPTIMIZEFLAG = -ot -ox
 !endif
+__THREADSFLAG =
+!ifeq USE_THREADS 0
+__THREADSFLAG = 
+!endif
+!ifeq USE_THREADS 1
+__THREADSFLAG = -bm
+!endif
 __RUNTIME_LIBS =
 !ifeq RUNTIME_LIBS dynamic
 __RUNTIME_LIBS = -br
@@ -131,19 +138,19 @@ __RUNTIME_LIBS = -br
 !ifeq RUNTIME_LIBS static
 __RUNTIME_LIBS = 
 !endif
-__EXCEPTIONSFLAG =
-!ifeq USE_EXCEPTIONS 0
-__EXCEPTIONSFLAG = 
+__RTTIFLAG =
+!ifeq USE_RTTI 0
+__RTTIFLAG = 
 !endif
-!ifeq USE_EXCEPTIONS 1
-__EXCEPTIONSFLAG = -xr
+!ifeq USE_RTTI 1
+__RTTIFLAG = -xr
 !endif
-__EXCEPTIONSFLAG_0 =
+__EXCEPTIONSFLAG =
 !ifeq USE_EXCEPTIONS 0
-__EXCEPTIONSFLAG_0 = 
+__EXCEPTIONSFLAG = 
 !endif
 !ifeq USE_EXCEPTIONS 1
-__EXCEPTIONSFLAG_0 = -xs
+__EXCEPTIONSFLAG = -xs
 !endif
 __WXLIB_BASE_p =
 !ifeq MONOLITHIC 0
@@ -197,12 +204,12 @@ OBJS = &
 LIBDIRNAME = .\..\lib\wat_$(LIBTYPE_SUFFIX)$(CFG)
 SETUPHDIR = &
        $(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
-TEST_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) -bm $(__RUNTIME_LIBS) &
-       -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) &
-       -i=.\..\include -i=$(SETUPHDIR) -wx -wcd=549 -wcd=656 -wcd=657 -wcd=667 -i=. &
-       $(__DLLFLAG_p) -dwxUSE_GUI=0 $(CPPUNIT_CFLAGS) &
-       /fh=$(OBJS)\testprec_test.pch $(__EXCEPTIONSFLAG) $(__EXCEPTIONSFLAG_0) &
-       $(CPPFLAGS) $(CXXFLAGS)
+TEST_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
+       $(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
+       $(__UNICODE_DEFINE_p) -i=.\..\include -i=$(SETUPHDIR) -wx -wcd=549 -wcd=656 &
+       -wcd=657 -wcd=667 -i=. $(__DLLFLAG_p) -dwxUSE_GUI=0 $(CPPUNIT_CFLAGS) &
+       /fh=$(OBJS)\testprec_test.pch $(__RTTIFLAG) $(__EXCEPTIONSFLAG) $(CPPFLAGS) &
+       $(CXXFLAGS)
 TEST_OBJECTS =  &
        $(OBJS)\test_dummy.obj &
        $(OBJS)\test_test.obj &
@@ -233,15 +240,16 @@ TEST_OBJECTS =  &
        $(OBJS)\test_largefile.obj &
        $(OBJS)\test_memstream.obj &
        $(OBJS)\test_sstream.obj &
+       $(OBJS)\test_tempfile.obj &
        $(OBJS)\test_textstreamtest.obj &
        $(OBJS)\test_zlibstream.obj &
        $(OBJS)\test_uris.obj
-TEST_GUI_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) -bm $(__RUNTIME_LIBS) &
-       -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) &
-       -i=.\..\include -i=$(SETUPHDIR) -wx -wcd=549 -wcd=656 -wcd=657 -wcd=667 -i=. &
-       $(__DLLFLAG_p) -i=.\..\samples -dNOPCH $(CPPUNIT_CFLAGS) &
-       /fh=$(OBJS)\testprec_test_gui.pch $(__EXCEPTIONSFLAG) &
-       $(__EXCEPTIONSFLAG_0) $(CPPFLAGS) $(CXXFLAGS)
+TEST_GUI_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG) $(__THREADSFLAG) &
+       $(__RUNTIME_LIBS) -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) &
+       $(__UNICODE_DEFINE_p) -i=.\..\include -i=$(SETUPHDIR) -wx -wcd=549 -wcd=656 &
+       -wcd=657 -wcd=667 -i=. $(__DLLFLAG_p) -i=.\..\samples -dNOPCH &
+       $(CPPUNIT_CFLAGS) /fh=$(OBJS)\testprec_test_gui.pch $(__RTTIFLAG) &
+       $(__EXCEPTIONSFLAG) $(CPPFLAGS) $(CXXFLAGS)
 TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_dummy.obj &
        $(OBJS)\test_gui_test.obj &
@@ -382,6 +390,9 @@ $(OBJS)\test_memstream.obj :  .AUTODEPEND .\streams\memstream.cpp
 $(OBJS)\test_sstream.obj :  .AUTODEPEND .\streams\sstream.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_tempfile.obj :  .AUTODEPEND .\streams\tempfile.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_textstreamtest.obj :  .AUTODEPEND .\streams\textstreamtest.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
index 82961cfbd638bf5cb40840d3d08e35389e43eb11..5b1e307e452c12ebf04e0579ee21e8ff8dfacc4f 100644 (file)
@@ -50,6 +50,7 @@ Test *StreamCase::suite()
     STREAM_REGISTER_SUB_SUITE(strStream);
     STREAM_REGISTER_SUB_SUITE(fileStream);
     STREAM_REGISTER_SUB_SUITE(ffileStream);
+    STREAM_REGISTER_SUB_SUITE(tempStream);
     STREAM_REGISTER_SUB_SUITE(zlibStream);
 
     extern CppUnit::Test* GetlargeFileSuite();
diff --git a/tests/streams/tempfile.cpp b/tests/streams/tempfile.cpp
new file mode 100644 (file)
index 0000000..9fe2880
--- /dev/null
@@ -0,0 +1,107 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/streams/tempfile.cpp
+// Purpose:     Test wxTempFileOutputStream
+// Author:      Mike Wetherell
+// RCS-ID:      $Id$
+// Copyright:   (c) 2005 Mike Wetherell
+// Licence:     wxWidgets licence
+///////////////////////////////////////////////////////////////////////////////
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+// for all others, include the necessary headers
+#ifndef WX_PRECOMP
+    #include "wx/wx.h"
+#endif
+
+#include "wx/wfstream.h"
+#include "wx/filename.h"
+#include "bstream.h"
+
+#if wxUSE_STREAMS && wxUSE_FILE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Self deleting test file
+
+class TestFile
+{
+public:
+    TestFile();
+    ~TestFile() { if (wxFileExists(m_name)) wxRemoveFile(m_name); }
+    wxString GetName() const { return m_name; }
+private:
+    wxString m_name;
+};
+
+// Initialise with a test pattern so we can see if the file is replaced
+//
+TestFile::TestFile()
+{
+    wxFile file;
+    m_name = wxFileName::CreateTempFileName(_T("wxtest"), &file);
+    file.Write("Before", 6);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// The test case
+
+class tempStream : public CppUnit::TestCase
+{
+    CPPUNIT_TEST_SUITE(tempStream);
+        CPPUNIT_TEST(DoNothing);
+        CPPUNIT_TEST(Close);
+        CPPUNIT_TEST(Commit);
+        CPPUNIT_TEST(Discard);
+    CPPUNIT_TEST_SUITE_END();
+
+    void DoNothing() { DoTest(DONOTHING, false); }
+    void Close()     { DoTest(CLOSE, true); }
+    void Commit()    { DoTest(COMMIT, true); }
+    void Discard()   { DoTest(DISCARD, false); }
+
+    enum Action { DONOTHING, CLOSE, COMMIT, DISCARD };
+    void DoTest(Action action, bool shouldHaveCommited);
+};
+
+// the common test code
+//
+void tempStream::DoTest(Action action, bool shouldHaveCommited)
+{
+    TestFile temp;
+
+    {
+        wxTempFileOutputStream out(temp.GetName());
+        out.Write("Affer", 5);
+        CPPUNIT_ASSERT(out.SeekO(2) == 2);
+        out.Write("t", 1);
+        CPPUNIT_ASSERT(out.IsSeekable());
+        CPPUNIT_ASSERT(out.GetLength() == 5);
+        CPPUNIT_ASSERT(out.TellO() == 3);
+
+        switch (action) {
+            case DONOTHING: break;
+            case COMMIT:    out.Commit(); break;
+            case DISCARD:   out.Discard(); break;
+            case CLOSE:     out.Close();
+        }
+    }
+
+    wxFileInputStream in(temp.GetName());
+    char buf[32];
+    in.Read(buf, sizeof(buf));
+    buf[in.LastRead()] = 0;
+    CPPUNIT_ASSERT(strcmp(buf, shouldHaveCommited ? "After" : "Before") == 0);
+}
+
+
+// Register the stream sub suite, by using some stream helper macro.
+// Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())
+STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(tempStream)
+
+#endif // wxUSE_STREAMS && wxUSE_FILE
index 16bb6666af8897a2e3c99027708390f85db4008e..0dbfbf1924f60bbb8dda910cc0284bba2196b330 100644 (file)
@@ -51,6 +51,7 @@
             streams/largefile.cpp
             streams/memstream.cpp
             streams/sstream.cpp
+            streams/tempfile.cpp
             streams/textstreamtest.cpp
             streams/zlibstream.cpp
             uris/uris.cpp
index 8d2a6df7d8f742ade7fe86a71360bcf80965f188..7999a9631b4a8779a49e5bb6bd35a61cab46aaeb 100644 (file)
@@ -537,6 +537,10 @@ SOURCE=.\strings\strings.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\streams\tempfile.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\test.cpp
 # End Source File
 # Begin Source File