From 7c34ca65a0b30d81b5fba000c259407148006063 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 30 Mar 2018 21:55:36 +0200 Subject: [PATCH] Add unit test for wxLZMA{Input,Output}Stream classes Create another generic stream test using BaseStreamTestCase framework. --- tests/Makefile.in | 4 ++ tests/makefile.bcc | 4 ++ tests/makefile.gcc | 4 ++ tests/makefile.vc | 4 ++ tests/streams/lzmastream.cpp | 90 ++++++++++++++++++++++++++++++++++++ tests/test.bkl | 1 + tests/test.vcxproj | 3 +- tests/test.vcxproj.filters | 5 +- tests/test_vc7_test.vcproj | 3 ++ tests/test_vc8_test.vcproj | 4 ++ tests/test_vc9_test.vcproj | 4 ++ 11 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 tests/streams/lzmastream.cpp diff --git a/tests/Makefile.in b/tests/Makefile.in index 69d960b891..d20559e8fe 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -120,6 +120,7 @@ TEST_OBJECTS = \ test_filestream.o \ test_iostreams.o \ test_largefile.o \ + test_lzmastream.o \ test_memstream.o \ test_socketstream.o \ test_sstream.o \ @@ -687,6 +688,9 @@ test_iostreams.o: $(srcdir)/streams/iostreams.cpp $(TEST_ODEP) test_largefile.o: $(srcdir)/streams/largefile.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/largefile.cpp +test_lzmastream.o: $(srcdir)/streams/lzmastream.cpp $(TEST_ODEP) + $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/lzmastream.cpp + test_memstream.o: $(srcdir)/streams/memstream.cpp $(TEST_ODEP) $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/memstream.cpp diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 25f9fc68d1..30897885eb 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -102,6 +102,7 @@ TEST_OBJECTS = \ $(OBJS)\test_filestream.obj \ $(OBJS)\test_iostreams.obj \ $(OBJS)\test_largefile.obj \ + $(OBJS)\test_lzmastream.obj \ $(OBJS)\test_memstream.obj \ $(OBJS)\test_socketstream.obj \ $(OBJS)\test_sstream.obj \ @@ -734,6 +735,9 @@ $(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp $(OBJS)\test_largefile.obj: .\streams\largefile.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\largefile.cpp +$(OBJS)\test_lzmastream.obj: .\streams\lzmastream.cpp + $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\lzmastream.cpp + $(OBJS)\test_memstream.obj: .\streams\memstream.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index c6971bac0b..b9a05edb64 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -94,6 +94,7 @@ TEST_OBJECTS = \ $(OBJS)\test_filestream.o \ $(OBJS)\test_iostreams.o \ $(OBJS)\test_largefile.o \ + $(OBJS)\test_lzmastream.o \ $(OBJS)\test_memstream.o \ $(OBJS)\test_socketstream.o \ $(OBJS)\test_sstream.o \ @@ -711,6 +712,9 @@ $(OBJS)\test_iostreams.o: ./streams/iostreams.cpp $(OBJS)\test_largefile.o: ./streams/largefile.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_lzmastream.o: ./streams/lzmastream.cpp + $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_memstream.o: ./streams/memstream.cpp $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 9ccebcdd66..8ae6c6c439 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -97,6 +97,7 @@ TEST_OBJECTS = \ $(OBJS)\test_filestream.obj \ $(OBJS)\test_iostreams.obj \ $(OBJS)\test_largefile.obj \ + $(OBJS)\test_lzmastream.obj \ $(OBJS)\test_memstream.obj \ $(OBJS)\test_socketstream.obj \ $(OBJS)\test_sstream.obj \ @@ -913,6 +914,9 @@ $(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp $(OBJS)\test_largefile.obj: .\streams\largefile.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\largefile.cpp +$(OBJS)\test_lzmastream.obj: .\streams\lzmastream.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\lzmastream.cpp + $(OBJS)\test_memstream.obj: .\streams\memstream.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp diff --git a/tests/streams/lzmastream.cpp b/tests/streams/lzmastream.cpp new file mode 100644 index 0000000000..6bd6f2dd61 --- /dev/null +++ b/tests/streams/lzmastream.cpp @@ -0,0 +1,90 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/streams/lzmastream.cpp +// Purpose: Unit tests for LZMA stream classes +// Author: Vadim Zeitlin +// Created: 2018-03-30 +// Copyright: (c) 2018 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_LIBLZMA && wxUSE_STREAMS + +#include "wx/mstream.h" +#include "wx/lzmastream.h" + +#include "bstream.h" + +class LZMAStream : public BaseStreamTestCase +{ +public: + LZMAStream(); + + CPPUNIT_TEST_SUITE(zlibStream); + // Base class stream tests. + CPPUNIT_TEST(Input_GetSizeFail); + CPPUNIT_TEST(Input_GetC); + CPPUNIT_TEST(Input_Read); + CPPUNIT_TEST(Input_Eof); + CPPUNIT_TEST(Input_LastRead); + CPPUNIT_TEST(Input_CanRead); + CPPUNIT_TEST(Input_SeekIFail); + CPPUNIT_TEST(Input_TellI); + CPPUNIT_TEST(Input_Peek); + CPPUNIT_TEST(Input_Ungetch); + + CPPUNIT_TEST(Output_PutC); + CPPUNIT_TEST(Output_Write); + CPPUNIT_TEST(Output_LastWrite); + CPPUNIT_TEST(Output_SeekOFail); + CPPUNIT_TEST(Output_TellO); + CPPUNIT_TEST_SUITE_END(); + +protected: + wxLZMAInputStream *DoCreateInStream() wxOVERRIDE; + wxLZMAOutputStream *DoCreateOutStream() wxOVERRIDE; + +private: + wxDECLARE_NO_COPY_CLASS(LZMAStream); +}; + +STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(LZMAStream) + +LZMAStream::LZMAStream() +{ + // Disable TellI() and TellO() tests in the base class which don't work + // with the compressed streams. + m_bSimpleTellITest = + m_bSimpleTellOTest = true; +} + +wxLZMAInputStream *LZMAStream::DoCreateInStream() +{ + // Compress some data. + const char data[] = "This is just some test data for LZMA streams unit test"; + const size_t len = sizeof(data); + + wxMemoryOutputStream outmem; + wxLZMAOutputStream outz(outmem); + outz.Write(data, len); + REQUIRE( outz.LastWrite() == len ); + REQUIRE( outz.Close() ); + + wxMemoryInputStream* const inmem = new wxMemoryInputStream(outmem); + REQUIRE( inmem->IsOk() ); + + // Give ownership of the memory input stream to the LZMA stream. + return new wxLZMAInputStream(inmem); +} + +wxLZMAOutputStream *LZMAStream::DoCreateOutStream() +{ + return new wxLZMAOutputStream(new wxMemoryOutputStream()); +} + +#endif // wxUSE_LIBLZMA && wxUSE_STREAMS diff --git a/tests/test.bkl b/tests/test.bkl index 95007b4836..47016bcf33 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -90,6 +90,7 @@ streams/filestream.cpp streams/iostreams.cpp streams/largefile.cpp + streams/lzmastream.cpp streams/memstream.cpp streams/socketstream.cpp streams/sstream.cpp diff --git a/tests/test.vcxproj b/tests/test.vcxproj index 0844c93994..d4626936c7 100644 --- a/tests/test.vcxproj +++ b/tests/test.vcxproj @@ -517,6 +517,7 @@ + @@ -553,4 +554,4 @@ - + \ No newline at end of file diff --git a/tests/test.vcxproj.filters b/tests/test.vcxproj.filters index d3365dc7e6..502e186b28 100644 --- a/tests/test.vcxproj.filters +++ b/tests/test.vcxproj.filters @@ -262,5 +262,8 @@ Source Files + + Source Files + - + \ No newline at end of file diff --git a/tests/test_vc7_test.vcproj b/tests/test_vc7_test.vcproj index 45b3604544..9443e3b8c9 100644 --- a/tests/test_vc7_test.vcproj +++ b/tests/test_vc7_test.vcproj @@ -448,6 +448,9 @@ + + diff --git a/tests/test_vc8_test.vcproj b/tests/test_vc8_test.vcproj index 6501c9dc08..d085fdc4a3 100644 --- a/tests/test_vc8_test.vcproj +++ b/tests/test_vc8_test.vcproj @@ -1066,6 +1066,10 @@ RelativePath=".\longlong\longlongtest.cpp" > + + diff --git a/tests/test_vc9_test.vcproj b/tests/test_vc9_test.vcproj index 1c9cfd4b7c..4570595312 100644 --- a/tests/test_vc9_test.vcproj +++ b/tests/test_vc9_test.vcproj @@ -1038,6 +1038,10 @@ RelativePath=".\longlong\longlongtest.cpp" > + +