diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-09-06 14:29:36 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-09-06 14:29:36 +0000 |
| commit | efbfe4c006cfb6e0bf3ee4ed57d0657c0cd85c19 (patch) | |
| tree | a72723a125c34220772259f051673ff88598bded /test/GZipDecodingStreamFilterTest.cc | |
| parent | 552c753dbba55005964ad60698d803a44dac6391 (diff) | |
2010-09-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Data from remote server in HTTP/FTP download are now written to
the disk(or memory) through StreamFilter. Decoding chunked and
gziped streams are done cascading StreamFilter.
Removed inefficient 1byte read code.
* src/ChunkedDecodingStreamFilter.cc
* src/ChunkedDecodingStreamFilter.h
* src/DownloadCommand.cc
* src/DownloadCommand.h
* src/GZipDecodingStreamFilter.cc
* src/GZipDecodingStreamFilter.h
* src/HttpConnection.cc
* src/HttpDownloadCommand.cc
* src/HttpResponse.cc
* src/HttpResponse.h
* src/HttpResponseCommand.cc
* src/HttpResponseCommand.h
* src/HttpSkipResponseCommand.cc
* src/HttpSkipResponseCommand.h
* src/Makefile.am
* src/NullSinkStreamFilter.cc
* src/NullSinkStreamFilter.h
* src/RequestGroup.cc
* src/SinkStreamFilter.cc
* src/SinkStreamFilter.h
* src/StreamFilter.cc
* src/StreamFilter.h
* test/ChunkedDecodingStreamFilterTest.cc
* test/GZipDecodingStreamFilterTest.cc
* test/HttpResponseTest.cc
* test/Makefile.am
* test/MockSegment.h
Diffstat (limited to 'test/GZipDecodingStreamFilterTest.cc')
| -rw-r--r-- | test/GZipDecodingStreamFilterTest.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/test/GZipDecodingStreamFilterTest.cc b/test/GZipDecodingStreamFilterTest.cc new file mode 100644 index 00000000..250f410e --- /dev/null +++ b/test/GZipDecodingStreamFilterTest.cc @@ -0,0 +1,81 @@ +#include "GZipDecodingStreamFilter.h" + +#include <cassert> +#include <iostream> +#include <fstream> + +#include <cppunit/extensions/HelperMacros.h> + +#include "Exception.h" +#include "util.h" +#include "Segment.h" +#include "ByteArrayDiskWriter.h" +#include "SinkStreamFilter.h" +#include "MockSegment.h" +#ifdef ENABLE_MESSAGE_DIGEST +# include "MessageDigestHelper.h" +#endif // ENABLE_MESSAGE_DIGEST + +namespace aria2 { + +class GZipDecodingStreamFilterTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(GZipDecodingStreamFilterTest); + CPPUNIT_TEST(testTransform); + CPPUNIT_TEST_SUITE_END(); + + class MockSegment2:public MockSegment { + private: + off_t positionToWrite_; + public: + MockSegment2():positionToWrite_(0) {} + + virtual void updateWrittenLength(size_t bytes) + { + positionToWrite_ += bytes; + } + + virtual off_t getPositionToWrite() const + { + return positionToWrite_; + } + }; + + SharedHandle<GZipDecodingStreamFilter> filter_; + SharedHandle<SinkStreamFilter> sinkFilter_; + SharedHandle<ByteArrayDiskWriter> writer_; + SharedHandle<MockSegment2> segment_; +public: + void setUp() + { + writer_.reset(new ByteArrayDiskWriter()); + sinkFilter_.reset(new SinkStreamFilter()); + filter_.reset(new GZipDecodingStreamFilter(sinkFilter_)); + sinkFilter_->init(); + filter_->init(); + segment_.reset(new MockSegment2()); + } + + void testTransform(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecodingStreamFilterTest); + +void GZipDecodingStreamFilterTest::testTransform() +{ + unsigned char buf[4096]; + std::ifstream in("gzip_decode_test.gz", std::ios::binary); + while(in) { + in.read(reinterpret_cast<char*>(buf), sizeof(buf)); + filter_->transform(writer_, segment_, buf, in.gcount()); + } + CPPUNIT_ASSERT(filter_->finished()); +#ifdef ENABLE_MESSAGE_DIGEST + CPPUNIT_ASSERT_EQUAL(std::string("8b577b33c0411b2be9d4fa74c7402d54a8d21f96"), + MessageDigestHelper::digestString + (MessageDigestContext::SHA1, writer_->getString())); +#endif // ENABLE_MESSAGE_DIGEST +} + +} // namespace aria2 |
