From 549a391d6438e828001eeeaf235b080c054a7bf3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 08:14:41 +0200 Subject: Adding upstream version 2.2.4. Signed-off-by: Daniel Baumann --- test/libapt/extracttar_test.cc | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/libapt/extracttar_test.cc (limited to 'test/libapt/extracttar_test.cc') diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc new file mode 100644 index 0000000..ae74341 --- /dev/null +++ b/test/libapt/extracttar_test.cc @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +#include "assert.h" +#include + +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); + } +} -- cgit v1.2.3