summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libapt/assert.h21
-rw-r--r--test/libapt/commandlineasstring_test.cc39
-rw-r--r--test/libapt/compareversion_test.cc123
-rw-r--r--test/libapt/getlanguages_test.cc149
-rw-r--r--test/libapt/makefile37
-rw-r--r--test/libapt/parsedepends_test.cc128
-rwxr-xr-xtest/libapt/run-tests.sh7
-rw-r--r--test/makefile15
-rw-r--r--test/versions.lst64
-rw-r--r--test/versiontest.cc233
10 files changed, 568 insertions, 248 deletions
diff --git a/test/libapt/assert.h b/test/libapt/assert.h
new file mode 100644
index 000000000..5da76ae0a
--- /dev/null
+++ b/test/libapt/assert.h
@@ -0,0 +1,21 @@
+#include <iostream>
+
+#define equals(x,y) assertEquals(x, y, __LINE__)
+
+template < typename X, typename Y >
+void OutputAssert(X expect, char const* compare, Y get, unsigned long const &line) {
+ std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
+}
+
+template < typename X, typename Y >
+void assertEquals(X expect, Y get, unsigned long const &line) {
+ if (expect == get)
+ return;
+ OutputAssert(expect, "==", get, line);
+}
+
+void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) {
+ if (get < 0)
+ OutputAssert(expect, "==", get, line);
+ assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
+}
diff --git a/test/libapt/commandlineasstring_test.cc b/test/libapt/commandlineasstring_test.cc
new file mode 100644
index 000000000..a38957d7e
--- /dev/null
+++ b/test/libapt/commandlineasstring_test.cc
@@ -0,0 +1,39 @@
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
+
+#include <string>
+
+#include "assert.h"
+
+class CLT: public CommandLine {
+
+ public:
+ std::string static AsString(const char * const * const argv,
+ unsigned int const argc) {
+ std::string const static conf = "Commandline::AsString";
+ _config->Clear(conf);
+ SaveInConfig(argc, argv);
+ return _config->Find(conf);
+ }
+};
+
+#define CMD(y,z) equals(CLT::AsString(argv, y), z);
+
+int main() {
+ {
+ const char* const argv[] = {"apt-get", "install", "-sf"};
+ CMD(3, "apt-get install -sf");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=Test");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"};
+ CMD(5, "apt-cache -s apt -so Debug::test=\"Das ist ein Test\"");
+ }
+ {
+ const char* const argv[] = {"apt-cache", "-s", "apt", "--hallo", "test=1.0"};
+ CMD(5, "apt-cache -s apt --hallo test=1.0");
+ }
+}
diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc
new file mode 100644
index 000000000..b6213e84c
--- /dev/null
+++ b/test/libapt/compareversion_test.cc
@@ -0,0 +1,123 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ Version Test - Simple program to run through a file and comare versions.
+
+ Each version is compared and the result is checked against an expected
+ result in the file. The format of the file is
+ a b Res
+ Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be
+ used to determine what Res should be. # at the start of the line
+ is a comment and blank lines are skipped
+
+ The runner will also call dpkg --compare-versions to check if APT and
+ dpkg have (still) the same idea.
+
+ ##################################################################### */
+ /*}}}*/
+#include <apt-pkg/macros.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/debversion.h>
+#include <apt-pkg/fileutl.h>
+#include <iostream>
+#include <fstream>
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+using namespace std;
+
+bool callDPkg(const char *val, const char *ref, const char &op) {
+ pid_t Process = ExecFork();
+ if (Process == 0)
+ {
+ const char * args[6];
+ args[0] = "/usr/bin/dpkg";
+ args[1] = "--compare-versions";
+ args[2] = val;
+ args[3] = (op == 1) ? ">>" : ( (op == 0) ? "=" : "<<");
+ args[4] = ref;
+ args[5] = 0;
+ execv(args[0], (char**) args);
+ exit(1);
+ }
+ int Ret;
+ waitpid(Process, &Ret, 0);
+ return WIFEXITED(Ret) == true && WEXITSTATUS(Ret) == 0;
+}
+
+void assertVersion(int const &CurLine, string const &A, string const &B, int const &Expected) {
+ int Res = debVS.CmpVersion(A.c_str(), B.c_str());
+ bool const dpkg = callDPkg(A.c_str(),B.c_str(), Expected);
+ Res = (Res < 0) ? -1 : ( (Res > 0) ? 1 : Res);
+
+ if (Res != Expected)
+ _error->Error("Comparison failed on line %u. '%s' '%s' '%s' %i != %i",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")) ,B.c_str(),Res,Expected);
+ if (dpkg == false)
+ _error->Error("DPkg differ with line: %u. '%s' '%s' '%s' == false",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")),B.c_str());
+}
+
+bool RunTest(const char *File)
+{
+ ifstream F(File,ios::in);
+ if (!F != 0)
+ return false;
+
+ char Buffer[300];
+ int CurLine = 0;
+
+ while (1)
+ {
+ F.getline(Buffer,sizeof(Buffer));
+ CurLine++;
+ if (F.eof() != 0)
+ return true;
+ if (!F != 0)
+ return _error->Error("Line %u in %s is too long",CurLine,File);
+
+ // Comment
+ if (Buffer[0] == '#' || Buffer[0] == 0)
+ continue;
+
+ // First version
+ char *I;
+ char *Start = Buffer;
+ for (I = Buffer; *I != 0 && *I != ' '; I++);
+ string A(Start, I - Start);
+
+ if (*I == 0)
+ return _error->Error("Invalid line %u",CurLine);
+
+ // Second version
+ I++;
+ Start = I;
+ for (I = Start; *I != 0 && *I != ' '; I++);
+ string B(Start,I - Start);
+
+ if (*I == 0 || I[1] == 0)
+ return _error->Error("Invalid line %u",CurLine);
+
+ // Result
+ I++;
+ int const Expected = atoi(I);
+ assertVersion(CurLine, A, B, Expected);
+ // Check the reverse as well
+ assertVersion(CurLine, B, A, Expected*-1);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc <= 1)
+ RunTest("../versions.lst");
+ else
+ RunTest(argv[1]);
+
+ // Print any errors or warnings found
+ _error->DumpErrors();
+ return 0;
+}
diff --git a/test/libapt/getlanguages_test.cc b/test/libapt/getlanguages_test.cc
new file mode 100644
index 000000000..9a8910b58
--- /dev/null
+++ b/test/libapt/getlanguages_test.cc
@@ -0,0 +1,149 @@
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/configuration.h>
+
+#include "assert.h"
+#include <string>
+#include <vector>
+
+#include <iostream>
+
+// simple helper to quickly output a vector of strings
+void dumpVector(std::vector<std::string> vec) {
+ for (std::vector<std::string>::const_iterator v = vec.begin();
+ v != vec.end(); v++)
+ std::cout << *v << std::endl;
+}
+
+int main(int argc,char *argv[])
+{
+ if (argc != 2) {
+ std::cout << "One parameter expected - given " << argc << std::endl;
+ return 100;
+ }
+
+ char const* env[2];
+ env[0] = "de_DE.UTF-8";
+ env[1] = "";
+
+ std::vector<std::string> vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ // Special: Check if the cache is actually in use
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, true, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ env[0] = "en_GB.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "en_GB");
+ equals(vec[1], "en");
+
+ // esperanto
+ env[0] = "eo.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "eo");
+ equals(vec[1], "en");
+
+ env[0] = "tr_DE@euro";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "tr");
+ equals(vec[1], "en");
+
+ env[0] = "de_NO";
+ env[1] = "se_NO:en_GB:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 5);
+ equals(vec[0], "de");
+ equals(vec[1], "en_GB");
+ equals(vec[2], "nb");
+ equals(vec[3], "no");
+ equals(vec[4], "en");
+
+ env[0] = "pt_PR.UTF-8";
+ env[1] = "";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 3);
+ equals(vec[0], "pt_PR");
+ equals(vec[1], "pt");
+ equals(vec[2], "en");
+
+ env[0] = "ast_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env); // bogus, but syntactical correct
+ equals(vec.size(), 2);
+ equals(vec[0], "ast");
+ equals(vec[1], "en");
+
+ env[0] = "C";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "en");
+
+ _config->Set("Acquire::Languages::1", "environment");
+ _config->Set("Acquire::Languages::2", "en");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ _config->Set("Acquire::Languages::3", "de");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+
+ _config->Set("Dir::State::lists", argv[1]);
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 5);
+ equals(vec[0], "de");
+ equals(vec[1], "en");
+ equals(vec[2], "none");
+ equals(vec[3], "pt");
+ equals(vec[4], "tr");
+
+ _config->Set("Dir::State::lists", "/non-existing-dir");
+ _config->Set("Acquire::Languages::1", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 0);
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec[0], "en");
+ equals(vec[1], "de");
+
+ _config->Set("Acquire::Languages::1", "fr");
+ _config->Set("Acquire::Languages", "de_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(false, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "de_DE");
+
+ _config->Set("Acquire::Languages", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 0);
+
+ _config->Set("Acquire::Languages", "");
+ //FIXME: Remove support for this deprecated setting
+ _config->Set("APT::Acquire::Translation", "ast_DE");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 2);
+ equals(vec[0], "ast_DE");
+ equals(vec[1], "en");
+ _config->Set("APT::Acquire::Translation", "none");
+ env[0] = "de_DE.UTF-8";
+ vec = APT::Configuration::getLanguages(true, false, env);
+ equals(vec.size(), 1);
+ equals(vec[0], "en");
+
+ return 0;
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
new file mode 100644
index 000000000..98bdb3348
--- /dev/null
+++ b/test/libapt/makefile
@@ -0,0 +1,37 @@
+# -*- make -*-
+BASE=../..
+SUBDIR=test/libapt
+BASENAME=_libapt_test
+
+# Bring in the default rules
+include ../../buildlib/defaults.mak
+
+# Program for testing getLanguageCode
+PROGRAM = getLanguages${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = getlanguages_test.cc
+include $(PROGRAM_H)
+
+# Program for testing ParseDepends
+PROGRAM = ParseDepends${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = parsedepends_test.cc
+include $(PROGRAM_H)
+
+# Program for testing GetListOfFilesInDir
+PROGRAM = GetListOfFilesInDir${BASENAME}
+SLIBS = -lapt-pkg
+SOURCE = getlistoffilesindir_test.cc
+include $(PROGRAM_H)
+
+# 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)
diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc
new file mode 100644
index 000000000..b7befa561
--- /dev/null
+++ b/test/libapt/parsedepends_test.cc
@@ -0,0 +1,128 @@
+#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/configuration.h>
+
+#include "assert.h"
+
+int main(int argc,char *argv[]) {
+ string Package;
+ string Version;
+ unsigned int Op = 5;
+ unsigned int Null = 0;
+ bool StripMultiArch = true;
+ bool ParseArchFlags = false;
+ _config->Set("APT::Architecture","dsk");
+
+ const char* Depends =
+ "debhelper:any (>= 5.0), "
+ "libdb-dev:any, "
+ "gettext:native (<= 0.12), "
+ "libcurl4-gnutls-dev:native | libcurl3-gnutls-dev (>> 7.15.5), "
+ "debiandoc-sgml, "
+ "apt (>= 0.7.25), "
+ "not-for-me [ !dsk ], "
+ "only-for-me [ dsk ], "
+ "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), "
+ ;
+
+ unsigned short runner = 0;
+test:
+// std::clog << (StripMultiArch ? "NO-Multi" : "Multi") << " " << (ParseArchFlags ? "Flags" : "NO-Flags") << std::endl;
+
+ // Stripping MultiArch is currently the default setting to not confuse
+ // non-MultiArch capable users of the library with "strange" extensions.
+ const char* Start = Depends;
+ const char* End = Depends + strlen(Depends);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("debhelper", Package);
+ else
+ equals("debhelper:any", Package);
+ equals("5.0", Version);
+ equals(Null | pkgCache::Dep::GreaterEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("libdb-dev", Package);
+ else
+ equals("libdb-dev:any", Package);
+ equals("", Version);
+ equals(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("gettext", Package);
+ else
+ equals("gettext:native", Package);
+ equals("0.12", Version);
+ equals(Null | pkgCache::Dep::LessEq, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("libcurl4-gnutls-dev", Package);
+ else
+ equals("libcurl4-gnutls-dev:native", Package);
+ equals("", Version);
+ equals(Null | pkgCache::Dep::Or, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("libcurl3-gnutls-dev", Package);
+ equals("7.15.5", Version);
+ equals(Null | pkgCache::Dep::Greater, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("debiandoc-sgml", Package);
+ equals("", Version);
+ equals(Null | pkgCache::Dep::NoOp, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("apt", Package);
+ equals("0.7.25", Version);
+ equals(Null | pkgCache::Dep::GreaterEq, Op);
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("", Package); // not-for-me
+ } else {
+ equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ if (ParseArchFlags == true) {
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ equals("only-for-me", Package);
+ equals("", Version);
+ equals(Null | pkgCache::Dep::NoOp, Op);
+ } else {
+ equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch));
+ Start = strstr(Start, ",");
+ Start++;
+ }
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("overlord-dev", Package);
+ else
+ equals("overlord-dev:any", Package);
+ equals("7.15.3~", Version);
+ equals(Null | pkgCache::Dep::Equals | pkgCache::Dep::Or, Op);
+
+ Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch);
+ if (StripMultiArch == true)
+ equals("overlord-dev", Package);
+ else
+ equals("overlord-dev:native", Package);
+ equals("7.15.5", Version);
+ equals(Null | pkgCache::Dep::Greater, Op);
+
+ if (StripMultiArch == false)
+ ParseArchFlags = true;
+ StripMultiArch = !StripMultiArch;
+
+ runner++;
+ if (runner < 4)
+ goto test; // this is the prove: tests are really evil ;)
+
+ return 0;
+}
diff --git a/test/libapt/run-tests.sh b/test/libapt/run-tests.sh
index 1fcfb6861..f9df1af5f 100755
--- a/test/libapt/run-tests.sh
+++ b/test/libapt/run-tests.sh
@@ -39,6 +39,13 @@ do
"${tmppath}/01invalíd"
ln -s "${tmppath}/anormalfile" "${tmppath}/linkedfile.list"
ln -s "${tmppath}/non-existing-file" "${tmppath}/brokenlink.list"
+ elif [ $name = "getLanguages${EXT}" ]; then
+ echo "Prepare Testarea for \033[1;35m$name\033[0m ..."
+ tmppath=$(mktemp -d)
+ touch "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-tr" \
+ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \
+ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \
+ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak"
fi
echo -n "Testing with \033[1;35m${name}\033[0m ... "
diff --git a/test/makefile b/test/makefile
index fb9123d0a..52adb96a2 100644
--- a/test/makefile
+++ b/test/makefile
@@ -25,13 +25,6 @@ SOURCE = scratch.cc
include $(PROGRAM_H)
# Version compare tester
-PROGRAM=versiontest
-SLIBS = -lapt-pkg
-LIB_MAKES = apt-pkg/makefile
-SOURCE = versiontest.cc
-include $(PROGRAM_H)
-
-# Version compare tester
PROGRAM=testextract
SLIBS = -lapt-pkg -lapt-inst
LIB_MAKES = apt-pkg/makefile apt-inst/makefile
@@ -75,7 +68,7 @@ SOURCE = test_udevcdrom.cc
include $(PROGRAM_H)
# Program for checking rpm versions
-PROGRAM=rpmver
-SLIBS = -lapt-pkg -lrpm
-SOURCE = rpmver.cc
-include $(PROGRAM_H)
+#PROGRAM=rpmver
+#SLIBS = -lapt-pkg -lrpm
+#SOURCE = rpmver.cc
+#include $(PROGRAM_H)
diff --git a/test/versions.lst b/test/versions.lst
index efc19c4f0..517214151 100644
--- a/test/versions.lst
+++ b/test/versions.lst
@@ -10,10 +10,11 @@
1.3 1.2.2 1
# Important attributes
-- . -1
-p - -1
-a - -1
-z - -1
+# disabled as dpkg --compare-versions doesn't like them…
+#- . -1
+#p - -1
+#a - -1
+#z - -1
a . -1
z . -1
@@ -22,6 +23,10 @@ z . -1
1:1.25-4 1:1.25-8 -1
0:1.18.36 1.18.36 0
+# native version
+1.18.36 1.18.35 1
+0:1.18.36 1.18.35 1
+
# Funky, but allowed, characters in upstream version
9:1.18.36:5.4-20 10:0.5.1-22 -1
9:1.18.36:5.4-20 9:1.18.36:5.5-1 -1
@@ -49,3 +54,54 @@ III-alpha9.8 III-alpha9.8-1.5 -1
# #205960
3.0~rc1-1 3.0-1 -1
+
+# #573592 - debian policy 5.6.12
+1.0 1.0-0 0
+0.2 1.0-0 -1
+1.0 1.0-0+b1 -1
+1.0 1.0-0~ 1
+
+# if a version includes a dash
+# it should be the debrev dash - policy says so…
+0:0-0-0 0-0 1
+
+# do we like strange versions? Yes we like strange versions…
+0 0 0
+0 00 0
+
+# "steal" the testcases from cupt
+1.2.3 1.2.3 0 # identical
+4.4.3-2 4.4.3-2 0 # identical
+1:2ab:5 1:2ab:5 0 # this is correct...
+7:1-a:b-5 7:1-a:b-5 0 # and this
+57:1.2.3abYZ+~-4-5 57:1.2.3abYZ+~-4-5 0 # and those too
+1.2.3 0:1.2.3 0 # zero epoch
+1.2.3 1.2.3-0 0 # zero revision
+009 9 0 # zeroes...
+009ab5 9ab5 0 # there as well
+1.2.3 1.2.3-1 -1 # added non-zero revision
+1.2.3 1.2.4 -1 # just bigger
+1.2.4 1.2.3 1 # order doesn't matter
+1.2.24 1.2.3 1 # bigger, eh?
+0.10.0 0.8.7 1 # bigger, eh?
+3.2 2.3 1 # major number rocks
+1.3.2a 1.3.2 1 # letters rock
+0.5.0~git 0.5.0~git2 -1 # numbers rock
+2a 21 -1 # but not in all places
+1.3.2a 1.3.2b -1 # but there is another letter
+1:1.2.3 1.2.4 1 # epoch rocks
+1:1.2.3 1:1.2.4 -1 # bigger anyway
+1.2a+~bCd3 1.2a++ -1 # tilde doesn't rock
+1.2a+~bCd3 1.2a+~ 1 # but first is longer!
+5:2 304-2 1 # epoch rocks
+5:2 304:2 -1 # so big epoch?
+25:2 3:2 1 # 25 > 3, obviously
+1:2:123 1:12:3 -1 # 12 > 2
+1.2-5 1.2-3-5 -1 # 1.2 < 1.2-3
+5.10.0 5.005 1 # preceding zeroes don't matters
+3a9.8 3.10.2 -1 # letters are before all letter symbols
+3a9.8 3~10 1 # but after the tilde
+1.4+OOo3.0.0~ 1.4+OOo3.0.0-4 -1 # another tilde check
+2.4.7-1 2.4.7-z -1 # revision comparing
+1.002-1+b2 1.00 1 # whatever...
+2.2.4-47978_Debian_lenny 2.2.4-47978_Debian_lenny 0 # and underscore...
diff --git a/test/versiontest.cc b/test/versiontest.cc
deleted file mode 100644
index 4ede4b280..000000000
--- a/test/versiontest.cc
+++ /dev/null
@@ -1,233 +0,0 @@
-// -*- mode: cpp; mode: fold -*-
-// Description /*{{{*/
-// $Id: versiontest.cc,v 1.5 2003/08/18 15:55:19 mdz Exp $
-/* ######################################################################
-
- Version Test - Simple program to run through a file and comare versions.
-
- Each version is compared and the result is checked against an expected
- result in the file. The format of the file is
- a b Res
- Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be
- used to determine what Res should be. # at the start of the line
- is a comment and blank lines are skipped
-
- ##################################################################### */
- /*}}}*/
-#include <apt-pkg/macros.h>
-#include <apt-pkg/error.h>
-#include <apt-pkg/version.h>
-#include <apt-pkg/debversion.h>
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
- static int verrevcmp(const char *val, const char *ref)
-{
- int vc, rc;
- long vl, rl;
- const char *vp, *rp;
-
- if (!val)
- val = "";
- if (!ref)
- ref = "";
- for (;;)
- {
- vp = val;
- while (*vp && !isdigit(*vp))
- vp++;
- rp = ref;
- while (*rp && !isdigit(*rp))
- rp++;
- for (;;)
- {
- vc= val == vp ? 0 : *val++;
- rc= ref == rp ? 0 : *ref++;
- if (!rc && !vc)
- break;
- if (vc && !isalpha(vc))
- vc += 256; /* assumes ASCII character set */
- if (rc && !isalpha(rc))
- rc += 256;
- if (vc != rc)
- return vc - rc;
- }
- val = vp;
- ref = rp;
- vl = 0;
- if (isdigit(*vp))
- vl = strtol(val,(char**)&val,10);
- rl = 0;
- if (isdigit(*rp))
- rl = strtol(ref,(char**)&ref,10);
- if (vl != rl)
- return vl - rl;
- if (!*val && !*ref)
- return 0;
- if (!*val)
- return -1;
- if (!*ref)
- return +1;
- }
-}
-
-#if 0
-static int verrevcmp(const char *val, const char *ref)
-{
- int vc, rc;
- long vl, rl;
- const char *vp, *rp;
-
- if (!val) val= "";
- if (!ref) ref= "";
- for (;;)
- {
- vp= val; while (*vp && !isdigit(*vp) && *vp != '~') vp++;
- rp= ref; while (*rp && !isdigit(*rp) && *rp != '~') rp++;
- for (;;)
- {
- vc= val == vp ? 0 : *val++;
- rc= ref == rp ? 0 : *ref++;
- if (!rc && !vc) break;
- if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
- if (rc && !isalpha(rc)) rc += 256;
- if (vc != rc) return vc - rc;
- }
-
- val= vp;
- ref= rp;
- if (*vp == '~') val++;
- if (*rp == '~') ref++;
- vl=0; if (isdigit(*val)) vl= strtol(val,(char**)&val,10);
- rl=0; if (isdigit(*ref)) rl= strtol(ref,(char**)&ref,10);
- if (vl == 0 && rl == 0)
- {
- if (*vp == '~' && *rp != '~') return -1;
- if (*vp != '~' && *rp == '~') return +1;
- }
- if (*vp == '~')
- vl *= -1;
- if (*rp == '~')
- rl *= -1;
- if (vl != rl) return vl - rl;
- if (!*val && !*ref) return 0;
- if (!*val)
- {
- if (*ref == '~')
- return +1;
- else
- return -1;
- }
-
- if (!*ref)
- {
- if (*val == '~')
- return -1;
- else
- return +1;
- }
- }
-}
-#endif
-
-bool RunTest(const char *File)
-{
- ifstream F(File,ios::in);
- if (!F != 0)
- return false;
-
- char Buffer[300];
- int CurLine = 0;
-
- while (1)
- {
- F.getline(Buffer,sizeof(Buffer));
- CurLine++;
- if (F.eof() != 0)
- return true;
- if (!F != 0)
- return _error->Error("Line %u in %s is too long",CurLine,File);
-
- // Comment
- if (Buffer[0] == '#' || Buffer[0] == 0)
- continue;
-
- // First version
- char *I;
- char *Start = Buffer;
- for (I = Buffer; *I != 0 && *I != ' '; I++);
- string A(Start, I - Start);
-
- if (*I == 0)
- return _error->Error("Invalid line %u",CurLine);
-
- // Second version
- I++;
- Start = I;
- for (I = Start; *I != 0 && *I != ' '; I++);
- string B(Start,I - Start);
-
- if (*I == 0 || I[1] == 0)
- return _error->Error("Invalid line %u",CurLine);
-
- // Result
- I++;
- int Expected = atoi(I);
- int Res = debVS.CmpVersion(A.c_str(), B.c_str());
- int Res2 = verrevcmp(A.c_str(),B.c_str());
- cout << "'" << A << "' ? '" << B << "' = " << Res << " (= " << Expected << ") " << Res2 << endl;
-
- if (Res < 0)
- Res = -1;
- else if (Res > 0)
- Res = 1;
-
- if (Res != Expected)
- _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,A.c_str(),B.c_str(),Res,Expected);
-
- // Check the reverse as well
- Expected = -1*Expected;
- Res = debVS.CmpVersion(B.c_str(), A.c_str());
- Res2 = verrevcmp(B.c_str(),A.c_str());
-
- cout << "'" << B << "' ? '" << A << "' = " << Res << " (= " << Expected << ") " << Res2 << endl;
-
- if (Res < 0)
- Res = -1;
- else if (Res > 0)
- Res = 1;
-
- if (Res != Expected)
- _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,B.c_str(),A.c_str(),Res,Expected);
- }
-}
-
-int main(int argc, char *argv[])
-{
- if (argc <= 1)
- {
- cerr << "You must specify a test file" << endl;
- return 0;
- }
-
- RunTest(argv[1]);
-
- // Print any errors or warnings found
- if (_error->empty() == false)
- {
- string Err;
- while (_error->empty() == false)
- {
-
- bool Type = _error->PopMessage(Err);
- if (Type == true)
- cout << "E: " << Err << endl;
- else
- cout << "W: " << Err << endl;
- }
-
- return 0;
- }
-}