summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libapt/assert.h21
-rw-r--r--test/libapt/getlanguages_test.cc91
-rw-r--r--test/libapt/getlistoffilesindir_test.cc82
-rw-r--r--test/libapt/makefile25
-rw-r--r--test/libapt/parsedepends_test.cc128
-rwxr-xr-xtest/libapt/run-tests.sh50
6 files changed, 393 insertions, 4 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/getlistoffilesindir_test.cc b/test/libapt/getlistoffilesindir_test.cc
new file mode 100644
index 000000000..ed8d2dad6
--- /dev/null
+++ b/test/libapt/getlistoffilesindir_test.cc
@@ -0,0 +1,82 @@
+#include <apt-pkg/fileutl.h>
+
+#include "assert.h"
+#include <string>
+#include <vector>
+
+#include <stdio.h>
+#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;
+}
+
+#define P(x) string(argv[1]).append("/").append(x)
+
+int main(int argc,char *argv[])
+{
+ if (argc != 2) {
+ std::cout << "One parameter expected - given " << argc << std::endl;
+ return 100;
+ }
+
+ // Files with no extension
+ std::vector<std::string> files = GetListOfFilesInDir(argv[1], "", true);
+ equals(files.size(), 2);
+ equals(files[0], P("01yet-anothernormalfile"));
+ equals(files[1], P("anormalfile"));
+
+ // Files with no extension - should be the same as above
+ files = GetListOfFilesInDir(argv[1], "", true, true);
+ equals(files.size(), 2);
+ equals(files[0], P("01yet-anothernormalfile"));
+ equals(files[1], P("anormalfile"));
+
+ // Files with impossible extension
+ files = GetListOfFilesInDir(argv[1], "impossible", true);
+ equals(files.size(), 0);
+
+ // Files with impossible or no extension
+ files = GetListOfFilesInDir(argv[1], "impossible", true, true);
+ equals(files.size(), 2);
+ equals(files[0], P("01yet-anothernormalfile"));
+ equals(files[1], P("anormalfile"));
+
+ // Files with list extension - nothing more
+ files = GetListOfFilesInDir(argv[1], "list", true);
+ equals(files.size(), 4);
+ equals(files[0], P("01yet-anotherapt.list"));
+ equals(files[1], P("anormalapt.list"));
+ equals(files[2], P("linkedfile.list"));
+ equals(files[3], P("multi.dot.list"));
+
+ // Files with conf or no extension
+ files = GetListOfFilesInDir(argv[1], "conf", true, true);
+ equals(files.size(), 5);
+ equals(files[0], P("01yet-anotherapt.conf"));
+ equals(files[1], P("01yet-anothernormalfile"));
+ equals(files[2], P("anormalapt.conf"));
+ equals(files[3], P("anormalfile"));
+ equals(files[4], P("multi.dot.conf"));
+
+ // Files with disabled extension - nothing more
+ files = GetListOfFilesInDir(argv[1], "disabled", true);
+ equals(files.size(), 3);
+ equals(files[0], P("disabledfile.conf.disabled"));
+ equals(files[1], P("disabledfile.disabled"));
+ equals(files[2], P("disabledfile.list.disabled"));
+
+ // Files with disabled or no extension
+ files = GetListOfFilesInDir(argv[1], "disabled", true, true);
+ equals(files.size(), 5);
+ equals(files[0], P("01yet-anothernormalfile"));
+ equals(files[1], P("anormalfile"));
+ equals(files[2], P("disabledfile.conf.disabled"));
+ equals(files[3], P("disabledfile.disabled"));
+ equals(files[4], P("disabledfile.list.disabled"));
+
+ return 0;
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
new file mode 100644
index 000000000..08f581e6d
--- /dev/null
+++ b/test/libapt/makefile
@@ -0,0 +1,25 @@
+# -*- 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)
+
+# Program for testing GetListOfFilesInDir
+PROGRAM = GetListOfFilesInDir${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = getlistoffilesindir_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;
+}
diff --git a/test/libapt/run-tests.sh b/test/libapt/run-tests.sh
index 365bbe215..1fcfb6861 100755
--- a/test/libapt/run-tests.sh
+++ b/test/libapt/run-tests.sh
@@ -1,10 +1,52 @@
#!/bin/sh
+set -e
+
echo "Compiling the tests ..."
make
echo "Running all testcases ..."
-PATH=$(pwd)/../../build/bin
-for testapp in $(/bin/ls ${PATH}/*_libapt_test)
+LDPATH=$(pwd)/../../build/bin
+EXT="_libapt_test"
+for testapp in $(ls ${LDPATH}/*$EXT)
do
- echo -n "Testing with \033[1;35m$(/usr/bin/basename ${testapp})\033[0m ... "
- LD_LIBRARY_PATH=${PATH} ${testapp} && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m"
+ name=$(basename ${testapp})
+ tmppath=""
+
+ if [ $name = "GetListOfFilesInDir${EXT}" ]; then
+ # TODO: very-low: move env creation to the actual test-app
+ echo "Prepare Testarea for \033[1;35m$name\033[0m ..."
+ tmppath=$(mktemp -d)
+ touch "${tmppath}/anormalfile" \
+ "${tmppath}/01yet-anothernormalfile" \
+ "${tmppath}/anormalapt.conf" \
+ "${tmppath}/01yet-anotherapt.conf" \
+ "${tmppath}/anormalapt.list" \
+ "${tmppath}/01yet-anotherapt.list" \
+ "${tmppath}/wrongextension.wron" \
+ "${tmppath}/wrong-extension.wron" \
+ "${tmppath}/strangefile." \
+ "${tmppath}/s.t.r.a.n.g.e.f.i.l.e" \
+ "${tmppath}/.hiddenfile" \
+ "${tmppath}/.hiddenfile.conf" \
+ "${tmppath}/.hiddenfile.list" \
+ "${tmppath}/multi..dot" \
+ "${tmppath}/multi.dot.conf" \
+ "${tmppath}/multi.dot.list" \
+ "${tmppath}/disabledfile.disabled" \
+ "${tmppath}/disabledfile.conf.disabled" \
+ "${tmppath}/disabledfile.list.disabled" \
+ "${tmppath}/invälid.conf" \
+ "${tmppath}/invalíd" \
+ "${tmppath}/01invalíd"
+ ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list"
+ ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list"
+ fi
+
+ echo -n "Testing with \033[1;35m${name}\033[0m ... "
+ LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m"
+
+ if [ -n "$tmppath" -a -d "$tmppath" ]; then
+ echo "Cleanup Testarea after \033[1;35m$name\033[0m ..."
+ rm -rf "$tmppath"
+ fi
+
done