From ba2de8d643e0ccde734a9e1be09004ec3cc19cf6 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 21 May 2010 19:58:35 +0200 Subject: [PATCH] Add IdString testcases --- tests/sat/CMakeLists.txt | 2 +- tests/sat/IdString_test.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++ tests/zypp/Deltarpm_test.cc | 6 ++--- tests/zypp/Edition_test.cc | 2 ++ 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/sat/IdString_test.cc diff --git a/tests/sat/CMakeLists.txt b/tests/sat/CMakeLists.txt index 1e34860..90e1319 100644 --- a/tests/sat/CMakeLists.txt +++ b/tests/sat/CMakeLists.txt @@ -2,6 +2,6 @@ # to find the KeyRingTest receiver INCLUDE_DIRECTORIES( ${LIBZYPP_SOURCE_DIR}/tests/zypp ) -ADD_TESTS(Solvable SolvParsing WhatProvides WhatObsoletes LookupAttr AttrMatcher) +ADD_TESTS(Solvable SolvParsing WhatProvides WhatObsoletes LookupAttr AttrMatcher IdString) diff --git a/tests/sat/IdString_test.cc b/tests/sat/IdString_test.cc new file mode 100644 index 0000000..900ff91 --- /dev/null +++ b/tests/sat/IdString_test.cc @@ -0,0 +1,59 @@ +#include "TestSetup.h" +#include + +BOOST_AUTO_TEST_CASE(idstring) +{ + // id 0 ==> NULL + // id 1 ==> "" + // evaluates id in a boolean context + IdString a0( 0 ); + IdString a1( 1 ); + + BOOST_CHECK_EQUAL( a0.id(), 0 ); + BOOST_CHECK_EQUAL( a1.id(), 1 ); + + BOOST_CHECK( !a0 ); + BOOST_CHECK( a1 ); + + BOOST_CHECK( !(a0 == a1) ); + BOOST_CHECK( (a0 != a1) ); + BOOST_CHECK( (a0 < a1) ); + BOOST_CHECK( (a1 > a0) ); + BOOST_CHECK( !(a0 >= a1) ); + BOOST_CHECK( !(a1 <= a0) ); + + BOOST_CHECK_EQUAL( a0.compare( (const char *)0 ), 0 ); + BOOST_CHECK_EQUAL( a0.compare( "" ), -1 ); + BOOST_CHECK_EQUAL( a0.compare( a1 ), -1 ); + + BOOST_CHECK_EQUAL( a1.compare( (const char *)0 ), 1 ); + BOOST_CHECK_EQUAL( a1.compare( "" ), 0 ); + BOOST_CHECK_EQUAL( a1.compare( a0 ), 1 ); +} + +BOOST_AUTO_TEST_CASE(idstringtype) +{ + sat::SolvAttr a0( sat::SolvAttr::allAttr ); + sat::SolvAttr a1( sat::SolvAttr::noAttr ); + + BOOST_CHECK_EQUAL( a0.id(), 0 ); + BOOST_CHECK_EQUAL( a1.id(), 1 ); + + BOOST_CHECK( !a0 ); + BOOST_CHECK( !a1 ); // evaluates empty string (id 0/1) in a boolean context + + BOOST_CHECK( !(a0 == a1) ); + BOOST_CHECK( (a0 != a1) ); + BOOST_CHECK( (a0 < a1) ); + BOOST_CHECK( (a1 > a0) ); + BOOST_CHECK( !(a0 >= a1) ); + BOOST_CHECK( !(a1 <= a0) ); + + BOOST_CHECK_EQUAL( a0.compare( (const char *)0 ), 0 ); + BOOST_CHECK_EQUAL( a0.compare( "" ), -1 ); + BOOST_CHECK_EQUAL( a0.compare( a1 ), -1 ); + + BOOST_CHECK_EQUAL( a1.compare( (const char *)0 ), 1 ); + BOOST_CHECK_EQUAL( a1.compare( "" ), 0 ); + BOOST_CHECK_EQUAL( a1.compare( a0 ), 1 ); +} diff --git a/tests/zypp/Deltarpm_test.cc b/tests/zypp/Deltarpm_test.cc index 5a927d6..77e1e67 100644 --- a/tests/zypp/Deltarpm_test.cc +++ b/tests/zypp/Deltarpm_test.cc @@ -63,9 +63,7 @@ BOOST_AUTO_TEST_CASE(delta) cout << (it->edition() == "4.21.3-2") << endl; // fine cout << (it->edition() == Edition("4.21.3-2")) << endl; // fine - cout << (it->edition().match(Edition("4.21.3-2")) == 0) << endl; // !match returns -1,0,1 - cout << (it->edition().match("4.21.3-2") == 0) << endl; // !match returns -1,0,1 + cout << (it->edition().match(Edition("4.21.3-2")) == 0) << endl; // match returns -1,0,1 + cout << (it->edition().match("4.21.3-2") == 0) << endl; // match returns -1,0,1 } - - //! \todo FIXME Edition("0:4.21.3-2") != Edition("4.21.3-2") (not even does Edition("0:4.21.3-2").match(Edition("4.21.3-2")) } diff --git a/tests/zypp/Edition_test.cc b/tests/zypp/Edition_test.cc index bd2f74b..09bca5b 100644 --- a/tests/zypp/Edition_test.cc +++ b/tests/zypp/Edition_test.cc @@ -27,6 +27,8 @@ BOOST_AUTO_TEST_CASE(edition) BOOST_CHECK_EQUAL(_ed1, Edition ("1", "")); BOOST_CHECK_EQUAL(_ed2, Edition ("1.1", "")); + BOOST_CHECK_EQUAL(_ed2, Edition ("1_1", "")); // Edition strings may differ in separator (non alphanum) + BOOST_CHECK_EQUAL(_ed2, Edition ("0:1.1")); // epoch 0 is no epoch BOOST_CHECK_EQUAL(_ed3, Edition ("1", "", "1")); BOOST_CHECK_EQUAL(_ed3, Edition ("1", "", 1)); BOOST_CHECK_EQUAL(_ed4, Edition ("1", "1", 2)); -- 2.7.4