summaryrefslogtreecommitdiff
path: root/test/libapt/parsedepends_test.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
committerMichael Vogt <mvo@debian.org>2014-04-25 13:51:50 +0200
commit15ccc2a685b0b884b393e356f9960e86f97f532d (patch)
tree920a1fcf6fa2c92a05d0d1d2ccb22eb32b88522e /test/libapt/parsedepends_test.cc
parenta40c6649b99814c7d30964accdd5ecc4f1ce369a (diff)
parent506ab3c78fb67f5e452a1748f4870af767de5ebb (diff)
Merge branch 'debian/sid' into ubuntu/master
Conflicts: debian/changelog
Diffstat (limited to 'test/libapt/parsedepends_test.cc')
-rw-r--r--test/libapt/parsedepends_test.cc458
1 files changed, 233 insertions, 225 deletions
diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc
index 5564e2bc0..1e0afb66c 100644
--- a/test/libapt/parsedepends_test.cc
+++ b/test/libapt/parsedepends_test.cc
@@ -7,230 +7,238 @@
#include <string.h>
#include <string>
-#include "assert.h"
-
-int main() {
- std::string Package;
- std::string Version;
- unsigned int Op = 5;
- unsigned int Null = 0;
- bool StripMultiArch = true;
- bool ParseArchFlags = false;
- bool ParseRestrictionsList = false;
- _config->Set("APT::Architecture","amd64");
- _config->Set("APT::Build-Profiles","stage1");
-
- const char* Depends =
- "debhelper:any (>= 5.0), "
- "libdb-dev:any, "
- "gettext:native (<= 0.12), "
- "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
- "debiandoc-sgml, "
- "apt (>= 0.7.25), "
- "not-for-me [ !amd64 ], "
- "only-for-me [ amd64 ], "
- "any-for-me [ any ], "
- "not-for-darwin [ !darwin-any ], "
- "cpu-for-me [ any-amd64 ], "
- "os-for-me [ linux-any ], "
- "cpu-not-for-me [ any-armel ], "
- "os-not-for-me [ kfreebsd-any ], "
- "not-in-stage1 <!profile.stage1>, "
- "not-in-stage1-or-nodoc <!profile.nodoc !profile.stage1>, "
- "only-in-stage1 <unknown.unknown profile.stage1>, "
- "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
- ;
-
- unsigned short runner = 0;
+#include <gtest/gtest.h>
+
+static void parseDependency(bool const StripMultiArch, bool const ParseArchFlags, bool const ParseRestrictionsList)
+{
+ std::string Package;
+ std::string Version;
+ unsigned int Op = 5;
+ unsigned int Null = 0;
+ _config->Set("APT::Architecture","amd64");
+ _config->Set("APT::Build-Profiles","stage1");
+
+ const char* Depends =
+ "debhelper:any (>= 5.0), "
+ "libdb-dev:any, "
+ "gettext:native (<= 0.12), "
+ "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
+ "debiandoc-sgml, "
+ "apt (>= 0.7.25), "
+ "not-for-me [ !amd64 ], "
+ "only-for-me [ amd64 ], "
+ "any-for-me [ any ], "
+ "not-for-darwin [ !darwin-any ], "
+ "cpu-for-me [ any-amd64 ], "
+ "os-for-me [ linux-any ], "
+ "cpu-not-for-me [ any-armel ], "
+ "os-not-for-me [ kfreebsd-any ], "
+ "not-in-stage1 <!profile.stage1>, "
+ "not-in-stage1-or-nodoc <!profile.nodoc !profile.stage1>, "
+ "only-in-stage1 <unknown.unknown profile.stage1>, "
+ "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
+ ;
+
+ // Stripping MultiArch is currently the default setting to not confuse
+ // non-MultiArch capable users of the library with "strange" extensions.
+ const char* Start = Depends;
+ const char* End = Depends + strlen(Depends);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("debhelper", Package);
+ else
+ EXPECT_EQ("debhelper:any", Package);
+ EXPECT_EQ("5.0", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("libdb-dev", Package);
+ else
+ EXPECT_EQ("libdb-dev:any", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("gettext", Package);
+ else
+ EXPECT_EQ("gettext:native", Package);
+ EXPECT_EQ("0.12", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::LessEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("libcurl4-gnutls-dev", Package);
+ else
+ EXPECT_EQ("libcurl4-gnutls-dev:native", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Or, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("libcurl3-gnutls-dev", Package);
+ EXPECT_EQ("7.15.5", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("debiandoc-sgml", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("apt", Package);
+ EXPECT_EQ("0.7.25", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("only-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("any-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("not-for-darwin", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("cpu-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("os-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // cpu-not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // os-not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-in-stage1
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-in-stage1-or-in-nodoc
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("only-in-stage1", Package);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("overlord-dev", Package);
+ else
+ EXPECT_EQ("overlord-dev:any", Package);
+ EXPECT_EQ("7.15.3~", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
+
+ debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("overlord-dev", Package);
+ else
+ EXPECT_EQ("overlord-dev:native", Package);
+ EXPECT_EQ("7.15.5", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
+}
+
+// FIXME: This testcase is too big/complex
+TEST(ParseDependsTest, Everything)
+{
+ bool StripMultiArch = true;
+ bool ParseArchFlags = false;
+ bool ParseRestrictionsList = false;
+ unsigned short runner = 0;
+
test:
-// std::clog << (StripMultiArch ? "NO-Multi" : "Multi") << " " << (ParseArchFlags ? "Flags" : "NO-Flags") << std::endl;
-
- // Stripping MultiArch is currently the default setting to not confuse
- // non-MultiArch capable users of the library with "strange" extensions.
- const char* Start = Depends;
- const char* End = Depends + strlen(Depends);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("debhelper", Package);
- else
- equals("debhelper:any", Package);
- equals("5.0", Version);
- equals(Null | pkgCache::Dep::GreaterEq, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("libdb-dev", Package);
- else
- equals("libdb-dev:any", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("gettext", Package);
- else
- equals("gettext:native", Package);
- equals("0.12", Version);
- equals(Null | pkgCache::Dep::LessEq, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("libcurl4-gnutls-dev", Package);
- else
- equals("libcurl4-gnutls-dev:native", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::Or, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("libcurl3-gnutls-dev", Package);
- equals("7.15.5", Version);
- equals(Null | pkgCache::Dep::Greater, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("debiandoc-sgml", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("apt", Package);
- equals("0.7.25", Version);
- equals(Null | pkgCache::Dep::GreaterEq, Op);
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("", Package); // not-for-me
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("only-for-me", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("any-for-me", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("not-for-darwin", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("cpu-for-me", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("os-for-me", Package);
- equals("", Version);
- equals(Null | pkgCache::Dep::NoOp, Op);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("", Package); // cpu-not-for-me
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseArchFlags == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("", Package); // os-not-for-me
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseRestrictionsList == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("", Package); // not-in-stage1
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseRestrictionsList == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("", Package); // not-in-stage1-or-in-nodoc
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- if (ParseRestrictionsList == true) {
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- equals("only-in-stage1", Package);
- } else {
- equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
- Start = strstr(Start, ",");
- Start++;
- }
-
- Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("overlord-dev", Package);
- else
- equals("overlord-dev:any", Package);
- equals("7.15.3~", Version);
- equals(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
-
- debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
- if (StripMultiArch == true)
- equals("overlord-dev", Package);
- else
- equals("overlord-dev:native", Package);
- equals("7.15.5", Version);
- equals(Null | pkgCache::Dep::Greater, Op);
-
- if (StripMultiArch == false)
- if (ParseArchFlags == false)
- ParseRestrictionsList = !ParseRestrictionsList;
- ParseArchFlags = !ParseArchFlags;
- StripMultiArch = !StripMultiArch;
-
- runner++;
- if (runner < 8)
- goto test; // this is the prove: tests are really evil ;)
-
- return 0;
+ {
+ SCOPED_TRACE(std::string("StripMultiArch: ") + (StripMultiArch ? "true" : "false"));
+ SCOPED_TRACE(std::string("ParseArchFlags: ") + (ParseArchFlags ? "true" : "false"));
+ SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList ? "true" : "false"));
+ parseDependency(StripMultiArch, ParseArchFlags, ParseRestrictionsList);
+ }
+ if (StripMultiArch == false)
+ if (ParseArchFlags == false)
+ ParseRestrictionsList = !ParseRestrictionsList;
+ ParseArchFlags = !ParseArchFlags;
+ StripMultiArch = !StripMultiArch;
+
+ runner++;
+ if (runner < 8)
+ goto test; // this is the prove: tests are really evil ;)
}