summaryrefslogtreecommitdiffstats
path: root/test/libapt/extracttar_test.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 09:59:37 +0000
commit76e2632459410dec81337edb6a9fee33c9a660f3 (patch)
treea73345df208eede4a4daad340515c9328f34625c /test/libapt/extracttar_test.cc
parentInitial commit. (diff)
downloadapt-76e2632459410dec81337edb6a9fee33c9a660f3.tar.xz
apt-76e2632459410dec81337edb6a9fee33c9a660f3.zip
Adding upstream version 2.7.12.upstream/2.7.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/libapt/extracttar_test.cc')
-rw-r--r--test/libapt/extracttar_test.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc
new file mode 100644
index 0000000..246aea7
--- /dev/null
+++ b/test/libapt/extracttar_test.cc
@@ -0,0 +1,52 @@
+#include <config.h>
+
+#include <apt-pkg/dirstream.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/extracttar.h>
+#include <cstdlib>
+#include <iostream>
+
+#include "assert.h"
+#include <gtest/gtest.h>
+
+class Stream : public pkgDirStream
+{
+ public:
+ int count;
+ Stream () { count = 0; }
+ bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE { (void)Itm; (void)Fd; count++; return true; }
+ bool Fail(Item &Itm,int Fd) APT_OVERRIDE { (void)Itm; (void)Fd; return true; }
+ bool FinishedFile(Item &Itm,int Fd) APT_OVERRIDE { (void)Itm; (void)Fd; return true; }
+ ~Stream() {}
+};
+
+TEST(ExtractTar, ExtractTar)
+{
+ FileFd tgz;
+ ASSERT_NE(nullptr, GetTempFile("extracttar", false, &tgz));
+ ASSERT_TRUE(tgz.Close());
+ ASSERT_FALSE(tgz.Name().empty());
+ // FIXME: We should do the right thing… but its a test and nobody will ever…
+ // Proposal: The first one who sees this assert fail will have to write a patch.
+ ASSERT_EQ(std::string::npos, tgz.Name().find('\''));
+ EXPECT_EQ(0, system(("tar c /etc/passwd 2>/dev/null | gzip > " + tgz.Name()).c_str()));
+
+ FileFd fd(tgz.Name(), FileFd::ReadOnly);
+ RemoveFile("ExtractTarTest", tgz.Name());
+ ASSERT_TRUE(fd.IsOpen());
+ 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++) {
+ SCOPED_TRACE(i);
+ Stream stream;
+ fd.Seek(0);
+ tar.Go(stream);
+ if (_error->PendingError()) {
+ _error->DumpErrors();
+ EXPECT_FALSE(true);
+ }
+ EXPECT_EQ(stream.count, 1);
+ }
+}