Imported Upstream version 17.25.4
[platform/upstream/libzypp.git] / tests / zypp / Vendor_test.cc
index 38880ea..9317878 100644 (file)
@@ -9,24 +9,25 @@
 #include <zypp/base/LogControl.h>
 #include <zypp/base/Logger.h>
 #include <zypp/base/Exception.h>
-#include <zypp/ZYpp.h>
 #include <zypp/VendorAttr.h>
 
 using boost::unit_test::test_case;
 using namespace zypp;
-
-namespace zypp
-{
-  void reconfigureZConfig( const Pathname & );
-}
+using std::cout;
+using std::endl;
 
 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/Vendor")
 
 BOOST_AUTO_TEST_CASE(vendor_empty)
 {
+  VendorAttr::noTargetInstance() = VendorAttr(); // suse defaults; no configfiles read
+
   BOOST_REQUIRE( VendorAttr::instance().equivalent("", "") );
   BOOST_REQUIRE( !VendorAttr::instance().equivalent("a", "") );
   BOOST_REQUIRE( !VendorAttr::instance().equivalent("", "a") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("a", "a") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("a", "aa") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("aa", "a") );
 
   BOOST_REQUIRE( VendorAttr::instance().equivalent( IdString::Null, IdString::Null ) );
   BOOST_REQUIRE( VendorAttr::instance().equivalent( IdString::Empty, IdString::Null ) );
@@ -36,23 +37,51 @@ BOOST_AUTO_TEST_CASE(vendor_empty)
 
 BOOST_AUTO_TEST_CASE(vendor_test1)
 {
-  reconfigureZConfig( DATADIR / "zypp1.conf" );
+
+  VendorAttr::noTargetInstance() = VendorAttr(); // suse defaults; no configfiles read
   // bsc#1030686: Remove legacy vendor equivalence between 'suse' and 'opensuse'
   // No vendor definition files has been read. So only suse* vendors are
   // equivalent
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "SuSE as prefix") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("SuSE as prefix", "suse") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("SuSE as prefix","foreign") );
+  // bnc#812608: All opensuse projects get their own class (no prefix compare in opensuse namespace)
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse",           "SuSE as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse as prefix", "SuSE as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse",           "opensuse as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse as prefix", "opensuse but different prefix") );
+}
+
+BOOST_AUTO_TEST_CASE(vendor_test2)
+{
+  VendorAttr::noTargetInstance() = VendorAttr( DATADIR / "vendors.d" );
+
   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") );
-
-  // but "opensuse build service" gets its own class:
-  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse build service", "suse") );
-  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse build service", "opensuse") );
-  // bnc#812608: All opensuse projects get their own class
-  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse-education", "suse") );
-  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse-education", "opensuse") );
-  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse-education", "opensuse build service") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("nvidia", "SuSE") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("nvidia_new_new", "SuSE") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("nvidia", "opensuse") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("ati", "SuSE") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("ati", "nvidia") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("ati_new", "ati") );
 }
 
+BOOST_AUTO_TEST_CASE(vendor_test3)
+{
+  VendorAttr::noTargetInstance() = VendorAttr(); // suse defaults; no configfiles read
+  VendorAttr::noTargetInstance().addVendorList( { "suse", "opensuse", "opensuse too" } );
+
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("SuSE as prefix", "opensuse") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("SuSE as prefix", "opensuse too") );
+  BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse", "opensuse too") );
+  // bnc#812608: All opensuse projects get their own class (no prefix compare in opensuse namespace)
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("SuSE as prefix", "opensuse as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("SuSE as prefix", "opensuse too as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse",           "opensuse too as prefix") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse as prefix", "opensuse too") );
+  BOOST_REQUIRE( !VendorAttr::instance().equivalent("opensuse as prefix", "opensuse too as prefix") );
+}