summaryrefslogtreecommitdiff
path: root/test/libapt/hashsums_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/hashsums_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/hashsums_test.cc')
-rw-r--r--test/libapt/hashsums_test.cc13
1 files changed, 3 insertions, 10 deletions
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index a8a826821..2d8079e5a 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -29,15 +29,10 @@ static void getSummationString(char const * const type, std::string &sum)
summation is a compressor – and open the 'compressed' file later on directly to
read out the summation sum calculated by it */
APT::Configuration::Compressor compress(type, ".ext", type, NULL, NULL, 99);
- std::string name("apt-test-");
- name.append("hashsums").append(".XXXXXX");
- char * tempfile = strdup(name.c_str());
- int tempfile_fd = mkstemp(tempfile);
- close(tempfile_fd);
- ASSERT_NE(-1, tempfile_fd);
FileFd fd;
- ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress));
+ auto const file = createTemporaryFile("hashsums");
+ ASSERT_TRUE(fd.Open(file.Name(), FileFd::WriteOnly | FileFd::Empty, compress));
ASSERT_TRUE(fd.IsOpen());
FileFd input("/etc/os-release", FileFd::ReadOnly);
ASSERT_TRUE(input.IsOpen());
@@ -48,12 +43,10 @@ static void getSummationString(char const * const type, std::string &sum)
ASSERT_FALSE(fd.Failed());
input.Close();
fd.Close();
- ASSERT_TRUE(fd.Open(tempfile, FileFd::ReadOnly, FileFd::None));
+ ASSERT_TRUE(fd.Open(file.Name(), FileFd::ReadOnly, FileFd::None));
ASSERT_TRUE(fd.IsOpen());
ASSERT_NE(0u, fd.FileSize());
ASSERT_FALSE(fd.Failed());
- unlink(tempfile);
- free(tempfile);
char readback[2000];
unsigned long long actual;
ASSERT_TRUE(fd.Read(readback, sizeof(readback)/sizeof(readback[0]), &actual));