diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-09-04 13:53:10 +0200 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-09-04 13:53:10 +0200 |
commit | ad2d0cef574ff0143ee27cdbd058cba179368dbd (patch) | |
tree | c97a2f993eb141cfae880d90dc0f4ea57c4be2db /test/libapt | |
parent | f352743312edeebf666e1c8304cdc4baf457469f (diff) | |
parent | 056c36565706cad136df288db777c01555f4ecd9 (diff) |
merged from lp:~donkult/apt/debian-experimental
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/assert.h | 21 | ||||
-rw-r--r-- | test/libapt/commandline_test.cc | 32 | ||||
-rw-r--r-- | test/libapt/configuration_test.cc | 18 | ||||
-rw-r--r-- | test/libapt/getlanguages_test.cc | 21 | ||||
-rw-r--r-- | test/libapt/hashsums_test.cc | 22 | ||||
-rw-r--r-- | test/libapt/makefile | 6 | ||||
-rw-r--r-- | test/libapt/parsedepends_test.cc | 10 | ||||
-rwxr-xr-x | test/libapt/run-tests | 3 |
8 files changed, 121 insertions, 12 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h index a07be4b57..fdf6740c6 100644 --- a/test/libapt/assert.h +++ b/test/libapt/assert.h @@ -1,6 +1,7 @@ #include <iostream> #define equals(x,y) assertEquals(y, x, __LINE__) +#define equalsNot(x,y) assertEqualsNot(y, x, __LINE__) template < typename X, typename Y > void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) { @@ -14,6 +15,13 @@ void assertEquals(X expect, Y get, unsigned long const &line) { OutputAssertEqual(expect, "==", get, line); } +template < typename X, typename Y > +void assertEqualsNot(X expect, Y get, unsigned long const &line) { + if (expect != get) + return; + OutputAssertEqual(expect, "!=", get, line); +} + void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) { if (get < 0) OutputAssertEqual(expect, "==", get, line); @@ -80,6 +88,19 @@ void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const OutputAssertEqualOr3(expect1, expect2, expect3, "==", get, line); } +#define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__) + +template < typename X, typename Y > +void OutputAssertEqualOr4(X expect1, X expect2, X expect3, X expect4, char const* compare, Y get, unsigned long const &line) { + std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« or »" << expect4 << "« " << compare << " »" << get << "« at line " << line << std::endl; +} + +template < typename X, typename Y > +void assertEqualsOr4(X expect1, X expect2, X expect3, X expect4, Y get, unsigned long const &line) { + if (expect1 == get || expect2 == get || expect3 == get || expect4 == get) + return; + OutputAssertEqualOr4(expect1, expect2, expect3, expect4, "==", get, line); +} // simple helper to quickly output a vectors template < typename X > diff --git a/test/libapt/commandline_test.cc b/test/libapt/commandline_test.cc new file mode 100644 index 000000000..de8a30bd6 --- /dev/null +++ b/test/libapt/commandline_test.cc @@ -0,0 +1,32 @@ +#include <apt-pkg/cmndline.h> + +#include "assert.h" + +int main() +{ + CommandLine::Args Args[] = { + { 't', 0, "Test::Worked", 0 }, + { 'z', "zero", "Test::Zero", 0 }, + {0,0,0,0} + }; + CommandLine CmdL(Args,_config); + + char const * argv[] = { "test", "--zero", "-t" }; + CmdL.Parse(3 , argv); + equals(true, _config->FindB("Test::Worked", false)); + equals(true, _config->FindB("Test::Zero", false)); + + _config->Clear("Test"); + equals(false, _config->FindB("Test::Worked", false)); + equals(false, _config->FindB("Test::Zero", false)); + + _config->Set("Test::Zero", true); + equals(true, _config->FindB("Test::Zero", false)); + + char const * argv2[] = { "test", "--no-zero", "-t" }; + CmdL.Parse(3 , argv2); + equals(true, _config->FindB("Test::Worked", false)); + equals(false, _config->FindB("Test::Zero", false)); + + return 0; +} diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc index 9a3e2c118..87d5699ef 100644 --- a/test/libapt/configuration_test.cc +++ b/test/libapt/configuration_test.cc @@ -80,6 +80,24 @@ int main(int argc,const char *argv[]) { equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt"); equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude"); + Cnf.Set("RootDir", "/"); + equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt"); + equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude"); + Cnf.Set("RootDir", "//./////.////"); + equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt"); + equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude"); + Cnf.Set("RootDir", "/rootdir"); + equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt"); + equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude"); + Cnf.Set("RootDir", "/rootdir/"); + equals(Cnf.FindFile("Dir::State"), "/rootdir/srv/sid/var/lib/apt"); + equals(Cnf.FindFile("Dir::Aptitude::State"), "/rootdir/srv/sid/var/lib/aptitude"); + + Cnf.Set("Dir::State", "/dev/null"); + Cnf.Set("Dir::State::lists", "lists/"); + equals(Cnf.FindDir("Dir::State"), "/rootdir/dev/null"); + equals(Cnf.FindDir("Dir::State::lists"), "/rootdir/dev/null"); + //FIXME: Test for configuration file parsing; // currently only integration/ tests test them implicitly diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc index a1c801ea2..cef89bde6 100644 --- a/test/libapt/getlanguages_test.cc +++ b/test/libapt/getlanguages_test.cc @@ -126,18 +126,26 @@ int main(int argc,char *argv[]) _config->Set("Dir::State::lists", argv[1]); vec = APT::Configuration::getLanguages(true, false, env); - equals(vec.size(), 7); + equals(vec.size(), 8); equals(vec[0], "de_DE"); equals(vec[1], "de"); equals(vec[2], "en"); equals(vec[3], "none"); - equalsOr3(vec[4], "pt", "tr", "ast_DE"); - equalsOr3(vec[5], "tr", "pt", "ast_DE"); - equalsOr3(vec[6], "tr", "pt", "ast_DE"); + equalsOr4(vec[4], "pt", "tr", "ast_DE", "tlh_DE"); + equalsOr4(vec[5], "tr", "pt", "ast_DE", "tlh_DE"); + equalsOr4(vec[6], "tr", "pt", "ast_DE", "tlh_DE"); + equalsOr4(vec[7], "tr", "pt", "ast_DE", "tlh_DE"); + equalsNot(vec[4], vec[5]); + equalsNot(vec[4], vec[6]); + equalsNot(vec[4], vec[7]); + equalsNot(vec[5], vec[6]); + equalsNot(vec[5], vec[7]); + equalsNot(vec[6], vec[7]); _config->Set("Acquire::Languages", "none"); vec = APT::Configuration::getLanguages(true, false, env); - equals(vec.size(), 0); + equals(vec.size(), 1); + equals(vec[0], "none"); _config->Set("Acquire::Languages", ""); _config->Set("Dir::State::lists", "/non-existing-dir"); @@ -161,7 +169,8 @@ int main(int argc,char *argv[]) _config->Set("Acquire::Languages", "none"); env[0] = "de_DE.UTF-8"; vec = APT::Configuration::getLanguages(true, false, env); - equals(vec.size(), 0); + equals(vec.size(), 1); + equals(vec[0], "none"); _config->Set("Acquire::Languages", ""); //FIXME: Remove support for this deprecated setting diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index 396e4cf6b..e2d0aec5b 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -42,6 +42,28 @@ template <class T> void TestMill(const char *Out) int main(int argc, char** argv) { + // test HashSumValue which doesn't calculate but just stores sums + { + string md5sum = argv[2]; + MD5SumValue md5(md5sum); + equals(md5.Value(), md5sum); + } + { + string sha1sum = argv[3]; + SHA1SumValue sha1(sha1sum); + equals(sha1.Value(), sha1sum); + } + { + string sha2sum = argv[4]; + SHA256SumValue sha2(sha2sum); + equals(sha2.Value(), sha2sum); + } + { + string sha2sum = argv[5]; + SHA512SumValue sha2(sha2sum); + equals(sha2.Value(), sha2sum); + } + // From FIPS PUB 180-1 Test<SHA1Summation>("","da39a3ee5e6b4b0d3255bfef95601890afd80709"); Test<SHA1Summation>("abc","a9993e364706816aba3e25717850c26c9cd0d89d"); diff --git a/test/libapt/makefile b/test/libapt/makefile index 1952051e2..b2e6db2dd 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -34,6 +34,12 @@ SOURCE = getlistoffilesindir_test.cc include $(PROGRAM_H) # Program for testing CommandLine reconstruction +PROGRAM = Commandline${BASENAME} +SLIBS = -lapt-pkg +SOURCE = commandline_test.cc +include $(PROGRAM_H) + +# Program for testing CommandLine reconstruction PROGRAM = CommandlineAsString${BASENAME} SLIBS = -lapt-pkg SOURCE = commandlineasstring_test.cc diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc index b5d92d9d2..677b1c892 100644 --- a/test/libapt/parsedepends_test.cc +++ b/test/libapt/parsedepends_test.cc @@ -10,7 +10,7 @@ int main(int argc,char *argv[]) { unsigned int Null = 0; bool StripMultiArch = true; bool ParseArchFlags = false; - _config->Set("APT::Architecture","dsk"); + _config->Set("APT::Architecture","amd64"); const char* Depends = "debhelper:any (>= 5.0), " @@ -19,13 +19,13 @@ int main(int argc,char *argv[]) { "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), " "debiandoc-sgml, " "apt (>= 0.7.25), " - "not-for-me [ !dsk ], " - "only-for-me [ dsk ], " + "not-for-me [ !amd64 ], " + "only-for-me [ amd64 ], " "any-for-me [ any ], " "not-for-darwin [ !darwin-any ], " - "cpu-for-me [ any-dsk ], " + "cpu-for-me [ any-amd64 ], " "os-for-me [ linux-any ], " - "cpu-not-for-me [ any-amd64 ], " + "cpu-not-for-me [ any-armel ], " "os-not-for-me [ kfreebsd-any ], " "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), " ; diff --git a/test/libapt/run-tests b/test/libapt/run-tests index 4ea9a916d..45a3157f7 100755 --- a/test/libapt/run-tests +++ b/test/libapt/run-tests @@ -65,7 +65,8 @@ do "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" \ - "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-ast_DE" + "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-ast_DE" \ + "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tlh%5fDE" elif [ $name = "HashSums${EXT}" ]; then TMP="$(readlink -f "./${0}")" echo -n "Testing with ${NAME} " |