diff options
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/assert.h | 21 | ||||
-rw-r--r-- | test/libapt/getlanguages_test.cc | 91 | ||||
-rw-r--r-- | test/libapt/makefile | 19 | ||||
-rw-r--r-- | test/libapt/parsedepends_test.cc | 128 |
4 files changed, 259 insertions, 0 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h new file mode 100644 index 000000000..5da76ae0a --- /dev/null +++ b/test/libapt/assert.h @@ -0,0 +1,21 @@ +#include <iostream> + +#define equals(x,y) assertEquals(x, y, __LINE__) + +template < typename X, typename Y > +void OutputAssert(X expect, char const* compare, Y get, unsigned long const &line) { + std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl; +} + +template < typename X, typename Y > +void assertEquals(X expect, Y get, unsigned long const &line) { + if (expect == get) + return; + OutputAssert(expect, "==", get, line); +} + +void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) { + if (get < 0) + OutputAssert(expect, "==", get, line); + assertEquals<unsigned int const&, unsigned int const&>(expect, get, line); +} diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc new file mode 100644 index 000000000..fd3c8269f --- /dev/null +++ b/test/libapt/getlanguages_test.cc @@ -0,0 +1,91 @@ +#include <apt-pkg/aptconfiguration.h> +#include <apt-pkg/configuration.h> + +#include "assert.h" +#include <string> +#include <vector> + +#include <iostream> + +// simple helper to quickly output a vector of strings +void dumpVector(std::vector<std::string> vec) { + for (std::vector<std::string>::const_iterator v = vec.begin(); + v != vec.end(); v++) + std::cout << *v << std::endl; +} + +int main(int argc,char *argv[]) +{ + std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + equals(vec.size(), 2); + equals(vec[0], "de"); + equals(vec[1], "en"); + + // Special: Check if the cache is actually in use + vec = APT::Configuration::getLanguages(false, true, "en_GB.UTF-8"); + equals(vec.size(), 2); + equals(vec[0], "de"); + equals(vec[1], "en"); + + vec = APT::Configuration::getLanguages(false, false, "en_GB.UTF-8"); + equals(vec.size(), 2); + equals(vec[0], "en_GB"); + equals(vec[1], "en"); + + vec = APT::Configuration::getLanguages(false, false, "pt_PR.UTF-8"); + equals(vec.size(), 3); + equals(vec[0], "pt_PR"); + equals(vec[1], "pt"); + equals(vec[2], "en"); + + vec = APT::Configuration::getLanguages(false, false, "ast_DE.UTF-8"); // bogus, but syntactical correct + equals(vec.size(), 2); + equals(vec[0], "ast"); + equals(vec[1], "en"); + + vec = APT::Configuration::getLanguages(false, false, "C"); + equals(vec.size(), 1); + equals(vec[0], "en"); + + _config->Set("Acquire::Languages::1", "environment"); + _config->Set("Acquire::Languages::2", "en"); + vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + equals(vec.size(), 2); + equals(vec[0], "de"); + equals(vec[1], "en"); + + _config->Set("Acquire::Languages::3", "de"); + vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + equals(vec.size(), 2); + equals(vec[0], "de"); + equals(vec[1], "en"); + + _config->Set("Acquire::Languages::1", "none"); + vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + equals(vec.size(), 0); + vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); + equals(vec[0], "en"); + equals(vec[1], "de"); + + _config->Set("Acquire::Languages::1", "fr"); + _config->Set("Acquire::Languages", "de_DE"); + vec = APT::Configuration::getLanguages(false, false, "de_DE.UTF-8"); + equals(vec.size(), 1); + equals(vec[0], "de_DE"); + + _config->Set("Acquire::Languages", "none"); + vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); + equals(vec.size(), 0); + + _config->Set("Acquire::Languages", ""); + //FIXME: Remove support for this deprecated setting + _config->Set("APT::Acquire::Translation", "ast_DE"); + vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); + equals(vec.size(), 1); + equals(vec[0], "ast_DE"); + _config->Set("APT::Acquire::Translation", "none"); + vec = APT::Configuration::getLanguages(true, false, "de_DE.UTF-8"); + equals(vec.size(), 0); + + return 0; +} diff --git a/test/libapt/makefile b/test/libapt/makefile new file mode 100644 index 000000000..5712c025a --- /dev/null +++ b/test/libapt/makefile @@ -0,0 +1,19 @@ +# -*- make -*- +BASE=../.. +SUBDIR=test/libapt +BASENAME=_libapt_test + +# Bring in the default rules +include ../../buildlib/defaults.mak + +# Program for testing getLanguageCode +PROGRAM = getLanguages${BASENAME} +SLIBS = -lapt-pkg +SOURCE = getlanguages_test.cc +include $(PROGRAM_H) + +# Program for testing ParseDepends +PROGRAM = ParseDepends${BASENAME} +SLIBS = -lapt-pkg +SOURCE = parsedepends_test.cc +include $(PROGRAM_H) diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc new file mode 100644 index 000000000..b7befa561 --- /dev/null +++ b/test/libapt/parsedepends_test.cc @@ -0,0 +1,128 @@ +#include <apt-pkg/deblistparser.h> +#include <apt-pkg/configuration.h> + +#include "assert.h" + +int main(int argc,char *argv[]) { + string Package; + string Version; + unsigned int Op = 5; + unsigned int Null = 0; + bool StripMultiArch = true; + bool ParseArchFlags = false; + _config->Set("APT::Architecture","dsk"); + + 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 [ !dsk ], " + "only-for-me [ dsk ], " + "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), " + ; + + 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); + 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); + 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); + 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); + 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); + 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); + equals("debiandoc-sgml", Package); + equals("", Version); + equals(Null | pkgCache::Dep::NoOp, Op); + + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + 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); + equals("", Package); // not-for-me + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + 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)); + Start = strstr(Start, ","); + Start++; + } + + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + 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); + + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + 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) + ParseArchFlags = true; + StripMultiArch = !StripMultiArch; + + runner++; + if (runner < 4) + goto test; // this is the prove: tests are really evil ;) + + return 0; +} |