summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/assert.h21
-rw-r--r--test/libapt/cdromreducesourcelist_test.cc86
-rw-r--r--test/libapt/commandline_test.cc32
-rw-r--r--test/libapt/configuration_test.cc18
-rw-r--r--test/libapt/getlanguages_test.cc21
-rw-r--r--test/libapt/hashsums_test.cc22
-rw-r--r--test/libapt/indexcopytosourcelist_test.cc86
-rw-r--r--test/libapt/makefile18
-rw-r--r--test/libapt/parsedepends_test.cc10
-rwxr-xr-xtest/libapt/run-tests7
10 files changed, 307 insertions, 14 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/cdromreducesourcelist_test.cc b/test/libapt/cdromreducesourcelist_test.cc
new file mode 100644
index 000000000..729da23a6
--- /dev/null
+++ b/test/libapt/cdromreducesourcelist_test.cc
@@ -0,0 +1,86 @@
+#include <apt-pkg/cdrom.h>
+#include <apt-pkg/error.h>
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include "assert.h"
+
+class Cdrom : public pkgCdrom {
+public:
+ std::vector<std::string> ReduceSourcelist(std::string CD,std::vector<std::string> List) {
+ pkgCdrom::ReduceSourcelist(CD, List);
+ return List;
+ }
+};
+
+int main(int argc, char const *argv[]) {
+ Cdrom cd;
+ std::vector<std::string> List;
+ std::string CD("/media/cdrom/");
+
+ std::vector<std::string> R = cd.ReduceSourcelist(CD, List);
+ equals(R.empty(), true);
+
+ List.push_back(" wheezy main");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 1);
+ equals(R[0], " wheezy main");
+
+ List.push_back(" wheezy main");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 1);
+ equals(R[0], " wheezy main");
+
+ List.push_back(" wheezy contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 1);
+ equals(R[0], " wheezy contrib main");
+
+ List.push_back(" wheezy-update contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 2);
+ equals(R[0], " wheezy contrib main");
+ equals(R[1], " wheezy-update contrib");
+
+ List.push_back(" wheezy-update contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 2);
+ equals(R[0], " wheezy contrib main");
+ equals(R[1], " wheezy-update contrib");
+
+ List.push_back(" wheezy-update non-free");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 2);
+ equals(R[0], " wheezy contrib main");
+ equals(R[1], " wheezy-update contrib non-free");
+
+ List.push_back(" wheezy-update main");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 2);
+ equals(R[0], " wheezy contrib main");
+ equals(R[1], " wheezy-update contrib main non-free");
+
+ List.push_back(" wheezy non-free");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 2);
+ equals(R[0], " wheezy contrib main non-free");
+ equals(R[1], " wheezy-update contrib main non-free");
+
+ List.push_back(" sid main");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 3);
+ equals(R[0], " sid main");
+ equals(R[1], " wheezy contrib main non-free");
+ equals(R[2], " wheezy-update contrib main non-free");
+
+ List.push_back(" sid main-reduce");
+ R = cd.ReduceSourcelist(CD, List);
+ equals(R.size(), 3);
+ equals(R[0], " sid main main-reduce");
+ equals(R[1], " wheezy contrib main non-free");
+ equals(R[2], " wheezy-update contrib main non-free");
+
+ return 0;
+}
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/indexcopytosourcelist_test.cc b/test/libapt/indexcopytosourcelist_test.cc
new file mode 100644
index 000000000..69d8fae86
--- /dev/null
+++ b/test/libapt/indexcopytosourcelist_test.cc
@@ -0,0 +1,86 @@
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/indexcopy.h>
+
+#include <string>
+
+#include "assert.h"
+
+class NoCopy : public IndexCopy {
+public:
+ std::string ConvertToSourceList(std::string CD,std::string Path) {
+ IndexCopy::ConvertToSourceList(CD, Path);
+ return Path;
+ }
+ bool GetFile(std::string &Filename,unsigned long long &Size) { return false; }
+ bool RewriteEntry(FILE *Target,std::string File) { return false; }
+ const char *GetFileName() { return NULL; }
+ const char *Type() { return NULL; }
+
+};
+
+int main(int argc, char const *argv[]) {
+ NoCopy ic;
+ std::string const CD("/media/cdrom/");
+
+ char const * Releases[] = { "unstable", "wheezy-updates", NULL };
+ char const * Components[] = { "main", "non-free", NULL };
+
+ for (char const ** Release = Releases; *Release != NULL; ++Release) {
+ for (char const ** Component = Components; *Component != NULL; ++Component) {
+ std::string const Path = std::string("dists/") + *Release + "/" + *Component + "/";
+ std::string const Binary = Path + "binary-";
+ std::string const A = Binary + "armel/";
+ std::string const B = Binary + "mips/";
+ std::string const C = Binary + "kfreebsd-mips/";
+ std::string const S = Path + "source/";
+ std::string const List = std::string(*Release) + " " + *Component;
+
+ _config->Clear("APT");
+ APT::Configuration::getArchitectures(false);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+ _config->Clear("APT");
+ _config->Set("APT::Architecture", "mips");
+ _config->Set("APT::Architectures::", "mips");
+ APT::Configuration::getArchitectures(false);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), List);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+ _config->Clear("APT");
+ _config->Set("APT::Architecture", "kfreebsd-mips");
+ _config->Set("APT::Architectures::", "kfreebsd-mips");
+ APT::Configuration::getArchitectures(false);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), A);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), List);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+ _config->Clear("APT");
+ _config->Set("APT::Architecture", "armel");
+ _config->Set("APT::Architectures::", "armel");
+ APT::Configuration::getArchitectures(false);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), List);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), B);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+
+ _config->Clear("APT");
+ _config->Set("APT::Architecture", "armel");
+ _config->Set("APT::Architectures::", "armel");
+ _config->Set("APT::Architectures::", "mips");
+ APT::Configuration::getArchitectures(false);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + A), List);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + B), List);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + C), C);
+ equals(ic.ConvertToSourceList("/media/cdrom/", CD + S), List);
+ }
+ }
+
+ return 0;
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index 1952051e2..5e225f240 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
@@ -80,3 +86,15 @@ PROGRAM = CdromFindPackages${BASENAME}
SLIBS = -lapt-pkg
SOURCE = cdromfindpackages_test.cc
include $(PROGRAM_H)
+
+# test cdroms index reduction for source.list
+PROGRAM = CdromReduceSourceList${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = cdromreducesourcelist_test.cc
+include $(PROGRAM_H)
+
+# text IndexCopy::ConvertToSourceList
+PROGRAM = IndexCopyToSourceList${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = indexcopytosourcelist_test.cc
+include $(PROGRAM_H)
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 d4341412d..45a3157f7 100755
--- a/test/libapt/run-tests
+++ b/test/libapt/run-tests
@@ -65,11 +65,12 @@ 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 \033[1;35m${name}\033[0m ... "
- LD_LIBRARY_PATH=${LDPATH} ${testapp} $TMP $(md5sum $TMP | cut -d' ' -f 1) $(sha1sum $TMP | cut -d' ' -f 1) $(sha256sum $TMP | cut -d' ' -f 1) $(sha512sum $TMP | cut -d' ' -f 1) && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m"
+ echo -n "Testing with ${NAME} "
+ LD_LIBRARY_PATH=${LDPATH} ${testapp} $TMP $(md5sum $TMP | cut -d' ' -f 1) $(sha1sum $TMP | cut -d' ' -f 1) $(sha256sum $TMP | cut -d' ' -f 1) $(sha512sum $TMP | cut -d' ' -f 1) && echo "$TESTOKAY" || echo "$TESTFAIL"
continue
elif [ $name = "CompareVersion${EXT}" ]; then
tmppath="${DIR}/versions.lst"