File: lzmastream.cpp

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (87 lines) | stat: -rw-r--r-- 2,479 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
///////////////////////////////////////////////////////////////////////////////
// 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"


#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