diff options
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/commandline_test.cc | 29 | ||||
-rw-r--r-- | test/libapt/parsedepends_test.cc | 33 | ||||
-rw-r--r-- | test/libapt/strutil_test.cc | 15 |
3 files changed, 66 insertions, 11 deletions
diff --git a/test/libapt/commandline_test.cc b/test/libapt/commandline_test.cc index 26e80bfde..e403a28c8 100644 --- a/test/libapt/commandline_test.cc +++ b/test/libapt/commandline_test.cc @@ -56,3 +56,32 @@ TEST(CommandLineTest,Parsing) EXPECT_TRUE(c.FindB("Test::Worked", false)); EXPECT_FALSE(c.FindB("Test::Zero", false)); } + +TEST(CommandLineTest, BoolParsing) +{ + CommandLine::Args Args[] = { + { 't', 0, "Test::Worked", 0 }, + {0,0,0,0} + }; + ::Configuration c; + CommandLine CmdL(Args, &c); + + // the commandline parser used to use strtol() on the argument + // to check if the argument is a boolean expression - that + // stopped after the "0". this test ensures that we always check + // that the entire string was consumed by strtol + { + char const * argv[] = { "show", "-t", "0ad" }; + bool res = CmdL.Parse(sizeof(argv)/sizeof(char*), argv); + EXPECT_TRUE(res); + ASSERT_EQ(std::string(CmdL.FileList[0]), "0ad"); + } + + { + char const * argv[] = { "show", "-t", "0", "ad" }; + bool res = CmdL.Parse(sizeof(argv)/sizeof(char*), argv); + EXPECT_TRUE(res); + ASSERT_EQ(std::string(CmdL.FileList[0]), "ad"); + } + +} diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc index 1e0afb66c..f644599bd 100644 --- a/test/libapt/parsedepends_test.cc +++ b/test/libapt/parsedepends_test.cc @@ -23,7 +23,7 @@ static void parseDependency(bool const StripMultiArch, bool const ParseArchFlag "libdb-dev:any, " "gettext:native (<= 0.12), " "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), " - "debiandoc-sgml, " + "docbook-xml, " "apt (>= 0.7.25), " "not-for-me [ !amd64 ], " "only-for-me [ amd64 ], " @@ -33,9 +33,10 @@ static void parseDependency(bool const StripMultiArch, bool const ParseArchFlag "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>, " + "not-in-stage1 <!stage1>, " + "not-stage1-and-not-nodoc <!nodoc !stage1>, " + "not-stage1-or-not-nodoc <!nodoc> <!stage1>, " + "unknown-profile <unknown stage1>, " "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), " ; @@ -82,7 +83,7 @@ static void parseDependency(bool const StripMultiArch, bool const ParseArchFlag 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("docbook-xml", Package); EXPECT_EQ("", Version); EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op); @@ -184,7 +185,7 @@ static void parseDependency(bool const StripMultiArch, bool const ParseArchFlag if (ParseRestrictionsList == true) { Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); - EXPECT_EQ("", Package); // not-in-stage1-or-in-nodoc + EXPECT_EQ("", Package); // not-stage1-and-not-nodoc } else { EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); Start = strstr(Start, ","); @@ -193,7 +194,16 @@ static void parseDependency(bool const StripMultiArch, bool const ParseArchFlag if (ParseRestrictionsList == true) { Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList); - EXPECT_EQ("only-in-stage1", Package); + EXPECT_EQ("not-stage1-or-not-nodoc", Package); + } 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); // unknown-profile } else { EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList)); Start = strstr(Start, ","); @@ -232,10 +242,11 @@ test: SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList ? "true" : "false")); parseDependency(StripMultiArch, ParseArchFlags, ParseRestrictionsList); } - if (StripMultiArch == false) - if (ParseArchFlags == false) - ParseRestrictionsList = !ParseRestrictionsList; - ParseArchFlags = !ParseArchFlags; + if (StripMultiArch == false) { + if (ParseArchFlags == false) + ParseRestrictionsList = !ParseRestrictionsList; + ParseArchFlags = !ParseArchFlags; + } StripMultiArch = !StripMultiArch; runner++; diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index e9b778c6b..194c9c074 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -19,6 +19,21 @@ TEST(StrUtilTest,DeEscapeString) EXPECT_EQ("foo\\ x", DeEscapeString("foo\\\\ x")); EXPECT_EQ("\\foo\\", DeEscapeString("\\\\foo\\\\")); } +TEST(StrUtilTest,StringStrip) +{ + EXPECT_EQ("", APT::String::Strip("")); + EXPECT_EQ("foobar", APT::String::Strip("foobar")); + EXPECT_EQ("foo bar", APT::String::Strip("foo bar")); + + EXPECT_EQ("", APT::String::Strip(" ")); + EXPECT_EQ("", APT::String::Strip(" \r\n \t ")); + + EXPECT_EQ("foo bar", APT::String::Strip("foo bar ")); + EXPECT_EQ("foo bar", APT::String::Strip("foo bar \r\n \t ")); + EXPECT_EQ("foo bar", APT::String::Strip("\r\n \t foo bar")); + EXPECT_EQ("bar foo", APT::String::Strip("\r\n \t bar foo \r\n \t ")); + EXPECT_EQ("bar \t\r\n foo", APT::String::Strip("\r\n \t bar \t\r\n foo \r\n \t ")); +} TEST(StrUtilTest,StringSplitBasic) { std::vector<std::string> result = StringSplit("", ""); |