From c3ccac9232c2684b15f75fa8622a9a290aeca123 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 27 Feb 2014 03:11:54 +0100 Subject: warning: no previous declaration for foobar() [-Wmissing-declarations] Git-Dch: Ignore Reported-By: gcc -Wmissing-declarations --- test/libapt/compareversion_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libapt/compareversion_test.cc') diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc index fdb1d5674..44f8e9d78 100644 --- a/test/libapt/compareversion_test.cc +++ b/test/libapt/compareversion_test.cc @@ -31,7 +31,7 @@ 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,7 +50,7 @@ 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) { +static 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); @@ -61,7 +61,7 @@ void assertVersion(int const &CurLine, string const &A, string const &B, int con _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) +static bool RunTest(const char *File) { if (FileExists(File) == false) return _error->Error("Versiontestfile %s doesn't exist!", File); -- cgit v1.2.3 From 453b82a388013e522b3a1b9fcd6ed0810dab1f4f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 5 Mar 2014 22:11:25 +0100 Subject: cleanup headers and especially #includes everywhere Beside being a bit cleaner it hopefully also resolves oddball problems I have with high levels of parallel jobs. Git-Dch: Ignore Reported-By: iwyu (include-what-you-use) --- test/libapt/compareversion_test.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/libapt/compareversion_test.cc') diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc index 44f8e9d78..43b98f240 100644 --- a/test/libapt/compareversion_test.cc +++ b/test/libapt/compareversion_test.cc @@ -16,17 +16,16 @@ ##################################################################### */ /*}}}*/ -#include +#include + #include -#include #include #include -#include -#include +#include +#include #include #include -#include #include using namespace std; -- cgit v1.2.3 From f00832cc273e52a47fb88e49849891b771de4e17 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 16 Apr 2014 17:09:37 +0200 Subject: use Google C++ Testing Framework for libapt tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My commit 45df0ad2 from 26. Nov 2009 had a little remark: "The commit also includes a very very simple testapp." This was never intended to be permanent, but as usually… The commit adds the needed make magic to compile gtest statically as it is required and links it against a small runner. All previous testcase binaries are reimplemented in gtest and combined in this runner. While most code is a 1:1 translation some had to be rewritten like compareversion_test.cc, but the coverage remains the same. --- test/libapt/compareversion_test.cc | 185 ++++++++++++++++++++++++------------- 1 file changed, 120 insertions(+), 65 deletions(-) (limited to 'test/libapt/compareversion_test.cc') diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc index 43b98f240..3b2c0c209 100644 --- a/test/libapt/compareversion_test.cc +++ b/test/libapt/compareversion_test.cc @@ -28,9 +28,11 @@ #include #include +#include + using namespace std; -static 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) { @@ -49,77 +51,130 @@ static bool callDPkg(const char *val, const char *ref, const char &op) { return WIFEXITED(Ret) == true && WEXITSTATUS(Ret) == 0; } -static 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 }; -static 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"); + + // 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"); -int main(int argc, char *argv[]) + // 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... + // */ } -- cgit v1.2.3