summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-07-15 14:12:50 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2017-07-26 19:09:04 +0200
commit3317ad864c997f4897756c0a2989c4199e9cda62 (patch)
tree1860985ad089486fc7eac2ed787a7057b9a693ac /test/libapt
parentf2f8e89f08cdf01c83a0b8ab053c65329d85ca90 (diff)
use FileFd to parse all apt configuration files
Using different ways of opening files means we have different behaviour and error messages for them, so by the same for all we can have more uniformity for users and apt developers alike.
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/configuration_test.cc41
-rw-r--r--test/libapt/fileutl_test.cc13
2 files changed, 52 insertions, 2 deletions
diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc
index bdc17cbf4..bfb7144ce 100644
--- a/test/libapt/configuration_test.cc
+++ b/test/libapt/configuration_test.cc
@@ -1,14 +1,14 @@
#include <config.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
#include <string>
#include <vector>
#include <gtest/gtest.h>
-//FIXME: Test for configuration file parsing;
-// currently only integration/ tests test them implicitly
+#include "file-helpers.h"
TEST(ConfigurationTest,Lists)
{
@@ -195,3 +195,40 @@ TEST(ConfigurationTest,Merge)
EXPECT_EQ("bar", Cnf.Find("option::foo"));
EXPECT_EQ("", Cnf.Find("option::empty"));
}
+TEST(ConfigurationTest, Parsing)
+{
+ Configuration Cnf;
+ std::string tempfile;
+ FileFd fd;
+ createTemporaryFile("doublesignedfile", fd, &tempfile, R"apt(
+SimpleOption "true";
+/* SimpleOption "false"; */
+Answer::Simple "42";
+# This is a comment
+List::Option { "In"; "One"; "Line"; };
+// this a comment as well
+List::Option2 { "Multi";
+"Line"; # inline comment
+ "Options";
+}; Trailing "true";
+/* Commented::Out "true"; */
+)apt");
+ EXPECT_TRUE(ReadConfigFile(Cnf, tempfile));
+ if (tempfile.empty() == false)
+ unlink(tempfile.c_str());
+ EXPECT_TRUE(Cnf.FindB("SimpleOption"));
+ EXPECT_EQ(42, Cnf.FindI("Answer::Simple"));
+ EXPECT_TRUE(Cnf.Exists("List::Option"));
+ auto const singleline = Cnf.FindVector("List::Option");
+ EXPECT_EQ(3, singleline.size());
+ EXPECT_EQ("In", singleline[0]);
+ EXPECT_EQ("One", singleline[1]);
+ EXPECT_EQ("Line", singleline[2]);
+ auto const multiline = Cnf.FindVector("List::Option2");
+ EXPECT_EQ(3, multiline.size());
+ EXPECT_EQ("Multi", multiline[0]);
+ EXPECT_EQ("Line", multiline[1]);
+ EXPECT_EQ("Options", multiline[2]);
+ EXPECT_TRUE(Cnf.FindB("Trailing"));
+ EXPECT_FALSE(Cnf.Exists("Commented::Out"));
+}
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 6cc850033..a702c16ec 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -152,6 +152,19 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission
EXPECT_EQ(strlen(expect), f.Tell());
}
#undef APT_INIT_READBACK
+ {
+ test.erase(test.length() - 1);
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ std::string line;
+ EXPECT_TRUE(f.ReadLine(line));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_EQ(line.length(), test.length());
+ EXPECT_EQ(line.length() + 1, f.Tell());
+ EXPECT_EQ(f.Size(), f.Tell());
+ EXPECT_EQ(line, test);
+ }
f.Close();
EXPECT_FALSE(f.IsOpen());