summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-05-11 15:08:08 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-05-11 17:22:33 +0200
commit88593886a42025d51d76051da5929b044e42efee (patch)
tree6212ec08e3ac872573ca5faefb400a7914051bee /test
parent8d058ea53b18348f81229049a27d14282bd8d8c1 (diff)
rewrite all TFRewrite instances to use the new pkgTagSection::Write
While it is mostly busywork to rewrite all instances it actually fixes bugs as the data storage used by the new method is std::string rather than a char*, the later mostly created by c_str() from a std::string which the caller has to ensure keeps in scope – something apt-ftparchive actually didn't ensure and relied on copy-on-write behavior instead which c++11 forbids and hence the new default gcc abi doesn't use it.
Diffstat (limited to 'test')
-rwxr-xr-xtest/integration/test-apt-cli-show4
-rw-r--r--test/libapt/indexcopytosourcelist_test.cc2
-rw-r--r--test/libapt/tagsection_test.cc270
3 files changed, 273 insertions, 3 deletions
diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show
index 5604620fd..43072cf03 100755
--- a/test/integration/test-apt-cli-show
+++ b/test/integration/test-apt-cli-show
@@ -25,11 +25,11 @@ APTARCHIVE=$(readlink -f ./aptarchive)
# note that we do not display Description-md5 with the "apt" cmd
# and also show some additional fields that are calculated
testsuccessequal "Package: foo
+Version: 1.0
Priority: optional
Section: other
-Installed-Size: 43.0 kB
Maintainer: Joe Sixpack <joe@example.org>
-Version: 1.0
+Installed-Size: 43.0 kB
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: file:$APTARCHIVE/ unstable/main i386 Packages
diff --git a/test/libapt/indexcopytosourcelist_test.cc b/test/libapt/indexcopytosourcelist_test.cc
index bec87601f..1b0427564 100644
--- a/test/libapt/indexcopytosourcelist_test.cc
+++ b/test/libapt/indexcopytosourcelist_test.cc
@@ -16,7 +16,7 @@ class NoCopy : public IndexCopy {
return Path;
}
bool GetFile(std::string &/*Filename*/, unsigned long long &/*Size*/) { return false; }
- bool RewriteEntry(FILE * /*Target*/, std::string /*File*/) { return false; }
+ bool RewriteEntry(FileFd & /*Target*/, std::string const &/*File*/) { return false; }
const char *GetFileName() { return NULL; }
const char *Type() { return NULL; }
diff --git a/test/libapt/tagsection_test.cc b/test/libapt/tagsection_test.cc
new file mode 100644
index 000000000..f250177af
--- /dev/null
+++ b/test/libapt/tagsection_test.cc
@@ -0,0 +1,270 @@
+#include <config.h>
+
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/tagfile.h>
+
+#include <string>
+#include <sstream>
+
+#include <gtest/gtest.h>
+
+#include "file-helpers.h"
+
+std::string packageValue = "aaaa";
+std::string typoValue = "aa\n"
+ " .\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;;
+*/
+
+void setupTestcaseStart(FileFd &fd, pkgTagSection &section, std::string &content)
+{
+ 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"));
+ 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(typoRawValue, section.FindRawS("TypoA"));
+ EXPECT_EQ(1, section.FindI("Override"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(4, section.Count());
+}
+TEST(TagSectionTest,WriteUnmodified)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ EXPECT_TRUE(section.Write(fd));
+ 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(4, section.Count());
+}
+TEST(TagSectionTest,WriteUnmodifiedOrder)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ char const * const order[] = { "Package", "TypoA", "Override", NULL };
+ EXPECT_TRUE(section.Write(fd, order));
+ 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(4, section.Count());
+}
+TEST(TagSectionTest,WriteUnmodifiedOrderReversed)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ char const * const order[] = { "Override", "TypoA", "Package", NULL };
+ EXPECT_TRUE(section.Write(fd, order));
+ 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(4, section.Count());
+}
+TEST(TagSectionTest,WriteUnmodifiedOrderNotAll)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ char const * const order[] = { "Override", NULL };
+ EXPECT_TRUE(section.Write(fd, order));
+ 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(4, section.Count());
+}
+TEST(TagSectionTest,WriteNoOrderRename)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Rename("TypoA", "TypoB"));
+ EXPECT_TRUE(section.Write(fd, NULL, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_FALSE(section.Exists("TypoA"));
+ EXPECT_TRUE(section.Exists("TypoB"));
+ EXPECT_TRUE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(typoValue, section.FindS("TypoB"));
+ EXPECT_EQ(1, section.FindI("Override"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(4, section.Count());
+}
+TEST(TagSectionTest,WriteNoOrderRemove)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Remove("TypoA"));
+ rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", ""));
+ EXPECT_TRUE(section.Write(fd, NULL, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_FALSE(section.Exists("TypoA"));
+ EXPECT_FALSE(section.Exists("TypoB"));
+ EXPECT_FALSE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(2, section.Count());
+}
+TEST(TagSectionTest,WriteNoOrderRewrite)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "42"));
+ EXPECT_TRUE(section.Write(fd, NULL, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_TRUE(section.Exists("TypoA"));
+ EXPECT_FALSE(section.Exists("TypoB"));
+ EXPECT_TRUE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(42, section.FindI("Override"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(4, section.Count());
+}
+TEST(TagSectionTest,WriteOrderRename)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Rename("TypoA", "TypoB"));
+ char const * const order[] = { "Package", "TypoA", "Override", NULL };
+ EXPECT_TRUE(section.Write(fd, order, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_FALSE(section.Exists("TypoA"));
+ EXPECT_TRUE(section.Exists("TypoB"));
+ EXPECT_TRUE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(typoValue, section.FindS("TypoB"));
+ EXPECT_EQ(1, section.FindI("Override"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(4, section.Count());
+}
+TEST(TagSectionTest,WriteOrderRemove)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Remove("TypoA"));
+ rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", ""));
+ char const * const order[] = { "Package", "TypoA", "Override", NULL };
+ EXPECT_TRUE(section.Write(fd, order, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_FALSE(section.Exists("TypoA"));
+ EXPECT_FALSE(section.Exists("TypoB"));
+ EXPECT_FALSE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(2, section.Count());
+}
+TEST(TagSectionTest,WriteOrderRewrite)
+{
+ FileFd fd;
+ pkgTagSection section;
+ std::string content;
+ setupTestcaseStart(fd, section, content);
+ std::vector<pkgTagSection::Tag> rewrite;
+ rewrite.push_back(pkgTagSection::Tag::Rewrite("Override", "42"));
+ char const * const order[] = { "Package", "TypoA", "Override", NULL };
+ EXPECT_TRUE(section.Write(fd, order, rewrite));
+ EXPECT_TRUE(fd.Seek(0));
+ pkgTagFile tfile(&fd);
+ ASSERT_TRUE(tfile.Step(section));
+ EXPECT_TRUE(section.Exists("Package"));
+ EXPECT_TRUE(section.Exists("TypoA"));
+ EXPECT_FALSE(section.Exists("TypoB"));
+ EXPECT_TRUE(section.Exists("Override"));
+ EXPECT_TRUE(section.Exists("Override-Backup"));
+ EXPECT_EQ(packageValue, section.FindS("Package"));
+ EXPECT_EQ(42, section.FindI("Override"));
+ EXPECT_EQ(1, section.FindI("Override-Backup"));
+ EXPECT_EQ(4, section.Count());
+}