summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/authconf_test.cc12
-rw-r--r--test/libapt/cdrom_test.cc9
-rw-r--r--test/libapt/configuration_test.cc10
-rw-r--r--test/libapt/extracttar_test.cc24
-rw-r--r--test/libapt/file-helpers.cc46
-rw-r--r--test/libapt/file-helpers.h18
-rw-r--r--test/libapt/fileutl_test.cc31
-rw-r--r--test/libapt/hashsums_test.cc13
-rw-r--r--test/libapt/openmaybeclearsignedfile_test.cc265
-rw-r--r--test/libapt/sourcelist_test.cc10
-rw-r--r--test/libapt/strutil_test.cc4
-rw-r--r--test/libapt/tagfile_test.cc12
-rw-r--r--test/libapt/tagsection_test.cc72
13 files changed, 179 insertions, 347 deletions
diff --git a/test/libapt/authconf_test.cc b/test/libapt/authconf_test.cc
index 04d54e9be..f703351cc 100644
--- a/test/libapt/authconf_test.cc
+++ b/test/libapt/authconf_test.cc
@@ -20,7 +20,7 @@ TEST(NetRCTest, Parsing)
EXPECT_EQ("file.not", U.Host);
EXPECT_EQ("/open", U.Path);
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
machine example.netter login bar password foo
machine example.net login foo password bar
@@ -138,7 +138,7 @@ machine socks5h://example.last/debian login debian password rules)apt");
TEST(NetRCTest, BadFileNoMachine)
{
FileFd fd;
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
foo example.org login foo1 password bar
machin example.org login foo2 password bar
machine2 example.org login foo3 password bar
@@ -152,7 +152,7 @@ machine2 example.org login foo3 password bar
TEST(NetRCTest, BadFileEndsMachine)
{
FileFd fd;
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
machine example.org login foo1 password bar
machine)apt");
@@ -176,7 +176,7 @@ machine)apt");
TEST(NetRCTest, BadFileEndsLogin)
{
FileFd fd;
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
machine example.org login foo1 password bar
machine example.net login)apt");
@@ -200,7 +200,7 @@ machine example.net login)apt");
TEST(NetRCTest, BadFileEndsPassword)
{
FileFd fd;
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
machine example.org login foo1 password bar
machine example.net password)apt");
@@ -225,7 +225,7 @@ machine example.net password)apt");
TEST(NetRCTest, MatchesOnlyHTTPS)
{
FileFd fd;
- createTemporaryFile("doublesignedfile", fd, nullptr, R"apt(
+ openTemporaryFile("doublesignedfile", fd, R"apt(
machine https.example login foo1 password bar
machine http://http.example login foo1 password bar
)apt");
diff --git a/test/libapt/cdrom_test.cc b/test/libapt/cdrom_test.cc
index b21492cb7..e2ec05ab8 100644
--- a/test/libapt/cdrom_test.cc
+++ b/test/libapt/cdrom_test.cc
@@ -91,16 +91,14 @@ TEST(CDROMTest,ReduceSourcelist)
}
TEST(CDROMTest, FindMountPointForDevice)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("mountpoints", fd, &tempfile,
+ auto const file = createTemporaryFile("mountpoints",
"rootfs / rootfs rw 0 0\n"
"sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
"sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
"/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n"
"/dev/sda1 /boot/efi vfat rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro 0 0\n"
"tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n");
- _config->Set("Dir::state::Mountpoints", tempfile);
+ _config->Set("Dir::state::Mountpoints", file.Name());
EXPECT_EQ("/", FindMountPointForDevice("rootfs"));
EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21"));
@@ -108,7 +106,4 @@ TEST(CDROMTest, FindMountPointForDevice)
EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0"));
EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));
-
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
}
diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc
index 8d6c404b3..4d297a9f2 100644
--- a/test/libapt/configuration_test.cc
+++ b/test/libapt/configuration_test.cc
@@ -198,9 +198,8 @@ TEST(ConfigurationTest,Merge)
TEST(ConfigurationTest, Parsing)
{
Configuration Cnf;
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("doublesignedfile", fd, &tempfile, R"apt(
+ {
+ auto const file = createTemporaryFile("doublesignedfile", R"apt(
SimpleOption "true";
/* SimpleOption "false"; */
Answer::Simple "42";
@@ -213,9 +212,8 @@ List::Option2 { "Multi";
}; Trailing "true";
/* Commented::Out "true"; */
)apt");
- EXPECT_TRUE(ReadConfigFile(Cnf, tempfile));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
+ EXPECT_TRUE(ReadConfigFile(Cnf, file.Name()));
+ }
EXPECT_TRUE(Cnf.FindB("SimpleOption"));
EXPECT_EQ(42, Cnf.FindI("Answer::Simple"));
EXPECT_TRUE(Cnf.Exists("List::Option"));
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);
diff --git a/test/libapt/file-helpers.cc b/test/libapt/file-helpers.cc
index aa16a2e30..85fc6838e 100644
--- a/test/libapt/file-helpers.cc
+++ b/test/libapt/file-helpers.cc
@@ -53,31 +53,31 @@ void helperCreateLink(std::string const &dir, std::string const &targetname, std
link.append(linkname);
ASSERT_EQ(0, symlink(target.c_str(), link.c_str()));
}
-void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content)
-{
- std::string name("apt-test-");
- name.append(id);
- size_t const giventmp = name.find(".XXXXXX.");
- if (giventmp == std::string::npos)
- name.append(".XXXXXX");
- char * tempfile = strdup(name.c_str());
- ASSERT_STRNE(NULL, tempfile);
- int tempfile_fd;
- if (giventmp == std::string::npos)
- tempfile_fd = mkstemp(tempfile);
- else
- tempfile_fd = mkstemps(tempfile, name.length() - (giventmp + 7));
- ASSERT_NE(-1, tempfile_fd);
- if (filename != NULL)
- *filename = tempfile;
- else
- unlink(tempfile);
- free(tempfile);
- EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite, true));
- if (content != NULL)
+void openTemporaryFile(std::string const &id, FileFd &fd, char const * const content, bool const ImmediateUnlink)
+{
+ EXPECT_NE(nullptr, GetTempFile("apt-" + id, ImmediateUnlink, &fd));
+ EXPECT_TRUE(ImmediateUnlink || not fd.Name().empty());
+ if (content != nullptr)
{
- ASSERT_TRUE(fd.Write(content, strlen(content)));
+ EXPECT_TRUE(fd.Write(content, strlen(content)));
+ EXPECT_TRUE(fd.Sync());
fd.Seek(0);
}
}
+ScopedFileDeleter::ScopedFileDeleter(std::string const &filename) : _filename{filename} {}
+ScopedFileDeleter::ScopedFileDeleter(ScopedFileDeleter &&sfd) = default;
+ScopedFileDeleter& ScopedFileDeleter::operator=(ScopedFileDeleter &&sfd) = default;
+ScopedFileDeleter::~ScopedFileDeleter() {
+ if (not _filename.empty())
+ RemoveFile("ScopedFileDeleter", _filename.c_str());
+}
+[[nodiscard]] ScopedFileDeleter createTemporaryFile(std::string const &id, char const * const content)
+{
+ FileFd fd;
+ openTemporaryFile(id, fd, content, false);
+ EXPECT_TRUE(fd.IsOpen());
+ EXPECT_TRUE(fd.Close());
+ EXPECT_FALSE(fd.Name().empty());
+ return ScopedFileDeleter{fd.Name()};
+}
diff --git a/test/libapt/file-helpers.h b/test/libapt/file-helpers.h
index f639c1cbc..4ce0fb2a3 100644
--- a/test/libapt/file-helpers.h
+++ b/test/libapt/file-helpers.h
@@ -22,8 +22,20 @@ void helperCreateDirectory(std::string const &dir, std::string const &name);
#define createLink(dir, targetname, linkname) \
ASSERT_NO_FATAL_FAILURE(helperCreateLink(dir, targetname, linkname))
void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
-#define createTemporaryFile(id, fd, filename, content) \
- ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
-void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content);
+
+class ScopedFileDeleter {
+ std::string _filename;
+public:
+ ScopedFileDeleter(std::string const &filename);
+ ScopedFileDeleter(ScopedFileDeleter const &) = delete;
+ ScopedFileDeleter(ScopedFileDeleter &&);
+ ScopedFileDeleter& operator=(ScopedFileDeleter const &) = delete;
+ ScopedFileDeleter& operator=(ScopedFileDeleter &&);
+ ~ScopedFileDeleter();
+
+ std::string Name() const { return _filename; }
+};
+void openTemporaryFile(std::string const &id, FileFd &fd, char const * const content = nullptr, bool const ImmediateUnlink = true);
+ScopedFileDeleter createTemporaryFile(std::string const &id, char const * const content = nullptr);
#endif
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 788ab76b2..ecab2eb50 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -23,15 +23,12 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission
strprintf(trace, "TestFileFd: Compressor: %s umask: %#o permission: %#o mode: %d", compressor.Name.c_str(), a_umask, ExpectedFilePermission, filemode);
SCOPED_TRACE(trace);
- static const char* fname = "apt-filefd-test.txt";
- if (FileExists(fname) == true)
- {
- EXPECT_EQ(0, unlink(fname));
- }
+ auto const file = createTemporaryFile("filefd-test");
+ EXPECT_TRUE(RemoveFile("TestFileFd", file.Name()));
FileFd f;
umask(a_umask);
- EXPECT_TRUE(f.Open(fname, filemode, compressor));
+ EXPECT_TRUE(f.Open(file.Name(), filemode, compressor));
EXPECT_TRUE(f.IsOpen());
EXPECT_FALSE(f.Failed());
EXPECT_EQ(umask(a_umask), a_umask);
@@ -45,7 +42,7 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission
EXPECT_FALSE(f.IsOpen());
EXPECT_FALSE(f.Failed());
- EXPECT_TRUE(f.Open(fname, FileFd::ReadOnly, compressor));
+ EXPECT_TRUE(f.Open(file.Name(), FileFd::ReadOnly, compressor));
EXPECT_TRUE(f.IsOpen());
EXPECT_FALSE(f.Failed());
EXPECT_FALSE(f.Eof());
@@ -172,8 +169,7 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission
// regression test for permission bug LP: #1304657
struct stat buf;
- EXPECT_EQ(0, stat(fname, &buf));
- EXPECT_EQ(0, unlink(fname));
+ EXPECT_EQ(0, stat(file.Name().c_str(), &buf));
EXPECT_EQ(ExpectedFilePermission, buf.st_mode & 0777);
}
@@ -385,24 +381,19 @@ static void TestFailingAtomicKeepsFile(char const * const label, std::string con
}
TEST(FileUtlTest, FailingAtomic)
{
- FileFd fd;
- std::string filename;
- createTemporaryFile("failingatomic", fd, &filename, TESTSTRING);
- TestFailingAtomicKeepsFile("init", filename);
+ auto const file = createTemporaryFile("failingatomic", TESTSTRING);
+ TestFailingAtomicKeepsFile("init", file.Name());
FileFd f;
- EXPECT_TRUE(f.Open(filename, FileFd::ReadWrite | FileFd::Atomic));
+ EXPECT_TRUE(f.Open(file.Name(), FileFd::ReadWrite | FileFd::Atomic));
f.EraseOnFailure();
EXPECT_FALSE(f.Failed());
EXPECT_TRUE(f.IsOpen());
- TestFailingAtomicKeepsFile("before-fail", filename);
+ TestFailingAtomicKeepsFile("before-fail", file.Name());
EXPECT_TRUE(f.Write("Bad file write", 10));
f.OpFail();
EXPECT_TRUE(f.Failed());
- TestFailingAtomicKeepsFile("after-fail", filename);
+ TestFailingAtomicKeepsFile("after-fail", file.Name());
EXPECT_TRUE(f.Close());
- TestFailingAtomicKeepsFile("closed", filename);
-
- if (filename.empty() == false)
- unlink(filename.c_str());
+ TestFailingAtomicKeepsFile("closed", file.Name());
}
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));
diff --git a/test/libapt/openmaybeclearsignedfile_test.cc b/test/libapt/openmaybeclearsignedfile_test.cc
index 0a4d4438a..4db89679a 100644
--- a/test/libapt/openmaybeclearsignedfile_test.cc
+++ b/test/libapt/openmaybeclearsignedfile_test.cc
@@ -13,12 +13,21 @@
/* The test files are created with the 'Joe Sixpack' and 'Marvin Paranoid'
test key included in the integration testing framework */
-TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile)
+static void EXPECT_SUCCESSFUL_PARSE(std::string const &tempfile)
{
- std::string tempfile;
FileFd fd;
+ EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
+ EXPECT_TRUE(fd.IsOpen());
+ char buffer[100];
+ EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
+ EXPECT_STREQ(buffer, "Test");
+ EXPECT_TRUE(fd.Eof());
+}
+
+TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile)
+{
// Using c++11 raw-strings would be nifty, but travis doesn't support it…
- createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("simplesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -33,23 +42,14 @@ TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
TEST(OpenMaybeClearSignedFileTest,WhitespaceSignedFile)
{
- std::string tempfile;
- FileFd fd;
// no raw-string here to protect the whitespace from cleanup
- createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- \t \n"
+ auto const file = createTemporaryFile("simplesignedfile", "-----BEGIN PGP SIGNED MESSAGE----- \t \n"
"Hash: SHA512 \n"
" \n"
"Test \n"
@@ -64,22 +64,13 @@ TEST(OpenMaybeClearSignedFileTest,WhitespaceSignedFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq \n"
"=TB1F \n"
"-----END PGP SIGNATURE-----");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
TEST(OpenMaybeClearSignedFileTest,SignedFileWithContentHeaders)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("headerssignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("headerssignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Version: 0.8.15~exp1\n"
"Hash: SHA512\n"
"Comment: I love you!\n"
@@ -100,22 +91,13 @@ TEST(OpenMaybeClearSignedFileTest,SignedFileWithContentHeaders)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
TEST(OpenMaybeClearSignedFileTest,SignedFileWithTwoSignatures)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("doublesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("doublesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -141,23 +123,29 @@ TEST(OpenMaybeClearSignedFileTest,SignedFileWithTwoSignatures)
"ASc9hsAZRG0xHuRU0F94V/XrkWw8QYAobJ/yxvs4L0EuA4optbSqawDB\n"
"=CP8j\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
-TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile)
+
+static void EXPECT_FAILED_PARSE(std::string const &tempfile, std::string const &error)
{
- std::string tempfile;
+ EXPECT_TRUE(_error->empty());
FileFd fd;
+ EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
+ EXPECT_FALSE(_error->empty());
+ EXPECT_FALSE(fd.IsOpen());
+ ASSERT_TRUE(_error->PendingError());
+
+ std::string msg;
+ EXPECT_TRUE(_error->PopMessage(msg));
+ EXPECT_EQ(msg, error);
+}
+
+TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile)
+{
// read only the first message
- createTemporaryFile("twosimplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("twosimplesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -188,41 +176,21 @@ TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile)
"=TB1F\n"
"-----END PGP SIGNATURE-----");
EXPECT_TRUE(_error->empty());
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
// technically they are signed, but we just want one message
- EXPECT_TRUE(_error->PendingError());
- std::string msg;
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg);
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unsigned lines.");
}
TEST(OpenMaybeClearSignedFileTest,UnsignedFile)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("unsignedfile", fd, &tempfile, "Test");
- EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ auto const file = createTemporaryFile("unsignedfile", "Test");
+ EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
TEST(OpenMaybeClearSignedFileTest,GarbageTop)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("garbagetop", fd, &tempfile, "Garbage\n"
+ auto const file = createTemporaryFile("garbagetop", "Garbage\n"
"-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
@@ -238,25 +206,13 @@ TEST(OpenMaybeClearSignedFileTest,GarbageTop)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(_error->empty());
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(fd.IsOpen());
- ASSERT_FALSE(_error->empty());
- ASSERT_TRUE(_error->PendingError());
-
- std::string msg;
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' does not start with a signed message block.", msg);
+ EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' does not start with a signed message block.");
}
TEST(OpenMaybeClearSignedFileTest,GarbageHeader)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("garbageheader", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n"
+ auto const file = createTemporaryFile("garbageheader", "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -271,11 +227,10 @@ TEST(OpenMaybeClearSignedFileTest,GarbageHeader)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile));
+ EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name()));
// beware: the file will be successfully opened as unsigned file
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
+ FileFd fd;
+ EXPECT_TRUE(OpenMaybeClearSignedFile(file.Name(), fd));
EXPECT_TRUE(fd.IsOpen());
char buffer[100];
EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
@@ -285,9 +240,7 @@ TEST(OpenMaybeClearSignedFileTest,GarbageHeader)
TEST(OpenMaybeClearSignedFileTest,GarbageBottom)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("garbagebottom", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("garbagebottom", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -303,68 +256,34 @@ TEST(OpenMaybeClearSignedFileTest,GarbageBottom)
"=TB1F\n"
"-----END PGP SIGNATURE-----\n"
"Garbage");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(_error->empty());
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(fd.IsOpen());
- ASSERT_FALSE(_error->empty());
- ASSERT_TRUE(_error->PendingError());
-
- std::string msg;
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unsigned lines.");
}
TEST(OpenMaybeClearSignedFileTest,BogusNoSig)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("bogusnosig", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(_error->empty());
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
- std::string msg;
- _error->PopMessage(msg);
- EXPECT_EQ("Splitting of clearsigned file " + tempfile + " failed as it doesn't contain all expected parts", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Splitting of clearsigned file " + file.Name() + " failed as it doesn't contain all expected parts");
}
TEST(OpenMaybeClearSignedFileTest,BogusSigStart)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("bogusnosig", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
"-----BEGIN PGP SIGNATURE-----");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(_error->empty());
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
- std::string msg;
- _error->PopMessage(msg);
- EXPECT_EQ("Signature in file " + tempfile + " wasn't closed", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Signature in file " + file.Name() + " wasn't closed");
}
TEST(OpenMaybeClearSignedFileTest,DashedSignedFile)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("dashedsignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("dashedsignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"- Test\n"
@@ -379,21 +298,12 @@ TEST(OpenMaybeClearSignedFileTest,DashedSignedFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_TRUE(fd.IsOpen());
- char buffer[100];
- EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer)));
- EXPECT_STREQ(buffer, "Test");
- EXPECT_TRUE(fd.Eof());
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_SUCCESSFUL_PARSE(file.Name());
}
TEST(OpenMaybeClearSignedFileTest,StrangeDashArmorFile)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"-Hash: SHA512\n"
"\n"
@@ -409,23 +319,12 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashArmorFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
- std::string msg;
- EXPECT_TRUE(_error->PendingError());
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (armor)", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (armor)");
}
TEST(OpenMaybeClearSignedFileTest,StrangeDashMsgFile)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"-Test\n"
@@ -440,23 +339,12 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashMsgFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
- std::string msg;
- EXPECT_TRUE(_error->PendingError());
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (msg)", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (msg)");
}
TEST(OpenMaybeClearSignedFileTest,StrangeDashSigFile)
{
- std::string tempfile;
- FileFd fd;
- createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n"
+ auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n"
"Hash: SHA512\n"
"\n"
"Test\n"
@@ -471,15 +359,6 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashSigFile)
"JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n"
"=TB1F\n"
"-----END PGP SIGNATURE-----\n");
- EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile));
- EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd));
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
- EXPECT_FALSE(_error->empty());
- EXPECT_FALSE(fd.IsOpen());
-
- std::string msg;
- EXPECT_TRUE(_error->PendingError());
- EXPECT_TRUE(_error->PopMessage(msg));
- EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (sig)", msg);
+ EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name()));
+ EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (sig)");
}
diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc
index 9441f56be..42fab65a9 100644
--- a/test/libapt/sourcelist_test.cc
+++ b/test/libapt/sourcelist_test.cc
@@ -14,9 +14,7 @@
TEST(SourceListTest,ParseFileDeb822)
{
- FileFd fd;
- std::string tempfile;
- createTemporaryFile("parsefiledeb822.XXXXXX.sources", fd, &tempfile,
+ auto const file = createTemporaryFile("parsefiledeb822.XXXXXX.sources",
"Types: deb\n"
"URIs: http://ftp.debian.org/debian\n"
"Suites: stable\n"
@@ -28,12 +26,8 @@ TEST(SourceListTest,ParseFileDeb822)
"URIs: http://ftp.debian.org/debian\n"
"Suites: unstable\n"
"Components: main non-free\n");
- fd.Close();
pkgSourceList sources;
- EXPECT_EQ(true, sources.Read(tempfile));
+ EXPECT_TRUE(sources.Read(file.Name()));
EXPECT_EQ(2u, sources.size());
-
- if (tempfile.empty() == false)
- unlink(tempfile.c_str());
}
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
index 5cb6cb9ff..b7132c35f 100644
--- a/test/libapt/strutil_test.cc
+++ b/test/libapt/strutil_test.cc
@@ -187,7 +187,7 @@ static void ReadMessagesTestWithNewLine(char const * const nl, char const * cons
"Description:\n"
" ccc";
- createTemporaryFile("readmessage", fd, NULL, (pkgA + nl + pkgB + nl + pkgC + nl).c_str());
+ openTemporaryFile("readmessage", fd, (pkgA + nl + pkgB + nl + pkgC + nl).c_str());
std::vector<std::string> list;
EXPECT_TRUE(ReadMessages(fd.Fd(), list));
EXPECT_EQ(3u, list.size());
@@ -196,7 +196,7 @@ static void ReadMessagesTestWithNewLine(char const * const nl, char const * cons
EXPECT_EQ(pkgC, list[2]);
size_t const msgsize = 63990;
- createTemporaryFile("readmessage", fd, NULL, NULL);
+ openTemporaryFile("readmessage", fd);
for (size_t j = 0; j < msgsize; ++j)
fd.Write(ab, strlen(ab));
for (size_t i = 0; i < 21; ++i)
diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc
index 919b46cdb..06ea01c32 100644
--- a/test/libapt/tagfile_test.cc
+++ b/test/libapt/tagfile_test.cc
@@ -16,7 +16,7 @@
TEST(TagFileTest,SingleField)
{
FileFd fd;
- createTemporaryFile("singlefield", fd, NULL, "FieldA-12345678: the value of the field");
+ openTemporaryFile("singlefield", fd, "FieldA-12345678: the value of the field");
pkgTagFile tfile(&fd);
pkgTagSection section;
@@ -41,7 +41,7 @@ TEST(TagFileTest,SingleField)
EXPECT_FALSE(section.Exists("FieldA-12345678"));
EXPECT_FALSE(section.Exists("FieldB-12345678"));
- createTemporaryFile("emptyfile", fd, NULL, NULL);
+ openTemporaryFile("emptyfile", fd);
ASSERT_FALSE(tfile.Step(section));
EXPECT_EQ(0u, section.Count());
}
@@ -49,7 +49,7 @@ TEST(TagFileTest,SingleField)
TEST(TagFileTest,MultipleSections)
{
FileFd fd;
- createTemporaryFile("bigsection", fd, NULL, "Package: pkgA\n"
+ openTemporaryFile("bigsection", fd, "Package: pkgA\n"
"Version: 1\n"
"Size: 100\n"
"Description: aaa\n"
@@ -140,7 +140,7 @@ TEST(TagFileTest,BigSection)
content << "Field-" << i << ": " << (2000 + i) << std::endl;
FileFd fd;
- createTemporaryFile("bigsection", fd, NULL, content.str().c_str());
+ openTemporaryFile("bigsection", fd, content.str().c_str());
pkgTagFile tfile(&fd);
pkgTagSection section;
@@ -230,7 +230,7 @@ TEST(TagFileTest, SpacesEverywhere)
TEST(TagFileTest, Comments)
{
FileFd fd;
- createTemporaryFile("commentfile", fd, NULL, "# Leading comments should be ignored.\n"
+ openTemporaryFile("commentfile", fd, "# Leading comments should be ignored.\n"
"\n"
"# A wild second comment appears!\n"
"\n"
@@ -289,7 +289,7 @@ TEST(TagFileTest, Comments)
TEST(TagFileTest, EmptyTagName)
{
FileFd fd;
- createTemporaryFile("emptytagname", fd, NULL, "0:\n"
+ openTemporaryFile("emptytagname", fd, "0:\n"
"PACKAGE:0\n"
"\n"
":\n"
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)
{