summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-05-07 17:55:10 +0200
committerMichael Vogt <mvo@debian.org>2014-05-07 17:55:10 +0200
commit38d2959ffb8c6f5f291b2910014a67b1b352ab4c (patch)
treec5977b8f34aaf973ed3956952ec3ff43ac59f143 /test
parentfce69e7a0f38299c57ef96ae1c1dd9a5379bfd5a (diff)
parent3fa4e98f62e469f4292d2811b4e15f4afb678fbd (diff)
Merge branch 'debian/sid' into debian/experimental
Conflicts: apt-pkg/cachefilter.h apt-pkg/contrib/fileutl.cc apt-pkg/contrib/netrc.h apt-pkg/deb/debsrcrecords.cc apt-pkg/init.h apt-pkg/pkgcache.cc debian/apt.install.in debian/changelog
Diffstat (limited to 'test')
-rw-r--r--test/integration/framework229
-rwxr-xr-xtest/integration/test-allow-scores-for-all-dependency-types144
-rwxr-xr-xtest/integration/test-apt-cdrom86
-rwxr-xr-xtest/integration/test-apt-cli-list18
-rwxr-xr-xtest/integration/test-apt-cli-search7
-rwxr-xr-xtest/integration/test-apt-extracttemplates45
-rwxr-xr-xtest/integration/test-apt-helper39
-rwxr-xr-xtest/integration/test-apt-https-no-redirect20
-rwxr-xr-xtest/integration/test-apt-progress-fd-error-postinst22
-rwxr-xr-xtest/integration/test-bug-612958-use-dpkg-multiarch-config9
-rwxr-xr-xtest/integration/test-bug-661537-build-profiles-support147
-rwxr-xr-xtest/integration/test-bug-735967-lib32-to-i386-unavailable3
-rwxr-xr-xtest/integration/test-bug-740843-versioned-up-down-breaks55
-rwxr-xr-xtest/integration/test-bug-multiarch-upgrade4
-rwxr-xr-xtest/integration/test-compressed-indexes1
-rwxr-xr-xtest/integration/test-conflicts-loop12
-rwxr-xr-xtest/integration/test-failing-maintainer-scripts132
-rwxr-xr-xtest/integration/test-ignore-provides-if-versioned-breaks4
-rwxr-xr-xtest/integration/test-ignore-provides-if-versioned-conflicts4
-rwxr-xr-xtest/integration/test-kernel-helper-autoremove122
-rw-r--r--test/integration/test-kernel-helper-autoremove.fake-dpkg13
-rwxr-xr-xtest/integration/test-partial-file-support43
-rwxr-xr-xtest/integration/test-prevent-markinstall-multiarch-same-versionscrew8
-rwxr-xr-xtest/integration/test-ubuntu-bug-1078697-missing-source-hashes (renamed from test/integration/test-bug-1078697-missing-source-hashes)0
-rwxr-xr-xtest/integration/test-ubuntu-bug-1304403-obsolete-priority-standard48
-rwxr-xr-xtest/integration/test-ubuntu-bug-365611-long-package-names6
-rwxr-xr-xtest/integration/test-very-tight-loop-configure-with-unpacking-new-packages4
-rw-r--r--test/interactive-helper/aptwebserver.cc64
-rw-r--r--test/interactive-helper/extract-control.cc5
-rw-r--r--test/interactive-helper/mthdcat.cc2
-rw-r--r--test/interactive-helper/rpmver.cc2
-rw-r--r--test/interactive-helper/test_udevcdrom.cc8
-rw-r--r--test/interactive-helper/testdeb.cc16
-rw-r--r--test/libapt/assert.h113
-rw-r--r--test/libapt/cdrom_test.cc114
-rw-r--r--test/libapt/cdromfindpackages_test.cc173
-rw-r--r--test/libapt/cdromreducesourcelist_test.cc86
-rw-r--r--test/libapt/commandline_test.cc54
-rw-r--r--test/libapt/commandlineasstring_test.cc39
-rw-r--r--test/libapt/compareversion_test.cc194
-rw-r--r--test/libapt/configuration_test.cc161
-rw-r--r--test/libapt/file-helpers.cc77
-rw-r--r--test/libapt/file-helpers.h29
-rw-r--r--test/libapt/fileutl_test.cc225
-rw-r--r--test/libapt/getarchitectures_test.cc119
-rw-r--r--test/libapt/getlanguages_test.cc406
-rw-r--r--test/libapt/getlistoffilesindir_test.cc164
-rw-r--r--test/libapt/globalerror_test.cc217
-rw-r--r--test/libapt/gtest_runner.cc19
-rw-r--r--test/libapt/hashsums_test.cc276
-rw-r--r--test/libapt/indexcopytosourcelist_test.cc76
-rw-r--r--test/libapt/install_progress_test.cc20
-rw-r--r--test/libapt/makefile172
-rw-r--r--test/libapt/parsedepends_test.cc430
-rwxr-xr-xtest/libapt/run-tests125
-rw-r--r--test/libapt/sourcelist_test.cc54
-rw-r--r--test/libapt/strutil_test.cc139
-rw-r--r--test/libapt/tagfile_test.cc64
-rw-r--r--test/libapt/uri_test.cc233
-rw-r--r--test/libapt/versions.lst106
60 files changed, 3070 insertions, 2137 deletions
diff --git a/test/integration/framework b/test/integration/framework
index 99214ef73..3b900a960 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -90,18 +90,22 @@ msgdone() {
echo "${CDONE}DONE${CNORMAL}";
fi
}
-
+getaptconfig() {
+ if [ -f ./aptconfig.conf ]; then
+ echo "./aptconfig.conf"
+ elif [ -f ../aptconfig.conf ]; then
+ echo "../aptconfig.conf"
+ fi
+}
runapt() {
msgdebug "Executing: ${CCMD}$*${CDEBUG} "
local CMD="$1"
shift
- if [ -f ./aptconfig.conf ]; then
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- elif [ -f ../aptconfig.conf ]; then
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- else
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- fi
+ case $CMD in
+ sh|aptitude|*/*) ;;
+ *) CMD="${BUILDDIRECTORY}/$CMD";;
+ esac
+ MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
}
aptconfig() { runapt apt-config "$@"; }
aptcache() { runapt apt-cache "$@"; }
@@ -111,27 +115,20 @@ aptftparchive() { runapt apt-ftparchive "$@"; }
aptkey() { runapt apt-key "$@"; }
aptmark() { runapt apt-mark "$@"; }
apt() { runapt apt "$@"; }
-aptwebserver() {
- LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver "$@";
-}
+apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
+aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
+aptitude() { runapt aptitude "$@"; }
+aptextracttemplates() { runapt apt-extracttemplates "$@"; }
+
dpkg() {
command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
}
-aptitude() {
- if [ -f ./aptconfig.conf ]; then
- APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- elif [ -f ../aptconfig.conf ]; then
- APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- else
- LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- fi
+dpkgcheckbuilddeps() {
+ command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
}
gdb() {
echo "gdb: run »$*«"
- APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command gdb ${BUILDDIRECTORY}/$1 --args "$@"
-}
-http() {
- LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
+ APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} command gdb ${BUILDDIRECTORY}/$1 --args "$@"
}
gpg() {
# see apt-key for the whole trickery. Setup is done in setupenvironment
@@ -176,7 +173,9 @@ setupenvironment() {
# allow overriding the default BUILDDIR location
BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}
+ LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}
METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}
+ APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}
APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}
test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
# -----
@@ -186,11 +185,18 @@ setupenvironment() {
mkdir rootdir aptarchive keys
cd rootdir
mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d
- mkdir -p var/cache var/lib var/log tmp
+ mkdir -p var/cache var/lib/apt var/log tmp
mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
touch var/lib/dpkg/available
mkdir -p usr/lib/apt
ln -s ${METHODSDIR} usr/lib/apt/methods
+ # use the autoremove from the BUILDDIRECTORY if its there, otherwise
+ # system
+ if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
+ ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
+ else
+ ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
+ fi
cd ..
local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
@@ -219,8 +225,6 @@ setupenvironment() {
echo 'quiet::NoUpdate "true";' >> aptconfig.conf
echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https
echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
- export LC_ALL=C.UTF-8
- export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
# gpg needs a trustdb to function, but it can't be invalid (not even empty)
@@ -236,6 +240,12 @@ setupenvironment() {
# newer gpg versions are fine without it, but play it safe for now
gpg --quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev/null 2>&1
+ # cleanup the environment a bit
+ export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
+ export LC_ALL=C.UTF-8
+ unset LANGUAGE APT_CONFIG
+ unset GREP_OPTIONS DEB_BUILD_PROFILES
+
msgdone "info"
}
@@ -256,6 +266,10 @@ getarchitectures() {
echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
}
+getarchitecturesfromcommalist() {
+ echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
+}
+
configarchitecture() {
{
echo "APT::Architecture \"$(getarchitecture $1)\";"
@@ -429,7 +443,7 @@ Package: $NAME" >> ${BUILDDIR}/debian/control
# fi
done
- for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+ for arch in $(getarchitecturesfromcommalist "$ARCH"); do
rm -rf ${BUILDDIR}/debian/tmp
mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
@@ -584,7 +598,7 @@ insertpackage() {
something went horribly wrong! They are autogenerated
und used only by testcases and surf no other propose…"}"
local ARCHS=""
- for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+ for arch in $(getarchitecturesfromcommalist "$ARCH"); do
if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
ARCHS="$(getarchitectures)"
else
@@ -646,7 +660,7 @@ insertinstalledpackage() {
local FILE='rootdir/var/lib/dpkg/status'
local INFO='rootdir/var/lib/dpkg/info'
- for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+ for arch in $(getarchitecturesfromcommalist "$ARCH"); do
echo "Package: $NAME
Status: $STATUS
Priority: $PRIORITY
@@ -852,18 +866,16 @@ signreleasefiles() {
webserverconfig() {
msgtest "Set webserver config option '${1}' to" "$2"
- downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
- local DOWNLOG='download-testfile.log'
- rm -f "$DOWNLOG"
- local STATUS="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
- downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
- if [ "$(cat "$STATUS")" = '200' ]; then
+ local DOWNLOG='rootdir/tmp/download-testfile.log'
+ local STATUS='rootdir/tmp/webserverconfig.status'
+ rm -f "$STATUS" "$DOWNLOG"
+ if downloadfile "http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
msgpass
else
- cat >&2 "$DOWNLOG"
- msgfail "Statuscode was $(cat "$STATUS")"
+ cat "$DOWNLOG" "$STATUS"
+ msgfail
fi
- rm "$STATUS"
+ testwebserverlaststatuscode '200'
}
rewritesourceslist() {
@@ -873,6 +885,20 @@ rewritesourceslist() {
done
}
+# wait for up to 10s for a pid file to appear to avoid possible race
+# when a helper is started and dosn't write the PID quick enough
+waitforpidfile() {
+ local PIDFILE="$1"
+ for i in $(seq 10); do
+ if test -s "$PIDFILE"; then
+ return 0
+ fi
+ sleep 1
+ done
+ msgdie "waiting for $PIDFILE failed"
+ return 1
+}
+
changetowebserver() {
if [ "$1" != '--no-rewrite' ]; then
rewritesourceslist 'http://localhost:8080/'
@@ -886,6 +912,7 @@ changetowebserver() {
cat $LOG
false
fi
+ waitforpidfile aptwebserver.pid
local PID="$(cat aptwebserver.pid)"
if [ -z "$PID" ]; then
msgdie 'Could not fork aptwebserver successfully'
@@ -913,7 +940,11 @@ accept = 4433
connect = 8080
" > ${TMPWORKINGDIRECTORY}/stunnel.conf
stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
+ waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
+ if [ -z "$PID" ]; then
+ msgdie 'Could not fork stunnel4 successfully'
+ fi
addtrap 'prefix' "kill ${PID};"
rewritesourceslist 'https://localhost:4433/'
}
@@ -921,54 +952,29 @@ connect = 8080
changetocdrom() {
mkdir -p rootdir/media/cdrom/.disk
local CD="$(readlink -f rootdir/media/cdrom)"
- echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom
- echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom
+ echo "acquire::cdrom::mount \"${CD}\";
+acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\";
+acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\";
+acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
echo -n "$1" > ${CD}/.disk/info
if [ ! -d aptarchive/dists ]; then
msgdie 'Flat file archive cdroms can not be created currently'
return 1
fi
- mv aptarchive/dists $CD
+ mv aptarchive/dists "$CD"
ln -s "$(readlink -f ./incoming)" $CD/pool
find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete
+ # start with an unmounted disk
+ mv "${CD}" "${CD}-unmounted"
+ # we don't want the disk to be modifiable
+ addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;"
+ chmod -R -w rootdir/media/cdrom-unmounted/dists
}
downloadfile() {
- PROTO="$(echo "$1" | cut -d':' -f 1)"
- if [ ! -x "${METHODSDIR}/${PROTO}" ]; then
- msgwarn "can not find ${METHODSDIR}/${PROTO}"
- return 1
- fi
- local DOWNLOG="${TMPWORKINGDIRECTORY}/download.log"
- rm -f "$DOWNLOG"
- touch "$DOWNLOG"
- {
- echo "601 Configuration
-Config-Item: Acquire::https::CaInfo=${TESTDIR}/apt.pem
-Config-Item: Debug::Acquire::${PROTO}=1
-
-600 Acquire URI
-URI: $1
-Filename: ${2}
-"
- # simple worker keeping stdin open until we are done (201) or error (400)
- # and requesting new URIs on try-agains/redirects in-between
- { tail -n 999 -f "$DOWNLOG" & echo "TAILPID: $!"; } | while read f1 f2; do
- if [ "$f1" = 'TAILPID:' ]; then
- TAILPID="$f2"
- elif [ "$f1" = 'New-URI:' ]; then
- echo "600 Acquire URI
-URI: $f2
-Filename: ${2}
-"
- elif [ "$f1" = '201' ] || [ "$f1" = '400' ]; then
- # tail would only die on next read – which never happens
- test -z "$TAILPID" || kill -s HUP "$TAILPID"
- break
- fi
- done
- } | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${METHODSDIR}/${PROTO} 2>&1 | tee "$DOWNLOG"
- rm "$DOWNLOG"
+ local PROTO="$(echo "$1" | cut -d':' -f 1 )"
+ apthelper -o Debug::Acquire::${PROTO}=1 \
+ download-file "$1" "$2" 2>&1 || true
# only if the file exists the download was successful
if [ -e "$2" ]; then
return 0
@@ -980,8 +986,8 @@ Filename: ${2}
checkdiff() {
local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
if [ -n "$DIFFTEXT" ]; then
- echo
- echo "$DIFFTEXT"
+ echo >&2
+ echo >&2 "$DIFFTEXT"
return 1
else
return 0
@@ -1030,11 +1036,17 @@ testequalor2() {
shift 2
msgtest "Test for equality OR of" "$*"
$* >$COMPAREAGAINST 2>&1 || true
- (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
- checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
- ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
- "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
- msgfail )
+ if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
+ checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
+ then
+ msgpass
+ else
+ echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
+ checkdiff $COMPAREFILE1 $COMPAREAGAINST || true
+ echo -n "${CINFO}Diff against OR 2${CNORMAL}"
+ checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
+ msgfail
+ fi
}
testshowvirtual() {
@@ -1060,24 +1072,24 @@ 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"
+ echo >&2
+ echo >&2 "$SHOWPKG"
msgfail
- return 1
+ else
+ msgpass
fi
- msgpass
}
testdpkginstalled() {
msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
if [ "$PKGS" != $# ]; then
- echo $PKGS
- dpkg -l "$@" | grep '^[a-z]'
+ echo >&2 $PKGS
+ dpkg -l "$@" | grep '^[a-z]' >&2
msgfail
- return 1
+ else
+ msgpass
fi
- msgpass
}
testdpkgnotinstalled() {
@@ -1085,11 +1097,11 @@ testdpkgnotinstalled() {
local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
if [ "$PKGS" != 0 ]; then
echo
- dpkg -l "$@" | grep '^[a-z]'
+ dpkg -l "$@" | grep '^[a-z]' >&2
msgfail
- return 1
+ else
+ msgpass
fi
- msgpass
}
testmarkedauto() {
@@ -1114,8 +1126,8 @@ testsuccess() {
if $@ >${OUTPUT} 2>&1; then
msgpass
else
- echo
- cat $OUTPUT
+ echo >&2
+ cat >&2 $OUTPUT
msgfail
fi
}
@@ -1128,14 +1140,35 @@ testfailure() {
fi
local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
if $@ >${OUTPUT} 2>&1; then
- echo
- cat $OUTPUT
+ echo >&2
+ cat >&2 $OUTPUT
msgfail
else
msgpass
fi
}
+testwebserverlaststatuscode() {
+ local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
+ local STATUS='rootdir/tmp/webserverstatus-statusfile.log'
+ rm -f "$DOWNLOG" "$STATUS"
+ msgtest 'Test last status code from the webserver was' "$1"
+ downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
+ if [ "$(cat "$STATUS")" = "$1" ]; then
+ msgpass
+ else
+ echo >&2
+ if [ -n "$2" ]; then
+ shift
+ echo >&2 '#### Additionally provided output files contain:'
+ cat >&2 "$@"
+ fi
+ echo >&2 '#### Download log of the status code:'
+ cat >&2 "$DOWNLOG"
+ msgfail "Status was $(cat "$STATUS")"
+ fi
+}
+
pause() {
echo "STOPPED execution. Press enter to continue"
local IGNORE
diff --git a/test/integration/test-allow-scores-for-all-dependency-types b/test/integration/test-allow-scores-for-all-dependency-types
new file mode 100755
index 000000000..a5c98f3d6
--- /dev/null
+++ b/test/integration/test-allow-scores-for-all-dependency-types
@@ -0,0 +1,144 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64'
+
+insertpackage 'unversioned' 'libdb-dev' 'amd64' '5.3.0' 'Depends: libdb5.3-dev
+Conflicts: libdb5.1-dev'
+insertpackage 'unversioned' 'libdb5.1-dev' 'amd64' '5.1.29-7'
+insertpackage 'unversioned' 'libdb5.3-dev' 'amd64' '5.3.28-3' 'Conflicts: libdb5.1-dev'
+
+insertpackage 'unversioned' 'foo' 'amd64' '1'
+insertpackage 'unversioned' 'bar' 'amd64' '1'
+insertpackage 'unversioned' 'foo' 'amd64' '2' 'Conflicts: bar'
+insertpackage 'unversioned' 'bar' 'amd64' '2' 'Conflicts: foo'
+insertpackage 'unversioned' 'baz' 'amd64' '2' 'Depends: bar | foo'
+
+insertpackage 'versioned' 'libdb-dev' 'amd64' '5.3.0' 'Depends: libdb5.3-dev
+Conflicts: libdb5.1-dev (<< 5.2)'
+insertpackage 'versioned' 'libdb5.3-dev' 'amd64' '5.3.28-3' 'Conflicts: libdb5.1-dev (<< 5.2)'
+
+insertpackage 'versioned' 'foo' 'amd64' '2' 'Conflicts: bar (<= 2)'
+insertpackage 'versioned' 'bar' 'amd64' '2' 'Conflicts: foo (<= 2)'
+insertpackage 'versioned' 'baz' 'amd64' '2' 'Depends: bar (>= 2) | foo (>= 2)'
+
+insertpackage 'multipleno' 'foo' 'amd64' '2.1' 'Conflicts: bar (<= 3)'
+insertpackage 'multipleno' 'bar' 'amd64' '2.1' 'Conflicts: foo (<= 3), foo (<= 1)'
+
+insertpackage 'multipleyes' 'foo' 'amd64' '2.2' 'Conflicts: bar (<= 3)'
+# having foo multiple times as conflict is a non-advisable hack in general
+insertpackage 'multipleyes' 'bar' 'amd64' '2.2' 'Conflicts: foo (<= 3), foo (<= 3)'
+
+cp rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status-backup
+setupaptarchive
+
+insertinstalledpackage 'libdb-dev' 'amd64' '5.1.7' 'Depends: libdb5.1-dev'
+insertinstalledpackage 'libdb5.1-dev' 'amd64' '5.1.29-7'
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ libdb5.1-dev
+The following NEW packages will be installed:
+ libdb5.3-dev
+The following packages will be upgraded:
+ libdb-dev
+1 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv libdb5.1-dev [5.1.29-7] [libdb-dev:amd64 ]
+Inst libdb-dev [5.1.7] (5.3.0 unversioned [amd64]) []
+Inst libdb5.3-dev (5.3.28-3 unversioned [amd64])
+Conf libdb5.3-dev (5.3.28-3 unversioned [amd64])
+Conf libdb-dev (5.3.0 unversioned [amd64])' aptget dist-upgrade -st unversioned
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ libdb5.1-dev
+The following NEW packages will be installed:
+ libdb5.3-dev
+The following packages will be upgraded:
+ libdb-dev
+1 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv libdb5.1-dev [5.1.29-7] [libdb-dev:amd64 ]
+Inst libdb-dev [5.1.7] (5.3.0 versioned [amd64]) []
+Inst libdb5.3-dev (5.3.28-3 versioned [amd64])
+Conf libdb5.3-dev (5.3.28-3 versioned [amd64])
+Conf libdb-dev (5.3.0 versioned [amd64])' aptget dist-upgrade -st versioned
+
+cp -f rootdir/var/lib/dpkg/status-backup rootdir/var/lib/dpkg/status
+insertinstalledpackage 'foo' 'amd64' '1'
+insertinstalledpackage 'bar' 'amd64' '1'
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+ bar foo
+0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.' aptget dist-upgrade -st unversioned
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+ bar foo
+0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.' aptget dist-upgrade -st versioned
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+ bar foo
+0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.' aptget dist-upgrade -st multipleno
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ foo
+The following packages will be upgraded:
+ bar
+1 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv foo [1]
+Inst bar [1] (2.2 multipleyes [amd64])
+Conf bar (2.2 multipleyes [amd64])' aptget dist-upgrade -st multipleyes
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ baz
+0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
+Inst baz (2 unversioned [amd64])
+Conf baz (2 unversioned [amd64])' aptget install baz -st unversioned
+testequal 'Reading package lists...
+Building dependency tree...
+The following extra packages will be installed:
+ foo
+The following packages will be REMOVED:
+ bar
+The following NEW packages will be installed:
+ baz
+The following packages will be upgraded:
+ foo
+1 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv bar [1]
+Inst foo [1] (2 versioned [amd64])
+Inst baz (2 versioned [amd64])
+Conf foo (2 versioned [amd64])
+Conf baz (2 versioned [amd64])' aptget install baz -st versioned
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ baz
+0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
+Inst baz (2 unversioned [amd64])
+Conf baz (2 unversioned [amd64])' aptget install baz -st unversioned
+testequal 'Reading package lists...
+Building dependency tree...
+The following extra packages will be installed:
+ foo
+The following packages will be REMOVED:
+ bar
+The following NEW packages will be installed:
+ baz
+The following packages will be upgraded:
+ foo
+1 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
+Remv bar [1]
+Inst foo [1] (2 versioned [amd64])
+Inst baz (2 versioned [amd64])
+Conf foo (2 versioned [amd64])
+Conf baz (2 versioned [amd64])' aptget install baz -st versioned
diff --git a/test/integration/test-apt-cdrom b/test/integration/test-apt-cdrom
index cc3483f9b..8d8fdf167 100755
--- a/test/integration/test-apt-cdrom
+++ b/test/integration/test-apt-cdrom
@@ -12,31 +12,60 @@ setupaptarchive --no-update
changetocdrom 'Debian APT Testdisk 0.8.15'
# -de is not in the Release file, but picked up anyway for compatibility
-cd rootdir/media/cdrom/dists/stable/main/i18n
+cd rootdir/media/cdrom-unmounted/dists/stable/main/i18n
+chmod +w .
sed -e '/^Description-en:/ d' -e '/^ / d' -e '/^$/ d' Translation-en > Translation-de
echo 'Description-de: automatisch generiertes Testpaket testing=0.8.15/stable
Diese Pakete sind nur für das testen von APT gedacht,
sie erfüllen keinen Zweck auf einem normalen System…
' >> Translation-de
compressfile Translation-de
-rm Translation-en Translation-de
+rm -f Translation-en Translation-de
+chmod -R -w .
cd - > /dev/null
-addtrap 'prefix' "chmod -R +w $PWD/rootdir/media/cdrom/dists/;"
-chmod -R -w rootdir/media/cdrom/dists
-aptcdrom add -m -o quiet=1 > apt-cdrom.log 2>&1
-sed -i -e '/^Using CD-ROM/ d' -e '/gpgv/ d' -e '/^Identifying/ d' -e '/Reading / d' apt-cdrom.log
-testfileequal apt-cdrom.log "Scanning disc for index files..
-Found 2 package indexes, 1 source indexes, 1 translation indexes and 1 signatures
-Found label 'Debian APT Testdisk 0.8.15'
-This disc is called:
+aptcdromlog() {
+ rm -f rootdir/tmp/apt-cdrom.log
+ test ! -e rootdir/media/cdrom || echo "CD-ROM is mounted, but shouldn't be!"
+ test -e rootdir/media/cdrom-unmounted || echo "Unmounted CD-ROM doesn't exist, but it should!"
+ aptcdrom "$@" -o quiet=1 >rootdir/tmp/apt-cdrom.log 2>&1 </dev/null
+ sed -e '/gpgv/ d' -e '/^Identifying/ d' -e '/Reading / d' rootdir/tmp/apt-cdrom.log
+ test ! -e rootdir/media/cdrom || echo "CD-ROM is mounted, but shouldn't be!"
+ test -e rootdir/media/cdrom-unmounted || echo "Unmounted CD-ROM doesn't exist, but it should!"
+}
+
+CDROM_PRE="Using CD-ROM mount point $(readlink -f ./rootdir/media)/cdrom/
+Unmounting CD-ROM...
+Waiting for disc...
+Please insert a Disc in the drive and press enter
+Mounting CD-ROM...
+Scanning disc for index files..."
+CDROM_POST="This disc is called:
'Debian APT Testdisk 0.8.15'
Writing new source list
Source list entries for this disc are:
deb cdrom:[Debian APT Testdisk 0.8.15]/ stable main
deb-src cdrom:[Debian APT Testdisk 0.8.15]/ stable main
+Unmounting CD-ROM...
Repeat this process for the rest of the CDs in your set."
+testequal "$CDROM_PRE
+Found 2 package indexes, 1 source indexes, 1 translation indexes and 1 signatures
+Found label 'Debian APT Testdisk 0.8.15'
+$CDROM_POST" aptcdromlog add
+
+testequal "Using CD-ROM mount point $(readlink -f ./rootdir/media)/cdrom/
+Mounting CD-ROM...
+Stored label: Debian APT Testdisk 0.8.15
+Unmounting CD-ROM..." aptcdromlog ident
+
+# apt-setup uses these commands (expect the tr in the id) to find id and label
+ident="$(LC_ALL=C aptcdrom ident 2>&1 )"
+CD_ID="$(echo "$ident" | grep "^Identifying" | head -n1 | cut -d" " -f2 | tr --delete '[]')"
+CD_LABEL="$(echo "$ident" | grep "^Stored label:" | head -n1 | sed "s/^[^:]*: //")"
+testequal "CD::${CD_ID} \"${CD_LABEL}\";
+CD::${CD_ID}::Label \"${CD_LABEL}\";" cat rootdir/var/lib/apt/cdroms.list
+
testequal 'Reading package lists...
Building dependency tree...
The following NEW packages will be installed:
@@ -54,49 +83,24 @@ Inst testing:i386 (0.8.15 stable [i386])
Conf testing:i386 (0.8.15 stable [i386])' aptget install testing:i386 -s
# check Idempotence of apt-cdrom (and disabling of Translation dropping)
-aptcdrom add -m -o quiet=1 -o APT::CDROM::DropTranslation=0 > apt-cdrom.log 2>&1
-sed -i -e '/^Using CD-ROM/ d' -e '/gpgv/ d' -e '/^Identifying/ d' -e '/Reading / d' apt-cdrom.log
-testfileequal apt-cdrom.log "Scanning disc for index files..
+testequal "$CDROM_PRE
Found 2 package indexes, 1 source indexes, 2 translation indexes and 1 signatures
-This disc is called:
-'Debian APT Testdisk 0.8.15'
-Writing new source list
-Source list entries for this disc are:
-deb cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-deb-src cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-Repeat this process for the rest of the CDs in your set."
+$CDROM_POST" aptcdromlog add -o APT::CDROM::DropTranslation=0
# take Translations from previous runs as needed
-aptcdrom add -m -o quiet=1 > apt-cdrom.log 2>&1
-sed -i -e '/^Using CD-ROM/ d' -e '/gpgv/ d' -e '/^Identifying/ d' -e '/Reading / d' apt-cdrom.log
-testfileequal apt-cdrom.log "Scanning disc for index files..
+testequal "$CDROM_PRE
Found 2 package indexes, 1 source indexes, 2 translation indexes and 1 signatures
-This disc is called:
-'Debian APT Testdisk 0.8.15'
-Writing new source list
-Source list entries for this disc are:
-deb cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-deb-src cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-Repeat this process for the rest of the CDs in your set."
+$CDROM_POST" aptcdromlog add
msgtest 'Test for the german description translation of' 'testing'
aptcache show testing -o Acquire::Languages=de | grep -q '^Description-de: ' && msgpass || msgfail
rm -rf rootdir/var/lib/apt/lists
mkdir -p rootdir/var/lib/apt/lists/partial
-aptcdrom add -m -o quiet=1 > apt-cdrom.log 2>&1
-sed -i -e '/^Using CD-ROM/ d' -e '/gpgv/ d' -e '/^Identifying/ d' -e '/Reading / d' apt-cdrom.log
-testfileequal apt-cdrom.log "Scanning disc for index files..
+testequal "$CDROM_PRE
Found 2 package indexes, 1 source indexes, 1 translation indexes and 1 signatures
-This disc is called:
-'Debian APT Testdisk 0.8.15'
-Writing new source list
-Source list entries for this disc are:
-deb cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-deb-src cdrom:[Debian APT Testdisk 0.8.15]/ stable main
-Repeat this process for the rest of the CDs in your set."
+$CDROM_POST" aptcdromlog add
msgtest 'Test for the english description translation of' 'testing'
aptcache show testing -o Acquire::Languages=en | grep -q '^Description-en: ' && msgpass || msgfail
-
# check that we really can install from a 'cdrom'
testdpkgnotinstalled testing
testsuccess aptget install testing -y
diff --git a/test/integration/test-apt-cli-list b/test/integration/test-apt-cli-list
index 47cfb624a..40bf81a39 100755
--- a/test/integration/test-apt-cli-list
+++ b/test/integration/test-apt-cli-list
@@ -19,12 +19,17 @@ insertinstalledpackage 'bar' 'i386' '1.0'
insertinstalledpackage 'foobar' 'i386' '1.0'
insertpackage 'unstable' 'foobar' 'i386' '2.0'
+insertinstalledpackage 'baz' 'all' '0.1'
+insertpackage 'testing' 'baz' 'all' '1.0'
+insertpackage 'unstable' 'baz' 'all' '2.0'
+
setupaptarchive
APTARCHIVE=$(readlink -f ./aptarchive)
testequal "Listing...
bar/now 1.0 i386 [installed,local]
+baz/unstable 2.0 all [upgradable from: 0.1]
foo/unstable 1.0 all
foobar/unstable 2.0 i386 [upgradable from: 1.0]" apt list
@@ -33,12 +38,14 @@ foo/unstable 1.0 all
foobar/unstable 2.0 i386 [upgradable from: 1.0]" apt list "foo*"
testequal "Listing...
+baz/unstable 2.0 all [upgradable from: 0.1]
foobar/unstable 2.0 i386 [upgradable from: 1.0]" apt list --upgradable
# FIXME: hm, hm - does it make sense to have this different? shouldn't
# we use "installed,upgradable" consitently?
testequal "Listing...
bar/now 1.0 i386 [installed,local]
+baz/now 0.1 all [installed,upgradable to: 2.0]
foobar/now 1.0 i386 [installed,upgradable to: 2.0]" apt list --installed
testequal "Listing...
@@ -51,3 +58,14 @@ bar/now 1.0 i386 [installed,local]
an autogenerated dummy bar=1.0/installed
" apt list bar --verbose
+# test for dpkg ^rc state
+insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files'
+testequal "Listing...
+conf-only/now 1.0 i386 [residual-config]" apt list conf-only
+
+# ensure that the users learns about multiple versions too
+testequal "Listing...
+baz/unstable 2.0 all [upgradable from: 0.1]
+N: There are 2 additional versions. Please use the '-a' switch to see them." apt list baz -o quiet=0
+
+
diff --git a/test/integration/test-apt-cli-search b/test/integration/test-apt-cli-search
index 84650b366..58613717b 100755
--- a/test/integration/test-apt-cli-search
+++ b/test/integration/test-apt-cli-search
@@ -13,7 +13,7 @@ if [ ! -x ${BUILDDIRECTORY}/apt ]; then
exit 0
fi
-DESCR='Some description that has a unusual word xxyyzz and aabbcc'
+DESCR='Some description that has a unusual word xxyyzz and aabbcc and a UPPERCASE'
DESCR2='Some other description with the unusual aabbcc only'
insertpackage 'unstable' 'foo' 'all' '1.0' '' '' "$DESCR"
insertpackage 'testing' 'bar' 'i386' '2.0' '' '' "$DESCR2"
@@ -39,6 +39,11 @@ testequal "foo/unstable 1.0 all
$DESCR
" apt search -qq aabbcc xxyyzz
+# search is not case-sensitive by default
+testequal "foo/unstable 1.0 all
+ $DESCR
+" apt search -qq uppercase
+
# output is sorted and search word finds both package
testequal "bar/testing 2.0 i386
$DESCR2
diff --git a/test/integration/test-apt-extracttemplates b/test/integration/test-apt-extracttemplates
new file mode 100755
index 000000000..ae2cc8bc2
--- /dev/null
+++ b/test/integration/test-apt-extracttemplates
@@ -0,0 +1,45 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'amd64'
+
+# apt-extracttemplates needs this
+insertinstalledpackage 'debconf' 'amd64' '1.5'
+insertinstalledpackage 'pkg-with-template' 'amd64' '1.0'
+
+# build a simple package that contains a config and a tempalte
+mkdir -p DEBIAN
+TEMPLATE_STR="Template: foo/bar
+Type: string
+Description: Some bar var
+"
+echo "$TEMPLATE_STR" > DEBIAN/templates
+
+CONFIG_STR="#!/bin/sh
+random shell stuff
+"
+echo "$CONFIG_STR" > DEBIAN/config
+
+buildsimplenativepackage 'pkg-with-template' 'amd64' '0.8.15' 'stable' '' 'pkg with template' '' '' './DEBIAN'
+
+# ensure we get the right stuff out of the file
+mkdir extracttemplates-out
+OUT="$(aptextracttemplates -t ./extracttemplates-out incoming/pkg-with-template*.deb)"
+
+PKG=$(printf "$OUT" | cut -f1 -d' ')
+INSTALLED_VER=$(printf "$OUT" | cut -f2 -d' ')
+TEMPLATE=$(printf "$OUT" | cut -f3 -d' ')
+CONFIG=$(printf "$OUT" | cut -f4 -d' ')
+
+testequal "$CONFIG_STR" cat $CONFIG
+testequal "$TEMPLATE_STR" cat $TEMPLATE
+
+# ensure that the format of the output string has the right number of dots
+for s in "$CONFIG" "$TEMPLATE"; do
+ NR_DOTS=$(basename "$s" | tr -c -d .)
+ testequal ".." echo $NR_DOTS
+done
diff --git a/test/integration/test-apt-helper b/test/integration/test-apt-helper
new file mode 100755
index 000000000..6505b5956
--- /dev/null
+++ b/test/integration/test-apt-helper
@@ -0,0 +1,39 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+changetohttpswebserver
+
+echo "foo" > aptarchive/foo
+
+msgtest 'apt-file download-file md5sum'
+apthelper -qq download-file http://localhost:8080/foo foo2 MD5Sum:d3b07384d113edec49eaa6238ad5ff00 && msgpass || msgfail
+testfileequal foo2 'foo'
+
+msgtest 'apt-file download-file sha1'
+apthelper -qq download-file http://localhost:8080/foo foo1 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 && msgpass || msgfail
+testfileequal foo1 'foo'
+
+msgtest 'apt-file download-file sha256'
+apthelper -qq download-file http://localhost:8080/foo foo3 SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c && msgpass || msgfail
+testfileequal foo3 'foo'
+
+msgtest 'apt-file download-file no-hash'
+apthelper -qq download-file http://localhost:8080/foo foo4 && msgpass || msgfail
+testfileequal foo4 'foo'
+
+msgtest 'apt-file download-file wrong hash'
+if ! apthelper -qq download-file http://localhost:8080/foo foo5 MD5Sum:aabbcc 2>&1 2> download.stderr; then
+ msgpass
+else
+ msgfail
+fi
+testfileequal download.stderr 'E: Failed to fetch http://localhost:8080/foo Hash Sum mismatch
+
+E: Download Failed'
+testfileequal foo5.FAILED 'foo'
diff --git a/test/integration/test-apt-https-no-redirect b/test/integration/test-apt-https-no-redirect
index c405d1167..73352a28c 100755
--- a/test/integration/test-apt-https-no-redirect
+++ b/test/integration/test-apt-https-no-redirect
@@ -7,18 +7,24 @@ TESTDIR=$(readlink -f $(dirname $0))
setupenvironment
configarchitecture "i386"
-buildsimplenativepackage 'apt' 'all' '1.0' 'stable'
+insertpackage 'stable' 'apt' 'all' '1'
setupaptarchive --no-update
+echo 'alright' > aptarchive/working
changetohttpswebserver -o 'aptwebserver::redirect::replace::/redirectme/=http://localhost:8080/'
-msgtest 'normal http download works'
-downloadfile 'http://localhost:8080/pool/apt_1.0/changelog' changelog2 >/dev/null 2>/dev/null && msgpass || msgfail
+msgtest 'download of a file works via' 'http'
+downloadfile 'http://localhost:8080/working' httpfile >/dev/null 2>&1 && msgpass || msgfail
+testfileequal httpfile 'alright'
-msgtest 'normal https download works'
-downloadfile 'https://localhost:4433/pool/apt_1.0/changelog' changelog >/dev/null 2>/dev/null && msgpass || msgfail
+msgtest 'download of a file works via' 'https'
+downloadfile 'https://localhost:4433/working' httpsfile >/dev/null 2>&1 && msgpass || msgfail
+testfileequal httpsfile 'alright'
-msgtest 'redirecting https to http does not work'
-downloadfile 'https://localhost:4433/redirectme/pool/apt_1.0/changelog' changelog3 2>&1 | grep "Protocol http not supported or disabled in libcurl" > /dev/null && msgpass
+msgtest 'download of a file does not work if' 'https redirected to http'
+downloadfile 'https://localhost:4433/redirectme/working' redirectfile >curloutput 2>&1 && msgfail || msgpass
+
+msgtest 'libcurl has forbidden access in last request to' 'http resource'
+grep -q -- 'Protocol http not supported or disabled in libcurl' curloutput && msgpass || msgfail
diff --git a/test/integration/test-apt-progress-fd-error-postinst b/test/integration/test-apt-progress-fd-error-postinst
deleted file mode 100755
index 0b6e70212..000000000
--- a/test/integration/test-apt-progress-fd-error-postinst
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-set -e
-
-TESTDIR=$(readlink -f $(dirname $0))
-. $TESTDIR/framework
-
-setupenvironment
-configarchitecture 'amd64' 'i386'
-
-mkdir -p DEBIAN/
-echo "#!/bin/sh\nexit 1" > DEBIAN/postinst
-chmod 755 DEBIAN/postinst
-
-buildsimplenativepackage 'postinst-error' 'amd64,i386' '0.8.15' 'stable' '' 'pkg with posinst error' '' '' './DEBIAN'
-
-setupaptarchive
-
-exec 3> apt-progress.log
-testfailure aptget install postinst-error -y -o APT::Status-Fd=3
-msgtest "Ensure correct error message for postinst error"
-grep -q "pmerror:postinst-error :80:subprocess installed post-installation script returned error exit status 2" apt-progress.log && msgpass || msgfail
-
diff --git a/test/integration/test-bug-612958-use-dpkg-multiarch-config b/test/integration/test-bug-612958-use-dpkg-multiarch-config
index 4d1f00ca0..7bf5781e8 100755
--- a/test/integration/test-bug-612958-use-dpkg-multiarch-config
+++ b/test/integration/test-bug-612958-use-dpkg-multiarch-config
@@ -43,6 +43,15 @@ testpass 'apt config' 'armel'
rm $CONFFILE
echo '#clear APT::Architectures;' >> $CONFFILE
+echo 'APT::Architectures "i386,amd64";' >> $CONFFILE
+
+testpass 'apt config' 'i386'
+testpass 'apt config' 'amd64'
+testfail 'apt config' 'armel'
+
+rm $CONFFILE
+
+echo '#clear APT::Architectures;' >> $CONFFILE
echo 'Dir::Bin::dpkg "./dpkg-printer";' >> $CONFFILE
echo '#! /bin/sh
diff --git a/test/integration/test-bug-661537-build-profiles-support b/test/integration/test-bug-661537-build-profiles-support
new file mode 100755
index 000000000..ae1403f71
--- /dev/null
+++ b/test/integration/test-bug-661537-build-profiles-support
@@ -0,0 +1,147 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64' 'i386' 'armel'
+
+insertinstalledpackage 'build-essential' 'all' '0' 'Multi-Arch: foreign'
+
+insertpackage 'unstable' 'foo' 'all' '1.0'
+insertpackage 'unstable' 'bar' 'all' '1.0'
+
+insertsource 'unstable' 'buildprofiles' 'any' '1' 'Build-Depends: foo (>= 1.0) [i386 arm] <!profile.stage1 !profile.cross>, bar'
+
+# table from https://wiki.debian.org/BuildProfileSpec
+insertsource 'unstable' 'spec-1' 'any' '1' 'Build-Depends: foo <!profile.stage1>'
+insertsource 'unstable' 'spec-2' 'any' '1' 'Build-Depends: foo <profile.stage1>'
+insertsource 'unstable' 'spec-3' 'any' '1' 'Build-Depends: foo <!profile.stage1 !profile.notest>'
+insertsource 'unstable' 'spec-4' 'any' '1' 'Build-Depends: foo <profile.stage1 profile.notest>'
+insertsource 'unstable' 'spec-5' 'any' '1' 'Build-Depends: foo <!profile.stage1 profile.notest>'
+insertsource 'unstable' 'spec-6' 'any' '1' 'Build-Depends: foo <profile.stage1 !profile.notest>'
+# multiple stanzas not supported: error out
+insertsource 'unstable' 'spec-7' 'any' '1' 'Build-Depends: foo <profile.stage1><!profile.notest>'
+insertsource 'unstable' 'spec-8' 'any' '1' 'Build-Depends: foo <profile.stage1> <!profile.notest>'
+
+setupaptarchive
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ bar
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst bar (1.0 unstable [all])
+Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ bar foo
+0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
+Inst bar (1.0 unstable [all])
+Inst foo (1.0 unstable [all])
+Conf bar (1.0 unstable [all])
+Conf foo (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=i386
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ bar
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst bar (1.0 unstable [all])
+Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=armel
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ bar
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst bar (1.0 unstable [all])
+Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=i386 -P stage1
+
+KEEP='Reading package lists...
+Building dependency tree...
+The following NEW packages will be installed:
+ foo
+0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
+Inst foo (1.0 unstable [all])
+Conf foo (1.0 unstable [all])'
+DROP='Reading package lists...
+Building dependency tree...
+0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.'
+
+msgtest 'Check if version of installed dpkg is high enough for' 'build profiles support'
+if dpkg --compare-versions "$(command dpkg-query --showformat='${Version}' --show dpkg)" 'ge' '1.17.2'; then
+ msgpass
+ testwithdpkg() {
+ msgtest "Test with" "dpkg-checkbuilddeps -d '$1' -P '$2'"
+ local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwithdpkg.output"
+ if dpkgcheckbuilddeps -d "$1" -P "$2" /dev/null >$OUTPUT 2>&1; then
+ if [ "$3" = "$DROP" ]; then
+ msgpass
+ else
+ cat $OUTPUT
+ msgfail
+ fi
+ else
+ if [ "$3" = "$KEEP" ]; then
+ msgpass
+ else
+ cat $OUTPUT
+ msgfail
+ fi
+ fi
+ }
+else
+ msgskip
+ testwithdpkg() {
+ msgtest "Test with" "dpkg-checkbuilddeps -d '$1' -P '$2'"
+ msgskip
+ }
+fi
+
+testprofile() {
+ if [ -n "$3" ]; then
+ testequal "$4" aptget build-dep "$1" -s -P "$3"
+ export DEB_BUILD_PROFILES="$(echo "$3" | tr ',' ' ')"
+ testequal "$4" aptget build-dep "$1" -s -o with::environment=1
+ unset DEB_BUILD_PROFILES
+ else
+ testequal "$4" aptget build-dep "$1" -s
+ fi
+ testwithdpkg "$2" "$3" "$4"
+}
+
+testprofile 'spec-1' 'foo <!profile.stage1>' '' "$KEEP"
+testprofile 'spec-1' 'foo <!profile.stage1>' 'stage1' "$DROP"
+testprofile 'spec-1' 'foo <!profile.stage1>' 'notest' "$KEEP"
+testprofile 'spec-1' 'foo <!profile.stage1>' 'stage1,notest' "$DROP"
+
+testprofile 'spec-2' 'foo <profile.stage1>' '' "$DROP"
+testprofile 'spec-2' 'foo <profile.stage1>' 'stage1' "$KEEP"
+testprofile 'spec-2' 'foo <profile.stage1>' 'notest' "$DROP"
+testprofile 'spec-2' 'foo <profile.stage1>' 'stage1,notest' "$KEEP"
+
+testprofile 'spec-3' 'foo <!profile.stage1 !profile.notest>' '' "$KEEP"
+testprofile 'spec-3' 'foo <!profile.stage1 !profile.notest>' 'stage1' "$DROP"
+testprofile 'spec-3' 'foo <!profile.stage1 !profile.notest>' 'notest' "$DROP"
+testprofile 'spec-3' 'foo <!profile.stage1 !profile.notest>' 'stage1,notest' "$DROP"
+
+testprofile 'spec-4' 'foo <profile.stage1 profile.notest>' '' "$DROP"
+testprofile 'spec-4' 'foo <profile.stage1 profile.notest>' 'stage1' "$KEEP"
+testprofile 'spec-4' 'foo <profile.stage1 profile.notest>' 'notest' "$KEEP"
+testprofile 'spec-4' 'foo <profile.stage1 profile.notest>' 'stage1,notest' "$KEEP"
+
+testprofile 'spec-5' 'foo <!profile.stage1 profile.notest>' '' "$KEEP"
+testprofile 'spec-5' 'foo <!profile.stage1 profile.notest>' 'stage1' "$DROP"
+testprofile 'spec-5' 'foo <!profile.stage1 profile.notest>' 'notest' "$KEEP"
+testprofile 'spec-5' 'foo <!profile.stage1 profile.notest>' 'stage1,notest' "$DROP"
+
+testprofile 'spec-6' 'foo <profile.stage1 !profile.notest>' '' "$KEEP"
+testprofile 'spec-6' 'foo <profile.stage1 !profile.notest>' 'stage1' "$KEEP"
+testprofile 'spec-6' 'foo <profile.stage1 !profile.notest>' 'notest' "$DROP"
+testprofile 'spec-6' 'foo <profile.stage1 !profile.notest>' 'stage1,notest' "$KEEP"
+
+testfailure aptget build-dep spec-7 -s
+testfailure aptget build-dep spec-8 -s
diff --git a/test/integration/test-bug-735967-lib32-to-i386-unavailable b/test/integration/test-bug-735967-lib32-to-i386-unavailable
index 4dbe1d25d..e9f3bf96d 100755
--- a/test/integration/test-bug-735967-lib32-to-i386-unavailable
+++ b/test/integration/test-bug-735967-lib32-to-i386-unavailable
@@ -12,6 +12,9 @@ insertpackage 'unstable' 'libnss-mdns' 'amd64,i386' '0.10-6' 'Multi-Arch: same
Breaks: lib32nss-mdns (<< 0.10-6)'
insertpackage 'unstable' 'libnss-mdns-i386' 'i386' '0.10-6' 'Multi-Arch: foreign
Depends: libnss-mdns'
+# introduce some dummies so that there are versions, but none works
+insertpackage 'unstable' 'libnss-mdns-i386' 'amd64' '0.1-6'
+insertpackage 'experimental' 'libnss-mdns-amd64' 'i386,amd64' '0.10-6' 'Provides: libnss-mdns-i386'
insertpackage 'unstable' 'foo' 'amd64' '1' 'Depends: libfoo'
insertpackage 'unstable' 'libfoo' 'amd64' '1' 'Depends: libfoo-bin'
diff --git a/test/integration/test-bug-740843-versioned-up-down-breaks b/test/integration/test-bug-740843-versioned-up-down-breaks
new file mode 100755
index 000000000..cb035a71f
--- /dev/null
+++ b/test/integration/test-bug-740843-versioned-up-down-breaks
@@ -0,0 +1,55 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64' 'i386'
+
+insertinstalledpackage 'foo-driver' 'amd64' '1' 'Depends: libfoo (= 1)
+Recommends: libgl1-foo-glx (= 1)
+Breaks: libgl1-foo-glx (<< 1), libgl1-foo-glx (>> 1)'
+insertinstalledpackage 'libgl1-foo-glx' 'amd64,i386' '1' 'Depends: libfoo (= 1)
+Multi-Arch: same'
+insertinstalledpackage 'libfoo' 'amd64,i386' '1' 'Multi-Arch: same'
+
+buildsimplenativepackage 'foo-driver' 'amd64' '2' 'stable' 'Depends: libfoo (= 2)
+Recommends: libgl1-foo-glx (= 2)
+Breaks: libgl1-foo-glx (<< 2), libgl1-foo-glx (>> 2)'
+buildsimplenativepackage 'libgl1-foo-glx' 'amd64,i386' '2' 'stable' 'Depends: libfoo (= 2)
+Multi-Arch: same'
+buildsimplenativepackage 'libfoo' 'amd64,i386' '2' 'stable' 'Multi-Arch: same'
+
+setupaptarchive
+
+testequalor2 'Reading package lists...
+Building dependency tree...
+The following packages will be upgraded:
+ foo-driver libfoo libfoo:i386 libgl1-foo-glx libgl1-foo-glx:i386
+5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+Inst libgl1-foo-glx [1] (2 stable [amd64]) [libgl1-foo-glx:amd64 on libgl1-foo-glx:i386] [libgl1-foo-glx:i386 on libgl1-foo-glx:amd64] [foo-driver:amd64 on libgl1-foo-glx:amd64] [libgl1-foo-glx:i386 foo-driver:amd64 ]
+Inst libgl1-foo-glx:i386 [1] (2 stable [i386]) [foo-driver:amd64 on libgl1-foo-glx:amd64] [foo-driver:amd64 on libgl1-foo-glx:i386] [foo-driver:amd64 ]
+Inst foo-driver [1] (2 stable [amd64]) []
+Inst libfoo:i386 [1] (2 stable [i386]) [libfoo:amd64 on libfoo:i386] [libfoo:i386 on libfoo:amd64] [libfoo:amd64 ]
+Inst libfoo [1] (2 stable [amd64])
+Conf libfoo:i386 (2 stable [i386])
+Conf libfoo (2 stable [amd64])
+Conf libgl1-foo-glx:i386 (2 stable [i386])
+Conf libgl1-foo-glx (2 stable [amd64])
+Conf foo-driver (2 stable [amd64])' 'Reading package lists...
+Building dependency tree...
+The following packages will be upgraded:
+ foo-driver libfoo libfoo:i386 libgl1-foo-glx libgl1-foo-glx:i386
+5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+Inst libgl1-foo-glx [1] (2 stable [amd64]) [foo-driver:amd64 on libgl1-foo-glx:amd64] [libgl1-foo-glx:amd64 on libgl1-foo-glx:i386] [libgl1-foo-glx:i386 on libgl1-foo-glx:amd64] [foo-driver:amd64 libgl1-foo-glx:i386 ]
+Inst libgl1-foo-glx:i386 [1] (2 stable [i386]) [foo-driver:amd64 on libgl1-foo-glx:amd64] [foo-driver:amd64 on libgl1-foo-glx:i386] [foo-driver:amd64 ]
+Inst foo-driver [1] (2 stable [amd64]) []
+Inst libfoo:i386 [1] (2 stable [i386]) [libfoo:amd64 on libfoo:i386] [libfoo:i386 on libfoo:amd64] [libfoo:amd64 ]
+Inst libfoo [1] (2 stable [amd64])
+Conf libfoo:i386 (2 stable [i386])
+Conf libfoo (2 stable [amd64])
+Conf libgl1-foo-glx:i386 (2 stable [i386])
+Conf libgl1-foo-glx (2 stable [amd64])
+Conf foo-driver (2 stable [amd64])' aptget dist-upgrade -s
+
+testsuccess aptget dist-upgrade -y -o Debug::pkgPackageManager=1 -o Debug::pkgOrderList=1
diff --git a/test/integration/test-bug-multiarch-upgrade b/test/integration/test-bug-multiarch-upgrade
index dc3725df1..c29e1f903 100755
--- a/test/integration/test-bug-multiarch-upgrade
+++ b/test/integration/test-bug-multiarch-upgrade
@@ -25,5 +25,5 @@ The following packages will be upgraded:
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Inst libcups2 [1] (2 unstable [amd64]) [libcups2:amd64 on libcups2:i386] [libcups2:i386 on libcups2:amd64] [libcups2:i386 ]
Inst libcups2:i386 [1] (2 unstable [i386])
-Conf libcups2 (2 unstable [amd64])
-Conf libcups2:i386 (2 unstable [i386])' aptget install -s libcups2:i386
+Conf libcups2:i386 (2 unstable [i386])
+Conf libcups2 (2 unstable [amd64])' aptget install -s libcups2:i386
diff --git a/test/integration/test-compressed-indexes b/test/integration/test-compressed-indexes
index c6f5ab49e..67ca0ba27 100755
--- a/test/integration/test-compressed-indexes
+++ b/test/integration/test-compressed-indexes
@@ -5,6 +5,7 @@ TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
setupenvironment
+configcompression '.' 'gz' # only gz is supported for this, so ensure it is used
configarchitecture "i386"
buildsimplenativepackage "testpkg" "i386" "1.0"
diff --git a/test/integration/test-conflicts-loop b/test/integration/test-conflicts-loop
index 4407fbd9d..4978fe1e8 100755
--- a/test/integration/test-conflicts-loop
+++ b/test/integration/test-conflicts-loop
@@ -6,11 +6,11 @@ TESTDIR=$(readlink -f $(dirname $0))
setupenvironment
configarchitecture "i386"
-insertinstalledpackage 'openjdk-6-jre' 'i386' '6b16-1.8-0ubuntu1'
+insertinstalledpackage 'openjdk-6-jre' 'i386' '6b16-1.8-0ubuntu1'
insertpackage 'unstable' 'openjdk-6-jre' 'i386' '6b20-1.9.8-0ubuntu1~10.04.1' 'Conflicts: openjdk-6-jre-headless (<< 6b17~pre3-1), openjdk-6-jre-lib (<< 6b17~pre3-1)'
-insertinstalledpackage 'openjdk-6-jre-lib' 'i386' '6b16-1.8-0ubuntu1'
+insertinstalledpackage 'openjdk-6-jre-lib' 'i386' '6b16-1.8-0ubuntu1'
insertpackage 'unstable' 'openjdk-6-jre-lib' 'i386' '6b20-1.9.8-0ubuntu1~10.04.1' 'Conflicts: openjdk-6-jre (<< 6b17~pre3-1), openjdk-6-jre-headless (<< 6b17~pre3-1)'
-insertinstalledpackage 'openjdk-6-jre-headless' 'i386' '6b16-1.8-0ubuntu1'
+insertinstalledpackage 'openjdk-6-jre-headless' 'i386' '6b16-1.8-0ubuntu1'
insertpackage 'unstable' 'openjdk-6-jre-headless' 'i386' '6b20-1.9.8-0ubuntu1~10.04.1' 'Conflicts: openjdk-6-jre (<< 6b17~pre3-1), openjdk-6-jre-lib (<< 6b17~pre3-1)'
setupaptarchive
@@ -19,16 +19,10 @@ testequal 'Reading package lists...
Building dependency tree...
The following packages will be upgraded:
openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib
- openjdk-6-jre-lib:i386 conflicts with openjdk-6-jre:i386
- openjdk-6-jre:i386 conflicts with openjdk-6-jre-headless:i386
- openjdk-6-jre-headless:i386 conflicts with openjdk-6-jre:i386
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Remv openjdk-6-jre [6b16-1.8-0ubuntu1]
- openjdk-6-jre-headless:i386 conflicts with openjdk-6-jre-lib:i386
Remv openjdk-6-jre-lib [6b16-1.8-0ubuntu1]
Inst openjdk-6-jre-headless [6b16-1.8-0ubuntu1] (6b20-1.9.8-0ubuntu1~10.04.1 unstable [i386])
- openjdk-6-jre:i386 conflicts with openjdk-6-jre-lib:i386
- openjdk-6-jre:i386 conflicts with openjdk-6-jre-lib:i386
Inst openjdk-6-jre [6b16-1.8-0ubuntu1] (6b20-1.9.8-0ubuntu1~10.04.1 unstable [i386])
Inst openjdk-6-jre-lib [6b16-1.8-0ubuntu1] (6b20-1.9.8-0ubuntu1~10.04.1 unstable [i386])
Conf openjdk-6-jre-lib (6b20-1.9.8-0ubuntu1~10.04.1 unstable [i386])
diff --git a/test/integration/test-failing-maintainer-scripts b/test/integration/test-failing-maintainer-scripts
new file mode 100755
index 000000000..3dd7d643e
--- /dev/null
+++ b/test/integration/test-failing-maintainer-scripts
@@ -0,0 +1,132 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'native'
+
+# create a bunch of failures
+createfailure() {
+ setupsimplenativepackage "failure-$1" 'native' '1.0' 'unstable' 'Depends: dependee'
+ BUILDDIR="incoming/failure-$1-1.0"
+ echo '#!/bin/sh
+exit 29' > ${BUILDDIR}/debian/$1
+ buildpackage "$BUILDDIR" 'unstable' 'main' 'native'
+ rm -rf "$BUILDDIR"
+}
+
+buildsimplenativepackage 'dependee' 'native' '1.0' 'unstable'
+createfailure 'preinst'
+createfailure 'postinst'
+createfailure 'prerm'
+createfailure 'postrm'
+
+setupaptarchive
+
+# create a library to noop chroot() and rewrite maintainer script executions
+# via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
+# chroot directory dpkg could chroot into to execute the maintainer scripts
+cat << EOF > noopchroot.c
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dlfcn.h>
+
+static char * chrootdir = NULL;
+
+int chroot(const char *path) {
+ printf("WARNING: CHROOTing to %s was ignored!\n", path);
+ free(chrootdir);
+ chrootdir = strdup(path);
+ return 0;
+}
+int execvp(const char *file, char *const argv[]) {
+ static int (*func_execvp) (const char *, char * const []) = NULL;
+ if (func_execvp == NULL)
+ func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
+ if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
+ return func_execvp(file, argv);
+ printf("REWRITE execvp call %s into %s\n", file, chrootdir);
+ char newfile[strlen(chrootdir) + strlen(file)];
+ strcpy(newfile, chrootdir);
+ strcat(newfile, file);
+ return func_execvp(newfile, argv);
+}
+EOF
+testsuccess gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+
+mkdir -p "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
+DPKG="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
+echo "#!/bin/sh
+if [ -n \"\$LD_PRELOAD\" ]; then
+ export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}\"
+else
+ export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so\"
+fi
+dpkg \"\$@\"" > $DPKG
+chmod +x $DPKG
+sed -ie "s|^DPKG::options:: \"dpkg\";\$|DPKG::options:: \"$DPKG\";|" aptconfig.conf
+
+# setup some pre- and post- invokes to check the output isn't garbled later
+APTHOOK="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apthook"
+echo '#!/bin/sh
+echo "$1: START"
+echo "$1: MaiN"
+echo "$1: ENd"' > $APTHOOK
+chmod +x $APTHOOK
+echo "DPKG::Pre-Invoke:: \"${APTHOOK} PRE\";
+DPKG::Post-Invoke:: \"${APTHOOK} POST\";" > rootdir/etc/apt/apt.conf.d/99apthooks
+
+testmyfailure() {
+ local PROGRESS='rootdir/tmp/progress.log'
+ exec 3> $PROGRESS
+ testfailure "$@" -o APT::Status-Fd=3
+ msgtest 'Test for failure message of maintainerscript in' 'console log'
+ local TEST='rootdir/tmp/testfailure.output'
+ if grep -q 'exit status 29' "$TEST"; then
+ msgpass
+ else
+ cat $TEST
+ msgfail
+ fi
+ msgtest 'Test for proper execution of invoke scripts in' 'console log'
+ if grep -q '^PRE: START$' $TEST &&
+ grep -q '^PRE: MaiN$' $TEST &&
+ grep -q '^PRE: ENd$' $TEST &&
+ grep -q '^POST: START$' $TEST &&
+ grep -q '^POST: MaiN$' $TEST &&
+ grep -q '^POST: ENd$' $TEST; then
+ msgpass
+ else
+ cat $TEST
+ msgfail
+ fi
+ msgtest 'Test for failure message of maintainerscript in' 'progress log'
+ if grep -q '^pmerror:.\+exit status 29$' "$PROGRESS"; then
+ msgpass
+ else
+ cat $PROGRESS
+ msgfail
+ fi
+ testmarkedauto 'dependee'
+}
+
+cp -a rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status.backup
+testmyfailure aptget install failure-preinst -y
+cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+testmyfailure aptget install failure-postinst -y
+cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+testsuccess aptget install failure-prerm -y
+testdpkginstalled failure-prerm
+testmyfailure aptget purge failure-prerm -y
+cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+testsuccess aptget install failure-postrm -y
+testdpkginstalled failure-postrm
+testmyfailure aptget purge failure-postrm -y
+
+# FIXME: test with output going to a PTY as it usually does
+#cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+#aptget install failure-preinst -y
diff --git a/test/integration/test-ignore-provides-if-versioned-breaks b/test/integration/test-ignore-provides-if-versioned-breaks
index f8b4544a0..745f7d206 100755
--- a/test/integration/test-ignore-provides-if-versioned-breaks
+++ b/test/integration/test-ignore-provides-if-versioned-breaks
@@ -142,9 +142,9 @@ The following packages will be upgraded:
2 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Inst foo-same:amd64 [2.0] (4.0 unstable [amd64]) [foo-same:amd64 on foo-same:i386] [foo-same:i386 on foo-same:amd64] [foo-same:i386 ]
Inst foo-same [2.0] (4.0 unstable [i386])
-Conf foo-same:amd64 (4.0 unstable [amd64])
-Conf foo-same (4.0 unstable [i386])
Inst foo-same-breaker-3 (1.0 unstable [i386])
Inst foo-same-provider (1.0 unstable [i386])
+Conf foo-same (4.0 unstable [i386])
+Conf foo-same:amd64 (4.0 unstable [amd64])
Conf foo-same-breaker-3 (1.0 unstable [i386])
Conf foo-same-provider (1.0 unstable [i386])' aptget install foo-same-provider foo-same-breaker-3 -s
diff --git a/test/integration/test-ignore-provides-if-versioned-conflicts b/test/integration/test-ignore-provides-if-versioned-conflicts
index 44eafcff1..a07252768 100755
--- a/test/integration/test-ignore-provides-if-versioned-conflicts
+++ b/test/integration/test-ignore-provides-if-versioned-conflicts
@@ -142,9 +142,9 @@ The following packages will be upgraded:
2 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Inst foo-same:amd64 [2.0] (4.0 unstable [amd64]) [foo-same:amd64 on foo-same:i386] [foo-same:i386 on foo-same:amd64] [foo-same:i386 ]
Inst foo-same [2.0] (4.0 unstable [i386])
-Conf foo-same:amd64 (4.0 unstable [amd64])
-Conf foo-same (4.0 unstable [i386])
Inst foo-same-breaker-3 (1.0 unstable [i386])
Inst foo-same-provider (1.0 unstable [i386])
+Conf foo-same (4.0 unstable [i386])
+Conf foo-same:amd64 (4.0 unstable [amd64])
Conf foo-same-breaker-3 (1.0 unstable [i386])
Conf foo-same-provider (1.0 unstable [i386])' aptget install foo-same-provider foo-same-breaker-3 -s
diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove
index 2b165d100..c51caa758 100755
--- a/test/integration/test-kernel-helper-autoremove
+++ b/test/integration/test-kernel-helper-autoremove
@@ -1,55 +1,101 @@
#!/bin/sh
-
set -e
-# setup testdir
TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
+setupenvironment
+configarchitecture 'amd64'
+
+# the executed script would use the installed apt-config,
+# which is outside of our control
+msgtest 'Check that the installed apt-config supports' '--no-empty'
+if apt-config dump --no-empty >/dev/null 2>&1; then
+ msgpass
+else
+ msgskip
+ exit 0
+fi
+
+CURRENTKERNEL="linux-image-$(uname -r)"
+insertinstalledpackage "$CURRENTKERNEL" 'amd64' '1'
+insertinstalledpackage 'linux-image-1.0.0-2-generic' 'amd64' '1.0.0-2'
+insertinstalledpackage 'linux-image-100.0.0-1-generic' 'amd64' '100.0.0-1'
+insertinstalledpackage 'linux-image-amd64' 'amd64' '100.0.0-1'
+# ensure that the '.' is really a dot and not a wildcard
+insertinstalledpackage 'linux-headers-1000000-1-generic' 'amd64' '100.0.0-1'
-TMPDIR=$(mktemp -d)
-cd $TMPDIR
-addtrap "cd /; rm -rf $TMPDIR"
+testsuccess aptmark auto "$CURRENTKERNEL" 'linux-image-1.0.0-2-generic' 'linux-image-100.0.0-1-generic' 'linux-headers-1000000-1-generic'
-# create mock environment
-mkdir apt.conf.d
-cat > aptconfig.conf <<EOF
-Dir::Etc::parts "$TMPDIR/apt.conf.d";
-Dir::bin::dpkg "$TMPDIR/fake-dpkg";
+cat > ./fake-dpkg <<EOF
+#!/bin/sh
+exec $(aptconfig dump --no-empty --format='%v ' 'DPKG::options') "\$@"
EOF
-APT_CONFIG=aptconfig.conf
-export APT_CONFIG
+chmod +x ./fake-dpkg
+echo 'Dir::Bin::dpkg "./fake-dpkg";' > rootdir/etc/apt/apt.conf.d/99fakedpkg
# install fake-dpkg into it
-install -m755 $TESTDIR/test-kernel-helper-autoremove.fake-dpkg $TMPDIR/fake-dpkg
+catfail() {
+ echo >&2
+ echo >&2 '### List of protected kernels:'
+ cat >&2 protected.list
+ msgfail
+}
-# run the helper
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh
+testprotected() {
+ rm -f rootdir/etc/apt/apt.conf.d/01autoremove-kernels protected.list
-msgtest 'Check that kernel autoremoval list is correctly created'
-# and ensure its there, valid and version 10.0.0-1 is there too
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels && msgpass || msgfail
+ testsuccess runapt sh ${TESTDIR}/../../debian/apt.auto-removal.sh "$@"
-msgtest 'Check that most recent kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" && msgpass || msgfail
+ msgtest 'Check kernel autoremoval protection list' 'is created'
+ test -e rootdir/etc/apt/apt.conf.d/01autoremove-kernels && msgpass || msgfail
-# ... and also that the running kernel is excluded
-msgtest 'Check that running kernel is saved from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" && msgpass || msgfail
+ msgtest 'Check kernel autoremoval protection list' 'can be dumped'
+ aptconfig dump --no-empty --format '%v%n' 'APT::NeverAutoRemove' >protected.list 2>&1 && msgpass || catfail
-# and that the old kernel is *not* excluded from autoremoval
-msgtest 'Check that older kernels are not excluded from autoremoval'
-apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic" && msgfail || msgpass
+ msgtest 'Check kernel autoremoval protection list' 'can be parsed'
+ grep -q '^[A-Z]: ' protected.list && catfail || msgpass
-msgtest "Check that the older kernel is retained when it's being installed"
-sh ${TESTDIR}/../../debian/apt.auto-removal.sh 1.0.01-2-generic
-test -e $TMPDIR/apt.conf.d/01autoremove-kernels
-if ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-10.0.0-1-generic" \
- || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-$(uname -r)" \
- || ! apt-config -c ${APT_CONFIG} dump|grep -q "APT::NeverAutoRemove::.*\^linux-image-1\.0\.01-2-generic"
-then
- msgfail
-else
- msgpass
-fi
+ msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel'
+ grep -q '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list && msgpass || catfail
+
+ msgtest 'Check kernel autoremoval protection list includes' 'running kernel'
+ grep -q "^\\^linux-image-$(uname -r | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list && msgpass || catfail
+}
+
+testequal "Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages will be REMOVED:
+ linux-headers-1000000-1-generic (100.0.0-1)
+ linux-image-1.0.0-2-generic (1.0.0-2)
+ linux-image-100.0.0-1-generic (100.0.0-1)
+ $CURRENTKERNEL (1)
+0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
+Remv linux-headers-1000000-1-generic [100.0.0-1]
+Remv linux-image-1.0.0-2-generic [1.0.0-2]
+Remv linux-image-100.0.0-1-generic [100.0.0-1]
+Remv $CURRENTKERNEL [1]" aptget autoremove -sV
+
+testprotected
+msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
+grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && catfail || msgpass
+
+testequal 'Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages will be REMOVED:
+ linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
+0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
+Remv linux-headers-1000000-1-generic [100.0.0-1]
+Remv linux-image-1.0.0-2-generic [1.0.0-2]' aptget autoremove -s
-# done
+testprotected 1.0.0-2-generic
+msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
+grep -q '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list && msgpass || catfail
+testequal 'Reading package lists...
+Building dependency tree...
+Reading state information...
+The following packages will be REMOVED:
+ linux-headers-1000000-1-generic
+0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv linux-headers-1000000-1-generic [100.0.0-1]' aptget autoremove -s
diff --git a/test/integration/test-kernel-helper-autoremove.fake-dpkg b/test/integration/test-kernel-helper-autoremove.fake-dpkg
deleted file mode 100644
index a365c5370..000000000
--- a/test/integration/test-kernel-helper-autoremove.fake-dpkg
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-set -e
-
-if [ "$1" = "-l" ]; then
- echo "ii linux-image-1.0.0-2-generic 1.0.01-2 amd64"
- echo "ii linux-image-$(uname -r) not-used amd64"
- echo "ii linux-image-10.0.0-1-generic 10.0.0.1-1 amd64"
-elif [ "$1" = "--compare-versions" ]; then
- dpkg "$1" "$2" "$3" "$4"
-else
- dpkg $@
-fi
-
diff --git a/test/integration/test-partial-file-support b/test/integration/test-partial-file-support
index 382789e68..5ab326def 100755
--- a/test/integration/test-partial-file-support
+++ b/test/integration/test-partial-file-support
@@ -13,17 +13,18 @@ copysource() {
touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
}
+DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'
+
testdownloadfile() {
- local DOWNLOG='download-testfile.log'
- rm -f "$DOWNLOG"
+ rm -f "$DOWNLOADLOG"
msgtest "Testing download of file $2 with" "$1"
- if ! downloadfile "$2" "$3" > "$DOWNLOG"; then
- cat >&2 "$DOWNLOG"
+ if ! downloadfile "$2" "$3" > "$DOWNLOADLOG"; then
+ cat >&2 "$DOWNLOADLOG"
msgfail
else
msgpass
fi
- cat "$DOWNLOG" | while read field hash; do
+ cat "$DOWNLOADLOG" | while read field hash; do
local EXPECTED
case "$field" in
'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
@@ -40,28 +41,12 @@ testdownloadfile() {
if [ "$EXPECTED" "$4" "$hash" ]; then
msgpass
else
- cat >&2 "$DOWNLOG"
+ cat >&2 "$DOWNLOADLOG"
msgfail "expected: $EXPECTED ; got: $hash"
fi
done
}
-testwebserverlaststatuscode() {
- local DOWNLOG='download-testfile.log'
- rm -f "$DOWNLOG"
- local STATUS="$(mktemp)"
- addtrap "rm $STATUS;"
- msgtest 'Test last status code from the webserver was' "$1"
- downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
- if [ "$(cat "$STATUS")" = "$1" ]; then
- msgpass
- else
- cat >&2 "$DOWNLOG"
- msgfail "Status was $(cat "$STATUS")"
- fi
-}
-
-
TESTFILE='aptarchive/testfile'
cp -a ${TESTDIR}/framework $TESTFILE
@@ -70,34 +55,34 @@ testrun() {
copysource $TESTFILE 0 ./testfile
testdownloadfile 'no data' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '200'
+ testwebserverlaststatuscode '200' "$DOWNLOADLOG"
copysource $TESTFILE 20 ./testfile
testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '206'
+ testwebserverlaststatuscode '206' "$DOWNLOADLOG"
copysource /dev/zero 20 ./testfile
testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
- testwebserverlaststatuscode '206'
+ testwebserverlaststatuscode '206' "$DOWNLOADLOG"
copysource $TESTFILE 1M ./testfile
testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '416'
+ testwebserverlaststatuscode '416' "$DOWNLOADLOG"
copysource /dev/zero 1M ./testfile
testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '200'
+ testwebserverlaststatuscode '200' "$DOWNLOADLOG"
copysource /dev/zero 20 ./testfile
touch ./testfile
testdownloadfile 'old data' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '200'
+ testwebserverlaststatuscode '200' "$DOWNLOADLOG"
webserverconfig 'aptwebserver::support::range' 'false'
copysource $TESTFILE 20 ./testfile
testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
- testwebserverlaststatuscode '200'
+ testwebserverlaststatuscode '200' "$DOWNLOADLOG"
}
testrun 'http://localhost:8080'
diff --git a/test/integration/test-prevent-markinstall-multiarch-same-versionscrew b/test/integration/test-prevent-markinstall-multiarch-same-versionscrew
index fed12dad0..d647856cb 100755
--- a/test/integration/test-prevent-markinstall-multiarch-same-versionscrew
+++ b/test/integration/test-prevent-markinstall-multiarch-same-versionscrew
@@ -55,14 +55,14 @@ Remv out-of-sync-gone-foreign:i386 [1]
Remv out-of-sync-gone-native [1]
Inst fine [1] (2 unstable [amd64]) [fine:amd64 on fine:i386] [fine:i386 on fine:amd64] [fine:i386 ]
Inst fine:i386 [1] (2 unstable [i386])
-Conf fine (2 unstable [amd64])
-Conf fine:i386 (2 unstable [i386])
Inst fine-installed [1] (2 unstable [amd64]) [fine-installed:amd64 on fine-installed:i386] [fine-installed:i386 on fine-installed:amd64] [fine-installed:i386 ]
Inst fine-installed:i386 [1] (2 unstable [i386])
-Conf fine-installed (2 unstable [amd64])
-Conf fine-installed:i386 (2 unstable [i386])
Inst out-of-sync-gone-foreign [1] (2 unstable [amd64])
Inst out-of-sync-gone-native:i386 [1] (2 unstable [i386])
+Conf fine:i386 (2 unstable [i386])
+Conf fine (2 unstable [amd64])
+Conf fine-installed:i386 (2 unstable [i386])
+Conf fine-installed (2 unstable [amd64])
Conf out-of-sync-gone-foreign (2 unstable [amd64])
Conf out-of-sync-gone-native:i386 (2 unstable [i386])' aptget dist-upgrade -s #-o Debug::pkgDepCache::Marker=1
diff --git a/test/integration/test-bug-1078697-missing-source-hashes b/test/integration/test-ubuntu-bug-1078697-missing-source-hashes
index 6fcb856b5..6fcb856b5 100755
--- a/test/integration/test-bug-1078697-missing-source-hashes
+++ b/test/integration/test-ubuntu-bug-1078697-missing-source-hashes
diff --git a/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard b/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard
new file mode 100755
index 000000000..2f2d384e1
--- /dev/null
+++ b/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard
@@ -0,0 +1,48 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'i386'
+
+# Regression test for LP: #1304403
+#
+# The issue here is that libkadm5srv-mit8 (priority standard) is replaced
+# by a new libkadm5srv-mit9 and libkbd5-7 breaks on the old -mit8 package.
+# The -mit8 package is no longer downloadable (and hence not upgradeable)
+
+# normal upradable pkg
+# (libkdb5-7 that breaks on libkadm5srv-mit8 (<< 1.11+dfsg~)
+insertinstalledpackage 'upgradable' 'all' '1.0' '' 'extra'
+insertpackage 'unstable' 'upgradable' 'all' '2.0' 'Breaks: not-downloadable (<< 1.1)' 'optional'
+
+# no longer downloadable pkg (libkadm5srv-mit8, replaced by libkadm5srv-mit9)
+# but priority standard pushes it higher
+insertinstalledpackage 'not-downloadable' 'all' '1.0' '' 'standard'
+
+setupaptarchive
+
+# discourage keeping obsolete high-priority packages …
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ not-downloadable
+The following packages will be upgraded:
+ upgradable
+1 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv not-downloadable [1.0]
+Inst upgradable [1.0] (2.0 unstable [all])
+Conf upgradable (2.0 unstable [all])' aptget -s dist-upgrade
+
+# … but if it has dependencies we want to keep it as usual
+for i in $(seq 1 10); do
+insertinstalledpackage "depender$i" 'all' '1.0' 'Depends: not-downloadable'
+done
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+ upgradable
+0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.' aptget -s dist-upgrade
diff --git a/test/integration/test-ubuntu-bug-365611-long-package-names b/test/integration/test-ubuntu-bug-365611-long-package-names
index 894c8dc97..f22986e21 100755
--- a/test/integration/test-ubuntu-bug-365611-long-package-names
+++ b/test/integration/test-ubuntu-bug-365611-long-package-names
@@ -4,8 +4,12 @@ set -e
TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
setupenvironment
-configarchitecture "i386"
+configarchitecture 'i386'
setupaptarchive
aptget install $(for i in $(seq 0 1000); do echo -n 'a'; done) 2> longpackagename.log > /dev/null || true
testfileequal 'longpackagename.log' "E: Unable to locate package $(for i in $(seq 0 1000); do echo -n 'a'; done)"
+
+# … and the opposite of long:
+aptget install "" -s >longpackagename.log 2>&1 || true
+testfileequal 'longpackagename.log' "$(aptget install -s)"
diff --git a/test/integration/test-very-tight-loop-configure-with-unpacking-new-packages b/test/integration/test-very-tight-loop-configure-with-unpacking-new-packages
index 5856cd744..c1d454f88 100755
--- a/test/integration/test-very-tight-loop-configure-with-unpacking-new-packages
+++ b/test/integration/test-very-tight-loop-configure-with-unpacking-new-packages
@@ -39,9 +39,9 @@ Inst libreoffice-core [3] (4 sid [amd64]) [libreoffice-core:amd64 on libreoffice
Inst libreoffice-common [3] (4 sid [all]) []
Inst ure (4 sid [amd64])
Conf ure (4 sid [amd64])
-Conf libreoffice-style-galaxy (4 sid [amd64])
Conf libreoffice-common (4 sid [all])
Conf libreoffice-core (4 sid [amd64])
+Conf libreoffice-style-galaxy (4 sid [amd64])
Conf libreoffice (4 sid [amd64])' 'Reading package lists...
Building dependency tree...
The following NEW packages will be installed:
@@ -55,7 +55,7 @@ Inst libreoffice-core [3] (4 sid [amd64]) [libreoffice-common:amd64 on libreoffi
Inst libreoffice-common [3] (4 sid [all]) []
Inst ure (4 sid [amd64])
Conf ure (4 sid [amd64])
-Conf libreoffice-style-galaxy (4 sid [amd64])
Conf libreoffice-common (4 sid [all])
Conf libreoffice-core (4 sid [amd64])
+Conf libreoffice-style-galaxy (4 sid [amd64])
Conf libreoffice (4 sid [amd64])' aptget dist-upgrade -s
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc
index 992f802a6..34476e1af 100644
--- a/test/interactive-helper/aptwebserver.cc
+++ b/test/interactive-helper/aptwebserver.cc
@@ -1,29 +1,31 @@
#include <config.h>
-#include <apt-pkg/strutl.h>
-#include <apt-pkg/fileutl.h>
-#include <apt-pkg/error.h>
#include <apt-pkg/cmndline.h>
#include <apt-pkg/configuration.h>
-#include <apt-pkg/init.h>
-
-#include <vector>
-#include <string>
-#include <list>
-#include <sstream>
+#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <regex.h>
+#include <signal.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#include <errno.h>
#include <time.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <signal.h>
+#include <unistd.h>
+#include <iostream>
+#include <sstream>
+#include <list>
+#include <string>
+#include <vector>
-char const * const httpcodeToStr(int const httpcode) /*{{{*/
+static char const * httpcodeToStr(int const httpcode) /*{{{*/
{
switch (httpcode)
{
@@ -77,7 +79,7 @@ char const * const httpcodeToStr(int const httpcode) /*{{{*/
return NULL;
}
/*}}}*/
-void addFileHeaders(std::list<std::string> &headers, FileFd &data) /*{{{*/
+static void addFileHeaders(std::list<std::string> &headers, FileFd &data)/*{{{*/
{
std::ostringstream contentlength;
contentlength << "Content-Length: " << data.FileSize();
@@ -88,14 +90,14 @@ void addFileHeaders(std::list<std::string> &headers, FileFd &data) /*{{{*/
headers.push_back(lastmodified);
}
/*}}}*/
-void addDataHeaders(std::list<std::string> &headers, std::string &data) /*{{{*/
+static void addDataHeaders(std::list<std::string> &headers, std::string &data)/*{{{*/
{
std::ostringstream contentlength;
contentlength << "Content-Length: " << data.size();
headers.push_back(contentlength.str());
}
/*}}}*/
-bool sendHead(int const client, int const httpcode, std::list<std::string> &headers)/*{{{*/
+static bool sendHead(int const client, int const httpcode, std::list<std::string> &headers)/*{{{*/
{
std::string response("HTTP/1.1 ");
response.append(httpcodeToStr(httpcode));
@@ -128,7 +130,7 @@ bool sendHead(int const client, int const httpcode, std::list<std::string> &head
return Success;
}
/*}}}*/
-bool sendFile(int const client, FileFd &data) /*{{{*/
+static bool sendFile(int const client, FileFd &data) /*{{{*/
{
bool Success = true;
char buffer[500];
@@ -144,7 +146,7 @@ bool sendFile(int const client, FileFd &data) /*{{{*/
return Success;
}
/*}}}*/
-bool sendData(int const client, std::string const &data) /*{{{*/
+static bool sendData(int const client, std::string const &data) /*{{{*/
{
if (FileFd::Write(client, data.c_str(), data.size()) == false)
{
@@ -154,7 +156,7 @@ bool sendData(int const client, std::string const &data) /*{{{*/
return true;
}
/*}}}*/
-void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/
+static void sendError(int const client, int const httpcode, std::string const &request,/*{{{*/
bool content, std::string const &error = "")
{
std::list<std::string> headers;
@@ -179,13 +181,13 @@ void sendError(int const client, int const httpcode, std::string const &request,
if (content == true)
sendData(client, response);
}
-void sendSuccess(int const client, std::string const &request,
+static void sendSuccess(int const client, std::string const &request,
bool content, std::string const &error = "")
{
sendError(client, 200, request, content, error);
}
/*}}}*/
-void sendRedirect(int const client, int const httpcode, std::string const &uri,/*{{{*/
+static void sendRedirect(int const client, int const httpcode, std::string const &uri,/*{{{*/
std::string const &request, bool content)
{
std::list<std::string> headers;
@@ -222,7 +224,7 @@ void sendRedirect(int const client, int const httpcode, std::string const &uri,/
sendData(client, response);
}
/*}}}*/
-int filter_hidden_files(const struct dirent *a) /*{{{*/
+static int filter_hidden_files(const struct dirent *a) /*{{{*/
{
if (a->d_name[0] == '.')
return 0;
@@ -236,7 +238,7 @@ int filter_hidden_files(const struct dirent *a) /*{{{*/
#endif
return 1;
}
-int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
+static int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
#ifdef _DIRENT_HAVE_D_TYPE
if ((*a)->d_type == DT_DIR && (*b)->d_type == DT_DIR);
else if ((*a)->d_type == DT_DIR && (*b)->d_type == DT_REG)
@@ -260,7 +262,7 @@ int grouped_alpha_case_sort(const struct dirent **a, const struct dirent **b) {
return strcasecmp((*a)->d_name, (*b)->d_name);
}
/*}}}*/
-void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
+static void sendDirectoryListing(int const client, std::string const &dir,/*{{{*/
std::string const &request, bool content)
{
std::list<std::string> headers;
@@ -312,7 +314,7 @@ void sendDirectoryListing(int const client, std::string const &dir, /*{{{*/
sendData(client, response);
}
/*}}}*/
-bool parseFirstLine(int const client, std::string const &request, /*{{{*/
+static bool parseFirstLine(int const client, std::string const &request,/*{{{*/
std::string &filename, std::string &params, bool &sendContent,
bool &closeConnection)
{
@@ -432,7 +434,7 @@ bool parseFirstLine(int const client, std::string const &request, /*{{{*/
return true;
}
/*}}}*/
-bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> const &parts)/*{{{*/
+static bool handleOnTheFlyReconfiguration(int const client, std::string const &request, std::vector<std::string> const &parts)/*{{{*/
{
size_t const pcount = parts.size();
if (pcount == 4 && parts[1] == "set")
@@ -475,7 +477,7 @@ bool handleOnTheFlyReconfiguration(int const client, std::string const &request,
return false;
}
/*}}}*/
-void * handleClient(void * voidclient) /*{{{*/
+static void * handleClient(void * voidclient) /*{{{*/
{
int client = *((int*)(voidclient));
std::clog << "ACCEPT client " << client << std::endl;
diff --git a/test/interactive-helper/extract-control.cc b/test/interactive-helper/extract-control.cc
index 3f7feabcb..852ec4ee9 100644
--- a/test/interactive-helper/extract-control.cc
+++ b/test/interactive-helper/extract-control.cc
@@ -1,13 +1,16 @@
+#include <config.h>
+
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
-bool ExtractMember(const char *File,const char *Member)
+static bool ExtractMember(const char *File,const char *Member)
{
FileFd Fd(File,FileFd::ReadOnly);
debDebFile Deb(Fd);
diff --git a/test/interactive-helper/mthdcat.cc b/test/interactive-helper/mthdcat.cc
index 25d09a3f5..2961b2080 100644
--- a/test/interactive-helper/mthdcat.cc
+++ b/test/interactive-helper/mthdcat.cc
@@ -2,6 +2,8 @@
All this does is cat a file into the method without closing the FD when
the file ends */
+#include <config.h>
+
#include <unistd.h>
int main()
diff --git a/test/interactive-helper/rpmver.cc b/test/interactive-helper/rpmver.cc
index 15c96cbbe..017c92fba 100644
--- a/test/interactive-helper/rpmver.cc
+++ b/test/interactive-helper/rpmver.cc
@@ -1,3 +1,5 @@
+#include <config.h>
+
#include <apt-pkg/debversion.h>
#include <rpm/rpmio.h>
#include <rpm/misc.h>
diff --git a/test/interactive-helper/test_udevcdrom.cc b/test/interactive-helper/test_udevcdrom.cc
index 88f5f0153..b87dcd935 100644
--- a/test/interactive-helper/test_udevcdrom.cc
+++ b/test/interactive-helper/test_udevcdrom.cc
@@ -1,7 +1,10 @@
+#include <config.h>
+
#include <apt-pkg/cdrom.h>
-#include <stdio.h>
-#include <assert.h>
+#include <stddef.h>
+#include <string>
+#include <assert.h>
#include <vector>
#include <iostream>
@@ -17,5 +20,4 @@ int main()
std::cerr << l[i].DeviceName << " "
<< l[i].Mounted << " "
<< l[i].MountPath << std::endl;
-
}
diff --git a/test/interactive-helper/testdeb.cc b/test/interactive-helper/testdeb.cc
index d28f20114..6aae9f563 100644
--- a/test/interactive-helper/testdeb.cc
+++ b/test/interactive-helper/testdeb.cc
@@ -1,15 +1,22 @@
+#include <config.h>
+
#include <apt-pkg/dirstream.h>
#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>
#include <apt-pkg/extracttar.h>
+#include <apt-pkg/arfile.h>
+#include <apt-pkg/fileutl.h>
+
+#include <iostream>
+#include <string>
class NullStream : public pkgDirStream
{
public:
- virtual bool DoItem(Item &Itm,int &Fd) {return true;};
+ virtual bool DoItem(Item &/*Itm*/, int &/*Fd*/) {return true;};
};
-bool Test(const char *File)
+static bool Test(const char *File)
{
FileFd Fd(File,FileFd::ReadOnly);
debDebFile Deb(Fd);
@@ -33,6 +40,11 @@ bool Test(const char *File)
int main(int argc, const char *argv[])
{
+ if (argc != 2) {
+ std::cout << "One parameter expected - given " << argc << std::endl;
+ return 100;
+ }
+
Test(argv[1]);
_error->DumpErrors();
return 0;
diff --git a/test/libapt/assert.h b/test/libapt/assert.h
deleted file mode 100644
index 113c057ed..000000000
--- a/test/libapt/assert.h
+++ /dev/null
@@ -1,113 +0,0 @@
-#include <iostream>
-#include <cstdlib>
-
-#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) {
- std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
- std::exit(EXIT_FAILURE);
-}
-
-template < typename X, typename Y >
-void assertEquals(X expect, Y get, unsigned long const &line) {
- if (expect == get)
- return;
- 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);
- assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
-}
-
-void assertEquals(int const &expect, unsigned int const &get, unsigned long const &line) {
- if (expect < 0)
- OutputAssertEqual(expect, "==", get, line);
- assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
-}
-
-void assertEquals(unsigned long const &expect, int const &get, unsigned long const &line) {
- if (get < 0)
- OutputAssertEqual(expect, "==", get, line);
- assertEquals<unsigned long const&, unsigned long const&>(expect, get, line);
-}
-
-void assertEquals(int const &expect, unsigned long const &get, unsigned long const &line) {
- if (expect < 0)
- OutputAssertEqual(expect, "==", get, line);
- assertEquals<unsigned long const&, unsigned long const&>(expect, get, line);
-}
-
-
-#define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
-
-template < typename X, typename Y >
-void OutputAssertEqualOr2(X expect1, X expect2, char const* compare, Y get, unsigned long const &line) {
- std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« " << compare << " »" << get << "« at line " << line << std::endl;
-}
-
-template < typename X, typename Y >
-void assertEqualsOr2(X expect1, X expect2, Y get, unsigned long const &line) {
- if (expect1 == get || expect2 == get)
- return;
- OutputAssertEqualOr2(expect1, expect2, "==", get, line);
-}
-
-void assertEqualsOr2(unsigned int const &expect1, unsigned int const &expect2, int const &get, unsigned long const &line) {
- if (get < 0)
- OutputAssertEqualOr2(expect1, expect2, "==", get, line);
- assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
-}
-
-void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const &get, unsigned long const &line) {
- if (expect1 < 0 && expect2 < 0)
- OutputAssertEqualOr2(expect1, expect2, "==", get, line);
- assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
-}
-
-
-#define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
-
-template < typename X, typename Y >
-void OutputAssertEqualOr3(X expect1, X expect2, X expect3, char const* compare, Y get, unsigned long const &line) {
- std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« " << compare << " »" << get << "« at line " << line << std::endl;
-}
-
-template < typename X, typename Y >
-void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const &line) {
- if (expect1 == get || expect2 == get || expect3 == get)
- return;
- 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 >
-void dumpVector(X vec) {
- for (typename X::const_iterator v = vec.begin();
- v != vec.end(); ++v)
- std::cout << *v << std::endl;
-}
diff --git a/test/libapt/cdrom_test.cc b/test/libapt/cdrom_test.cc
new file mode 100644
index 000000000..626ef538e
--- /dev/null
+++ b/test/libapt/cdrom_test.cc
@@ -0,0 +1,114 @@
+#include <config.h>
+
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/cdrom.h>
+#include <apt-pkg/cdromutl.h>
+#include <apt-pkg/fileutl.h>
+
+#include <string>
+#include <string.h>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "file-helpers.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;
+ }
+};
+
+TEST(CDROMTest,ReduceSourcelist)
+{
+ Cdrom cd;
+ std::vector<std::string> List;
+ std::string CD("/media/cdrom/");
+
+ std::vector<std::string> R = cd.ReduceSourcelist(CD, List);
+ EXPECT_TRUE(R.empty());
+
+ List.push_back(" wheezy main");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(1, R.size());
+ EXPECT_EQ(" wheezy main", R[0]);
+
+ List.push_back(" wheezy main");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(1, R.size());
+ EXPECT_EQ(" wheezy main", R[0]);
+
+ List.push_back(" wheezy contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(1, R.size());
+ EXPECT_EQ(" wheezy contrib main", R[0]);
+
+ List.push_back(" wheezy-update contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(2, R.size());
+ EXPECT_EQ(" wheezy contrib main", R[0]);
+ EXPECT_EQ(" wheezy-update contrib", R[1]);
+
+ List.push_back(" wheezy-update contrib");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(2, R.size());
+ EXPECT_EQ(" wheezy contrib main", R[0]);
+ EXPECT_EQ(" wheezy-update contrib", R[1]);
+
+ List.push_back(" wheezy-update non-free");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(2, R.size());
+ EXPECT_EQ(" wheezy contrib main", R[0]);
+ EXPECT_EQ(" wheezy-update contrib non-free", R[1]);
+
+ List.push_back(" wheezy-update main");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(2, R.size());
+ EXPECT_EQ(" wheezy contrib main", R[0]);
+ EXPECT_EQ(" wheezy-update contrib main non-free", R[1]);
+
+ List.push_back(" wheezy non-free");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(2, R.size());
+ EXPECT_EQ(" wheezy contrib main non-free", R[0]);
+ EXPECT_EQ(" wheezy-update contrib main non-free", R[1]);
+
+ List.push_back(" sid main");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(3, R.size());
+ EXPECT_EQ(" sid main", R[0]);
+ EXPECT_EQ(" wheezy contrib main non-free", R[1]);
+ EXPECT_EQ(" wheezy-update contrib main non-free", R[2]);
+
+ List.push_back(" sid main-reduce");
+ R = cd.ReduceSourcelist(CD, List);
+ ASSERT_EQ(3, R.size());
+ EXPECT_EQ(" sid main main-reduce", R[0]);
+ EXPECT_EQ(" wheezy contrib main non-free", R[1]);
+ EXPECT_EQ(" wheezy-update contrib main non-free", R[2]);
+}
+TEST(CDROMTest, FindMountPointForDevice)
+{
+ char * tempfile;
+ FileFd fd;
+ createTemporaryFile("mountpoints", fd, &tempfile,
+ "rootfs / rootfs rw 0 0\n"
+ "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
+ "sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
+ "/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n"
+ "/dev/sda1 /boot/efi vfat rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro 0 0\n"
+ "tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n");
+ _config->Set("Dir::state::Mountpoints", tempfile);
+
+ EXPECT_EQ("/", FindMountPointForDevice("rootfs"));
+ EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21"));
+ EXPECT_EQ("/sys", FindMountPointForDevice("sysfs"));
+ EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0"));
+ EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1"));
+ EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs"));
+
+ unlink(tempfile);
+ free(tempfile);
+}
diff --git a/test/libapt/cdromfindpackages_test.cc b/test/libapt/cdromfindpackages_test.cc
index e9f5a51b0..719dd8f63 100644
--- a/test/libapt/cdromfindpackages_test.cc
+++ b/test/libapt/cdromfindpackages_test.cc
@@ -1,86 +1,121 @@
+#include <config.h>
+
#include <apt-pkg/cdrom.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <algorithm>
#include <string>
#include <vector>
+#include <stddef.h>
+#include <iostream>
+
+#include <gtest/gtest.h>
-#include "assert.h"
+#include "file-helpers.h"
class Cdrom : public pkgCdrom {
- public:
- bool FindPackages(std::string const &CD,
- std::vector<std::string> &List,
- std::vector<std::string> &SList,
- std::vector<std::string> &SigList,
- std::vector<std::string> &TransList,
- std::string &InfoDir) {
- bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
- std::sort(List.begin(), List.end());
- std::sort(SList.begin(), SList.end());
- std::sort(SigList.begin(), SigList.end());
- std::sort(TransList.begin(), TransList.end());
- return result;
- }
+ public:
+ bool FindPackages(std::string const &CD,
+ std::vector<std::string> &List,
+ std::vector<std::string> &SList,
+ std::vector<std::string> &SigList,
+ std::vector<std::string> &TransList,
+ std::string &InfoDir) {
+ std::string const startdir = SafeGetCWD();
+ EXPECT_FALSE(startdir.empty());
+ bool const result = pkgCdrom::FindPackages(CD, List, SList, SigList, TransList, InfoDir, NULL, 0);
+ std::sort(List.begin(), List.end());
+ std::sort(SList.begin(), SList.end());
+ std::sort(SigList.begin(), SigList.end());
+ std::sort(TransList.begin(), TransList.end());
+ EXPECT_EQ(0, chdir(startdir.c_str()));
+ return result;
+ }
- bool DropRepeats(std::vector<std::string> &List, char const *Name) {
- return pkgCdrom::DropRepeats(List, Name);
- }
+ using pkgCdrom::DropRepeats;
};
-int main(int argc, char const *argv[]) {
- if (argc != 2) {
- std::cout << "One parameter expected - given " << argc << std::endl;
- return 100;
- }
+TEST(CDROMTest,FindPackages)
+{
+ std::string path;
+ createTemporaryDirectory("findpackage", path);
+
+ createDirectory(path, ".disk");
+ createDirectory(path, "pool");
+ createDirectory(path, "dists/stable/main/binary-i386");
+ createDirectory(path, "dists/stable/main/source");
+ createDirectory(path, "dists/stable/contrib/binary-amd64");
+ createDirectory(path, "dists/stable/contrib/binary-all");
+ createDirectory(path, "dists/unstable/main/binary-i386");
+ createDirectory(path, "dists/unstable/main/i18n");
+ createDirectory(path, "dists/unstable/main/source");
+ createDirectory(path, "dists/broken/non-free/source");
+ createFile(path, "dists/broken/.aptignr");
+ createFile(path, "dists/stable/main/binary-i386/Packages");
+ createFile(path, "dists/stable/main/binary-i386/Packages.bz2");
+ createFile(path, "dists/stable/main/source/Sources.xz");
+ createFile(path, "dists/stable/contrib/binary-amd64/Packages");
+ createFile(path, "dists/stable/contrib/binary-amd64/Packages.gz");
+ createFile(path, "dists/stable/contrib/binary-all/Packages");
+ createFile(path, "dists/unstable/main/binary-i386/Packages.xz");
+ createFile(path, "dists/unstable/main/binary-i386/Packages.lzma");
+ createFile(path, "dists/unstable/main/i18n/Translation-en");
+ createFile(path, "dists/unstable/main/i18n/Translation-de.bz2");
+ createFile(path, "dists/unstable/main/source/Sources.xz");
+ createFile(path, "dists/broken/non-free/source/Sources.gz");
+ createFile(path, "dists/stable/Release.gpg");
+ createFile(path, "dists/stable/Release");
+ createFile(path, "dists/unstable/InRelease");
+ createFile(path, "dists/broken/Release.gpg");
+ createLink(path, "dists/unstable", "dists/sid");
- Cdrom cd;
- std::vector<std::string> Packages, Sources, Signatur, Translation;
- std::string InfoDir;
- std::string path = argv[1];
- equals(true, cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
- equals(4, Packages.size());
- equals(path + "/dists/sid/main/binary-i386/", Packages[0]);
- equals(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
- equals(path + "/dists/stable/main/binary-i386/", Packages[2]);
- equals(path + "/dists/unstable/main/binary-i386/", Packages[3]);
- equals(3, Sources.size());
- equals(path + "/dists/sid/main/source/", Sources[0]);
- equals(path + "/dists/stable/main/source/", Sources[1]);
- equals(path + "/dists/unstable/main/source/", Sources[2]);
- equals(3, Signatur.size());
- equals(path + "/dists/sid/", Signatur[0]);
- equals(path + "/dists/stable/", Signatur[1]);
- equals(path + "/dists/unstable/", Signatur[2]);
- equals(4, Translation.size());
- equals(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
- equals(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
- equals(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
- equals(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
- equals(path + "/.disk/", InfoDir);
+ Cdrom cd;
+ std::vector<std::string> Packages, Sources, Signatur, Translation;
+ std::string InfoDir;
+ EXPECT_TRUE(cd.FindPackages(path, Packages, Sources, Signatur, Translation, InfoDir));
+ EXPECT_EQ(4, Packages.size());
+ EXPECT_EQ(path + "/dists/sid/main/binary-i386/", Packages[0]);
+ EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[1]);
+ EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[2]);
+ EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[3]);
+ EXPECT_EQ(3, Sources.size());
+ EXPECT_EQ(path + "/dists/sid/main/source/", Sources[0]);
+ EXPECT_EQ(path + "/dists/stable/main/source/", Sources[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[2]);
+ EXPECT_EQ(3, Signatur.size());
+ EXPECT_EQ(path + "/dists/sid/", Signatur[0]);
+ EXPECT_EQ(path + "/dists/stable/", Signatur[1]);
+ EXPECT_EQ(path + "/dists/unstable/", Signatur[2]);
+ EXPECT_EQ(4, Translation.size());
+ EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-de", Translation[0]);
+ EXPECT_EQ(path + "/dists/sid/main/i18n/Translation-en", Translation[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[2]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[3]);
+ EXPECT_EQ(path + "/.disk/", InfoDir);
- cd.DropRepeats(Packages, "Packages");
- cd.DropRepeats(Sources, "Sources");
- _error->PushToStack();
- cd.DropRepeats(Signatur, "InRelease");
- cd.DropRepeats(Signatur, "Release.gpg");
- _error->RevertToStack();
- _error->DumpErrors();
- cd.DropRepeats(Translation, "");
+ cd.DropRepeats(Packages, "Packages");
+ cd.DropRepeats(Sources, "Sources");
+ _error->PushToStack();
+ cd.DropRepeats(Signatur, "InRelease");
+ cd.DropRepeats(Signatur, "Release.gpg");
+ _error->RevertToStack();
+ _error->DumpErrors();
+ cd.DropRepeats(Translation, "");
- equals(3, Packages.size());
- equals(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
- equals(path + "/dists/stable/main/binary-i386/", Packages[1]);
- equals(path + "/dists/unstable/main/binary-i386/", Packages[2]);
- equals(2, Sources.size());
- equals(path + "/dists/stable/main/source/", Sources[0]);
- equals(path + "/dists/unstable/main/source/", Sources[1]);
- equals(2, Signatur.size());
- equals(path + "/dists/stable/", Signatur[0]);
- equals(path + "/dists/unstable/", Signatur[1]);
- equals(2, Translation.size());
- equals(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
- equals(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
+ EXPECT_EQ(3, Packages.size());
+ EXPECT_EQ(path + "/dists/stable/contrib/binary-amd64/", Packages[0]);
+ EXPECT_EQ(path + "/dists/stable/main/binary-i386/", Packages[1]);
+ EXPECT_EQ(path + "/dists/unstable/main/binary-i386/", Packages[2]);
+ EXPECT_EQ(2, Sources.size());
+ EXPECT_EQ(path + "/dists/stable/main/source/", Sources[0]);
+ EXPECT_EQ(path + "/dists/unstable/main/source/", Sources[1]);
+ EXPECT_EQ(2, Signatur.size());
+ EXPECT_EQ(path + "/dists/stable/", Signatur[0]);
+ EXPECT_EQ(path + "/dists/unstable/", Signatur[1]);
+ EXPECT_EQ(2, Translation.size());
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-de", Translation[0]);
+ EXPECT_EQ(path + "/dists/unstable/main/i18n/Translation-en", Translation[1]);
- return 0;
+ removeDirectory(path);
}
diff --git a/test/libapt/cdromreducesourcelist_test.cc b/test/libapt/cdromreducesourcelist_test.cc
deleted file mode 100644
index 729da23a6..000000000
--- a/test/libapt/cdromreducesourcelist_test.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-#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
index de8a30bd6..26e80bfde 100644
--- a/test/libapt/commandline_test.cc
+++ b/test/libapt/commandline_test.cc
@@ -1,32 +1,58 @@
+#include <config.h>
+
#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
+
+#include <gtest/gtest.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);
+ }
+};
-#include "assert.h"
+#define EXPECT_CMD(x, ...) { const char * const argv[] = { __VA_ARGS__ }; EXPECT_EQ(x, CLT::AsString(argv, sizeof(argv)/sizeof(argv[0]))); }
-int main()
+TEST(CommandLineTest,SaveInConfig)
+{
+ EXPECT_CMD("apt-get install -sf",
+ "apt-get", "install", "-sf");
+ EXPECT_CMD("apt-cache -s apt -so Debug::test=Test",
+ "apt-cache", "-s", "apt", "-so", "Debug::test=Test");
+ EXPECT_CMD("apt-cache -s apt -so Debug::test=\"Das ist ein Test\"",
+ "apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test");
+ EXPECT_CMD("apt-cache -s apt --hallo test=1.0",
+ "apt-cache", "-s", "apt", "--hallo", "test=1.0");
+}
+TEST(CommandLineTest,Parsing)
{
CommandLine::Args Args[] = {
{ 't', 0, "Test::Worked", 0 },
{ 'z', "zero", "Test::Zero", 0 },
{0,0,0,0}
};
- CommandLine CmdL(Args,_config);
+ ::Configuration c;
+ CommandLine CmdL(Args, &c);
char const * argv[] = { "test", "--zero", "-t" };
CmdL.Parse(3 , argv);
- equals(true, _config->FindB("Test::Worked", false));
- equals(true, _config->FindB("Test::Zero", false));
+ EXPECT_TRUE(c.FindB("Test::Worked", false));
+ EXPECT_TRUE(c.FindB("Test::Zero", false));
- _config->Clear("Test");
- equals(false, _config->FindB("Test::Worked", false));
- equals(false, _config->FindB("Test::Zero", false));
+ c.Clear("Test");
+ EXPECT_FALSE(c.FindB("Test::Worked", false));
+ EXPECT_FALSE(c.FindB("Test::Zero", false));
- _config->Set("Test::Zero", true);
- equals(true, _config->FindB("Test::Zero", false));
+ c.Set("Test::Zero", true);
+ EXPECT_TRUE(c.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;
+ EXPECT_TRUE(c.FindB("Test::Worked", false));
+ EXPECT_FALSE(c.FindB("Test::Zero", false));
}
diff --git a/test/libapt/commandlineasstring_test.cc b/test/libapt/commandlineasstring_test.cc
deleted file mode 100644
index a38957d7e..000000000
--- a/test/libapt/commandlineasstring_test.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-#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
index fdb1d5674..3b2c0c209 100644
--- a/test/libapt/compareversion_test.cc
+++ b/test/libapt/compareversion_test.cc
@@ -16,22 +16,23 @@
##################################################################### */
/*}}}*/
-#include <apt-pkg/macros.h>
+#include <config.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 <fstream>
+#include <string>
#include <stdlib.h>
#include <unistd.h>
-#include <sys/types.h>
#include <sys/wait.h>
+#include <gtest/gtest.h>
+
using namespace std;
-bool callDPkg(const char *val, const char *ref, const char &op) {
+static bool callDPKG(const char *val, const char *ref, const char &op) {
pid_t Process = ExecFork();
if (Process == 0)
{
@@ -50,77 +51,130 @@ bool callDPkg(const char *val, const char *ref, const char &op) {
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());
+#define EXPECT_VERSION_PART(A, compare, B) \
+{ \
+ int Res = debVS.CmpVersion(A, B); \
+ Res = (Res < 0) ? -1 : ( (Res > 0) ? 1 : Res); \
+ EXPECT_EQ(compare, Res) << "APT: A: »" << A << "« B: »" << B << "«"; \
+ EXPECT_PRED3(callDPKG, A, B, compare); \
}
+#define EXPECT_VERSION(A, compare, B) \
+ EXPECT_VERSION_PART(A, compare, B); \
+ EXPECT_VERSION_PART(B, compare * -1, A)
+
+// History-Remark: The versions used to be specified in a versions.lst file
+
+enum CompareVersionType { LESS = -1, GREATER = 1, EQUAL = 0 };
-bool RunTest(const char *File)
+TEST(CompareVersionTest,Basic)
{
- if (FileExists(File) == false)
- return _error->Error("Versiontestfile %s doesn't exist!", File);
+ EXPECT_VERSION("7.6p2-4", GREATER, "7.6-0");
+ EXPECT_VERSION("1.0.3-3", GREATER, "1.0-1");
+ EXPECT_VERSION("1.3", GREATER, "1.2.2-2");
+ EXPECT_VERSION("1.3", GREATER, "1.2.2");
- ifstream F(File,ios::in);
- if (!F != 0)
- return false;
+ /* disabled as dpkg doesn't like them… (versions have to start with a number)
+ EXPECT_VERSION("-", LESS, ".");
+ EXPECT_VERSION("p", LESS, "-");
+ EXPECT_VERSION("a", LESS, "-");
+ EXPECT_VERSION("z", LESS, "-");
+ EXPECT_VERSION("a", LESS, ".");
+ EXPECT_VERSION("z", LESS, ".");
+ // */
- 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);
- }
+ /* disabled as dpkg doesn't like them… (versions have to start with a number)
+ EXPECT_VERSION("III-alpha9.8", LESS, "III-alpha9.8-1.5");
+ // */
+
+ // Test some properties of text strings
+ EXPECT_VERSION("0-pre", EQUAL, "0-pre");
+ EXPECT_VERSION("0-pre", LESS, "0-pree");
+
+ EXPECT_VERSION("1.1.6r2-2", GREATER, "1.1.6r-1");
+ EXPECT_VERSION("2.6b2-1", GREATER, "2.6b-2");
+
+ EXPECT_VERSION("98.1p5-1", LESS, "98.1-pre2-b6-2");
+ EXPECT_VERSION("0.4a6-2", GREATER, "0.4-1");
+
+ EXPECT_VERSION("1:3.0.5-2", LESS, "1:3.0.5.1");
+}
+TEST(CompareVersionTest,Epochs)
+{
+ EXPECT_VERSION("1:0.4", GREATER, "10.3");
+ EXPECT_VERSION("1:1.25-4", LESS, "1:1.25-8");
+ EXPECT_VERSION("0:1.18.36", EQUAL, "1.18.36");
+
+ EXPECT_VERSION("1.18.36", GREATER, "1.18.35");
+ EXPECT_VERSION("0:1.18.36", GREATER, "1.18.35");
}
+TEST(CompareVersionTest,Strangeness)
+{
+ // Funky, but allowed, characters in upstream version
+ EXPECT_VERSION("9:1.18.36:5.4-20", LESS, "10:0.5.1-22");
+ EXPECT_VERSION("9:1.18.36:5.4-20", LESS, "9:1.18.36:5.5-1");
+ EXPECT_VERSION("9:1.18.36:5.4-20", LESS, " 9:1.18.37:4.3-22");
+ EXPECT_VERSION("1.18.36-0.17.35-18", GREATER, "1.18.36-19");
-int main(int argc, char *argv[])
+ // Junk
+ EXPECT_VERSION("1:1.2.13-3", LESS, "1:1.2.13-3.1");
+ EXPECT_VERSION("2.0.7pre1-4", LESS, "2.0.7r-1");
+
+ // if a version includes a dash, it should be the debrev dash - policy says so…
+ EXPECT_VERSION("0:0-0-0", GREATER, "0-0");
+
+ // do we like strange versions? Yes we like strange versions…
+ EXPECT_VERSION("0", EQUAL, "0");
+ EXPECT_VERSION("0", EQUAL, "00");
+}
+TEST(CompareVersionTest,DebianBug)
+{
+ // #205960
+ EXPECT_VERSION("3.0~rc1-1", LESS, "3.0-1");
+ // #573592 - debian policy 5.6.12
+ EXPECT_VERSION("1.0", EQUAL, "1.0-0");
+ EXPECT_VERSION("0.2", LESS, "1.0-0");
+ EXPECT_VERSION("1.0", LESS, "1.0-0+b1");
+ EXPECT_VERSION("1.0", GREATER, "1.0-0~");
+}
+TEST(CompareVersionTest,CuptTests)
{
- if (argc != 2)
- return 1;
- else
- RunTest(argv[1]);
-
- // Print any errors or warnings found
- _error->DumpErrors();
- return 0;
+ // "steal" the testcases from (old perl) cupt
+ EXPECT_VERSION("1.2.3", EQUAL, "1.2.3"); // identical
+ EXPECT_VERSION("4.4.3-2", EQUAL, "4.4.3-2"); // identical
+ EXPECT_VERSION("1:2ab:5", EQUAL, "1:2ab:5"); // this is correct...
+ EXPECT_VERSION("7:1-a:b-5", EQUAL, "7:1-a:b-5"); // and this
+ EXPECT_VERSION("57:1.2.3abYZ+~-4-5", EQUAL, "57:1.2.3abYZ+~-4-5"); // and those too
+ EXPECT_VERSION("1.2.3", EQUAL, "0:1.2.3"); // zero epoch
+ EXPECT_VERSION("1.2.3", EQUAL, "1.2.3-0"); // zero revision
+ EXPECT_VERSION("009", EQUAL, "9"); // zeroes…
+ EXPECT_VERSION("009ab5", EQUAL, "9ab5"); // there as well
+ EXPECT_VERSION("1.2.3", LESS, "1.2.3-1"); // added non-zero revision
+ EXPECT_VERSION("1.2.3", LESS, "1.2.4"); // just bigger
+ EXPECT_VERSION("1.2.4", GREATER, "1.2.3"); // order doesn't matter
+ EXPECT_VERSION("1.2.24", GREATER, "1.2.3"); // bigger, eh?
+ EXPECT_VERSION("0.10.0", GREATER, "0.8.7"); // bigger, eh?
+ EXPECT_VERSION("3.2", GREATER, "2.3"); // major number rocks
+ EXPECT_VERSION("1.3.2a", GREATER, "1.3.2"); // letters rock
+ EXPECT_VERSION("0.5.0~git", LESS, "0.5.0~git2"); // numbers rock
+ EXPECT_VERSION("2a", LESS, "21"); // but not in all places
+ EXPECT_VERSION("1.3.2a", LESS, "1.3.2b"); // but there is another letter
+ EXPECT_VERSION("1:1.2.3", GREATER, "1.2.4"); // epoch rocks
+ EXPECT_VERSION("1:1.2.3", LESS, "1:1.2.4"); // bigger anyway
+ EXPECT_VERSION("1.2a+~bCd3", LESS, "1.2a++"); // tilde doesn't rock
+ EXPECT_VERSION("1.2a+~bCd3", GREATER, "1.2a+~"); // but first is longer!
+ EXPECT_VERSION("5:2", GREATER, "304-2"); // epoch rocks
+ EXPECT_VERSION("5:2", LESS, "304:2"); // so big epoch?
+ EXPECT_VERSION("25:2", GREATER, "3:2"); // 25 > 3, obviously
+ EXPECT_VERSION("1:2:123", LESS, "1:12:3"); // 12 > 2
+ EXPECT_VERSION("1.2-5", LESS, "1.2-3-5"); // 1.2 < 1.2-3
+ EXPECT_VERSION("5.10.0", GREATER, "5.005"); // preceding zeroes don't matters
+ EXPECT_VERSION("3a9.8", LESS, "3.10.2"); // letters are before all letter symbols
+ EXPECT_VERSION("3a9.8", GREATER, "3~10"); // but after the tilde
+ EXPECT_VERSION("1.4+OOo3.0.0~", LESS, "1.4+OOo3.0.0-4"); // another tilde check
+ EXPECT_VERSION("2.4.7-1", LESS, "2.4.7-z"); // revision comparing
+ EXPECT_VERSION("1.002-1+b2", GREATER, "1.00"); // whatever...
+ /* disabled as dpkg doesn't like them… (versions with illegal char)
+ EXPECT_VERSION("2.2.4-47978_Debian_lenny", EQUAL, "2.2.4-47978_Debian_lenny"); // and underscore...
+ // */
}
diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc
index 2c974ee0a..647d8a4af 100644
--- a/test/libapt/configuration_test.cc
+++ b/test/libapt/configuration_test.cc
@@ -1,109 +1,146 @@
+#include <config.h>
+
#include <apt-pkg/configuration.h>
#include <string>
#include <vector>
-#include "assert.h"
+#include <gtest/gtest.h>
+
+//FIXME: Test for configuration file parsing;
+// currently only integration/ tests test them implicitly
-int main(int argc,const char *argv[]) {
+TEST(ConfigurationTest,Lists)
+{
Configuration Cnf;
- std::vector<std::string> fds;
Cnf.Set("APT::Keep-Fds::",28);
Cnf.Set("APT::Keep-Fds::",17);
Cnf.Set("APT::Keep-Fds::2",47);
Cnf.Set("APT::Keep-Fds::","broken");
- fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds[0], "28");
- equals(fds[1], "17");
- equals(fds[2], "47");
- equals(fds[3], "broken");
- equals(fds.size(), 4);
- equals(Cnf.Exists("APT::Keep-Fds::2"), true);
- equals(Cnf.Find("APT::Keep-Fds::2"), "47");
- equals(Cnf.FindI("APT::Keep-Fds::2"), 47);
- equals(Cnf.Exists("APT::Keep-Fds::3"), false);
- equals(Cnf.Find("APT::Keep-Fds::3"), "");
- equals(Cnf.FindI("APT::Keep-Fds::3", 56), 56);
- equals(Cnf.Find("APT::Keep-Fds::3", "not-set"), "not-set");
+ std::vector<std::string> fds = Cnf.FindVector("APT::Keep-Fds");
+ ASSERT_EQ(4, fds.size());
+ EXPECT_EQ("28", fds[0]);
+ EXPECT_EQ("17", fds[1]);
+ EXPECT_EQ("47", fds[2]);
+ EXPECT_EQ("broken", fds[3]);
+
+ EXPECT_TRUE(Cnf.Exists("APT::Keep-Fds::2"));
+ EXPECT_EQ("47", Cnf.Find("APT::Keep-Fds::2"));
+ EXPECT_EQ(47, Cnf.FindI("APT::Keep-Fds::2"));
+ EXPECT_FALSE(Cnf.Exists("APT::Keep-Fds::3"));
+ EXPECT_EQ("", Cnf.Find("APT::Keep-Fds::3"));
+ EXPECT_EQ(56, Cnf.FindI("APT::Keep-Fds::3", 56));
+ EXPECT_EQ("not-set", Cnf.Find("APT::Keep-Fds::3", "not-set"));
Cnf.Clear("APT::Keep-Fds::2");
+ EXPECT_TRUE(Cnf.Exists("APT::Keep-Fds::2"));
fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds[0], "28");
- equals(fds[1], "17");
- equals(fds[2], "");
- equals(fds[3], "broken");
- equals(fds.size(), 4);
- equals(Cnf.Exists("APT::Keep-Fds::2"), true);
+ ASSERT_EQ(4, fds.size());
+ EXPECT_EQ("28", fds[0]);
+ EXPECT_EQ("17", fds[1]);
+ EXPECT_EQ("", fds[2]);
+ EXPECT_EQ("broken", fds[3]);
Cnf.Clear("APT::Keep-Fds",28);
fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds[0], "17");
- equals(fds[1], "");
- equals(fds[2], "broken");
- equals(fds.size(), 3);
+ ASSERT_EQ(3, fds.size());
+ EXPECT_EQ("17", fds[0]);
+ EXPECT_EQ("", fds[1]);
+ EXPECT_EQ("broken", fds[2]);
Cnf.Clear("APT::Keep-Fds","");
- equals(Cnf.Exists("APT::Keep-Fds::2"), false);
+ EXPECT_FALSE(Cnf.Exists("APT::Keep-Fds::2"));
Cnf.Clear("APT::Keep-Fds",17);
Cnf.Clear("APT::Keep-Fds","broken");
fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds.empty(), true);
+ EXPECT_TRUE(fds.empty());
Cnf.Set("APT::Keep-Fds::",21);
Cnf.Set("APT::Keep-Fds::",42);
fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds[0], "21");
- equals(fds[1], "42");
- equals(fds.size(), 2);
+ ASSERT_EQ(2, fds.size());
+ EXPECT_EQ("21", fds[0]);
+ EXPECT_EQ("42", fds[1]);
Cnf.Clear("APT::Keep-Fds");
fds = Cnf.FindVector("APT::Keep-Fds");
- equals(fds.empty(), true);
+ EXPECT_TRUE(fds.empty());
+}
+TEST(ConfigurationTest,Integers)
+{
+ Configuration Cnf;
Cnf.CndSet("APT::Version", 42);
Cnf.CndSet("APT::Version", "66");
- equals(Cnf.Find("APT::Version"), "42");
- equals(Cnf.FindI("APT::Version"), 42);
- equals(Cnf.Find("APT::Version", "33"), "42");
- equals(Cnf.FindI("APT::Version", 33), 42);
- equals(Cnf.Find("APT2::Version", "33"), "33");
- equals(Cnf.FindI("APT2::Version", 33), 33);
-
- equals(Cnf.FindFile("Dir::State"), "");
- equals(Cnf.FindFile("Dir::Aptitude::State"), "");
+ EXPECT_EQ("42", Cnf.Find("APT::Version"));
+ EXPECT_EQ(42, Cnf.FindI("APT::Version"));
+ EXPECT_EQ("42", Cnf.Find("APT::Version", "33"));
+ EXPECT_EQ(42, Cnf.FindI("APT::Version", 33));
+ EXPECT_EQ("33", Cnf.Find("APT2::Version", "33"));
+ EXPECT_EQ(33, Cnf.FindI("APT2::Version", 33));
+}
+TEST(ConfigurationTest,DirsAndFiles)
+{
+ Configuration Cnf;
+
+ EXPECT_EQ("", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("", Cnf.FindFile("Dir::Aptitude::State"));
Cnf.Set("Dir", "/srv/sid");
- equals(Cnf.FindFile("Dir::State"), "");
+ EXPECT_EQ("", Cnf.FindFile("Dir::State"));
Cnf.Set("Dir::State", "var/lib/apt");
Cnf.Set("Dir::Aptitude::State", "var/lib/aptitude");
- equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
- equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
+ EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
Cnf.Set("RootDir", "/");
- equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
- equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
+ EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
Cnf.Set("RootDir", "//./////.////");
- equals(Cnf.FindFile("Dir::State"), "/srv/sid/var/lib/apt");
- equals(Cnf.FindFile("Dir::Aptitude::State"), "/srv/sid/var/lib/aptitude");
+ EXPECT_EQ("/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
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");
+ EXPECT_EQ("/rootdir/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("/rootdir/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
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");
+ EXPECT_EQ("/rootdir/srv/sid/var/lib/apt", Cnf.FindFile("Dir::State"));
+ EXPECT_EQ("/rootdir/srv/sid/var/lib/aptitude", Cnf.FindFile("Dir::Aptitude::State"));
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");
-
- Cnf.Set("Moo::Bar", "1");
- Cnf.Clear();
- equals(Cnf.Find("Moo::Bar"), "");
-
- //FIXME: Test for configuration file parsing;
- // currently only integration/ tests test them implicitly
+ EXPECT_EQ("/rootdir/dev/null", Cnf.FindDir("Dir::State"));
+ EXPECT_EQ("/rootdir/dev/null", Cnf.FindDir("Dir::State::lists"));
+}
+TEST(ConfigurationTest,Vector)
+{
+ Configuration Cnf;
- return 0;
+ std::vector<std::string> vec = Cnf.FindVector("Test::Vector", "");
+ EXPECT_EQ(0, vec.size());
+ vec = Cnf.FindVector("Test::Vector", "foo");
+ ASSERT_EQ(1, vec.size());
+ EXPECT_EQ("foo", vec[0]);
+ vec = Cnf.FindVector("Test::Vector", "foo,bar");
+ EXPECT_EQ(2, vec.size());
+ EXPECT_EQ("foo", vec[0]);
+ EXPECT_EQ("bar", vec[1]);
+ Cnf.Set("Test::Vector::", "baz");
+ Cnf.Set("Test::Vector::", "bob");
+ Cnf.Set("Test::Vector::", "dob");
+ vec = Cnf.FindVector("Test::Vector");
+ ASSERT_EQ(3, vec.size());
+ EXPECT_EQ("baz", vec[0]);
+ EXPECT_EQ("bob", vec[1]);
+ EXPECT_EQ("dob", vec[2]);
+ vec = Cnf.FindVector("Test::Vector", "foo,bar");
+ ASSERT_EQ(3, vec.size());
+ EXPECT_EQ("baz", vec[0]);
+ EXPECT_EQ("bob", vec[1]);
+ EXPECT_EQ("dob", vec[2]);
+ Cnf.Set("Test::Vector", "abel,bravo");
+ vec = Cnf.FindVector("Test::Vector", "foo,bar");
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("abel", vec[0]);
+ EXPECT_EQ("bravo", vec[1]);
}
diff --git a/test/libapt/file-helpers.cc b/test/libapt/file-helpers.cc
new file mode 100644
index 000000000..5edb9a9fe
--- /dev/null
+++ b/test/libapt/file-helpers.cc
@@ -0,0 +1,77 @@
+#include <apt-pkg/fileutl.h>
+
+#include <string>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <gtest/gtest.h>
+
+#include "file-helpers.h"
+
+void helperCreateTemporaryDirectory(std::string const &id, std::string &dir)
+{
+ std::string const strtempdir = GetTempDir().append("/apt-tests-").append(id).append(".XXXXXX");
+ char * tempdir = strdup(strtempdir.c_str());
+ ASSERT_STREQ(tempdir, mkdtemp(tempdir));
+ dir = tempdir;
+ free(tempdir);
+}
+void helperRemoveDirectory(std::string const &dir)
+{
+ // basic sanity check to avoid removing random directories based on earlier failures
+ if (dir.find("/apt-tests-") == std::string::npos || dir.find_first_of("*?") != std::string::npos)
+ FAIL() << "Directory '" << dir << "' seems invalid. It is therefore not removed!";
+ else
+ ASSERT_EQ(0, system(std::string("rm -rf ").append(dir).c_str()));
+}
+void helperCreateFile(std::string const &dir, std::string const &name)
+{
+ std::string file = dir;
+ file.append("/");
+ file.append(name);
+ int const fd = creat(file.c_str(), 0600);
+ ASSERT_NE(-1, fd);
+ close(fd);
+}
+void helperCreateDirectory(std::string const &dir, std::string const &name)
+{
+ std::string file = dir;
+ file.append("/");
+ file.append(name);
+ ASSERT_TRUE(CreateDirectory(dir, file));
+}
+void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname)
+{
+ std::string target = dir;
+ target.append("/");
+ target.append(targetname);
+ std::string link = dir;
+ link.append("/");
+ link.append(linkname);
+ ASSERT_EQ(0, symlink(target.c_str(), link.c_str()));
+}
+void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content)
+{
+ std::string name("apt-test-");
+ name.append(id).append(".XXXXXXXX");
+ char * tempfile = strdup(name.c_str());
+ int tempfile_fd = mkstemp(tempfile);
+ ASSERT_NE(-1, tempfile_fd);
+ if (filename != NULL)
+ *filename = tempfile;
+ else
+ {
+ unlink(tempfile);
+ free(tempfile);
+ }
+
+ EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite));
+ if (content != NULL)
+ {
+ ASSERT_TRUE(fd.Write(content, strlen(content)));
+ fd.Seek(0);
+ }
+}
diff --git a/test/libapt/file-helpers.h b/test/libapt/file-helpers.h
new file mode 100644
index 000000000..e8472d503
--- /dev/null
+++ b/test/libapt/file-helpers.h
@@ -0,0 +1,29 @@
+#ifndef APT_TESTS_FILE_HELPERS
+#define APT_TESTS_FILE_HELPERS
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+class FileFd;
+
+#define createTemporaryDirectory(id, dir) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryDirectory(id, dir))
+void helperCreateTemporaryDirectory(std::string const &id, std::string &dir);
+#define removeDirectory(dir) \
+ ASSERT_NO_FATAL_FAILURE(helperRemoveDirectory(dir))
+void helperRemoveDirectory(std::string const &dir);
+#define createFile(dir, name) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateFile(dir, name))
+void helperCreateFile(std::string const &dir, std::string const &name);
+#define createDirectory(dir, name) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateDirectory(dir, name))
+void helperCreateDirectory(std::string const &dir, std::string const &name);
+#define createLink(dir, targetname, linkname) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateLink(dir, targetname, linkname))
+void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
+#define createTemporaryFile(id, fd, filename, content) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
+void helperCreateTemporaryFile(std::string const &id, FileFd &fd, char * * const filename, char const * const content);
+
+#endif
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 462bdefd9..643c02297 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -1,55 +1,226 @@
+#include <config.h>
+
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/aptconfiguration.h>
-#include "assert.h"
#include <string>
#include <vector>
-
-#include <stdio.h>
-#include <iostream>
#include <stdlib.h>
+#include <string.h>
+
+#include <gtest/gtest.h>
+#include "file-helpers.h"
-int main(int argc,char *argv[])
+static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission,
+ unsigned int const filemode, APT::Configuration::Compressor const &compressor)
{
- std::vector<std::string> files;
+ std::string trace;
+ strprintf(trace, "TestFileFd: Compressor: %s umask: %#o permission: %#o mode: %d", compressor.Name.c_str(), a_umask, ExpectedFilePermission, filemode);
+ SCOPED_TRACE(trace);
- // normal match
- files = Glob("*.lst");
- if (files.size() != 1)
+ static const char* fname = "apt-filefd-test.txt";
+ if (FileExists(fname) == true)
+ EXPECT_EQ(0, unlink(fname));
+
+ FileFd f;
+ umask(a_umask);
+ EXPECT_TRUE(f.Open(fname, filemode, compressor));
+ EXPECT_TRUE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+ EXPECT_EQ(umask(a_umask), a_umask);
+
+ std::string test = "This is a test!\n";
+ EXPECT_TRUE(f.Write(test.c_str(), test.size()));
+ EXPECT_TRUE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+
+ f.Close();
+ EXPECT_FALSE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+
+ EXPECT_TRUE(f.Open(fname, FileFd::ReadOnly, compressor));
+ EXPECT_TRUE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_NE(0, f.FileSize());
+ EXPECT_FALSE(f.Failed());
+ EXPECT_NE(0, f.ModificationTime());
+ EXPECT_FALSE(f.Failed());
+
+ // ensure the memory is as predictably messed up
+#define APT_INIT_READBACK \
+ char readback[20]; \
+ memset(readback, 'D', sizeof(readback)/sizeof(readback[0])); \
+ readback[19] = '\0';
+#define EXPECT_N_STR(expect, actual) \
+ EXPECT_EQ(0, strncmp(expect, actual, strlen(expect)));
+
+ {
+ APT_INIT_READBACK
+ char const * const expect = "This";
+ EXPECT_TRUE(f.Read(readback, strlen(expect)));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_N_STR(expect, readback);
+ EXPECT_EQ(strlen(expect), f.Tell());
+ }
+ {
+ APT_INIT_READBACK
+ char const * const expect = "test!\n";
+ EXPECT_TRUE(f.Skip((test.size() - f.Tell()) - strlen(expect)));
+ EXPECT_TRUE(f.Read(readback, strlen(expect)));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_N_STR(expect, readback);
+ EXPECT_EQ(test.size(), f.Tell());
+ }
+ {
+ APT_INIT_READBACK
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ EXPECT_TRUE(f.Read(readback, 20, true));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_TRUE(f.Eof());
+ EXPECT_N_STR(test.c_str(), readback);
+ EXPECT_EQ(f.Size(), f.Tell());
+ }
+ {
+ APT_INIT_READBACK
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ EXPECT_TRUE(f.Read(readback, test.size(), true));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_N_STR(test.c_str(), readback);
+ EXPECT_EQ(f.Size(), f.Tell());
+ }
+ {
+ APT_INIT_READBACK
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ unsigned long long actual;
+ EXPECT_TRUE(f.Read(readback, 20, &actual));
+ EXPECT_FALSE(f.Failed());
+ EXPECT_TRUE(f.Eof());
+ EXPECT_EQ(test.size(), actual);
+ EXPECT_N_STR(test.c_str(), readback);
+ EXPECT_EQ(f.Size(), f.Tell());
+ }
{
- _error->DumpErrors();
- return 1;
+ APT_INIT_READBACK
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ f.ReadLine(readback, 20);
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_EQ(test, readback);
+ EXPECT_EQ(f.Size(), f.Tell());
}
+ {
+ APT_INIT_READBACK
+ EXPECT_TRUE(f.Seek(0));
+ EXPECT_FALSE(f.Eof());
+ char const * const expect = "This";
+ f.ReadLine(readback, strlen(expect) + 1);
+ EXPECT_FALSE(f.Failed());
+ EXPECT_FALSE(f.Eof());
+ EXPECT_N_STR(expect, readback);
+ EXPECT_EQ(strlen(expect), f.Tell());
+ }
+#undef APT_INIT_READBACK
- // not there
- files = Glob("xxxyyyzzz");
- if (files.size() != 0 || _error->PendingError())
+ f.Close();
+ EXPECT_FALSE(f.IsOpen());
+ EXPECT_FALSE(f.Failed());
+
+ // regression test for permission bug LP: #1304657
+ struct stat buf;
+ EXPECT_EQ(0, stat(fname, &buf));
+ EXPECT_EQ(0, unlink(fname));
+ EXPECT_EQ(ExpectedFilePermission, buf.st_mode & 0777);
+}
+
+static void TestFileFd(unsigned int const filemode)
+{
+ std::vector<APT::Configuration::Compressor> compressors = APT::Configuration::getCompressors();
+
+ // testing the (un)compress via pipe, as the 'real' compressors are usually built in via libraries
+ compressors.push_back(APT::Configuration::Compressor("rev", ".reversed", "rev", NULL, NULL, 42));
+ //compressors.push_back(APT::Configuration::Compressor("cat", ".ident", "cat", NULL, NULL, 42));
+
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); c != compressors.end(); ++c)
{
- _error->DumpErrors();
- return 1;
+ if ((filemode & FileFd::ReadWrite) == FileFd::ReadWrite &&
+ (c->Name.empty() != true && c->Binary.empty() != true))
+ continue;
+ TestFileFd(0002, 0664, filemode, *c);
+ TestFileFd(0022, 0644, filemode, *c);
+ TestFileFd(0077, 0600, filemode, *c);
+ TestFileFd(0026, 0640, filemode, *c);
}
+}
+
+TEST(FileUtlTest, FileFD)
+{
+ std::string const startdir = SafeGetCWD();
+ EXPECT_FALSE(startdir.empty());
+ std::string tempdir;
+ createTemporaryDirectory("filefd", tempdir);
+ EXPECT_EQ(0, chdir(tempdir.c_str()));
+
+ TestFileFd(FileFd::WriteOnly | FileFd::Create);
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Empty);
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive);
+ TestFileFd(FileFd::WriteOnly | FileFd::Atomic);
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Atomic);
+ // short-hands for ReadWrite with these modes
+ TestFileFd(FileFd::WriteEmpty);
+ TestFileFd(FileFd::WriteAny);
+ TestFileFd(FileFd::WriteTemp);
+ TestFileFd(FileFd::WriteAtomic);
+
+ EXPECT_EQ(0, chdir(startdir.c_str()));
+ removeDirectory(tempdir);
+}
+TEST(FileUtlTest, Glob)
+{
+ std::vector<std::string> files;
+ // normal match
+ files = Glob("*akefile");
+ EXPECT_EQ(1, files.size());
+
+ // not there
+ files = Glob("xxxyyyzzz");
+ EXPECT_TRUE(files.empty());
+ EXPECT_FALSE(_error->PendingError());
// many matches (number is a bit random)
files = Glob("*.cc");
- if (files.size() < 10)
- {
- _error->DumpErrors();
- return 1;
- }
+ EXPECT_LT(10, files.size());
+}
+TEST(FileUtlTest, GetTempDir)
+{
+ char const * const envtmp = getenv("TMPDIR");
+ std::string old_tmpdir;
+ if (envtmp != NULL)
+ old_tmpdir = envtmp;
- // GetTempDir()
unsetenv("TMPDIR");
- equals(GetTempDir(), "/tmp");
+ EXPECT_EQ("/tmp", GetTempDir());
setenv("TMPDIR", "", 1);
- equals(GetTempDir(), "/tmp");
+ EXPECT_EQ("/tmp", GetTempDir());
setenv("TMPDIR", "/not-there-no-really-not", 1);
- equals(GetTempDir(), "/tmp");
+ EXPECT_EQ("/tmp", GetTempDir());
setenv("TMPDIR", "/usr", 1);
- equals(GetTempDir(), "/usr");
+ EXPECT_EQ("/usr", GetTempDir());
- return 0;
+ unsetenv("TMPDIR");
+ if (old_tmpdir.empty() == false)
+ setenv("TMPDIR", old_tmpdir.c_str(), 1);
}
diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc
index 807469263..53c00cd8f 100644
--- a/test/libapt/getarchitectures_test.cc
+++ b/test/libapt/getarchitectures_test.cc
@@ -1,60 +1,77 @@
+#include <config.h>
+
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
-#include "assert.h"
#include <string>
#include <vector>
-#include <iostream>
+#include <gtest/gtest.h>
-int main(int argc,char *argv[])
+TEST(ArchitecturesTest,SimpleLists)
{
- 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], "armel");
- equals(vec[1], "i386");
-
- _config->Set("APT::Architectures::2", "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;
+ _config->Clear();
+ std::vector<std::string> vec;
+
+ _config->Set("APT::Architectures::1", "i386");
+ _config->Set("APT::Architectures::2", "amd64");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("i386", vec[0]);
+ EXPECT_EQ("amd64", vec[1]);
+
+ _config->Set("APT::Architecture", "i386");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("i386", vec[0]);
+ EXPECT_EQ("amd64", vec[1]);
+
+ _config->Set("APT::Architectures::2", "");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(1, vec.size());
+ EXPECT_EQ("i386", vec[0]);
+
+ _config->Set("APT::Architecture", "armel");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("armel", vec[0]);
+ EXPECT_EQ("i386", vec[1]);
+
+ _config->Set("APT::Architectures::2", "armel");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("i386", vec[0]);
+ EXPECT_EQ("armel", vec[1]);
+
+ _config->Set("APT::Architectures", "armel,armhf");
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("armel", vec[0]);
+ EXPECT_EQ("armhf", vec[1]);
+ _config->Clear();
+}
+TEST(ArchitecturesTest,Duplicates)
+{
+ _config->Clear();
+
+ _config->Set("APT::Architecture", "armel");
+ _config->Set("APT::Architectures::", "i386");
+ _config->Set("APT::Architectures::", "amd64");
+ _config->Set("APT::Architectures::", "i386");
+ _config->Set("APT::Architectures::", "armel");
+ _config->Set("APT::Architectures::", "i386");
+ _config->Set("APT::Architectures::", "amd64");
+ _config->Set("APT::Architectures::", "armel");
+ _config->Set("APT::Architectures::", "armel");
+ _config->Set("APT::Architectures::", "amd64");
+ _config->Set("APT::Architectures::", "amd64");
+ std::vector<std::string> vec = _config->FindVector("APT::Architectures");
+ ASSERT_EQ(10, vec.size());
+ vec = APT::Configuration::getArchitectures(false);
+ ASSERT_EQ(3, vec.size());
+ EXPECT_EQ("i386", vec[0]);
+ EXPECT_EQ("amd64", vec[1]);
+ EXPECT_EQ("armel", vec[2]);
+
+ _config->Clear();
}
diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc
index cef89bde6..c50ff6ff8 100644
--- a/test/libapt/getlanguages_test.cc
+++ b/test/libapt/getlanguages_test.cc
@@ -1,190 +1,234 @@
+#include <config.h>
+
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
-#include "assert.h"
+#include <algorithm>
+#include <iostream>
#include <string>
#include <vector>
-#include <iostream>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <gtest/gtest.h>
+
+#include "file-helpers.h"
+
+TEST(LanguagesTest,Environment)
+{
+ _config->Clear();
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(3 ,vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ // Special: Check if the cache is actually in use
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, true, env);
+ ASSERT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("en_GB", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+
+ // esperanto
+ env[0] = "eo.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ ASSERT_EQ(2, vec.size());
+ EXPECT_EQ("eo", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+
+ env[0] = "tr_DE@euro";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("tr_DE", vec[0]);
+ EXPECT_EQ("tr", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "de_NO";
+ env[1] = "de_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(6, vec.size());
+ EXPECT_EQ("de_NO", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en_GB", vec[2]);
+ EXPECT_EQ("nb_NO", vec[3]);
+ EXPECT_EQ("nb", vec[4]);
+ EXPECT_EQ("en", vec[5]);
+
+ env[0] = "pt_PR.UTF-8";
+ env[1] = "";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("pt_PR", vec[0]);
+ EXPECT_EQ("pt", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("ast_DE", vec[0]);
+ EXPECT_EQ("ast", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_TRUE(vec.empty());
+
+ _config->Set("Acquire::Languages", "environment");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+ _config->Set("Acquire::Languages", "de");
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("de", vec[0]);
+
+ _config->Set("Acquire::Languages", "fr");
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("fr", vec[0]);
+
+ _config->Set("Acquire::Languages", "environment,en");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+ _config->Set("Acquire::Languages", "");
+
+ _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);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ _config->Set("Acquire::Languages::3", "de");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ EXPECT_EQ(3, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+
+ _config->Clear();
+}
-int main(int argc,char *argv[])
+TEST(LanguagesTest,TranslationFiles)
{
- 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(), 3);
- equals(vec[0], "de_DE");
- equals(vec[1], "de");
- equals(vec[2], "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(), 3);
- equals(vec[0], "de_DE");
- equals(vec[1], "de");
- equals(vec[2], "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(), 3);
- equals(vec[0], "tr_DE");
- equals(vec[1], "tr");
- equals(vec[2], "en");
-
- env[0] = "de_NO";
- env[1] = "de_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(), 6);
- equals(vec[0], "de_NO");
- equals(vec[1], "de");
- equals(vec[2], "en_GB");
- equals(vec[3], "nb_NO");
- equals(vec[4], "nb");
- equals(vec[5], "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(), 3);
- equals(vec[0], "ast_DE");
- equals(vec[1], "ast");
- equals(vec[2], "en");
-
- env[0] = "C";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 1);
- equals(vec[0], "en");
-
- _config->Set("Acquire::Languages", "none");
- env[0] = "C";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 0);
-
- _config->Set("Acquire::Languages", "environment");
- env[0] = "C";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 1);
- equals(vec[0], "en");
-
- _config->Set("Acquire::Languages", "de");
- env[0] = "C";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 1);
- equals(vec[0], "de");
-
- _config->Set("Acquire::Languages", "fr");
- env[0] = "ast_DE.UTF-8";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 1);
- equals(vec[0], "fr");
- _config->Set("Acquire::Languages", "");
-
- _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(), 3);
- equals(vec[0], "de_DE");
- equals(vec[1], "de");
- equals(vec[2], "en");
-
- _config->Set("Acquire::Languages::3", "de");
- env[0] = "de_DE.UTF-8";
- vec = APT::Configuration::getLanguages(false, false, env);
- equals(vec.size(), 3);
- equals(vec[0], "de_DE");
- equals(vec[1], "de");
- equals(vec[2], "en");
-
- _config->Set("Dir::State::lists", argv[1]);
- vec = APT::Configuration::getLanguages(true, false, env);
- equals(vec.size(), 8);
- equals(vec[0], "de_DE");
- equals(vec[1], "de");
- equals(vec[2], "en");
- equals(vec[3], "none");
- 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(), 1);
- equals(vec[0], "none");
- _config->Set("Acquire::Languages", "");
-
- _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.size(), 2);
- 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(), 1);
- equals(vec[0], "none");
-
- _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;
+ _config->Clear();
+ _config->Set("Acquire::Languages::1", "environment");
+ _config->Set("Acquire::Languages::2", "en");
+ _config->Set("Acquire::Languages::3", "de");
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::string tempdir;
+ createTemporaryDirectory("languages", tempdir);
+
+#define createTranslation(lang) \
+ createFile(tempdir, std::string("/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-").append(lang));
+
+ createTranslation("tr");
+ createTranslation("pt");
+ createTranslation("se~");
+ createTranslation("st.bak");
+ createTranslation("ast_DE");
+ createTranslation("tlh%5fDE");
+
+ _config->Set("Dir::State::lists", tempdir);
+ std::vector<std::string> vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(8, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+ EXPECT_EQ("en", vec[2]);
+ EXPECT_EQ("none", vec[3]);
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "pt"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "tr"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "ast_DE"));
+ EXPECT_NE(vec.end(), std::find(vec.begin(), vec.end(), "tlh_DE"));
+ EXPECT_NE(vec[4], vec[5]);
+ EXPECT_NE(vec[4], vec[6]);
+ EXPECT_NE(vec[4], vec[7]);
+ EXPECT_NE(vec[5], vec[6]);
+ EXPECT_NE(vec[5], vec[7]);
+ EXPECT_NE(vec[6], vec[7]);
+
+ _config->Set("Acquire::Languages", "none");
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("none", vec[0]);
+ _config->Set("Acquire::Languages", "");
+
+ _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);
+ EXPECT_TRUE(vec.empty());
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(2, vec.size());
+ EXPECT_EQ("en", vec[0]);
+ EXPECT_EQ("de", vec[1]);
+
+ _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);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("de_DE", vec[0]);
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("none", vec[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);
+ EXPECT_EQ(2, vec.size());
+ EXPECT_EQ("ast_DE", vec[0]);
+ EXPECT_EQ("en", vec[1]);
+ _config->Set("APT::Acquire::Translation", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ EXPECT_EQ(1, vec.size());
+ EXPECT_EQ("en", vec[0]);
+
+
+ EXPECT_EQ(0, system(std::string("rm -rf ").append(tempdir).c_str()));
+ _config->Clear();
}
diff --git a/test/libapt/getlistoffilesindir_test.cc b/test/libapt/getlistoffilesindir_test.cc
index b2c95e840..2369c911a 100644
--- a/test/libapt/getlistoffilesindir_test.cc
+++ b/test/libapt/getlistoffilesindir_test.cc
@@ -1,75 +1,107 @@
+#include <config.h>
+
#include <apt-pkg/fileutl.h>
-#include "assert.h"
#include <string>
#include <vector>
-
-#include <stdio.h>
#include <iostream>
-#define P(x) std::string(argv[1]).append("/").append(x)
+#include <gtest/gtest.h>
+
+#include "file-helpers.h"
+
+#define P(x) std::string(tempdir).append("/").append(x)
-int main(int argc,char *argv[])
+TEST(FileUtlTest,GetListOfFilesInDir)
{
- 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;
+ std::string tempdir;
+ createTemporaryDirectory("getlistoffiles", tempdir);
+
+ createFile(tempdir, "anormalfile");
+ createFile(tempdir, "01yet-anothernormalfile");
+ createFile(tempdir, "anormalapt.conf");
+ createFile(tempdir, "01yet-anotherapt.conf");
+ createFile(tempdir, "anormalapt.list");
+ createFile(tempdir, "01yet-anotherapt.list");
+ createFile(tempdir, "wrongextension.wron");
+ createFile(tempdir, "wrong-extension.wron");
+ createFile(tempdir, "strangefile.");
+ createFile(tempdir, "s.t.r.a.n.g.e.f.i.l.e");
+ createFile(tempdir, ".hiddenfile");
+ createFile(tempdir, ".hiddenfile.conf");
+ createFile(tempdir, ".hiddenfile.list");
+ createFile(tempdir, "multi..dot");
+ createFile(tempdir, "multi.dot.conf");
+ createFile(tempdir, "multi.dot.list");
+ createFile(tempdir, "disabledfile.disabled");
+ createFile(tempdir, "disabledfile.conf.disabled");
+ createFile(tempdir, "disabledfile.list.disabled");
+ createFile(tempdir, "invälid.conf");
+ createFile(tempdir, "invalíd");
+ createFile(tempdir, "01invalíd");
+ createDirectory(tempdir, "invaliddir");
+ createDirectory(tempdir, "directory.conf");
+ createDirectory(tempdir, "directory.list");
+ createDirectory(tempdir, "directory.wron");
+ createDirectory(tempdir, "directory.list.disabled");
+ createLink(tempdir, "anormalfile", "linkedfile.list");
+ createLink(tempdir, "invaliddir", "linkeddir.list");
+ createLink(tempdir, "non-existing-file", "brokenlink.list");
+
+ // Files with no extension
+ std::vector<std::string> files = GetListOfFilesInDir(tempdir, "", true);
+ ASSERT_EQ(2, files.size());
+ EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
+ EXPECT_EQ(P("anormalfile"), files[1]);
+
+ // Files with no extension - should be the same as above
+ files = GetListOfFilesInDir(tempdir, "", true, true);
+ ASSERT_EQ(2, files.size());
+ EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
+ EXPECT_EQ(P("anormalfile"), files[1]);
+
+ // Files with impossible extension
+ files = GetListOfFilesInDir(tempdir, "impossible", true);
+ EXPECT_TRUE(files.empty());
+
+ // Files with impossible or no extension
+ files = GetListOfFilesInDir(tempdir, "impossible", true, true);
+ ASSERT_EQ(2, files.size());
+ EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
+ EXPECT_EQ(P("anormalfile"), files[1]);
+
+ // Files with list extension - nothing more
+ files = GetListOfFilesInDir(tempdir, "list", true);
+ ASSERT_EQ(4, files.size());
+ EXPECT_EQ(P("01yet-anotherapt.list"), files[0]);
+ EXPECT_EQ(P("anormalapt.list"), files[1]);
+ EXPECT_EQ(P("linkedfile.list"), files[2]);
+ EXPECT_EQ(P("multi.dot.list"), files[3]);
+
+ // Files with conf or no extension
+ files = GetListOfFilesInDir(tempdir, "conf", true, true);
+ ASSERT_EQ(5, files.size());
+ EXPECT_EQ(P("01yet-anotherapt.conf"), files[0]);
+ EXPECT_EQ(P("01yet-anothernormalfile"), files[1]);
+ EXPECT_EQ(P("anormalapt.conf"), files[2]);
+ EXPECT_EQ(P("anormalfile"), files[3]);
+ EXPECT_EQ(P("multi.dot.conf"), files[4]);
+
+ // Files with disabled extension - nothing more
+ files = GetListOfFilesInDir(tempdir, "disabled", true);
+ ASSERT_EQ(3, files.size());
+ EXPECT_EQ(P("disabledfile.conf.disabled"), files[0]);
+ EXPECT_EQ(P("disabledfile.disabled"), files[1]);
+ EXPECT_EQ(P("disabledfile.list.disabled"), files[2]);
+
+ // Files with disabled or no extension
+ files = GetListOfFilesInDir(tempdir, "disabled", true, true);
+ ASSERT_EQ(5, files.size());
+ EXPECT_EQ(P("01yet-anothernormalfile"), files[0]);
+ EXPECT_EQ(P("anormalfile"), files[1]);
+ EXPECT_EQ(P("disabledfile.conf.disabled"), files[2]);
+ EXPECT_EQ(P("disabledfile.disabled"), files[3]);
+ EXPECT_EQ(P("disabledfile.list.disabled"), files[4]);
+
+ removeDirectory(tempdir);
}
diff --git a/test/libapt/globalerror_test.cc b/test/libapt/globalerror_test.cc
index b6939231d..05b95db85 100644
--- a/test/libapt/globalerror_test.cc
+++ b/test/libapt/globalerror_test.cc
@@ -1,112 +1,135 @@
+#include <config.h>
+
#include <apt-pkg/error.h>
-#include "assert.h"
+#include <stddef.h>
#include <string>
#include <errno.h>
#include <string.h>
-int main(int argc,char *argv[])
-{
- std::string const textOfErrnoZero(strerror(0));
-
- 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", "happened", 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 happened 2 times");
- equals(_error->empty(GlobalError::DEBUG), true);
- equals(_error->PendingError(), false);
- equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false);
- equals(_error->PendingError(), true);
- equals(_error->empty(GlobalError::FATAL), false);
- _error->Discard();
+#include <gtest/gtest.h>
- equals(_error->empty(), true);
- equals(_error->PendingError(), false);
- equals(_error->Notice("%s Notice", "A"), false);
- equals(_error->Error("%s horrible %s %d times", "Something", "happened", 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 happened 2 times");
- equals(_error->PendingError(), false);
- equals(_error->empty(), true);
+TEST(GlobalErrorTest,BasicDiscard)
+{
+ GlobalError e;
+ EXPECT_TRUE(e.empty());
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.Notice("%s Notice", "A"));
+ EXPECT_TRUE(e.empty());
+ EXPECT_FALSE(e.empty(GlobalError::DEBUG));
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.Error("%s horrible %s %d times", "Something", "happened", 2));
+ EXPECT_TRUE(e.PendingError());
- equals(_error->Notice("%s Notice", "A"), false);
- equals(_error->Error("%s horrible %s %d times", "Something", "happened", 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 happened 2 times");
- equals(_error->PendingError(), false);
- equals(_error->empty(), false);
- equals(_error->PopMessage(text), false);
- equals(text, "A Warning");
- equals(_error->empty(), true);
+ std::string text;
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_EQ("A Notice", text);
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_EQ("Something horrible happened 2 times", text);
+ EXPECT_TRUE(e.empty(GlobalError::DEBUG));
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.Error("%s horrible %s %d times", "Something", "happened", 2));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_FALSE(e.empty(GlobalError::FATAL));
+ e.Discard();
- errno = 0;
- equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happened", 2), false);
- equals(_error->empty(), false);
- equals(_error->PendingError(), true);
- equals(_error->PopMessage(text), true);
- equals(_error->PendingError(), false);
- equals(text, std::string("Something horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
- equals(_error->empty(), true);
+ EXPECT_TRUE(e.empty());
+ EXPECT_FALSE(e.PendingError());
+}
+TEST(GlobalErrorTest,StackPushing)
+{
+ GlobalError e;
+ EXPECT_FALSE(e.Notice("%s Notice", "A"));
+ EXPECT_FALSE(e.Error("%s horrible %s %d times", "Something", "happened", 2));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_FALSE(e.empty(GlobalError::NOTICE));
+ e.PushToStack();
+ EXPECT_TRUE(e.empty(GlobalError::NOTICE));
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.Warning("%s Warning", "A"));
+ EXPECT_TRUE(e.empty(GlobalError::ERROR));
+ EXPECT_FALSE(e.PendingError());
+ e.RevertToStack();
+ EXPECT_FALSE(e.empty(GlobalError::ERROR));
+ EXPECT_TRUE(e.PendingError());
- std::string longText;
- for (size_t i = 0; i < 500; ++i)
- longText.append("a");
- equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happened", 2), false);
- equals(_error->PopMessage(text), true);
- equals(text, std::string(longText).append(" horrible happened 2 times"));
+ std::string text;
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_EQ("A Notice", text);
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_EQ("Something horrible happened 2 times", text);
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_TRUE(e.empty());
- equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happened", 2), false);
- equals(_error->PopMessage(text), true);
- equals(text, std::string(longText).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
+ EXPECT_FALSE(e.Notice("%s Notice", "A"));
+ EXPECT_FALSE(e.Error("%s horrible %s %d times", "Something", "happened", 2));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_FALSE(e.empty(GlobalError::NOTICE));
+ e.PushToStack();
+ EXPECT_TRUE(e.empty(GlobalError::NOTICE));
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.Warning("%s Warning", "A"));
+ EXPECT_TRUE(e.empty(GlobalError::ERROR));
+ EXPECT_FALSE(e.PendingError());
+ e.MergeWithStack();
+ EXPECT_FALSE(e.empty(GlobalError::ERROR));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_TRUE(e.PendingError());
+ EXPECT_EQ("A Notice", text);
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_EQ("Something horrible happened 2 times", text);
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_FALSE(e.empty());
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_EQ("A Warning", text);
+ EXPECT_TRUE(e.empty());
+}
+TEST(GlobalErrorTest,Errno)
+{
+ GlobalError e;
+ std::string const textOfErrnoZero(strerror(0));
+ errno = 0;
+ EXPECT_FALSE(e.Errno("errno", "%s horrible %s %d times", "Something", "happened", 2));
+ EXPECT_FALSE(e.empty());
+ EXPECT_TRUE(e.PendingError());
+ std::string text;
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_FALSE(e.PendingError());
+ EXPECT_EQ(std::string("Something horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"), text);
+ EXPECT_TRUE(e.empty());
+}
+TEST(GlobalErrorTest,LongMessage)
+{
+ GlobalError e;
+ std::string const textOfErrnoZero(strerror(0));
+ errno = 0;
+ std::string text, longText;
+ for (size_t i = 0; i < 500; ++i)
+ longText.append("a");
+ EXPECT_FALSE(e.Error("%s horrible %s %d times", longText.c_str(), "happened", 2));
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_EQ(std::string(longText).append(" horrible happened 2 times"), text);
- equals(_error->Warning("Репозиторий не обновлён и будут %d %s", 4, "test"), false);
- equals(_error->PopMessage(text), false);
- equals(text, "Репозиторий не обновлён и будут 4 test");
+ EXPECT_FALSE(e.Errno("errno", "%s horrible %s %d times", longText.c_str(), "happened", 2));
+ EXPECT_TRUE(e.PopMessage(text));
+ EXPECT_EQ(std::string(longText).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"), text);
+}
+TEST(GlobalErrorTest,UTF8Message)
+{
+ GlobalError e;
+ std::string text;
- longText.clear();
- for (size_t i = 0; i < 50; ++i)
- longText.append("РезийбёбAZ");
- equals(_error->Warning("%s", longText.c_str()), false);
- equals(_error->PopMessage(text), false);
- equals(text, longText);
+ EXPECT_FALSE(e.Warning("Репозиторий не обновлён и будут %d %s", 4, "test"));
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_EQ("Репозиторий не обновлён и будут 4 test", text);
- return 0;
+ std::string longText;
+ for (size_t i = 0; i < 50; ++i)
+ longText.append("РезийбёбAZ");
+ EXPECT_FALSE(e.Warning("%s", longText.c_str()));
+ EXPECT_FALSE(e.PopMessage(text));
+ EXPECT_EQ(longText, text);
}
diff --git a/test/libapt/gtest_runner.cc b/test/libapt/gtest_runner.cc
new file mode 100644
index 000000000..5823c55de
--- /dev/null
+++ b/test/libapt/gtest_runner.cc
@@ -0,0 +1,19 @@
+#include <gtest/gtest.h>
+#include <apt-pkg/error.h>
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ int result = RUN_ALL_TESTS();
+ if (_error->empty() == false)
+ {
+ std::cerr << "The test generated the following global messages:" << std::endl;
+ _error->DumpErrors(std::cerr);
+ // messages on the stack can't be right, error out
+ // even if we have no idea where this message came from
+ if (result == 0)
+ {
+ std::cerr << "All tests successful, but messages were generated, so still a failure!" << std::endl;
+ return 29;
+ }
+ }
+ return result;
+}
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index 3da89052b..c06d85e03 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -1,14 +1,19 @@
+#include <config.h>
+
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
#include <apt-pkg/sha2.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/hashes.h>
#include <apt-pkg/fileutl.h>
+
#include <iostream>
+#include <stdlib.h>
+#include <string>
-#include <stdio.h>
+#include <gtest/gtest.h>
-#include "assert.h"
+#include "file-helpers.h"
template <class T> void Test(const char *In,const char *Out)
{
@@ -17,162 +22,201 @@ template <class T> void Test(const char *In,const char *Out)
equals(Sum.Result().Value(), Out);
}
-template <class T> void TestMill(const char *Out)
+
+
+TEST(HashSumsTest,SummationStrings)
{
- T Sum;
+#define EXPECT_SUM(Summation, In, Out) \
+ { \
+ Summation Sum; \
+ Sum.Add(In); \
+ EXPECT_EQ(Sum.Result().Value(), Out) << #Summation << " for '" << In << "'"; \
+ }
+
+ // From FIPS PUB 180-1
+ EXPECT_SUM(SHA1Summation, "","da39a3ee5e6b4b0d3255bfef95601890afd80709");
+ EXPECT_SUM(SHA1Summation, "abc","a9993e364706816aba3e25717850c26c9cd0d89d");
+ EXPECT_SUM(SHA1Summation, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
+
+ // MD5 tests from RFC 1321
+ EXPECT_SUM(MD5Summation, "","d41d8cd98f00b204e9800998ecf8427e");
+ EXPECT_SUM(MD5Summation, "a","0cc175b9c0f1b6a831c399e269772661");
+ EXPECT_SUM(MD5Summation, "abc","900150983cd24fb0d6963f7d28e17f72");
+ EXPECT_SUM(MD5Summation, "message digest","f96b697d7cb7938d525a2f31aaf161d0");
+ EXPECT_SUM(MD5Summation, "abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b");
+ EXPECT_SUM(MD5Summation, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "d174ab98d277d9f5a5611c2c9f419d9f");
+ EXPECT_SUM(MD5Summation, "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
+ "57edf4a22be3c955ac49da2e2107b67a");
- const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
- unsigned Count = 1000000;
- for (; Count != 0;)
+ // SHA-256, From FIPS 180-2
+ EXPECT_SUM(SHA256Summation, "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+ EXPECT_SUM(SHA256Summation, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+ "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
+
+ // SHA-512
+ EXPECT_SUM(SHA512Summation, "",
+ "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce"
+ "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+ EXPECT_SUM(SHA512Summation, "abc",
+ "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
+ "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
+
+
+ EXPECT_SUM(MD5Summation, "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6");
+ EXPECT_SUM(MD5Summation, "The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0");
+ EXPECT_SUM(SHA1Summation, "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
+ EXPECT_SUM(SHA1Summation, "The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3");
+ EXPECT_SUM(SHA256Summation, "The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592");
+ EXPECT_SUM(SHA256Summation, "The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c");
+ EXPECT_SUM(SHA512Summation, "The quick brown fox jumps over the lazy dog", "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb64"
+ "2e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6");
+ EXPECT_SUM(SHA512Summation, "The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb"
+ "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed");
+
+#undef EXPECT_SUM
+}
+TEST(HashSumsTest, Mill)
+{
+ SHA1Summation Sum1;
+
+ const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ size_t const AsCount = sizeof(As)/sizeof(As[0]) - 1;
+ size_t Count = 1000000;
+ while (Count != 0)
{
- if (Count >= 64)
+ if (Count >= AsCount)
{
- Sum.Add(As,64);
- Count -= 64;
+ Sum1.Add(As, AsCount);
+ Count -= AsCount;
}
else
{
- Sum.Add(As,Count);
+ Sum1.Add(As,Count);
Count = 0;
}
}
- if (stringcasecmp(Sum.Result().Value(), Out) != 0)
- abort();
+ EXPECT_EQ("34aa973cd4c4daa4f61eeb2bdbad27316534016f", Sum1.Result().Value());
}
-int main(int argc, char** argv)
+static void getSummationString(char const * const type, std::string &sum)
{
- // 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);
- }
+ /* to compare our result with an independent source we call the specific binaries
+ and read their result back. We do this with a little trick by claiming that the
+ summation is a compressor – and open the 'compressed' file later on directly to
+ read out the summation sum calculated by it */
+ APT::Configuration::Compressor compress(type, ".ext", type, NULL, NULL, 99);
+ std::string name("apt-test-");
+ name.append("hashsums").append(".XXXXXX");
+ char * tempfile = strdup(name.c_str());
+ int tempfile_fd = mkstemp(tempfile);
+ close(tempfile_fd);
+ ASSERT_NE(-1, tempfile_fd);
+
+ FileFd fd;
+ ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress));
+ ASSERT_TRUE(fd.IsOpen());
+ FileFd input(__FILE__, FileFd::ReadOnly);
+ ASSERT_TRUE(input.IsOpen());
+ ASSERT_NE(0, input.FileSize());
+ ASSERT_TRUE(CopyFile(input, fd));
+ ASSERT_TRUE(input.IsOpen());
+ ASSERT_TRUE(fd.IsOpen());
+ ASSERT_FALSE(fd.Failed());
+ input.Close();
+ fd.Close();
+ ASSERT_TRUE(fd.Open(tempfile, FileFd::ReadOnly, FileFd::None));
+ ASSERT_TRUE(fd.IsOpen());
+ ASSERT_NE(0, fd.FileSize());
+ ASSERT_FALSE(fd.Failed());
+ unlink(tempfile);
+ free(tempfile);
+ char readback[2000];
+ unsigned long long actual;
+ ASSERT_TRUE(fd.Read(readback, sizeof(readback)/sizeof(readback[0]), &actual));
+ actual -= 4;
+ readback[actual] = '\0';
+ sum = readback;
+}
+TEST(HashSumsTest, FileBased)
+{
+ std::string summation;
- // From FIPS PUB 180-1
- Test<SHA1Summation>("","da39a3ee5e6b4b0d3255bfef95601890afd80709");
- Test<SHA1Summation>("abc","a9993e364706816aba3e25717850c26c9cd0d89d");
- Test<SHA1Summation>("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
- TestMill<SHA1Summation>("34aa973cd4c4daa4f61eeb2bdbad27316534016f");
+ getSummationString("md5sum", summation);
+ MD5SumValue md5(summation);
+ EXPECT_EQ(md5.Value(), summation);
- // MD5 tests from RFC 1321
- Test<MD5Summation>("","d41d8cd98f00b204e9800998ecf8427e");
- Test<MD5Summation>("a","0cc175b9c0f1b6a831c399e269772661");
- Test<MD5Summation>("abc","900150983cd24fb0d6963f7d28e17f72");
- Test<MD5Summation>("message digest","f96b697d7cb7938d525a2f31aaf161d0");
- Test<MD5Summation>("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b");
- Test<MD5Summation>("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "d174ab98d277d9f5a5611c2c9f419d9f");
- Test<MD5Summation>("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
- "57edf4a22be3c955ac49da2e2107b67a");
+ getSummationString("sha1sum", summation);
+ SHA1SumValue sha1(summation);
+ EXPECT_EQ(sha1.Value(), summation);
- // SHA-256, From FIPS 180-2
- Test<SHA256Summation>("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
- Test<SHA256Summation>("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
- "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
+ getSummationString("sha256sum", summation);
+ SHA256SumValue sha256(summation);
+ EXPECT_EQ(sha256.Value(), summation);
+
+ getSummationString("sha512sum", summation);
+ SHA512SumValue sha512(summation);
+ EXPECT_EQ(sha512.Value(), summation);
+
+ FileFd fd(__FILE__, FileFd::ReadOnly);
+ EXPECT_TRUE(fd.IsOpen());
- // SHA-512
- Test<SHA512Summation>("",
- "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce"
- "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
- Test<SHA512Summation>(
- "abc",
- "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
- "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f");
-
-
- Test<MD5Summation>("The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6");
- Test<MD5Summation>("The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0");
- Test<SHA1Summation>("The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
- Test<SHA1Summation>("The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3");
- Test<SHA256Summation>("The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592");
- Test<SHA256Summation>("The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c");
- Test<SHA512Summation>("The quick brown fox jumps over the lazy dog", "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb64"
- "2e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6");
- Test<SHA512Summation>("The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb"
- "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed");
-
- FileFd fd(argv[1], FileFd::ReadOnly);
- if (fd.IsOpen() == false) {
- std::cerr << "Can't open file for 1. testing: " << argv[1] << std::endl;
- return 1;
- }
{
- Hashes hashes;
- hashes.AddFD(fd.Fd());
- equals(argv[2], hashes.MD5.Result().Value());
- equals(argv[3], hashes.SHA1.Result().Value());
- equals(argv[4], hashes.SHA256.Result().Value());
- equals(argv[5], hashes.SHA512.Result().Value());
+ Hashes hashes;
+ hashes.AddFD(fd.Fd());
+ EXPECT_EQ(md5.Value(), hashes.MD5.Result().Value());
+ EXPECT_EQ(sha1.Value(), hashes.SHA1.Result().Value());
+ EXPECT_EQ(sha256.Value(), hashes.SHA256.Result().Value());
+ EXPECT_EQ(sha512.Value(), hashes.SHA512.Result().Value());
}
unsigned long sz = fd.FileSize();
fd.Seek(0);
{
- Hashes hashes;
- hashes.AddFD(fd.Fd(), sz);
- equals(argv[2], hashes.MD5.Result().Value());
- equals(argv[3], hashes.SHA1.Result().Value());
- equals(argv[4], hashes.SHA256.Result().Value());
- equals(argv[5], hashes.SHA512.Result().Value());
+ Hashes hashes;
+ hashes.AddFD(fd.Fd(), sz);
+ EXPECT_EQ(md5.Value(), hashes.MD5.Result().Value());
+ EXPECT_EQ(sha1.Value(), hashes.SHA1.Result().Value());
+ EXPECT_EQ(sha256.Value(), hashes.SHA256.Result().Value());
+ EXPECT_EQ(sha512.Value(), hashes.SHA512.Result().Value());
}
fd.Seek(0);
{
- MD5Summation md5;
- md5.AddFD(fd.Fd());
- equals(argv[2], md5.Result().Value());
+ MD5Summation MD5;
+ MD5.AddFD(fd.Fd());
+ EXPECT_EQ(md5.Value(), MD5.Result().Value());
}
fd.Seek(0);
{
- SHA1Summation sha1;
- sha1.AddFD(fd.Fd());
- equals(argv[3], sha1.Result().Value());
+ SHA1Summation SHA1;
+ SHA1.AddFD(fd.Fd());
+ EXPECT_EQ(sha1.Value(), SHA1.Result().Value());
}
fd.Seek(0);
{
- SHA256Summation sha2;
- sha2.AddFD(fd.Fd());
- equals(argv[4], sha2.Result().Value());
+ SHA256Summation SHA2;
+ SHA2.AddFD(fd.Fd());
+ EXPECT_EQ(sha256.Value(), SHA2.Result().Value());
}
fd.Seek(0);
{
- SHA512Summation sha2;
- sha2.AddFD(fd.Fd());
- equals(argv[5], sha2.Result().Value());
+ SHA512Summation SHA2;
+ SHA2.AddFD(fd.Fd());
+ EXPECT_EQ(sha512.Value(), SHA2.Result().Value());
}
fd.Close();
- // test HashString code
{
- HashString sha2("SHA256", argv[4]);
- equals(sha2.VerifyFile(argv[1]), true);
+ HashString sha2("SHA256", sha256.Value());
+ EXPECT_TRUE(sha2.VerifyFile(__FILE__));
}
{
- HashString sha2("SHA512", argv[5]);
- equals(sha2.VerifyFile(argv[1]), true);
+ HashString sha2("SHA512", sha512.Value());
+ EXPECT_TRUE(sha2.VerifyFile(__FILE__));
}
{
- HashString sha2("SHA256:" + std::string(argv[4]));
- equals(sha2.VerifyFile(argv[1]), true);
+ HashString sha2("SHA256:" + sha256.Value());
+ EXPECT_TRUE(sha2.VerifyFile(__FILE__));
}
-
- return 0;
}
-
-
diff --git a/test/libapt/indexcopytosourcelist_test.cc b/test/libapt/indexcopytosourcelist_test.cc
index 69d8fae86..bec87601f 100644
--- a/test/libapt/indexcopytosourcelist_test.cc
+++ b/test/libapt/indexcopytosourcelist_test.cc
@@ -1,33 +1,41 @@
+#include <config.h>
+
#include <apt-pkg/configuration.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/indexcopy.h>
#include <string>
+#include <stdio.h>
-#include "assert.h"
+#include <gtest/gtest.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; }
+ 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[]) {
+TEST(IndexCopyTest, ConvertToSourceList)
+{
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) {
+ for (char const ** Release = Releases; *Release != NULL; ++Release)
+ {
+ SCOPED_TRACE(std::string("Release ") + *Release);
+ for (char const ** Component = Components; *Component != NULL; ++Component)
+ {
+ SCOPED_TRACE(std::string("Component ") + *Component);
std::string const Path = std::string("dists/") + *Release + "/" + *Component + "/";
std::string const Binary = Path + "binary-";
std::string const A = Binary + "armel/";
@@ -38,49 +46,47 @@ int main(int argc, char const *argv[]) {
_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);
+ EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
+ EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
+ EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
_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);
+ EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
+ EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
_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);
+ EXPECT_EQ(A, ic.ConvertToSourceList("/media/cdrom/", CD + A));
+ EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + C));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
_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);
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
+ EXPECT_EQ(B, ic.ConvertToSourceList("/media/cdrom/", CD + B));
+ EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
_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);
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + A));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + B));
+ EXPECT_EQ(C, ic.ConvertToSourceList("/media/cdrom/", CD + C));
+ EXPECT_EQ(List, ic.ConvertToSourceList("/media/cdrom/", CD + S));
}
}
-
- return 0;
}
diff --git a/test/libapt/install_progress_test.cc b/test/libapt/install_progress_test.cc
new file mode 100644
index 000000000..a70fc9261
--- /dev/null
+++ b/test/libapt/install_progress_test.cc
@@ -0,0 +1,20 @@
+#include <config.h>
+
+#include <apt-pkg/install-progress.h>
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+TEST(InstallProgressTest, FancyGetTextProgressStr)
+{
+ APT::Progress::PackageManagerFancy p;
+
+ EXPECT_EQ(60, p.GetTextProgressStr(0.5, 60).size());
+ EXPECT_EQ("[#.]", p.GetTextProgressStr(0.5, 4));
+ EXPECT_EQ("[#.........]", p.GetTextProgressStr(0.1, 12));
+ EXPECT_EQ("[#########.]", p.GetTextProgressStr(0.9, 12));
+
+ // deal with incorrect inputs gracefully (or should we die instead?)
+ EXPECT_EQ("", p.GetTextProgressStr(-999, 12));
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index a8e053d6e..69a13fd92 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -8,112 +8,66 @@ APT_DOMAIN=none
include ../../buildlib/defaults.mak
.PHONY: test
-test:
- ./run-tests
-
-# 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 = 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
-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)
-
-# test the different Hashsum classes
-PROGRAM = HashSums${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = hashsums_test.cc
-include $(PROGRAM_H)
-
-# test the strutils stuff
-PROGRAM = StrUtil${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = strutil_test.cc
-include $(PROGRAM_H)
-
-# test the URI parsing stuff
-PROGRAM = URI${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = uri_test.cc
-include $(PROGRAM_H)
-
-# test the Configuration class
-PROGRAM = Configuration${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = configuration_test.cc
-include $(PROGRAM_H)
-
-# test cdroms core FindPackages
-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)
-
-# test IndexCopy::ConvertToSourceList
-PROGRAM = IndexCopyToSourceList${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = indexcopytosourcelist_test.cc
-
-# test fileutls
-PROGRAM = FileUtl${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = fileutl_test.cc
-include $(PROGRAM_H)
-
-# test tagfile
-PROGRAM = PkgTagFile${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = tagfile_test.cc
-include $(PROGRAM_H)
-
-# test sourcelist
-PROGRAM = SourceList${BASENAME}
-SLIBS = -lapt-pkg
-SOURCE = sourcelist_test.cc
-include $(PROGRAM_H)
-
+test: $(BIN)/gtest$(BASENAME)
+ MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME)
+
+$(BIN)/gtest$(BASENAME): $(LIB)/gtest.a
+
+PROGRAM = gtest${BASENAME}
+SLIBS = -lapt-pkg -pthread $(LIB)/gtest.a
+LIB_MAKES = apt-pkg/makefile
+SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc)
+include $(PROGRAM_H)
+
+
+MKDIRS += $(OBJ) $(LIB)
+LOCAL=gtest
+SOURCE=gtest-all
+gtest-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(SOURCE)))
+
+# The rest of the file is based on the example found in
+# /usr/share/doc/libgtest-dev/examples/make/Makefile
+GTEST_DIR = /usr/src/gtest
+
+# Flags passed to the preprocessor.
+# Set Google Test's header directory as a system directory, such that
+# the compiler doesn't generate warnings in Google Test headers.
+CPPFLAGS += -isystem $(GTEST_DIR)/include
+
+# Flags passed to the C++ compiler.
+CXXFLAGS += -pthread
+# disable some flags for gtest again
+CXXFLAGS+= -Wno-missing-declarations
+CXXFLAGS+= -Wno-missing-field-initializers
+CXXFLAGS+= -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn
+
+# All Google Test headers. Usually you shouldn't change this definition.
+GTEST_HEADERS = /usr/include/gtest/*.h \
+ /usr/include/gtest/internal/*.h
+
+# House-keeping build targets.
+.PHONY: clean/gtest veryclean/gtest
+clean: clean/gtest
+clean/gtest:
+ rm -f $(gtest-OBJS)
+veryclean: veryclean/gtest
+veryclean/gtest: clean/gtest
+ rm -f $(LIB)/gtest.a
+
+# Usually you shouldn't tweak such internal variables, indicated by a
+# trailing _.
+GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
+
+# Builds gtest.a
+# For simplicity and to avoid depending on Google Test's
+# implementation details, the dependencies specified below are
+# conservative and not optimized. This is fine as Google Test
+# compiles fast and for ordinary users its source rarely changes.
+$(gtest-OBJS): $(GTEST_SRCS_)
+ echo Compiling $@
+ $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
+
+$(LIB)/gtest.a: $(OBJ)/gtest-all.o
+ echo Building static library $@
+ -rm -f $@
+ $(AR) $(ARFLAGS) $@ $^
diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc
index e95016240..1e0afb66c 100644
--- a/test/libapt/parsedepends_test.cc
+++ b/test/libapt/parsedepends_test.cc
@@ -1,196 +1,244 @@
+#include <config.h>
+
#include <apt-pkg/deblistparser.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/pkgcache.h>
+
+#include <string.h>
+#include <string>
+
+#include <gtest/gtest.h>
+
+static void parseDependency(bool const StripMultiArch, bool const ParseArchFlags, bool const ParseRestrictionsList)
+{
+ std::string Package;
+ std::string Version;
+ unsigned int Op = 5;
+ unsigned int Null = 0;
+ _config->Set("APT::Architecture","amd64");
+ _config->Set("APT::Build-Profiles","stage1");
+
+ 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 [ !amd64 ], "
+ "only-for-me [ amd64 ], "
+ "any-for-me [ any ], "
+ "not-for-darwin [ !darwin-any ], "
+ "cpu-for-me [ any-amd64 ], "
+ "os-for-me [ linux-any ], "
+ "cpu-not-for-me [ any-armel ], "
+ "os-not-for-me [ kfreebsd-any ], "
+ "not-in-stage1 <!profile.stage1>, "
+ "not-in-stage1-or-nodoc <!profile.nodoc !profile.stage1>, "
+ "only-in-stage1 <unknown.unknown profile.stage1>, "
+ "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
+ ;
+
+ // 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, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("debhelper", Package);
+ else
+ EXPECT_EQ("debhelper:any", Package);
+ EXPECT_EQ("5.0", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("libdb-dev", Package);
+ else
+ EXPECT_EQ("libdb-dev:any", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("gettext", Package);
+ else
+ EXPECT_EQ("gettext:native", Package);
+ EXPECT_EQ("0.12", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::LessEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("libcurl4-gnutls-dev", Package);
+ else
+ EXPECT_EQ("libcurl4-gnutls-dev:native", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Or, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("libcurl3-gnutls-dev", Package);
+ EXPECT_EQ("7.15.5", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("debiandoc-sgml", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("apt", Package);
+ EXPECT_EQ("0.7.25", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::GreaterEq, Op);
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("only-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("any-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("not-for-darwin", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("cpu-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("os-for-me", Package);
+ EXPECT_EQ("", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // cpu-not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // os-not-for-me
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-in-stage1
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("", Package); // not-in-stage1-or-in-nodoc
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseRestrictionsList == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ EXPECT_EQ("only-in-stage1", Package);
+ } else {
+ EXPECT_EQ(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("overlord-dev", Package);
+ else
+ EXPECT_EQ("overlord-dev:any", Package);
+ EXPECT_EQ("7.15.3~", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
+
+ debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch, ParseRestrictionsList);
+ if (StripMultiArch == true)
+ EXPECT_EQ("overlord-dev", Package);
+ else
+ EXPECT_EQ("overlord-dev:native", Package);
+ EXPECT_EQ("7.15.5", Version);
+ EXPECT_EQ(Null | pkgCache::Dep::Greater, Op);
+}
+
+// FIXME: This testcase is too big/complex
+TEST(ParseDependsTest, Everything)
+{
+ bool StripMultiArch = true;
+ bool ParseArchFlags = false;
+ bool ParseRestrictionsList = false;
+ unsigned short runner = 0;
-#include "assert.h"
-
-int main(int argc,char *argv[]) {
- std::string Package;
- std::string Version;
- unsigned int Op = 5;
- unsigned int Null = 0;
- bool StripMultiArch = true;
- bool ParseArchFlags = false;
- _config->Set("APT::Architecture","amd64");
-
- 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 [ !amd64 ], "
- "only-for-me [ amd64 ], "
- "any-for-me [ any ], "
- "not-for-darwin [ !darwin-any ], "
- "cpu-for-me [ any-amd64 ], "
- "os-for-me [ linux-any ], "
- "cpu-not-for-me [ any-armel ], "
- "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);
-
- 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;
+ {
+ SCOPED_TRACE(std::string("StripMultiArch: ") + (StripMultiArch ? "true" : "false"));
+ SCOPED_TRACE(std::string("ParseArchFlags: ") + (ParseArchFlags ? "true" : "false"));
+ SCOPED_TRACE(std::string("ParseRestrictionsList: ") + (ParseRestrictionsList ? "true" : "false"));
+ parseDependency(StripMultiArch, ParseArchFlags, ParseRestrictionsList);
+ }
+ if (StripMultiArch == false)
+ if (ParseArchFlags == false)
+ ParseRestrictionsList = !ParseRestrictionsList;
+ ParseArchFlags = !ParseArchFlags;
+ StripMultiArch = !StripMultiArch;
+
+ runner++;
+ if (runner < 8)
+ goto test; // this is the prove: tests are really evil ;)
}
diff --git a/test/libapt/run-tests b/test/libapt/run-tests
deleted file mode 100755
index a056f31f9..000000000
--- a/test/libapt/run-tests
+++ /dev/null
@@ -1,125 +0,0 @@
-#!/bin/sh
-set -e
-
-DIR=$(readlink -f $(dirname $0))
-if [ -z "$MAKELEVEL" ]; then
- echo 'Compiling the tests …'
- (cd $DIR && make)
- echo 'Running all testcases …'
-fi
-LDPATH="$DIR/../../build/bin"
-EXT="_libapt_test"
-EXIT_CODE=0
-
-# detect if output is on a terminal (colorful) or better not
-if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null; then
- COLHIGH='\033[1;35m'
- COLRESET='\033[0m'
- TESTOKAY='\033[1;32mOKAY\033[0m'
- TESTFAIL='\033[1;31mFAILED\033[0m'
-else
- COLHIGH=''
- COLRESET=''
- TESTOKAY='OK'
- TESTFAIL='###FAILED###'
-fi
-
-for testapp in $(ls ${LDPATH}/*$EXT)
-do
- name=$(basename ${testapp})
- NAME="${COLHIGH}${name}${COLRESET}"
- tmppath=""
-
- if [ $name = "GetListOfFilesInDir${EXT}" ]; then
- # TODO: very-low: move env creation to the actual test-app
- 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"
- mkdir "${tmppath}/invaliddir" \
- "${tmppath}/directory.conf" \
- "${tmppath}/directory.list" \
- "${tmppath}/directory.wron" \
- "${tmppath}/directory.list.disabled"
- ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list"
- ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list"
- elif [ $name = "getLanguages${EXT}" ]; then
- 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" \
- "${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}")"
- tmppath="$TMP"
- tmppath="${tmppath} $(md5sum $TMP | cut -d' ' -f 1)"
- tmppath="${tmppath} $(sha1sum $TMP | cut -d' ' -f 1)"
- tmppath="${tmppath} $(sha256sum $TMP | cut -d' ' -f 1)"
- tmppath="${tmppath} $(sha512sum $TMP | cut -d' ' -f 1)"
- elif [ $name = "CompareVersion${EXT}" ]; then
- tmppath="${DIR}/versions.lst"
- elif [ $name = "CdromFindPackages${EXT}" ]; then
- tmppath=$(mktemp -d)
- mkdir -p "${tmppath}/.disk" "${tmppath}/pool" \
- "${tmppath}/dists/stable/main/binary-i386" \
- "${tmppath}/dists/stable/main/source" \
- "${tmppath}/dists/stable/contrib/binary-amd64" \
- "${tmppath}/dists/stable/contrib/binary-all" \
- "${tmppath}/dists/unstable/main/binary-i386" \
- "${tmppath}/dists/unstable/main/i18n" \
- "${tmppath}/dists/unstable/main/source" \
- "${tmppath}/dists/broken/non-free/source"
- touch "${tmppath}/dists/broken/.aptignr" \
- "${tmppath}/dists/stable/main/binary-i386/Packages" \
- "${tmppath}/dists/stable/main/binary-i386/Packages.bz2" \
- "${tmppath}/dists/stable/main/source/Sources.xz" \
- "${tmppath}/dists/stable/contrib/binary-amd64/Packages" \
- "${tmppath}/dists/stable/contrib/binary-amd64/Packages.gz" \
- "${tmppath}/dists/stable/contrib/binary-all/Packages" \
- "${tmppath}/dists/unstable/main/binary-i386/Packages.xz" \
- "${tmppath}/dists/unstable/main/binary-i386/Packages.lzma" \
- "${tmppath}/dists/unstable/main/i18n/Translation-en" \
- "${tmppath}/dists/unstable/main/i18n/Translation-de.bz2" \
- "${tmppath}/dists/unstable/main/source/Sources.xz" \
- "${tmppath}/dists/broken/non-free/source/Sources.gz" \
- "${tmppath}/dists/stable/Release.gpg" \
- "${tmppath}/dists/stable/Release" \
- "${tmppath}/dists/unstable/InRelease" \
- "${tmppath}/dists/broken/Release.gpg"
- ln -s "${tmppath}/dists/unstable" "${tmppath}/dists/sid"
- fi
-
- echo -n "Testing with ${NAME} "
- if MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${LDPATH} ${testapp} ${tmppath} ; then
- echo "$TESTOKAY"
- else
- echo "$TESTFAIL"
- EXIT_CODE=1
- fi
-
- if [ -n "$tmppath" -a -d "$tmppath" ]; then
- rm -rf "$tmppath"
- fi
-done
-exit $EXIT_CODE
diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc
index 0300ce929..eb2d76c43 100644
--- a/test/libapt/sourcelist_test.cc
+++ b/test/libapt/sourcelist_test.cc
@@ -1,29 +1,27 @@
+#include <config.h>
+
#include <apt-pkg/sourcelist.h>
-#include <apt-pkg/tagfile.h>
+#include <apt-pkg/fileutl.h>
-#include "assert.h"
+#include <string>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-char *tempfile = NULL;
-int tempfile_fd = -1;
+#include <gtest/gtest.h>
-void remove_tmpfile(void)
-{
- if (tempfile_fd > 0)
- close(tempfile_fd);
- if (tempfile != NULL) {
- unlink(tempfile);
- free(tempfile);
- }
-}
+#include "file-helpers.h"
-int main(int argc, char *argv[])
-{
- _config->Set("APT::Sources::Use-Deb822", true);
+class SourceList : public pkgSourceList {
+ public:
+ using pkgSourceList::ParseFileDeb822;
+};
- const char contents[] = ""
+TEST(SourceListTest,ParseFileDeb822)
+{
+ FileFd fd;
+ char * tempfile;
+ createTemporaryFile("parsefiledeb822", fd, &tempfile,
"Types: deb\n"
"URIs: http://ftp.debian.org/debian\n"
"Suites: stable\n"
@@ -34,22 +32,12 @@ int main(int argc, char *argv[])
"Types: deb\n"
"URIs: http://ftp.debian.org/debian\n"
"Suites: unstable\n"
- "Sections: main non-free\n"
- ;
-
- FileFd fd;
- atexit(remove_tmpfile);
- tempfile = strdup("apt-test.XXXXXXXX");
- tempfile_fd = mkstemp(tempfile);
-
- /* (Re-)Open (as FileFd), write and seek to start of the temp file */
- equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
- equals(fd.Write(contents, strlen(contents)), true);
- equals(fd.Seek(0), true);
+ "Sections: main non-free\n");
+ fd.Close();
- pkgSourceList sources(tempfile);
- equals(sources.size(), 2);
+ SourceList sources;
+ EXPECT_EQ(2, sources.ParseFileDeb822(tempfile));
+ EXPECT_EQ(2, sources.size());
- /* clean up handled by atexit handler, so just return here */
- return 0;
+ unlink(tempfile);
}
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc
index 8215654d0..bc004fd66 100644
--- a/test/libapt/strutil_test.cc
+++ b/test/libapt/strutil_test.cc
@@ -1,91 +1,72 @@
+#include <config.h>
#include <apt-pkg/strutl.h>
+#include <string>
+#include <vector>
-#include "assert.h"
+#include <gtest/gtest.h>
-int main(int argc,char *argv[])
+TEST(StrUtilTest,DeEscapeString)
{
- std::string input, output, expected;
-
- // no input
- input = "foobar";
- expected = "foobar";
- output = DeEscapeString(input);
- equals(output, expected);
-
+ // nothing special
+ EXPECT_EQ("", DeEscapeString(""));
+ EXPECT_EQ("foobar", DeEscapeString("foobar"));
// hex and octal
- input = "foo\\040bar\\x0abaz";
- expected = "foo bar\nbaz";
- output = DeEscapeString(input);
- equals(output, expected);
-
- // at the end
- input = "foo\\040";
- expected = "foo ";
- output = DeEscapeString(input);
- equals(output, expected);
-
- // double escape
- input = "foo\\\\ x";
- expected = "foo\\ x";
- output = DeEscapeString(input);
- equals(output, expected);
-
- // double escape at the end
- input = "\\\\foo\\\\";
- expected = "\\foo\\";
- output = DeEscapeString(input);
- equals(output, expected);
+ EXPECT_EQ("foo bar\nbaz", DeEscapeString("foo\\040bar\\x0abaz"));
+ EXPECT_EQ("foo ", DeEscapeString("foo\\040"));
+ EXPECT_EQ("\nbaz", DeEscapeString("\\x0abaz"));
+ EXPECT_EQ("/media/Ubuntu 11.04 amd64", DeEscapeString("/media/Ubuntu\\04011.04\\040amd64"));
+ // double slashes
+ EXPECT_EQ("foo\\ x", DeEscapeString("foo\\\\ x"));
+ EXPECT_EQ("\\foo\\", DeEscapeString("\\\\foo\\\\"));
+}
+TEST(StrUtilTest,StringSplitBasic)
+{
+ std::vector<std::string> result = StringSplit("", "");
+ EXPECT_EQ(result.size(), 0);
- // the string that we actually need it for
- input = "/media/Ubuntu\\04011.04\\040amd64";
- expected = "/media/Ubuntu 11.04 amd64";
- output = DeEscapeString(input);
- equals(output, expected);
+ result = StringSplit("abc", "");
+ EXPECT_EQ(result.size(), 0);
- // Split
- input = "status: libnet1:amd64: unpacked";
- vector<std::string> result = StringSplit(input, ": ");
- equals(result[0], "status");
- equals(result[1], "libnet1:amd64");
- equals(result[2], "unpacked");
- equals(result.size(), 3);
+ result = StringSplit("", "abc");
+ EXPECT_EQ(result.size(), 1);
- input = "status: libnet1:amd64: unpacked";
- result = StringSplit(input, "xxx");
- equals(result[0], input);
- equals(result.size(), 1);
+ result = StringSplit("abc", "b");
+ ASSERT_EQ(result.size(), 2);
+ EXPECT_EQ(result[0], "a");
+ EXPECT_EQ(result[1], "c");
- input = "status: libnet1:amd64: unpacked";
- result = StringSplit(input, "");
- equals(result.size(), 0);
-
- input = "x:y:z";
- result = StringSplit(input, ":", 2);
- equals(result.size(), 2);
- equals(result[0], "x");
- equals(result[1], "y:z");
+ result = StringSplit("abc", "abc");
+ ASSERT_EQ(result.size(), 2);
+ EXPECT_EQ(result[0], "");
+ EXPECT_EQ(result[1], "");
+}
+TEST(StrUtilTest,StringSplitDpkgStatus)
+{
+ std::string const input = "status: libnet1:amd64: unpacked";
+ std::vector<std::string> result = StringSplit(input, "xxx");
+ ASSERT_EQ(result.size(), 1);
+ EXPECT_EQ(result[0], input);
- input = "abc";
result = StringSplit(input, "");
- equals(result.size(), 0);
-
- // endswith
- bool b;
- input = "abcd";
- b = APT::String::Endswith(input, "d");
- equals(b, true);
-
- b = APT::String::Endswith(input, "cd");
- equals(b, true);
-
- b = APT::String::Endswith(input, "abcd");
- equals(b, true);
-
- b = APT::String::Endswith(input, "x");
- equals(b, false);
-
- b = APT::String::Endswith(input, "abcndefg");
- equals(b, false);
-
- return 0;
+ EXPECT_EQ(result.size(), 0);
+
+ result = StringSplit(input, ": ");
+ ASSERT_EQ(result.size(), 3);
+ EXPECT_EQ(result[0], "status");
+ EXPECT_EQ(result[1], "libnet1:amd64");
+ EXPECT_EQ(result[2], "unpacked");
+
+ result = StringSplit("x:y:z", ":", 2);
+ ASSERT_EQ(result.size(), 2);
+ EXPECT_EQ(result[0], "x");
+ EXPECT_EQ(result[1], "y:z");
+}
+TEST(StrUtilTest,EndsWith)
+{
+ using APT::String::Endswith;
+ EXPECT_TRUE(Endswith("abcd", "d"));
+ EXPECT_TRUE(Endswith("abcd", "cd"));
+ EXPECT_TRUE(Endswith("abcd", "abcd"));
+ EXPECT_FALSE(Endswith("abcd", "x"));
+ EXPECT_FALSE(Endswith("abcd", "abcndefg"));
}
diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc
index d12c74c95..1bac75b55 100644
--- a/test/libapt/tagfile_test.cc
+++ b/test/libapt/tagfile_test.cc
@@ -1,58 +1,36 @@
+#include <config.h>
+
#include <apt-pkg/fileutl.h>
#include <apt-pkg/tagfile.h>
-#include "assert.h"
+#include <string>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-char *tempfile = NULL;
-int tempfile_fd = -1;
+#include <gtest/gtest.h>
-void remove_tmpfile(void)
-{
- if (tempfile_fd > 0)
- close(tempfile_fd);
- if (tempfile != NULL) {
- unlink(tempfile);
- free(tempfile);
- }
-}
+#include "file-helpers.h"
-int main(int argc, char *argv[])
+TEST(TagFileTest,SingleField)
{
FileFd fd;
- const char contents[] = "FieldA-12345678: the value of the field";
- atexit(remove_tmpfile);
- tempfile = strdup("apt-test.XXXXXXXX");
- tempfile_fd = mkstemp(tempfile);
-
- /* (Re-)Open (as FileFd), write and seek to start of the temp file */
- equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true);
- equals(fd.Write(contents, strlen(contents)), true);
- equals(fd.Seek(0), true);
+ createTemporaryFile("singlefield", fd, NULL, "FieldA-12345678: the value of the field");
pkgTagFile tfile(&fd);
pkgTagSection section;
- equals(tfile.Step(section), true);
-
- /* It has one field */
- equals(section.Count(), 1);
-
- /* ... and it is called FieldA-12345678 */
- equals(section.Exists("FieldA-12345678"), true);
-
- /* its value is correct */
- equals(section.FindS("FieldA-12345678"), std::string("the value of the field"));
- /* A non-existent field has an empty string as value */
- equals(section.FindS("FieldB-12345678"), std::string());
-
- /* ... and Exists does not lie about missing fields... */
- equalsNot(section.Exists("FieldB-12345678"), true);
-
- /* There is only one section in this tag file */
- equals(tfile.Step(section), false);
-
- /* clean up handled by atexit handler, so just return here */
- return 0;
+ ASSERT_TRUE(tfile.Step(section));
+
+ // It has one field
+ EXPECT_EQ(1, section.Count());
+ // ... and it is called FieldA-12345678
+ EXPECT_TRUE(section.Exists("FieldA-12345678"));
+ // its value is correct
+ EXPECT_EQ("the value of the field", section.FindS("FieldA-12345678"));
+ // A non-existent field has an empty string as value
+ EXPECT_EQ("", section.FindS("FieldB-12345678"));
+ // ... and Exists does not lie about missing fields...
+ EXPECT_FALSE(section.Exists("FieldB-12345678"));
+ // There is only one section in this tag file
+ EXPECT_FALSE(tfile.Step(section));
}
diff --git a/test/libapt/uri_test.cc b/test/libapt/uri_test.cc
index 8216ade71..1662f51f0 100644
--- a/test/libapt/uri_test.cc
+++ b/test/libapt/uri_test.cc
@@ -1,120 +1,119 @@
+#include <config.h>
#include <apt-pkg/strutl.h>
+#include <string>
+#include <gtest/gtest.h>
-#include "assert.h"
-
-int main() {
- // Basic stuff
- {
- URI U("http://www.debian.org:90/temp/test");
- equals("http", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(90, U.Port);
- equals("www.debian.org", U.Host);
- equals("/temp/test", U.Path);
- } {
- URI U("http://jgg:foo@ualberta.ca/blah");
- equals("http", U.Access);
- equals("jgg", U.User);
- equals("foo", U.Password);
- equals(0, U.Port);
- equals("ualberta.ca", U.Host);
- equals("/blah", U.Path);
- } {
- URI U("file:/usr/bin/foo");
- equals("file", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("", U.Host);
- equals("/usr/bin/foo", U.Path);
- } {
- URI U("cdrom:Moo Cow Rom:/debian");
- equals("cdrom", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("Moo Cow Rom", U.Host);
- equals("/debian", U.Path);
- } {
- URI U("gzip:./bar/cow");
- equals("gzip", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals(".", U.Host);
- equals("/bar/cow", U.Path);
- } {
- URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
- equals("ftp", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("ftp.fr.debian.org", U.Host);
- equals("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
- }
-
- // RFC 2732 stuff
- {
- URI U("http://[1080::8:800:200C:417A]/foo");
- equals("http", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("1080::8:800:200C:417A", U.Host);
- equals("/foo", U.Path);
- } {
- URI U("http://[::FFFF:129.144.52.38]:80/index.html");
- equals("http", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(80, U.Port);
- equals("::FFFF:129.144.52.38", U.Host);
- equals("/index.html", U.Path);
- } {
- URI U("http://[::FFFF:129.144.52.38:]:80/index.html");
- equals("http", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(80, U.Port);
- equals("::FFFF:129.144.52.38:", U.Host);
- equals("/index.html", U.Path);
- } {
- URI U("http://[::FFFF:129.144.52.38:]/index.html");
- equals("http", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("::FFFF:129.144.52.38:", U.Host);
- equals("/index.html", U.Path);
- }
- /* My Evil Corruption of RFC 2732 to handle CDROM names! Fun for
- the whole family! */
- {
- URI U("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
- equals("cdrom", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("The Debian 1.2 disk, 1/2 R1:6", U.Host);
- equals("/debian/", U.Path);
- } {
- URI U("cdrom:Foo Bar Cow/debian/");
- equals("cdrom", U.Access);
- equals("", U.User);
- equals("", U.Password);
- equals(0, U.Port);
- equals("Foo Bar Cow", U.Host);
- equals("/debian/", U.Path);
- }
-
- // Percent-encoding.
- {
- URI U("ftp://foo:b%40r@example.org");
- equals("foo", U.User);
- equals("b@r", U.Password);
- equals("ftp://foo:b%40r@example.org/", (std::string) U);
- }
-
- return 0;
+TEST(URITest, BasicHTTP)
+{
+ URI U("http://www.debian.org:90/temp/test");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(90, U.Port);
+ EXPECT_EQ("www.debian.org", U.Host);
+ EXPECT_EQ("/temp/test", U.Path);
+ // Login data
+ U = URI("http://jgg:foo@ualberta.ca/blah");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("jgg", U.User);
+ EXPECT_EQ("foo", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("ualberta.ca", U.Host);
+ EXPECT_EQ("/blah", U.Path);
+}
+TEST(URITest, SingeSlashFile)
+{
+ URI U("file:/usr/bin/foo");
+ EXPECT_EQ("file", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("", U.Host);
+ EXPECT_EQ("/usr/bin/foo", U.Path);
+}
+TEST(URITest, BasicCDROM)
+{
+ URI U("cdrom:Moo Cow Rom:/debian");
+ EXPECT_EQ("cdrom", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("Moo Cow Rom", U.Host);
+ EXPECT_EQ("/debian", U.Path);
+}
+TEST(URITest, RelativeGzip)
+{
+ URI U("gzip:./bar/cow");
+ EXPECT_EQ("gzip", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ(".", U.Host);
+ EXPECT_EQ("/bar/cow", U.Path);
+}
+TEST(URITest, NoSlashFTP)
+{
+ URI U("ftp:ftp.fr.debian.org/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb");
+ EXPECT_EQ("ftp", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("ftp.fr.debian.org", U.Host);
+ EXPECT_EQ("/debian/pool/main/x/xtel/xtel_3.2.1-15_i386.deb", U.Path);
+}
+TEST(URITest, RFC2732)
+{
+ URI U("http://[1080::8:800:200C:417A]/foo");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("1080::8:800:200C:417A", U.Host);
+ EXPECT_EQ("/foo", U.Path);
+ // with port
+ U = URI("http://[::FFFF:129.144.52.38]:80/index.html");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(80, U.Port);
+ EXPECT_EQ("::FFFF:129.144.52.38", U.Host);
+ EXPECT_EQ("/index.html", U.Path);
+ // extra colon
+ U = URI("http://[::FFFF:129.144.52.38:]:80/index.html");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(80, U.Port);
+ EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
+ EXPECT_EQ("/index.html", U.Path);
+ // extra colon port
+ U = URI("http://[::FFFF:129.144.52.38:]/index.html");
+ EXPECT_EQ("http", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("::FFFF:129.144.52.38:", U.Host);
+ EXPECT_EQ("/index.html", U.Path);
+ // My Evil Corruption of RFC 2732 to handle CDROM names!
+ // Fun for the whole family! */
+ U = URI("cdrom:[The Debian 1.2 disk, 1/2 R1:6]/debian/");
+ EXPECT_EQ("cdrom", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("The Debian 1.2 disk, 1/2 R1:6", U.Host);
+ EXPECT_EQ("/debian/", U.Path);
+ // no brackets
+ U = URI("cdrom:Foo Bar Cow/debian/");
+ EXPECT_EQ("cdrom", U.Access);
+ EXPECT_EQ("", U.User);
+ EXPECT_EQ("", U.Password);
+ EXPECT_EQ(0, U.Port);
+ EXPECT_EQ("Foo Bar Cow", U.Host);
+ EXPECT_EQ("/debian/", U.Path);
+ // percent encoded
+ U = URI("ftp://foo:b%40r@example.org");
+ EXPECT_EQ("foo", U.User);
+ EXPECT_EQ("b@r", U.Password);
+ EXPECT_EQ("ftp://foo:b%40r@example.org/", (std::string) U);
}
diff --git a/test/libapt/versions.lst b/test/libapt/versions.lst
deleted file mode 100644
index 8dd8ebdc9..000000000
--- a/test/libapt/versions.lst
+++ /dev/null
@@ -1,106 +0,0 @@
-# List of
-# ver1 ver2 ret
-# Of versions worth testing
-# 1 means that ver1 > ver2
-# -1 means that ver1 < ver2
-# 0 means that ver1 = ver2
-7.6p2-4 7.6-0 1
-1.0.3-3 1.0-1 1
-1.3 1.2.2-2 1
-1.3 1.2.2 1
-
-# Important attributes
-# disabled as dpkg --compare-versions doesn't like them… (versions have to start with a number)
-#- . -1
-#p - -1
-#a - -1
-#z - -1
-#a . -1
-#z . -1
-
-# disabled as dpkg --compare-versions doesn't like them… (versions have to start with a number)
-#III-alpha9.8 III-alpha9.8-1.5 -1
-
-# Epochs
-1:0.4 10.3 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
-9:1.18.36:5.4-20 9:1.18.37:4.3-22 -1
-1.18.36-0.17.35-18 1.18.36-19 1
-
-# Junk
-1:1.2.13-3 1:1.2.13-3.1 -1
-2.0.7pre1-4 2.0.7r-1 -1
-
-# Test some properties of text strings
-0-pre 0-pre 0
-0-pre 0-pree -1
-
-1.1.6r2-2 1.1.6r-1 1
-2.6b2-1 2.6b-2 1
-
-98.1p5-1 98.1-pre2-b6-2 -1
-0.4a6-2 0.4-1 1
-
-1:3.0.5-2 1:3.0.5.1 -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...