]> git.saurik.com Git - wxWidgets.git/commitdiff
Add tests for wxBackingFile.
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Mon, 23 Oct 2006 21:58:35 +0000 (21:58 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Mon, 23 Oct 2006 21:58:35 +0000 (21:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42306 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/streams/fileback.cpp [new file with mode: 0644]
tests/test.bkl
tests/test_test.dsp

index 7c645ca69f7f07676c3358f69cf2996b795672a2..44667596376c6d79c68e6ade72460cbd03ddb397 100644 (file)
@@ -73,6 +73,7 @@ TEST_OBJECTS =  \
        test_bstream.o \
        test_datastreamtest.o \
        test_ffilestream.o \
+       test_fileback.o \
        test_filestream.o \
        test_largefile.o \
        test_memstream.o \
@@ -370,6 +371,9 @@ test_datastreamtest.o: $(srcdir)/streams/datastreamtest.cpp $(TEST_ODEP)
 test_ffilestream.o: $(srcdir)/streams/ffilestream.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/ffilestream.cpp
 
+test_fileback.o: $(srcdir)/streams/fileback.cpp $(TEST_ODEP)
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/fileback.cpp
+
 test_filestream.o: $(srcdir)/streams/filestream.cpp $(TEST_ODEP)
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/filestream.cpp
 
index 3ff71fdb315de900e9f7200e1c2ad06731478031..a3f236e409eaa89e6f0df24c62a4697db3838467 100644 (file)
@@ -64,6 +64,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_bstream.obj \
        $(OBJS)\test_datastreamtest.obj \
        $(OBJS)\test_ffilestream.obj \
+       $(OBJS)\test_fileback.obj \
        $(OBJS)\test_filestream.obj \
        $(OBJS)\test_largefile.obj \
        $(OBJS)\test_memstream.obj \
@@ -409,6 +410,9 @@ $(OBJS)\test_datastreamtest.obj: .\streams\datastreamtest.cpp
 $(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_fileback.obj: .\streams\fileback.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_filestream.obj: .\streams\filestream.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
index 5a5f27cbd1634cbe7774cad94247e06dbf6d6653..d8b6ec7cc2425b5b67d7dea31894172b239375a1 100644 (file)
@@ -56,6 +56,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_bstream.o \
        $(OBJS)\test_datastreamtest.o \
        $(OBJS)\test_ffilestream.o \
+       $(OBJS)\test_fileback.o \
        $(OBJS)\test_filestream.o \
        $(OBJS)\test_largefile.o \
        $(OBJS)\test_memstream.o \
@@ -387,6 +388,9 @@ $(OBJS)\test_datastreamtest.o: ./streams/datastreamtest.cpp
 $(OBJS)\test_ffilestream.o: ./streams/ffilestream.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\test_fileback.o: ./streams/fileback.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_filestream.o: ./streams/filestream.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
 
index fb110ed2ecac06fa842f61e6be12082c974825e1..be7db5bdb1d75686f6ad5175dbff40671222fbe4 100644 (file)
@@ -56,6 +56,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_bstream.obj \
        $(OBJS)\test_datastreamtest.obj \
        $(OBJS)\test_ffilestream.obj \
+       $(OBJS)\test_fileback.obj \
        $(OBJS)\test_filestream.obj \
        $(OBJS)\test_largefile.obj \
        $(OBJS)\test_memstream.obj \
@@ -493,6 +494,9 @@ $(OBJS)\test_datastreamtest.obj: .\streams\datastreamtest.cpp
 $(OBJS)\test_ffilestream.obj: .\streams\ffilestream.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_fileback.obj: .\streams\fileback.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_filestream.obj: .\streams\filestream.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
index edd6508ce2dc8318f8531475f45713bc26e8af96..fec8ef6c4c77c9e44753eac9e11225f1f716b8ac 100644 (file)
@@ -261,6 +261,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_bstream.obj &
        $(OBJS)\test_datastreamtest.obj &
        $(OBJS)\test_ffilestream.obj &
+       $(OBJS)\test_fileback.obj &
        $(OBJS)\test_filestream.obj &
        $(OBJS)\test_largefile.obj &
        $(OBJS)\test_memstream.obj &
@@ -442,6 +443,9 @@ $(OBJS)\test_datastreamtest.obj :  .AUTODEPEND .\streams\datastreamtest.cpp
 $(OBJS)\test_ffilestream.obj :  .AUTODEPEND .\streams\ffilestream.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_fileback.obj :  .AUTODEPEND .\streams\fileback.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_filestream.obj :  .AUTODEPEND .\streams\filestream.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
diff --git a/tests/streams/fileback.cpp b/tests/streams/fileback.cpp
new file mode 100644 (file)
index 0000000..0fbce3e
--- /dev/null
@@ -0,0 +1,202 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/streams/backfile.cpp
+// Purpose:     Test wxBackingFile
+// Author:      Mike Wetherell
+// RCS-ID:      $Id$
+// Copyright:   (c) 2006 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/mstream.h"
+#include "wx/fileback.h"
+#include "bstream.h"
+
+#if wxUSE_STREAMS
+
+const size_t TESTSIZE = 256;
+const size_t BUFSIZE = 100;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Parent stream for testing
+
+class TestStream : public wxMemoryInputStream
+{
+public:
+    TestStream(const void *buf, size_t size)
+        : wxMemoryInputStream(buf, size) { }
+
+    wxFileOffset GetLength() const { return wxInvalidOffset; }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// The test case
+
+class backStream : public CppUnit::TestCase
+{
+public:
+    backStream();
+
+    CPPUNIT_TEST_SUITE(backStream);
+        CPPUNIT_TEST(ReadLenSeek);
+        CPPUNIT_TEST(LenSeekRead);
+        CPPUNIT_TEST(SeekReadLen);
+        CPPUNIT_TEST(ReadAll);
+        CPPUNIT_TEST(ReadTooMuch);
+        CPPUNIT_TEST(EmptyStream);
+    CPPUNIT_TEST_SUITE_END();
+
+    void ReadLenSeek();
+    void LenSeekRead();
+    void SeekReadLen();
+    void ReadAll();
+    void ReadTooMuch();
+    void EmptyStream();
+
+private:
+    void Read(wxInputStream& in, size_t size1, size_t size2, size_t size3);
+    void Len(wxInputStream& in);
+    void Seek(wxInputStream& in);
+
+    char m_testdata[TESTSIZE];
+};
+
+backStream::backStream()
+{
+    for (unsigned i = 0; i < TESTSIZE; i++)
+        m_testdata[i] = i;
+}
+
+void backStream::ReadLenSeek()
+{
+    wxBackingFile bf(new TestStream(m_testdata, TESTSIZE), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    Read(in, BUFSIZE, BUFSIZE / 2, 2 * BUFSIZE / 3);
+    Len(in);
+    Seek(in);
+}
+
+void backStream::LenSeekRead()
+{
+    wxBackingFile bf(new wxMemoryInputStream(m_testdata, TESTSIZE), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    Len(in);
+    Seek(in);
+    Read(in, BUFSIZE, BUFSIZE / 2, 2 * BUFSIZE / 3);
+}
+
+void backStream::SeekReadLen()
+{
+    wxBackingFile bf(new TestStream(m_testdata, TESTSIZE), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    Seek(in);
+    Read(in, BUFSIZE, BUFSIZE / 2, 2 * BUFSIZE / 3);
+    Len(in);
+}
+
+void backStream::ReadAll()
+{
+    wxBackingFile bf(new TestStream(m_testdata, TESTSIZE), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    Read(in, TESTSIZE, 0, 0);
+}
+
+void backStream::ReadTooMuch()
+{
+    wxBackingFile bf(new TestStream(m_testdata, TESTSIZE), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    char buf[TESTSIZE * 2];
+
+    CPPUNIT_ASSERT_EQUAL(TESTSIZE, in.Read(buf, TESTSIZE * 2).LastRead());
+    CPPUNIT_ASSERT(in.Eof());
+    CPPUNIT_ASSERT(memcmp(buf, m_testdata, TESTSIZE) == 0);
+}
+
+void backStream::EmptyStream()
+{
+    wxBackingFile bf(new TestStream(m_testdata, 0), BUFSIZE);
+    wxBackedInputStream in(bf);
+
+    char buf[1];
+
+    CPPUNIT_ASSERT_EQUAL(size_t(0), in.Read(buf, 1).LastRead());
+    CPPUNIT_ASSERT(in.Eof());
+}
+
+void backStream::Read(wxInputStream& in,
+                      size_t size1,
+                      size_t size2,
+                      size_t size3)
+{
+    const size_t remainder = TESTSIZE - size1 - size2 - size3;
+    char buf[TESTSIZE];
+    char *testdata = m_testdata;
+
+    in.SeekI(0);
+
+    CPPUNIT_ASSERT_EQUAL(size1, in.Read(buf, size1).LastRead());
+    CPPUNIT_ASSERT(in.IsOk());
+    CPPUNIT_ASSERT(memcmp(buf, testdata, size1) == 0);
+    testdata += size1;
+
+    CPPUNIT_ASSERT_EQUAL(size2, in.Read(buf, size2).LastRead());
+    CPPUNIT_ASSERT(in.IsOk());
+    CPPUNIT_ASSERT(memcmp(buf, testdata, size2) == 0);
+    testdata += size2;
+
+    CPPUNIT_ASSERT_EQUAL(size3, in.Read(buf, size3).LastRead());
+    CPPUNIT_ASSERT(in.IsOk());
+    CPPUNIT_ASSERT(memcmp(buf, testdata, size3) == 0);
+    testdata += size3;
+
+    CPPUNIT_ASSERT_EQUAL(remainder, in.Read(buf, TESTSIZE).LastRead());
+    CPPUNIT_ASSERT(in.Eof());
+    CPPUNIT_ASSERT(memcmp(buf, testdata, remainder) == 0);
+
+    CPPUNIT_ASSERT_EQUAL(size_t(0), in.Read(buf, TESTSIZE).LastRead());
+    CPPUNIT_ASSERT(in.Eof());
+}
+
+void backStream::Len(wxInputStream& in)
+{
+    CPPUNIT_ASSERT_EQUAL(wxFileOffset(TESTSIZE), in.GetLength());
+}
+
+void backStream::Seek(wxInputStream& in)
+{
+    CPPUNIT_ASSERT_EQUAL(wxFileOffset(TESTSIZE), in.SeekI(TESTSIZE));
+    in.GetC();
+    CPPUNIT_ASSERT_EQUAL(size_t(0), in.LastRead());
+    CPPUNIT_ASSERT(in.Eof());
+
+    for (wxFileOffset i = TESTSIZE - 1; i >= 0; i--) {
+        CPPUNIT_ASSERT_EQUAL(i, in.SeekI(i));
+        CPPUNIT_ASSERT_EQUAL(i, in.TellI());
+        CPPUNIT_ASSERT_EQUAL(char(i), in.GetC());
+        CPPUNIT_ASSERT_EQUAL(size_t(1), in.LastRead());
+        CPPUNIT_ASSERT(in.IsOk());
+    }
+}
+
+// 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(backStream)
+
+#endif // wxUSE_STREAMS
index 67aeca9930befeabf4c25061aff291c33621c8e1..b5ee07080f26adbeaa297413ee42c9856f6dfa90 100644 (file)
@@ -51,6 +51,7 @@
             streams/bstream.cpp
             streams/datastreamtest.cpp
             streams/ffilestream.cpp
+            streams/fileback.cpp
             streams/filestream.cpp
             streams/largefile.cpp
             streams/memstream.cpp
index 17f88cbbda1ab99b9146f87ead4ab4e6f75b5fda..ba9224b9da17ecb7328a970dc6032307fe6ef742 100644 (file)
@@ -473,6 +473,10 @@ SOURCE=.\streams\ffilestream.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\streams\fileback.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\fileconf\fileconftest.cpp
 # End Source File
 # Begin Source File