From: Stefan Schubert Date: Thu, 31 Jan 2008 13:36:14 +0000 (+0000) Subject: -testcase for vendors added X-Git-Tag: BASE-SuSE-Linux-11_0-Branch~586^2~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f84722a47ba2a929f94483d3c546032b7cca939;p=platform%2Fupstream%2Flibzypp.git -testcase for vendors added -bugfix in zypp.config and vendor definition --- diff --git a/tests/zypp/CMakeLists.txt b/tests/zypp/CMakeLists.txt index 35ba7be..a023f85 100644 --- a/tests/zypp/CMakeLists.txt +++ b/tests/zypp/CMakeLists.txt @@ -65,6 +65,9 @@ TARGET_LINK_LIBRARIES( RepoInfo zypp boost_unit_test_framework ) ADD_EXECUTABLE( ProgressData ProgressData_test.cc ) TARGET_LINK_LIBRARIES( ProgressData zypp boost_unit_test_framework ) +ADD_EXECUTABLE(Vendor1 Vendor1.cc) +TARGET_LINK_LIBRARIES(Vendor1 zypp boost_unit_test_framework ) + ADD_TEST(ArchTest ${CMAKE_CURRENT_BINARY_DIR}/Arch) ADD_TEST(UrlTest ${CMAKE_CURRENT_BINARY_DIR}/Url) ADD_TEST(Edition ${CMAKE_CURRENT_BINARY_DIR}/Edition) @@ -83,3 +86,4 @@ ADD_TEST(RepoManagerTest ${CMAKE_CURRENT_BINARY_DIR}/RepoManager ${CMAKE_CURRENT ADD_TEST(RepoInfoTest ${CMAKE_CURRENT_BINARY_DIR}/RepoInfo ${CMAKE_CURRENT_SOURCE_DIR}/data/RepoInfo) ADD_TEST(FetcherTest ${CMAKE_CURRENT_BINARY_DIR}/Fetcher) ADD_TEST(ProgressData_test ${CMAKE_CURRENT_BINARY_DIR}/ProgressData) +ADD_TEST(Vendor1Test ${CMAKE_CURRENT_BINARY_DIR}/Vendor1) diff --git a/tests/zypp/Vendor1.cc b/tests/zypp/Vendor1.cc new file mode 100644 index 0000000..888c74e --- /dev/null +++ b/tests/zypp/Vendor1.cc @@ -0,0 +1,49 @@ + +#include +#include +#include + +// Boost.Test +#include +#include + +using boost::unit_test::test_suite; +using boost::unit_test::test_case; +using boost::test_tools::close_at_tolerance; + +// parameterized test +// http://www.boost.org/libs/test/example/unit_test_example4.cpp + +#include "zypp/base/LogControl.h" +#include "zypp/base/Logger.h" +#include "zypp/base/Exception.h" +#include "zypp/ZYpp.h" +#include "zypp/VendorAttr.h" + +using namespace std; +using namespace zypp; + + +// most frequently you implement test cases as a free functions +void vendor_test() +{ + // No vendor definition files has been readed. So only suse,opensuse vendors are + // equivalent + BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "suse") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("equal", "equal") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "SuSE") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse", "SuSE") ); + BOOST_REQUIRE( !VendorAttr::instance().equivalent("open", "SuSE") ); + BOOST_REQUIRE( !VendorAttr::instance().equivalent("nothing", "SuSE") ); +} + +test_suite* +init_unit_test_suite( int, char* [] ) +{ + setenv("ZYPP_CONF", "./../../tests/zypp/data/Vendor/zypp1.conf", 1 ); + zypp::base::LogControl::instance().logfile( "-" ); + test_suite* test= BOOST_TEST_SUITE( "VendorTest" ); + test->add( BOOST_TEST_CASE( &vendor_test ), 5 /* expected zero error */ , 0); + return test; +} + diff --git a/tests/zypp/data/Vendor/zypp1.conf b/tests/zypp/data/Vendor/zypp1.conf new file mode 100644 index 0000000..5c017e0 --- /dev/null +++ b/tests/zypp/data/Vendor/zypp1.conf @@ -0,0 +1,126 @@ +## Configuration file for software management +## /etc/zypp/zypp.conf +## +## Boolean values are 0 1 yes no on off true false + + +[main] + + +## +## Override the detected architecture +## +## Valid values: i586, i686, x86_64, ppc, ppc64, ia64, s390, s390x, .. +## Default value: Autodetected +## +## ** CAUTION: Only set if you know what you're doing ! +## ** Changing this needs a full refresh (incl. download) +## ** of all repository data. +## +# arch = s390 + + +## +## Path where the repo metadata is downloaded and kept. +## +## Valid values: A directory +## Default value: /var/cache/zypp/raw +## +## Changing this needs a full refresh (incl. download) of all repository data +## +# metadatadir = /var/cache/zypp/raw + + +## +## Path where the known repositories .repo files are kept +## +## Valid values: A directory +## Default value: /etc/zypp/repos.d +## +## Changing this invalidates all known repositories +## +# reposdir = /etc/zypp/repos.d + + +## +## Path where the processed cache is kept (this is where zypp.db is located) +## +## Valid values: A directory +## Default value: /var/cache/zypp +## +## Changing this needs a full refresh (except download) of all repository data +## +# cachedir = /var/cache/zypp + + +## +## Whether repository urls should be probed when added +## +## Valid values: boolean +## Default value: false +## +## If true, accessability of repositories is checked immediately (when added) +## (e.g. 'zypper ar' will check immediately) +## If false, accessability of repositories is checked when refreshed +## (e.g. 'zypper ar' will delay the check until the next refresh) +## +# repo.add.probe = false + + +## +## Amount of time in minutes that must pass before another refresh. +## +## Valid values: Integer +## Default value: 10 +## +## If you have autorefresh enabled for a repository, it is checked for +## up-to-date metadata not more often than every +## minutes. If an automatic request for refresh comes before +## minutes passed since the last check, the request is ignored. +## +## A value of 0 means the repository will always be checked. To get the oposite +## effect, disable autorefresh for your repositories. +## +## This option has no effect for repositories with autorefresh disabled, nor for +## user-requested refresh. +## +# repo.refresh.delay = 10 + + +## +## Whether to consider using a .patch.rpm when downloading a package +## +## Valid values: boolean +## Default value: true +## +## Using a patch rpm will decrease the download size for package updates +## since it does not contain all files of the package but only the changed +## ones. The .patch.rpm is ready to be installed immediately after download. +## There is no further processing needed, as it is for a .delta.rpm. +## +# download.use_patchrpm = true + + +## +## Whether to consider using a .delta.rpm when downloading a package +## +## Valid values: boolean +## Default value: true +## +## Using a delta rpm will decrease the download size for package updates +## since it does not contain all files of the package but only the binary +## diff of changed ones. Recreating the rpm package on the local machine +## is an expensive operation (memory,CPU). If your network connection is +## not too slow, you benefit from disabling .delta.rpm. +## +# download.use_deltarpm = true + + +## +## Defining directory for equivalent vendors +## +## Valid values: A directory +## Default value: /etc/zypp/vondors.d +## +vendordir = data/Vendor/notExist + diff --git a/zypp/VendorAttr.cc b/zypp/VendorAttr.cc index 3c0bcbf..13809c5 100644 --- a/zypp/VendorAttr.cc +++ b/zypp/VendorAttr.cc @@ -107,7 +107,7 @@ namespace zypp VendorAttr::VendorAttr () { vendorGroupCounter = 1; - + Pathname xxx = ZConfig::instance().repoCachePath(); Pathname vendorPath (ZConfig::instance().vendorPath()); try { @@ -126,18 +126,24 @@ namespace zypp //checking if suse,opensuse has been defined. If not create entries if (_vendorMap.find("suse") != _vendorMap.end()) { if (_vendorMap.find("opensuse") == _vendorMap.end()) { - _vendorMap["opensuse"] = ++vendorGroupCounter; + _vendorMap["opensuse"] = vendorGroupCounter; } } else { if (_vendorMap.find("opensuse") == _vendorMap.end()) { // both are not available. Create one group with suse,opensuse - _vendorMap["opensuse"] = ++vendorGroupCounter; + _vendorMap["opensuse"] = vendorGroupCounter; _vendorMap["suse"] = vendorGroupCounter; } else { - _vendorMap["suse"] = ++vendorGroupCounter; + _vendorMap["suse"] = vendorGroupCounter; } } - + + MIL << "Equivalent vendors:" << endl; + for (VendorMap::iterator it = _vendorMap.begin(); + it != _vendorMap.end(); + it ++) { + MIL << " " << it->first << " (group " << it->second << ")" << endl; + } } bool VendorAttr::addVendorFile( const Pathname & filename ) const @@ -179,13 +185,6 @@ namespace zypp } } } - - MIL << "Equivalent vendors:" << endl; - for (VendorMap::iterator it = _vendorMap.begin(); - it != _vendorMap.end(); - it ++) { - MIL << " " << it->first << "(group " << it->second << ")" << endl; - } return true; } @@ -218,13 +217,15 @@ namespace zypp } - bool VendorAttr::equivalent( const Vendor & lhs, const Vendor & rhs ) const + bool VendorAttr::equivalent( const Vendor & lVendor, const Vendor & rVendor ) const { - if ( lhs == rhs ) - return true; - unsigned int lhsID = 0; unsigned int rhsID = 0; + Vendor lhs = str::toLower (lVendor); + Vendor rhs = str::toLower (rVendor); + + if ( lhs == rhs ) + return true; if (_matchMap.find(lhs) != _matchMap.end()) { lhsID = _matchMap[lhs]; @@ -255,8 +256,8 @@ namespace zypp } } } - - return( lhsID == lhsID ); + + return( lhsID && rhsID && lhsID == lhsID ); } ///////////////////////////////////////////////////////////////// diff --git a/zypp/VendorAttr.h b/zypp/VendorAttr.h index fd0a349..d9cd380 100644 --- a/zypp/VendorAttr.h +++ b/zypp/VendorAttr.h @@ -44,7 +44,7 @@ class VendorAttr : private base::NonCopyable * equivalent vendor when updating. Replacing a package with one of a * different vendor usually must be confirmed by the user. */ - bool equivalent( const Vendor & lhs, const Vendor & rhs ) const; + bool equivalent( const Vendor & lVendor, const Vendor & rVendor ) const; private: VendorAttr(); diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index 294dc54..6e8b788 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -51,6 +51,7 @@ namespace zypp // ZYPP_CONF might override /etc/zypp/zypp.conf const char *env_confpath = getenv( "ZYPP_CONF" ); + Pathname confpath( env_confpath ? env_confpath : "/etc/zypp/zypp.conf" ); if ( PathInfo(confpath).isExist()) { @@ -106,19 +107,17 @@ namespace zypp { download_use_patchrpm = str::strToBool( value, download_use_patchrpm ); } - else if ( entry == "download.use_deltarpm" ) - { + else if ( entry == "download.use_deltarpm" ) + { download_use_deltarpm = str::strToBool( value, download_use_deltarpm ); - } - } - else if ( section == "vendordir" ) - { - cfg_vendor_path = Pathname(value); + } + else if ( entry == "vendordir" ) + { + cfg_vendor_path = Pathname(value); + } } - } } - } ~Impl()