summaryrefslogtreecommitdiff
path: root/test/libapt/tagsection_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/tagsection_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/tagsection_test.cc')
-rw-r--r--test/libapt/tagsection_test.cc72
1 files changed, 17 insertions, 55 deletions
diff --git a/test/libapt/tagsection_test.cc b/test/libapt/tagsection_test.cc
index 3f170b25a..80cecca5b 100644
--- a/test/libapt/tagsection_test.cc
+++ b/test/libapt/tagsection_test.cc
@@ -16,23 +16,9 @@ std::string typoValue = "aa\n"
" cc";
std::string typoRawValue = "\n " + typoValue;
std::string overrideValue = "1";
-/*
- std::cerr << "FILECONTENT: »";
- char buffer[3000];
- while (fd.ReadLine(buffer, sizeof(buffer)))
- std::cerr << buffer;
- std::cerr << "«" << std::endl;;
-*/
-static void setupTestcaseStart(FileFd &fd, pkgTagSection &section, std::string &content)
+static void EXPECT_SECTION_WITH_ALL_CONTENT(pkgTagSection const &section)
{
- createTemporaryFile("writesection", fd, NULL, NULL);
- content = "Package: " + packageValue + "\n"
- "TypoA:\n " + typoValue + "\n"
- "Override: " + overrideValue + "\n"
- "Override-Backup: " + overrideValue + "\n"
- "\n";
- EXPECT_TRUE(section.Scan(content.c_str(), content.length(), true));
EXPECT_TRUE(section.Exists("Package"));
EXPECT_TRUE(section.Exists("TypoA"));
EXPECT_TRUE(section.Exists("Override"));
@@ -45,6 +31,18 @@ static void setupTestcaseStart(FileFd &fd, pkgTagSection &section, std::string &
EXPECT_EQ(1, section.FindI("Override-Backup"));
EXPECT_EQ(4u, section.Count());
}
+
+static void setupTestcaseStart(FileFd &fd, pkgTagSection &section, std::string &content)
+{
+ openTemporaryFile("writesection", fd);
+ content = "Package: " + packageValue + "\n"
+ "TypoA:\n " + typoValue + "\n"
+ "Override: " + overrideValue + "\n"
+ "Override-Backup: " + overrideValue + "\n"
+ "\n";
+ EXPECT_TRUE(section.Scan(content.c_str(), content.length(), true));
+ EXPECT_SECTION_WITH_ALL_CONTENT(section);
+}
TEST(TagSectionTest,WriteUnmodified)
{
FileFd fd;
@@ -55,16 +53,7 @@ TEST(TagSectionTest,WriteUnmodified)
EXPECT_TRUE(fd.Seek(0));
pkgTagFile tfile(&fd);
ASSERT_TRUE(tfile.Step(section));
- EXPECT_TRUE(section.Exists("Package"));
- EXPECT_TRUE(section.Exists("TypoA"));
- EXPECT_TRUE(section.Exists("Override"));
- EXPECT_TRUE(section.Exists("Override-Backup"));
- EXPECT_FALSE(section.Exists("TypoB"));
- EXPECT_EQ(packageValue, section.FindS("Package"));
- EXPECT_EQ(typoValue, section.FindS("TypoA"));
- EXPECT_EQ(1, section.FindI("Override"));
- EXPECT_EQ(1, section.FindI("Override-Backup"));
- EXPECT_EQ(4u, section.Count());
+ EXPECT_SECTION_WITH_ALL_CONTENT(section);
}
TEST(TagSectionTest,WriteUnmodifiedOrder)
{
@@ -77,16 +66,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrder)
EXPECT_TRUE(fd.Seek(0));
pkgTagFile tfile(&fd);
ASSERT_TRUE(tfile.Step(section));
- EXPECT_TRUE(section.Exists("Package"));
- EXPECT_TRUE(section.Exists("TypoA"));
- EXPECT_TRUE(section.Exists("Override"));
- EXPECT_TRUE(section.Exists("Override-Backup"));
- EXPECT_FALSE(section.Exists("TypoB"));
- EXPECT_EQ(packageValue, section.FindS("Package"));
- EXPECT_EQ(typoValue, section.FindS("TypoA"));
- EXPECT_EQ(1, section.FindI("Override"));
- EXPECT_EQ(1, section.FindI("Override-Backup"));
- EXPECT_EQ(4u, section.Count());
+ EXPECT_SECTION_WITH_ALL_CONTENT(section);
}
TEST(TagSectionTest,WriteUnmodifiedOrderReversed)
{
@@ -99,16 +79,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrderReversed)
EXPECT_TRUE(fd.Seek(0));
pkgTagFile tfile(&fd);
ASSERT_TRUE(tfile.Step(section));
- EXPECT_TRUE(section.Exists("Package"));
- EXPECT_TRUE(section.Exists("TypoA"));
- EXPECT_TRUE(section.Exists("Override"));
- EXPECT_TRUE(section.Exists("Override-Backup"));
- EXPECT_FALSE(section.Exists("TypoB"));
- EXPECT_EQ(packageValue, section.FindS("Package"));
- EXPECT_EQ(typoValue, section.FindS("TypoA"));
- EXPECT_EQ(1, section.FindI("Override"));
- EXPECT_EQ(1, section.FindI("Override-Backup"));
- EXPECT_EQ(4u, section.Count());
+ EXPECT_SECTION_WITH_ALL_CONTENT(section);
}
TEST(TagSectionTest,WriteUnmodifiedOrderNotAll)
{
@@ -121,16 +92,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrderNotAll)
EXPECT_TRUE(fd.Seek(0));
pkgTagFile tfile(&fd);
ASSERT_TRUE(tfile.Step(section));
- EXPECT_TRUE(section.Exists("Package"));
- EXPECT_TRUE(section.Exists("TypoA"));
- EXPECT_TRUE(section.Exists("Override"));
- EXPECT_TRUE(section.Exists("Override-Backup"));
- EXPECT_FALSE(section.Exists("TypoB"));
- EXPECT_EQ(packageValue, section.FindS("Package"));
- EXPECT_EQ(typoValue, section.FindS("TypoA"));
- EXPECT_EQ(1, section.FindI("Override"));
- EXPECT_EQ(1, section.FindI("Override-Backup"));
- EXPECT_EQ(4u, section.Count());
+ EXPECT_SECTION_WITH_ALL_CONTENT(section);
}
TEST(TagSectionTest,WriteNoOrderRename)
{