From 2bb255740bf18b5e0524fe833523303abb5c9051 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 12 Mar 2010 19:41:30 +0100 Subject: * apt-pkg/deb/dpkgpm.cc: - if available store the Commandline in the history * apt-pkg/contrib/cmndline.cc: - save Commandline in Commandline::AsString for logging --- test/libapt/commandlineasstring_test.cc | 39 +++++++++++++++++++++++++++++++++ test/libapt/makefile | 6 +++++ 2 files changed, 45 insertions(+) create mode 100644 test/libapt/commandlineasstring_test.cc (limited to 'test/libapt') 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 +#include + +#include + +#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/makefile b/test/libapt/makefile index 08f581e6d..cb76d5ee6 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -23,3 +23,9 @@ 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) -- cgit v1.2.3 From ea5624c3d04c35f5a269b6f7431c135330c9b9b5 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 13 Mar 2010 14:11:22 +0100 Subject: * apt-pkg/deb/debversion.cc: - consider absent of debian revision equivalent to 0 (Closes: #573592) This moves the existing testcase for version comparison to "my" directory, adds a few more tests (e.g. the tests used in cupt) and rewrites the testcases runner: The runner does now call dpkg --compare-versions to check what dpkg thinks about the comparison - all done in less code ;) --- test/libapt/compareversion_test.cc | 123 +++++++++++++++++++++++++++++++++++++ test/libapt/makefile | 6 ++ 2 files changed, 129 insertions(+) create mode 100644 test/libapt/compareversion_test.cc (limited to 'test/libapt') 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +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/makefile b/test/libapt/makefile index cb76d5ee6..98bdb3348 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -29,3 +29,9 @@ 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) -- cgit v1.2.3