Add unit test for wxLZMA{Input,Output}Stream classes

Create another generic stream test using BaseStreamTestCase framework.
This commit is contained in:
Vadim Zeitlin
2018-03-30 21:55:36 +02:00
parent 50b102ffd2
commit 7c34ca65a0
11 changed files with 124 additions and 2 deletions

View File

@@ -120,6 +120,7 @@ TEST_OBJECTS = \
test_filestream.o \ test_filestream.o \
test_iostreams.o \ test_iostreams.o \
test_largefile.o \ test_largefile.o \
test_lzmastream.o \
test_memstream.o \ test_memstream.o \
test_socketstream.o \ test_socketstream.o \
test_sstream.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) test_largefile.o: $(srcdir)/streams/largefile.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/largefile.cpp $(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) test_memstream.o: $(srcdir)/streams/memstream.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/memstream.cpp $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/memstream.cpp

View File

@@ -102,6 +102,7 @@ TEST_OBJECTS = \
$(OBJS)\test_filestream.obj \ $(OBJS)\test_filestream.obj \
$(OBJS)\test_iostreams.obj \ $(OBJS)\test_iostreams.obj \
$(OBJS)\test_largefile.obj \ $(OBJS)\test_largefile.obj \
$(OBJS)\test_lzmastream.obj \
$(OBJS)\test_memstream.obj \ $(OBJS)\test_memstream.obj \
$(OBJS)\test_socketstream.obj \ $(OBJS)\test_socketstream.obj \
$(OBJS)\test_sstream.obj \ $(OBJS)\test_sstream.obj \
@@ -734,6 +735,9 @@ $(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp
$(OBJS)\test_largefile.obj: .\streams\largefile.cpp $(OBJS)\test_largefile.obj: .\streams\largefile.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\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 $(OBJS)\test_memstream.obj: .\streams\memstream.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp

View File

@@ -94,6 +94,7 @@ TEST_OBJECTS = \
$(OBJS)\test_filestream.o \ $(OBJS)\test_filestream.o \
$(OBJS)\test_iostreams.o \ $(OBJS)\test_iostreams.o \
$(OBJS)\test_largefile.o \ $(OBJS)\test_largefile.o \
$(OBJS)\test_lzmastream.o \
$(OBJS)\test_memstream.o \ $(OBJS)\test_memstream.o \
$(OBJS)\test_socketstream.o \ $(OBJS)\test_socketstream.o \
$(OBJS)\test_sstream.o \ $(OBJS)\test_sstream.o \
@@ -711,6 +712,9 @@ $(OBJS)\test_iostreams.o: ./streams/iostreams.cpp
$(OBJS)\test_largefile.o: ./streams/largefile.cpp $(OBJS)\test_largefile.o: ./streams/largefile.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< $(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 $(OBJS)\test_memstream.o: ./streams/memstream.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $< $(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<

View File

@@ -97,6 +97,7 @@ TEST_OBJECTS = \
$(OBJS)\test_filestream.obj \ $(OBJS)\test_filestream.obj \
$(OBJS)\test_iostreams.obj \ $(OBJS)\test_iostreams.obj \
$(OBJS)\test_largefile.obj \ $(OBJS)\test_largefile.obj \
$(OBJS)\test_lzmastream.obj \
$(OBJS)\test_memstream.obj \ $(OBJS)\test_memstream.obj \
$(OBJS)\test_socketstream.obj \ $(OBJS)\test_socketstream.obj \
$(OBJS)\test_sstream.obj \ $(OBJS)\test_sstream.obj \
@@ -913,6 +914,9 @@ $(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp
$(OBJS)\test_largefile.obj: .\streams\largefile.cpp $(OBJS)\test_largefile.obj: .\streams\largefile.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\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 $(OBJS)\test_memstream.obj: .\streams\memstream.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp

View File

@@ -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 <vadim@wxwidgets.org>
// 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<wxLZMAInputStream, wxLZMAOutputStream>
{
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

View File

@@ -90,6 +90,7 @@
streams/filestream.cpp streams/filestream.cpp
streams/iostreams.cpp streams/iostreams.cpp
streams/largefile.cpp streams/largefile.cpp
streams/lzmastream.cpp
streams/memstream.cpp streams/memstream.cpp
streams/socketstream.cpp streams/socketstream.cpp
streams/sstream.cpp streams/sstream.cpp

View File

@@ -517,6 +517,7 @@
<ClCompile Include="streams\filestream.cpp" /> <ClCompile Include="streams\filestream.cpp" />
<ClCompile Include="streams\iostreams.cpp" /> <ClCompile Include="streams\iostreams.cpp" />
<ClCompile Include="streams\largefile.cpp" /> <ClCompile Include="streams\largefile.cpp" />
<ClCompile Include="streams\lzmastream.cpp" />
<ClCompile Include="streams\memstream.cpp" /> <ClCompile Include="streams\memstream.cpp" />
<ClCompile Include="streams\socketstream.cpp" /> <ClCompile Include="streams\socketstream.cpp" />
<ClCompile Include="streams\sstream.cpp" /> <ClCompile Include="streams\sstream.cpp" />
@@ -553,4 +554,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>

View File

@@ -262,5 +262,8 @@
<ClCompile Include="streams\zlibstream.cpp"> <ClCompile Include="streams\zlibstream.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="streams\lzmastream.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -448,6 +448,9 @@
<File <File
RelativePath=".\longlong\longlongtest.cpp"> RelativePath=".\longlong\longlongtest.cpp">
</File> </File>
<File
RelativePath=".\streams\lzmastream.cpp">
</File>
<File <File
RelativePath=".\mbconv\mbconvtest.cpp"> RelativePath=".\mbconv\mbconvtest.cpp">
</File> </File>

View File

@@ -1066,6 +1066,10 @@
RelativePath=".\longlong\longlongtest.cpp" RelativePath=".\longlong\longlongtest.cpp"
> >
</File> </File>
<File
RelativePath=".\streams\lzmastream.cpp"
>
</File>
<File <File
RelativePath=".\mbconv\mbconvtest.cpp" RelativePath=".\mbconv\mbconvtest.cpp"
> >

View File

@@ -1038,6 +1038,10 @@
RelativePath=".\longlong\longlongtest.cpp" RelativePath=".\longlong\longlongtest.cpp"
> >
</File> </File>
<File
RelativePath=".\streams\lzmastream.cpp"
>
</File>
<File <File
RelativePath=".\mbconv\mbconvtest.cpp" RelativePath=".\mbconv\mbconvtest.cpp"
> >