summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/integration/framework170
-rwxr-xr-xtest/integration/run-tests8
-rwxr-xr-xtest/integration/test-bug-590041-prefer-non-virtual-packages51
-rw-r--r--test/libapt/assert.h21
-rw-r--r--test/libapt/commandlineasstring_test.cc39
-rw-r--r--test/libapt/compareversion_test.cc123
-rw-r--r--test/libapt/getarchitectures_test.cc61
-rw-r--r--test/libapt/getlanguages_test.cc149
-rw-r--r--test/libapt/globalerror_test.cc77
-rw-r--r--test/libapt/makefile48
-rw-r--r--test/libapt/parsedepends_test.cc196
-rwxr-xr-xtest/libapt/run-tests (renamed from test/libapt/run-tests.sh)17
-rw-r--r--test/makefile15
-rwxr-xr-xtest/pre-upload-check.py14
-rwxr-xr-xtest/test-indexes.sh226
-rw-r--r--test/testsources.list/sources.list.all-validuntil-broken1
-rw-r--r--test/versions.lst64
-rw-r--r--test/versiontest.cc233
18 files changed, 1261 insertions, 252 deletions
diff --git a/test/integration/framework b/test/integration/framework
new file mode 100644
index 000000000..97dce1e19
--- /dev/null
+++ b/test/integration/framework
@@ -0,0 +1,170 @@
+#!/bin/sh -- # no runable script, just for vi
+
+# we all like colorful messages
+CERROR="" # red
+CWARNING="" # yellow
+CMSG="" # green
+CINFO="" # light blue
+CDEBUG="" # blue
+CNORMAL="" # default system console color
+CDONE="" # green
+CPASS="" # green
+CFAIL="" # red
+CCMD="" # pink
+
+msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
+msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
+msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
+msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
+msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
+msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
+msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
+msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
+msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
+msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
+msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
+msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
+msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
+msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
+
+# enable / disable Debugging
+msginfo() { true; }
+msgdebug() { true; }
+msgninfo() { true; }
+msgndebug() { true; }
+msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
+
+runapt() {
+ msgdebug "Executing: ${CCMD}$*${CDEBUG} "
+ APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+}
+aptconfig() { runapt apt-config $*; }
+aptcache() { runapt apt-cache $*; }
+aptget() { runapt apt-get $*; }
+aptftparchive() { runapt apt-ftparchive $*; }
+
+setupenvironment() {
+ local TMPWORKINGDIRECTORY=$(mktemp -d)
+ msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
+ BUILDDIRECTORY=$(readlink -f $(dirname $0)/../../build/bin)
+ test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
+ local OLDWORKINGDIRECTORY=$(pwd)
+ trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+ cd $TMPWORKINGDIRECTORY
+ mkdir rootdir aptarchive
+ cd rootdir
+ mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg
+ mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
+ touch var/lib/dpkg/status
+ mkdir -p usr/lib/apt
+ ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
+ cd ..
+ echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
+ echo "Debug::NoLocking \"true\";" >> aptconfig.conf
+ echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
+ export LC_ALL=C
+ msgdone "info"
+}
+
+configarchitecture() {
+ local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
+ echo "APT::Architecture \"$1\";" > $CONFFILE
+ shift
+ while [ -n "$1" ]; do
+ echo "APT::Architectures:: \"$1\";" >> $CONFFILE
+ shift
+ done
+}
+
+buildflataptarchive() {
+ msginfo "Build APT archive for ${CCMD}$0${CINFO}…"
+ cd aptarchive
+ APTARCHIVE=$(readlink -f .)
+ if [ -f Packages ]; then
+ msgninfo "\tPackages file… "
+ cat Packages | gzip > Packages.gz
+ cat Packages | bzip2 > Packages.bz2
+ cat Packages | lzma > Packages.lzma
+ msgdone "info"
+ fi
+ if [ -f Sources ]; then
+ msgninfo "\tSources file… "
+ cat Sources | gzip > Sources.gz
+ cat Sources | bzip2 > Sources.bz2
+ cat Sources | lzma > Sources.lzma
+ msgdone "info"
+ fi
+ cd ..
+ aptftparchive release . > Release
+}
+
+setupflataptarchive() {
+ buildflataptarchive
+ APTARCHIVE=$(readlink -f ./aptarchive)
+ if [ -f ${APTARCHIVE}/Packages ]; then
+ msgninfo "\tadd deb sources.list line… "
+ echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
+ msgdone "info"
+ else
+ rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
+ fi
+ if [ -f ${APTARCHIVE}/Sources ]; then
+ msgninfo "\tadd deb-src sources.list line… "
+ echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
+ msgdone "info"
+ else
+ rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
+ fi
+ aptget update -qq
+}
+
+diff() {
+ local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
+ if [ -n "$DIFFTEXT" ]; then
+ echo
+ echo "$DIFFTEXT"
+ return 1
+ else
+ return 0
+ fi
+}
+
+testequal() {
+ local COMPAREFILE=$(mktemp)
+ echo "$1" > $COMPAREFILE
+ shift
+ msgtest "Test for equality of" "$*"
+ $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
+}
+
+testshowvirtual() {
+ local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual"
+ local PACKAGE="$1"
+ shift
+ while [ -n "$1" ]; do
+ VIRTUAL="${VIRTUAL}
+E: Can't select versions from package '$1' as it purely virtual"
+ PACKAGE="${PACKAGE} $1"
+ shift
+ done
+ msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
+ VIRTUAL="${VIRTUAL}
+E: No packages found"
+ local COMPAREFILE=$(mktemp)
+ local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
+ eval `apt-config shell ARCH APT::Architecture`
+ echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
+ aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
+}
+
+testnopackage() {
+ msgtest "Test for non-existent packages" "apt-cache show $*"
+ local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
+ if [ -n "$SHOWPKG" ]; then
+ echo
+ echo "$SHOWPKG"
+ msgfail
+ return 1
+ fi
+ msgpass
+}
diff --git a/test/integration/run-tests b/test/integration/run-tests
new file mode 100755
index 000000000..cb74f21e7
--- /dev/null
+++ b/test/integration/run-tests
@@ -0,0 +1,8 @@
+#!/bin/sh
+set -e
+
+local DIR=$(readlink -f $(dirname $0))
+for testcase in $(run-parts --list $DIR | grep '/test-'); do
+ echo "\033[1;32mRun Testcase \033[1;35m$(basename ${testcase})\033[0m"
+ ${testcase}
+done
diff --git a/test/integration/test-bug-590041-prefer-non-virtual-packages b/test/integration/test-bug-590041-prefer-non-virtual-packages
new file mode 100755
index 000000000..aa9e487e1
--- /dev/null
+++ b/test/integration/test-bug-590041-prefer-non-virtual-packages
@@ -0,0 +1,51 @@
+#!/bin/sh
+set -e
+
+. $(readlink -f $(dirname $0))/framework
+setupenvironment
+configarchitecture "i386" "armel"
+
+pkglibc6="Package: libc6
+Architecture: armel
+Version: 2.11.2-2~0.3
+Description: Embedded GNU C Library: Shared libraries
+Filename: pool/main/e/eglibc/libc6_2.11.2-2_armel.deb
+Installed-Size: 9740
+MD5sum: f5b878ce5fb8aa01a7927fa1460df537
+Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>
+Priority: required
+SHA1: 0464d597dfbf949e8c17a42325b1f93fb4914afd
+SHA256: faca4a3d9ccff57568abf41f6cb81ddd835be7b5d8b0161e2d5f9a7f26aae3c0
+Section: libs
+Size: 4178958
+"
+
+pkglibdb1="Package: libdb1
+Architecture: i386
+Version: 2.1.3-13~0.3
+Replaces: libc6 (<< 2.2.5-13~0.3)
+Description: The Berkeley database routines [glibc 2.0/2.1 compatibility]
+Filename: pool/main/d/db1-compat/libdb1-compat_2.1.3-13_armel.deb
+Installed-Size: 136
+MD5sum: 4043f176ab2b40b0c01bc1211b8c103c
+Maintainer: Colin Watson <cjwatson@debian.org>
+Priority: extra
+SHA1: b9396fdd2e3e8d1d4ba9e74e7346075852d85666
+SHA256: f17decaa28d1db3eeb9eb17bebe50d437d293a509bcdd7cdfd3ebb56f5de3cea
+Section: oldlibs
+Size: 44168
+"
+
+cat <<-EOF >aptarchive/Packages
+$pkglibc6
+$pkglibdb1
+EOF
+
+setupflataptarchive
+
+testshowvirtual libc6:i386
+testequal "$pkglibc6" aptcache show libc6:armel
+testequal "$pkglibc6" aptcache show libc6
+testequal "$pkglibdb1" aptcache show libdb1:i386
+testnopackage libdb1:armel
+testequal "$pkglibdb1" aptcache show libdb1
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/commandlineasstring_test.cc b/test/libapt/commandlineasstring_test.cc
new file mode 100644
index 000000000..a38957d7e
--- /dev/null
+++ b/test/libapt/commandlineasstring_test.cc
@@ -0,0 +1,39 @@
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
+
+#include <string>
+
+#include "assert.h"
+
+class CLT: public CommandLine {
+
+ public:
+ std::string static AsString(const char * const * const argv,
+ unsigned int const argc) {
+ std::string const static conf = "Commandline::AsString";
+ _config->Clear(conf);
+ SaveInConfig(argc, argv);
+ return _config->Find(conf);
+ }
+};
+
+#define CMD(y,z) equals(CLT::AsString(argv, y), z);
+
+int main() {
+ {
+ const char* const argv[] = {"apt-get", "install", "-sf"};
+ CMD(3, "apt-get install -sf");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=Test");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=\"Das ist ein Test\"");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "--hallo", "test=1.0"};
+ CMD(5, "apt-cache -s apt --hallo test=1.0");
+ }
+}
diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc
new file mode 100644
index 000000000..b6213e84c
--- /dev/null
+++ b/test/libapt/compareversion_test.cc
@@ -0,0 +1,123 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ Version Test - Simple program to run through a file and comare versions.
+
+ Each version is compared and the result is checked against an expected
+ result in the file. The format of the file is
+ a b Res
+ Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be
+ used to determine what Res should be. # at the start of the line
+ is a comment and blank lines are skipped
+
+ The runner will also call dpkg --compare-versions to check if APT and
+ dpkg have (still) the same idea.
+
+ ##################################################################### */
+ /*}}}*/
+#include <apt-pkg/macros.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/debversion.h>
+#include <apt-pkg/fileutl.h>
+#include <iostream>
+#include <fstream>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+using namespace std;
+
+bool callDPkg(const char *val, const char *ref, const char &op) {
+ pid_t Process = ExecFork();
+ if (Process == 0)
+ {
+ const char * args[6];
+ args[0] = "/usr/bin/dpkg";
+ args[1] = "--compare-versions";
+ args[2] = val;
+ args[3] = (op == 1) ? ">>" : ( (op == 0) ? "=" : "<<");
+ args[4] = ref;
+ args[5] = 0;
+ execv(args[0], (char**) args);
+ exit(1);
+ }
+ int Ret;
+ waitpid(Process, &Ret, 0);
+ return WIFEXITED(Ret) == true && WEXITSTATUS(Ret) == 0;
+}
+
+void assertVersion(int const &CurLine, string const &A, string const &B, int const &Expected) {
+ int Res = debVS.CmpVersion(A.c_str(), B.c_str());
+ bool const dpkg = callDPkg(A.c_str(),B.c_str(), Expected);
+ Res = (Res < 0) ? -1 : ( (Res > 0) ? 1 : Res);
+
+ if (Res != Expected)
+ _error->Error("Comparison failed on line %u. '%s' '%s' '%s' %i != %i",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")) ,B.c_str(),Res,Expected);
+ if (dpkg == false)
+ _error->Error("DPkg differ with line: %u. '%s' '%s' '%s' == false",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")),B.c_str());
+}
+
+bool RunTest(const char *File)
+{
+ ifstream F(File,ios::in);
+ if (!F != 0)
+ return false;
+
+ char Buffer[300];
+ int CurLine = 0;
+
+ while (1)
+ {
+ F.getline(Buffer,sizeof(Buffer));
+ CurLine++;
+ if (F.eof() != 0)
+ return true;
+ if (!F != 0)
+ return _error->Error("Line %u in %s is too long",CurLine,File);
+
+ // Comment
+ if (Buffer[0] == '#' || Buffer[0] == 0)
+ continue;
+
+ // First version
+ char *I;
+ char *Start = Buffer;
+ for (I = Buffer; *I != 0 && *I != ' '; I++);
+ string A(Start, I - Start);
+
+ if (*I == 0)
+ return _error->Error("Invalid line %u",CurLine);
+
+ // Second version
+ I++;
+ Start = I;
+ for (I = Start; *I != 0 && *I != ' '; I++);
+ string B(Start,I - Start);
+
+ if (*I == 0 || I[1] == 0)
+ return _error->Error("Invalid line %u",CurLine);
+
+ // Result
+ I++;
+ int const Expected = atoi(I);
+ assertVersion(CurLine, A, B, Expected);
+ // Check the reverse as well
+ assertVersion(CurLine, B, A, Expected*-1);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc <= 1)
+ RunTest("../versions.lst");
+ else
+ RunTest(argv[1]);
+
+ // Print any errors or warnings found
+ _error->DumpErrors();
+ return 0;
+}
diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc
new file mode 100644
index 000000000..1500caeed
--- /dev/null
+++ b/test/libapt/getarchitectures_test.cc
@@ -0,0 +1,61 @@
+#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;
+
+ _config->Set("APT::Architectures::1", "i386");
+ _config->Set("APT::Architectures::2", "amd64");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 2);
+ equals(vec[0], "i386");
+ equals(vec[1], "amd64");
+
+ _config->Set("APT::Architecture", "i386");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 2);
+ equals(vec[0], "i386");
+ equals(vec[1], "amd64");
+
+ _config->Set("APT::Architectures::2", "");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 1);
+ equals(vec[0], "i386");
+
+ _config->Set("APT::Architecture", "armel");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 2);
+ equals(vec[0], "i386");
+ equals(vec[1], "armel");
+
+ _config->Set("APT::Architectures::2", "amd64");
+ _config->Set("APT::Architectures::3", "i386");
+ _config->Set("APT::Architectures::4", "armel");
+ _config->Set("APT::Architectures::5", "i386");
+ _config->Set("APT::Architectures::6", "amd64");
+ _config->Set("APT::Architectures::7", "armel");
+ _config->Set("APT::Architectures::8", "armel");
+ _config->Set("APT::Architectures::9", "amd64");
+ _config->Set("APT::Architectures::10", "amd64");
+ vec = APT::Configuration::getArchitectures(false);
+ equals(vec.size(), 3);
+ equals(vec[0], "i386");
+ equals(vec[1], "amd64");
+ equals(vec[2], "armel");
+
+ return 0;
+}
diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc
new file mode 100644
index 000000000..9a8910b58
--- /dev/null
+++ b/test/libapt/getlanguages_test.cc
@@ -0,0 +1,149 @@
+#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[])
+{
+ if (argc != 2) {
+ std::cout << "One parameter expected - given " << argc << std::endl;
+ return 100;
+ }
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ // Special: Check if the cache is actually in use
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, true, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "en_GB");
+ equals(vec[1], "en");
+
+ // esperanto
+ env[0] = "eo.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "eo");
+ equals(vec[1], "en");
+
+ env[0] = "tr_DE@euro";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "tr");
+ equals(vec[1], "en");
+
+ env[0] = "de_NO";
+ env[1] = "se_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 5);
+ equals(vec[0], "de");
+ equals(vec[1], "en_GB");
+ equals(vec[2], "nb");
+ equals(vec[3], "no");
+ equals(vec[4], "en");
+
+ env[0] = "pt_PR.UTF-8";
+ env[1] = "";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 3);
+ equals(vec[0], "pt_PR");
+ equals(vec[1], "pt");
+ equals(vec[2], "en");
+
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
+ equals(vec.size(), 2);
+ equals(vec[0], "ast");
+ equals(vec[1], "en");
+
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "en");
+
+ _config->Set("Acquire::Languages::1", "environment");
+ _config->Set("Acquire::Languages::2", "en");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ _config->Set("Acquire::Languages::3", "de");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ _config->Set("Dir::State::lists", argv[1]);
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 5);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+ equals(vec[2], "none");
+ equals(vec[3], "pt");
+ equals(vec[4], "tr");
+
+ _config->Set("Dir::State::lists", "/non-existing-dir");
+ _config->Set("Acquire::Languages::1", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 0);
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec[0], "en");
+ equals(vec[1], "de");
+
+ _config->Set("Acquire::Languages::1", "fr");
+ _config->Set("Acquire::Languages", "de_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "de_DE");
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 0);
+
+ _config->Set("Acquire::Languages", "");
+ //FIXME: Remove support for this deprecated setting
+ _config->Set("APT::Acquire::Translation", "ast_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "ast_DE");
+ equals(vec[1], "en");
+ _config->Set("APT::Acquire::Translation", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "en");
+
+ return 0;
+}
diff --git a/test/libapt/globalerror_test.cc b/test/libapt/globalerror_test.cc
new file mode 100644
index 000000000..b2752255f
--- /dev/null
+++ b/test/libapt/globalerror_test.cc
@@ -0,0 +1,77 @@
+#include <apt-pkg/error.h>
+
+#include "assert.h"
+#include <string>
+
+int main(int argc,char *argv[])
+{
+ equals(_error->empty(), true);
+ equals(_error->PendingError(), false);
+ equals(_error->Notice("%s Notice", "A"), false);
+ equals(_error->empty(), true);
+ equals(_error->empty(GlobalError::DEBUG), false);
+ equals(_error->PendingError(), false);
+ equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
+ equals(_error->PendingError(), true);
+ std::string text;
+ equals(_error->PopMessage(text), false);
+ equals(_error->PendingError(), true);
+ equals(text, "A Notice");
+ equals(_error->PopMessage(text), true);
+ equals(text, "Something horrible happend 2 times");
+ equals(_error->empty(GlobalError::DEBUG), true);
+ equals(_error->PendingError(), false);
+ equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
+ equals(_error->PendingError(), true);
+ equals(_error->empty(GlobalError::FATAL), false);
+ _error->Discard();
+
+ equals(_error->empty(), true);
+ equals(_error->PendingError(), false);
+ equals(_error->Notice("%s Notice", "A"), false);
+ equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
+ equals(_error->PendingError(), true);
+ equals(_error->empty(GlobalError::NOTICE), false);
+ _error->PushToStack();
+ equals(_error->empty(GlobalError::NOTICE), true);
+ equals(_error->PendingError(), false);
+ equals(_error->Warning("%s Warning", "A"), false);
+ equals(_error->empty(GlobalError::ERROR), true);
+ equals(_error->PendingError(), false);
+ _error->RevertToStack();
+ equals(_error->empty(GlobalError::ERROR), false);
+ equals(_error->PendingError(), true);
+ equals(_error->PopMessage(text), false);
+ equals(_error->PendingError(), true);
+ equals(text, "A Notice");
+ equals(_error->PopMessage(text), true);
+ equals(text, "Something horrible happend 2 times");
+ equals(_error->PendingError(), false);
+ equals(_error->empty(), true);
+
+ equals(_error->Notice("%s Notice", "A"), false);
+ equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
+ equals(_error->PendingError(), true);
+ equals(_error->empty(GlobalError::NOTICE), false);
+ _error->PushToStack();
+ equals(_error->empty(GlobalError::NOTICE), true);
+ equals(_error->PendingError(), false);
+ equals(_error->Warning("%s Warning", "A"), false);
+ equals(_error->empty(GlobalError::ERROR), true);
+ equals(_error->PendingError(), false);
+ _error->MergeWithStack();
+ equals(_error->empty(GlobalError::ERROR), false);
+ equals(_error->PendingError(), true);
+ equals(_error->PopMessage(text), false);
+ equals(_error->PendingError(), true);
+ equals(text, "A Notice");
+ equals(_error->PopMessage(text), true);
+ equals(text, "Something horrible happend 2 times");
+ equals(_error->PendingError(), false);
+ equals(_error->empty(), false);
+ equals(_error->PopMessage(text), false);
+ equals(text, "A Warning");
+ equals(_error->empty(), true);
+
+ return 0;
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
new file mode 100644
index 000000000..50058262e
--- /dev/null
+++ b/test/libapt/makefile
@@ -0,0 +1,48 @@
+# -*- 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 = getArchitectures${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = getarchitectures_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)
+
+# Program for testing CommandLine reconstruction
+PROGRAM = CommandlineAsString${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = commandlineasstring_test.cc
+include $(PROGRAM_H)
+
+# Program for testing debians version comparing
+PROGRAM = CompareVersion${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = compareversion_test.cc
+include $(PROGRAM_H)
+
+# test the GlobalError stack class
+PROGRAM = GlobalError${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = globalerror_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..7b496878d
--- /dev/null
+++ b/test/libapt/parsedepends_test.cc
@@ -0,0 +1,196 @@
+#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 ], "
+ "any-for-me [ any ], "
+ "not-for-darwin [ !darwin-any ], "
+ "cpu-for-me [ any-dsk ], "
+ "os-for-me [ linux-any ], "
+ "cpu-not-for-me [ any-amd64 ], "
+ "os-not-for-me [ kfreebsd-any ], "
+ "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++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("any-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++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("not-for-darwin", 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++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("cpu-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++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("os-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++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("", Package); // cpu-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("", Package); // os-not-for-me
+ } 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
index 1fcfb6861..0f55f7386 100755
--- a/test/libapt/run-tests.sh
+++ b/test/libapt/run-tests
@@ -1,10 +1,12 @@
#!/bin/sh
set -e
-echo "Compiling the tests ..."
-make
-echo "Running all testcases ..."
-LDPATH=$(pwd)/../../build/bin
+local DIR=$(readlink -f $(dirname $0))
+echo "Compiling the tests …"
+test -d "$DIR/../../build/obj/test/libapt/" || mkdir -p "$DIR/../../build/obj/test/libapt/"
+$(cd $DIR && make)
+echo "Running all testcases …"
+LDPATH="$DIR/../../build/bin"
EXT="_libapt_test"
for testapp in $(ls ${LDPATH}/*$EXT)
do
@@ -39,6 +41,13 @@ do
"${tmppath}/01invalíd"
ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list"
ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list"
+ elif [ $name = "getLanguages${EXT}" ]; then
+ echo "Prepare Testarea for \033[1;35m$name\033[0m ..."
+ tmppath=$(mktemp -d)
+ touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \
+ "${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"
fi
echo -n "Testing with \033[1;35m${name}\033[0m ... "
diff --git a/test/makefile b/test/makefile
index fb9123d0a..52adb96a2 100644
--- a/test/makefile
+++ b/test/makefile
@@ -25,13 +25,6 @@ SOURCE = scratch.cc
include $(PROGRAM_H)
# Version compare tester
-PROGRAM=versiontest
-SLIBS = -lapt-pkg
-LIB_MAKES = apt-pkg/makefile
-SOURCE = versiontest.cc
-include $(PROGRAM_H)
-
-# Version compare tester
PROGRAM=testextract
SLIBS = -lapt-pkg -lapt-inst
LIB_MAKES = apt-pkg/makefile apt-inst/makefile
@@ -75,7 +68,7 @@ SOURCE = test_udevcdrom.cc
include $(PROGRAM_H)
# Program for checking rpm versions
-PROGRAM=rpmver
-SLIBS = -lapt-pkg -lrpm
-SOURCE = rpmver.cc
-include $(PROGRAM_H)
+#PROGRAM=rpmver
+#SLIBS = -lapt-pkg -lrpm
+#SOURCE = rpmver.cc
+#include $(PROGRAM_H)
diff --git a/test/pre-upload-check.py b/test/pre-upload-check.py
index 97a0ec4c4..f9da8f941 100755
--- a/test/pre-upload-check.py
+++ b/test/pre-upload-check.py
@@ -192,6 +192,20 @@ class testAuthentication(unittest.TestCase):
self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0,
"partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*"))
+ def testValid(self):
+ for f in glob.glob("testsources.list/sources.list*validuntil*"):
+ self._cleanup()
+ (prefix, testtype, result) = f.split("-")
+ expected_res = self._expectedRes(result)
+ cmd = ["update"]
+ res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args,
+ stdout=stdout, stderr=stderr)
+ self.assert_(res == expected_res,
+ "test '%s' failed (got %s expected %s" % (f,res,expected_res))
+ if expected_res == 0:
+ self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0,
+ "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*"))
+
class testLocalRepositories(unittest.TestCase):
" test local repository regressions "
diff --git a/test/test-indexes.sh b/test/test-indexes.sh
new file mode 100755
index 000000000..dad3e1fb2
--- /dev/null
+++ b/test/test-indexes.sh
@@ -0,0 +1,226 @@
+#!/bin/sh -e
+
+# Test behaviour of index retrieval and usage, in particular with uncompressed
+# and gzip compressed indexes.
+# Author: Martin Pitt <martin.pitt@ubuntu.com>
+# (C) 2010 Canonical Ltd.
+
+BUILDDIR=$(readlink -f $(dirname $0)/../build)
+
+TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
+GPG_KEYSERVER=gpg-keyserver.de
+# should be a small package with dependencies satisfiable in TEST_SOURCE, i. e.
+# ideally no depends at all
+TEST_PKG="python-psyco-doc"
+
+export LD_LIBRARY_PATH=$BUILDDIR/bin
+
+OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
+DEBUG=""
+#DEBUG="-o Debug::pkgCacheGen=true"
+#DEBUG="-o Debug::pkgAcquire=true"
+APT_GET="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
+APT_CACHE="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"
+APT_FTPARCHIVE="$BUILDDIR/bin/apt-ftparchive"
+
+[ -x "$BUILDDIR/bin/apt-get" ] || {
+ echo "please build the tree first" >&2
+ exit 1
+}
+
+check_update() {
+ echo "--- apt-get update $@ (no trusted keys)"
+
+ rm -f etc/apt/trusted.gpg etc/apt/secring.gpg
+ touch etc/apt/trusted.gpg etc/apt/secring.gpg
+ find var/lib/apt/lists/ -type f | xargs -r rm
+
+ # first attempt should fail, no trusted GPG key
+ out=$($APT_GET "$@" update 2>&1)
+ echo "$out" | grep -q NO_PUBKEY
+ key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
+
+ # get keyring
+ gpg -q --no-options --no-default-keyring --secret-keyring etc/apt/secring.gpg --trustdb-name etc/apt/trustdb.gpg --keyring etc/apt/trusted.gpg --primary-keyring etc/apt/trusted.gpg --keyserver $GPG_KEYSERVER --recv-keys $key
+
+ # now it should work
+ echo "--- apt-get update $@ (with trusted keys)"
+ find var/lib/apt/lists/ -type f | xargs -r rm
+ $APT_GET "$@" update
+}
+
+# if $1 == "compressed", check that we have compressed indexes, otherwise
+# uncompressed ones
+check_indexes() {
+ echo "--- only ${1:-uncompressed} index files present"
+ local F
+ if [ "$1" = "compressed" ]; then
+ ! test -e var/lib/apt/lists/*_Packages || F=1
+ ! test -e var/lib/apt/lists/*_Sources || F=1
+ test -e var/lib/apt/lists/*_Packages.gz || F=1
+ test -e var/lib/apt/lists/*_Sources.gz || F=1
+ else
+ test -e var/lib/apt/lists/*_Packages || F=1
+ test -e var/lib/apt/lists/*_Sources || F=1
+ ! test -e var/lib/apt/lists/*_Packages.gz || F=1
+ ! test -e var/lib/apt/lists/*_Sources.gz || F=1
+ fi
+
+ if [ -n "$F" ]; then
+ ls -laR var/lib/apt/lists/
+ exit 1
+ fi
+}
+
+# test apt-cache commands
+check_cache() {
+ echo "--- apt-cache commands"
+
+ $APT_CACHE show $TEST_PKG | grep -q ^Version:
+ # again (with cache)
+ $APT_CACHE show $TEST_PKG | grep -q ^Version:
+ rm var/cache/apt/*.bin
+ $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
+ # again (with cache)
+ $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
+
+ TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
+ rm var/cache/apt/*.bin
+ $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
+ # again (with cache)
+ $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
+}
+
+# test apt-get install
+check_install() {
+ echo "--- apt-get install"
+
+ $APT_GET install -d $TEST_PKG
+ test -e var/cache/apt/archives/$TEST_PKG*.deb
+ $APT_GET clean
+ ! test -e var/cache/apt/archives/$TEST_PKG*.deb
+}
+
+# test apt-get source
+check_get_source() {
+ echo "--- apt-get source"
+ # quiesce: it'll complain about not being able to verify the signature
+ $APT_GET source $TEST_PKG >/dev/null 2>&1
+ test -f $TEST_SRC_*.dsc
+ test -d $TEST_SRC-*
+ rm -r $TEST_SRC*
+}
+
+############################################################################
+# main
+############################################################################
+
+echo "===== building sandbox ====="
+WORKDIR=$(mktemp -d)
+trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+cd $WORKDIR
+
+rm -fr etc var
+rm -f home
+ln -s /home home
+mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d etc/apt/apt.conf.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
+cp /etc/apt/trusted.gpg etc/apt
+touch var/lib/dpkg/status
+echo "deb $TEST_SOURCE" > etc/apt/sources.list
+echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
+
+# specifying -o RootDir at the command line does not work for
+# etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
+# checked first, so this works
+echo "RootDir \"$WORKDIR\";" > apt_config
+export APT_CONFIG=`pwd`/apt_config
+
+echo "===== uncompressed indexes ====="
+check_update
+check_indexes
+check_cache
+check_install
+check_get_source
+
+echo "--- apt-get update with preexisting indexes"
+$APT_GET update
+check_indexes
+check_cache
+
+echo "--- apt-get update with preexisting indexes and pdiff mode"
+$APT_GET -o Acquire::PDiffs=true update
+check_indexes
+check_cache
+
+echo "===== compressed indexes (CLI option) ====="
+check_update -o Acquire::GzipIndexes=true
+check_indexes compressed
+check_cache
+check_install
+check_get_source
+
+echo "--- apt-get update with preexisting indexes"
+$APT_GET -o Acquire::GzipIndexes=true update
+check_indexes compressed
+check_cache
+
+echo "--- apt-get update with preexisting indexes and pdiff mode"
+$APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
+check_indexes compressed
+check_cache
+
+echo "===== compressed indexes (apt.conf.d option) ====="
+cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
+Acquire::GzipIndexes "true";
+Acquire::CompressionTypes::Order:: "gz";
+EOF
+
+check_update
+check_indexes compressed
+check_cache
+check_install
+check_get_source
+
+echo "--- apt-get update with preexisting indexes"
+$APT_GET update
+check_indexes compressed
+check_cache
+
+echo "--- apt-get update with preexisting indexes and pdiff mode"
+$APT_GET -o Acquire::PDiffs=true update
+check_indexes compressed
+check_cache
+
+rm etc/apt/apt.conf.d/02compress-indexes
+
+echo "==== apt-ftparchive ===="
+mkdir arch
+$APT_GET install -d $TEST_PKG
+cp var/cache/apt/archives/$TEST_PKG*.deb arch/
+cd arch
+$APT_GET source -d $TEST_PKG >/dev/null 2>&1
+$APT_FTPARCHIVE packages . | gzip -9 > Packages.gz
+$APT_FTPARCHIVE sources . | gzip -9 > Sources.gz
+cd ..
+
+echo "deb file://$WORKDIR/arch /
+deb-src file://$WORKDIR/arch /" > etc/apt/sources.list
+$APT_GET clean
+
+echo "==== uncompressed indexes from local file:// archive ===="
+echo "--- apt-get update"
+$APT_GET update
+check_indexes
+check_cache
+check_get_source
+
+echo "==== compressed indexes from local file:// archive ===="
+echo "--- apt-get update"
+$APT_GET -o Acquire::GzipIndexes=true update
+# EXFAIL: file:/ URIs currently decompress even with above option
+#check_indexes compressed
+check_indexes
+check_cache
+check_get_source
+
+echo "===== ALL TESTS PASSED ====="
diff --git a/test/testsources.list/sources.list.all-validuntil-broken b/test/testsources.list/sources.list.all-validuntil-broken
new file mode 100644
index 000000000..bab59bb81
--- /dev/null
+++ b/test/testsources.list/sources.list.all-validuntil-broken
@@ -0,0 +1 @@
+deb http://people.ubuntu.com/~mvo/apt/auth-test-suit/all-validuntil-broken/ /
diff --git a/test/versions.lst b/test/versions.lst
index efc19c4f0..517214151 100644
--- a/test/versions.lst
+++ b/test/versions.lst
@@ -10,10 +10,11 @@
1.3 1.2.2 1
# Important attributes
-- . -1
-p - -1
-a - -1
-z - -1
+# disabled as dpkg --compare-versions doesn't like them…
+#- . -1
+#p - -1
+#a - -1
+#z - -1
a . -1
z . -1
@@ -22,6 +23,10 @@ z . -1
1:1.25-4 1:1.25-8 -1
0:1.18.36 1.18.36 0
+# native version
+1.18.36 1.18.35 1
+0:1.18.36 1.18.35 1
+
# Funky, but allowed, characters in upstream version
9:1.18.36:5.4-20 10:0.5.1-22 -1
9:1.18.36:5.4-20 9:1.18.36:5.5-1 -1
@@ -49,3 +54,54 @@ III-alpha9.8 III-alpha9.8-1.5 -1
# #205960
3.0~rc1-1 3.0-1 -1
+
+# #573592 - debian policy 5.6.12
+1.0 1.0-0 0
+0.2 1.0-0 -1
+1.0 1.0-0+b1 -1
+1.0 1.0-0~ 1
+
+# if a version includes a dash
+# it should be the debrev dash - policy says so…
+0:0-0-0 0-0 1
+
+# do we like strange versions? Yes we like strange versions…
+0 0 0
+0 00 0
+
+# "steal" the testcases from cupt
+1.2.3 1.2.3 0 # identical
+4.4.3-2 4.4.3-2 0 # identical
+1:2ab:5 1:2ab:5 0 # this is correct...
+7:1-a:b-5 7:1-a:b-5 0 # and this
+57:1.2.3abYZ+~-4-5 57:1.2.3abYZ+~-4-5 0 # and those too
+1.2.3 0:1.2.3 0 # zero epoch
+1.2.3 1.2.3-0 0 # zero revision
+009 9 0 # zeroes...
+009ab5 9ab5 0 # there as well
+1.2.3 1.2.3-1 -1 # added non-zero revision
+1.2.3 1.2.4 -1 # just bigger
+1.2.4 1.2.3 1 # order doesn't matter
+1.2.24 1.2.3 1 # bigger, eh?
+0.10.0 0.8.7 1 # bigger, eh?
+3.2 2.3 1 # major number rocks
+1.3.2a 1.3.2 1 # letters rock
+0.5.0~git 0.5.0~git2 -1 # numbers rock
+2a 21 -1 # but not in all places
+1.3.2a 1.3.2b -1 # but there is another letter
+1:1.2.3 1.2.4 1 # epoch rocks
+1:1.2.3 1:1.2.4 -1 # bigger anyway
+1.2a+~bCd3 1.2a++ -1 # tilde doesn't rock
+1.2a+~bCd3 1.2a+~ 1 # but first is longer!
+5:2 304-2 1 # epoch rocks
+5:2 304:2 -1 # so big epoch?
+25:2 3:2 1 # 25 > 3, obviously
+1:2:123 1:12:3 -1 # 12 > 2
+1.2-5 1.2-3-5 -1 # 1.2 < 1.2-3
+5.10.0 5.005 1 # preceding zeroes don't matters
+3a9.8 3.10.2 -1 # letters are before all letter symbols
+3a9.8 3~10 1 # but after the tilde
+1.4+OOo3.0.0~ 1.4+OOo3.0.0-4 -1 # another tilde check
+2.4.7-1 2.4.7-z -1 # revision comparing
+1.002-1+b2 1.00 1 # whatever...
+2.2.4-47978_Debian_lenny 2.2.4-47978_Debian_lenny 0 # and underscore...
diff --git a/test/versiontest.cc b/test/versiontest.cc
deleted file mode 100644
index 4ede4b280..000000000
--- a/test/versiontest.cc
+++ /dev/null
@@ -1,233 +0,0 @@
-// -*- mode: cpp; mode: fold -*-
-// Description /*{{{*/
-// $Id: versiontest.cc,v 1.5 2003/08/18 15:55:19 mdz Exp $
-/* ######################################################################
-
- Version Test - Simple program to run through a file and comare versions.
-
- Each version is compared and the result is checked against an expected
- result in the file. The format of the file is
- a b Res
- Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be
- used to determine what Res should be. # at the start of the line
- is a comment and blank lines are skipped
-
- ##################################################################### */
- /*}}}*/
-#include <apt-pkg/macros.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/debversion.h>
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
- static int verrevcmp(const char *val, const char *ref)
-{
- int vc, rc;
- long vl, rl;
- const char *vp, *rp;
-
- if (!val)
- val = "";
- if (!ref)
- ref = "";
- for (;;)
- {
- vp = val;
- while (*vp && !isdigit(*vp))
- vp++;
- rp = ref;
- while (*rp && !isdigit(*rp))
- rp++;
- for (;;)
- {
- vc= val == vp ? 0 : *val++;
- rc= ref == rp ? 0 : *ref++;
- if (!rc && !vc)
- break;
- if (vc && !isalpha(vc))
- vc += 256; /* assumes ASCII character set */
- if (rc && !isalpha(rc))
- rc += 256;
- if (vc != rc)
- return vc - rc;
- }
- val = vp;
- ref = rp;
- vl = 0;
- if (isdigit(*vp))
- vl = strtol(val,(char**)&val,10);
- rl = 0;
- if (isdigit(*rp))
- rl = strtol(ref,(char**)&ref,10);
- if (vl != rl)
- return vl - rl;
- if (!*val && !*ref)
- return 0;
- if (!*val)
- return -1;
- if (!*ref)
- return +1;
- }
-}
-
-#if 0
-static int verrevcmp(const char *val, const char *ref)
-{
- int vc, rc;
- long vl, rl;
- const char *vp, *rp;
-
- if (!val) val= "";
- if (!ref) ref= "";
- for (;;)
- {
- vp= val; while (*vp && !isdigit(*vp) && *vp != '~') vp++;
- rp= ref; while (*rp && !isdigit(*rp) && *rp != '~') rp++;
- for (;;)
- {
- vc= val == vp ? 0 : *val++;
- rc= ref == rp ? 0 : *ref++;
- if (!rc && !vc) break;
- if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
- if (rc && !isalpha(rc)) rc += 256;
- if (vc != rc) return vc - rc;
- }
-
- val= vp;
- ref= rp;
- if (*vp == '~') val++;
- if (*rp == '~') ref++;
- vl=0; if (isdigit(*val)) vl= strtol(val,(char**)&val,10);
- rl=0; if (isdigit(*ref)) rl= strtol(ref,(char**)&ref,10);
- if (vl == 0 && rl == 0)
- {
- if (*vp == '~' && *rp != '~') return -1;
- if (*vp != '~' && *rp == '~') return +1;
- }
- if (*vp == '~')
- vl *= -1;
- if (*rp == '~')
- rl *= -1;
- if (vl != rl) return vl - rl;
- if (!*val && !*ref) return 0;
- if (!*val)
- {
- if (*ref == '~')
- return +1;
- else
- return -1;
- }
-
- if (!*ref)
- {
- if (*val == '~')
- return -1;
- else
- return +1;
- }
- }
-}
-#endif
-
-bool RunTest(const char *File)
-{
- ifstream F(File,ios::in);
- if (!F != 0)
- return false;
-
- char Buffer[300];
- int CurLine = 0;
-
- while (1)
- {
- F.getline(Buffer,sizeof(Buffer));
- CurLine++;
- if (F.eof() != 0)
- return true;
- if (!F != 0)
- return _error->Error("Line %u in %s is too long",CurLine,File);
-
- // Comment
- if (Buffer[0] == '#' || Buffer[0] == 0)
- continue;
-
- // First version
- char *I;
- char *Start = Buffer;
- for (I = Buffer; *I != 0 && *I != ' '; I++);
- string A(Start, I - Start);
-
- if (*I == 0)
- return _error->Error("Invalid line %u",CurLine);
-
- // Second version
- I++;
- Start = I;
- for (I = Start; *I != 0 && *I != ' '; I++);
- string B(Start,I - Start);
-
- if (*I == 0 || I[1] == 0)
- return _error->Error("Invalid line %u",CurLine);
-
- // Result
- I++;
- int Expected = atoi(I);
- int Res = debVS.CmpVersion(A.c_str(), B.c_str());
- int Res2 = verrevcmp(A.c_str(),B.c_str());
- cout << "'" << A << "' ? '" << B << "' = " << Res << " (= " << Expected << ") " << Res2 << endl;
-
- if (Res < 0)
- Res = -1;
- else if (Res > 0)
- Res = 1;
-
- if (Res != Expected)
- _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,A.c_str(),B.c_str(),Res,Expected);
-
- // Check the reverse as well
- Expected = -1*Expected;
- Res = debVS.CmpVersion(B.c_str(), A.c_str());
- Res2 = verrevcmp(B.c_str(),A.c_str());
-
- cout << "'" << B << "' ? '" << A << "' = " << Res << " (= " << Expected << ") " << Res2 << endl;
-
- if (Res < 0)
- Res = -1;
- else if (Res > 0)
- Res = 1;
-
- if (Res != Expected)
- _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,B.c_str(),A.c_str(),Res,Expected);
- }
-}
-
-int main(int argc, char *argv[])
-{
- if (argc <= 1)
- {
- cerr << "You must specify a test file" << endl;
- return 0;
- }
-
- RunTest(argv[1]);
-
- // Print any errors or warnings found
- if (_error->empty() == false)
- {
- string Err;
- while (_error->empty() == false)
- {
-
- bool Type = _error->PopMessage(Err);
- if (Type == true)
- cout << "E: " << Err << endl;
- else
- cout << "W: " << Err << endl;
- }
-
- return 0;
- }
-}