diff options
author | Julian Andres Klode <jak@debian.org> | 2014-03-16 14:48:39 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2015-08-27 13:45:57 +0200 |
commit | 992a1e83eb3fa4a7e6a19288e7c0af7c5d2b25c0 (patch) | |
tree | ae68c194ce60eae8401cbd97d24fe79300a9b1f6 | |
parent | 2da8aae5550440742674758280f2d339ba612a31 (diff) |
Add test for using ExtractTar on compressed files
Git-Dch: ignore
-rw-r--r-- | test/libapt/extracttar_test.cc | 41 | ||||
-rw-r--r-- | test/libapt/makefile | 4 |
2 files changed, 43 insertions, 2 deletions
diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc new file mode 100644 index 000000000..b4e1fd37f --- /dev/null +++ b/test/libapt/extracttar_test.cc @@ -0,0 +1,41 @@ +#include <apt-pkg/error.h> +#include <apt-pkg/extracttar.h> +#include <iostream> +#include <stdlib.h> + +#include <gtest/gtest.h> +#include "assert.h" + +class Stream : public pkgDirStream +{ + public: + int count; + Stream () { count = 0; } + virtual bool DoItem(Item &Itm,int &Fd) { (void)Itm; (void)Fd; count++; return true; } + virtual bool Fail(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; } + virtual bool FinishedFile(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; } + virtual bool Process(Item &Itm,const unsigned char * Data, unsigned long Size,unsigned long Pos) { (void)Itm; (void) Data; (void) Size; (void) Pos; return true; } + virtual ~Stream() {} +}; + +TEST(ExtractTar, ExtractTar) +{ + EXPECT_EQ(system("tar c makefile | gzip > tar.tgz"), 0); + + FileFd fd("tar.tgz", FileFd::ReadOnly); + unlink("tar.tgz"); + ExtractTar tar(fd, -1, "gzip"); + + // Run multiple times, because we want to check not only that extraction + // works, but also that it works multiple times (important for python-apt) + for (int i = 0; i < 5; i++) { + Stream stream; + fd.Seek(0); + tar.Go(stream); + if (_error->PendingError()) { + _error->DumpErrors(); + EXPECT_FALSE(true); + } + EXPECT_EQ(stream.count, 1); + } +} diff --git a/test/libapt/makefile b/test/libapt/makefile index c078cc568..5ff9cf68a 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -15,8 +15,8 @@ test: $(BIN)/gtest$(BASENAME) $(BIN)/gtest$(BASENAME): $(LIB)/gtest.a PROGRAM = gtest${BASENAME} -SLIBS = -lapt-pkg -lapt-private -pthread $(LIB)/gtest.a -LIB_MAKES = apt-pkg/makefile apt-private/makefile +SLIBS = -lapt-pkg -lapt-private -lapt-inst -pthread $(LIB)/gtest.a +LIB_MAKES = apt-pkg/makefile apt-private/makefile apt-inst/makefile SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc) include $(PROGRAM_H) |