summaryrefslogtreecommitdiffstats
path: root/test/libapt/extracttar_test.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
commit636c7dc17286d93d788c741d15fd756aeda066d5 (patch)
treee7ae158cc54f591041a061b9865bcae51854f15c /test/libapt/extracttar_test.cc
parentInitial commit. (diff)
downloadapt-636c7dc17286d93d788c741d15fd756aeda066d5.tar.xz
apt-636c7dc17286d93d788c741d15fd756aeda066d5.zip
Adding upstream version 1.8.2.3.upstream/1.8.2.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/libapt/extracttar_test.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc
new file mode 100644
index 0000000..3093414
--- /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 "assert.h"
+#include <gtest/gtest.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 /etc/passwd 2>/dev/null | 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);
+ }
+}