summaryrefslogtreecommitdiff
path: root/test/libapt/extracttar_test.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-05-18 11:55:54 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2020-05-18 15:55:36 +0200
commitc470d92366d7c3c239a689f0a10d6d0d9daafbff (patch)
tree955534f65524c3f81f36119012b6cd995a9619d0 /test/libapt/extracttar_test.cc
parent37cc8dcda9e97e0b9420d37bb886081fa629847d (diff)
Allow prefix to be a complete filename for GetTempFile
Our testcases had their own implementation of GetTempFile with the feature of a temporary file with a choosen suffix. Merging this into GetTempFile lets us drop this duplicate and hence test more our code rather than testing our helpers for test implementation. And then hashsums_test had another implementation… and extracttar wasn't even trying to use a real tempfile… one GetTempFile to rule them all! That also ensures that these tempfiles are created in a temporary directory rather than the current directory which is a nice touch and tries a little harder to clean up those tempfiles.
Diffstat (limited to 'test/libapt/extracttar_test.cc')
-rw-r--r--test/libapt/extracttar_test.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc
index 67e0461c2..ae74341e6 100644
--- a/test/libapt/extracttar_test.cc
+++ b/test/libapt/extracttar_test.cc
@@ -12,24 +12,32 @@ 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() {}
+ 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)
{
- EXPECT_EQ(system("tar c /etc/passwd 2>/dev/null | gzip > tar.tgz"), 0);
+ 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("tar.tgz", FileFd::ReadOnly);
- unlink("tar.tgz");
+ 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);