Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / tests / repo / ExtendedMetadata_test.cc
1 #include <iostream>
2 #include <sstream>
3 #include <fstream>
4 #include <list>
5 #include <string>
6
7 #include <boost/test/unit_test.hpp>
8
9 #include "zypp/base/Logger.h"
10 #include "zypp/base/Exception.h"
11 #include "zypp/PathInfo.h"
12 #include "zypp/TmpPath.h"
13 #include "zypp/Package.h"
14 #include "zypp/RepoManager.h"
15 #include "zypp/sat/Pool.h"
16 #include "KeyRingTestReceiver.h"
17
18 #include "TestSetup.h"
19
20 using boost::unit_test::test_case;
21
22 using namespace std;
23 using namespace zypp;
24 using namespace zypp::repo;
25 using namespace zypp::filesystem;
26
27 #define TEST_DIR TESTS_SRC_DIR "/repo/yum/data/extensions"
28
29 BOOST_AUTO_TEST_CASE(extended_metadata)
30 {
31   KeyRingTestReceiver rec;
32   //rec.answerAcceptUnknownKey(true);
33   rec.answerAcceptUnsignedFile(true);
34
35
36 //  rec.answerImportKey(true);
37   Pathname repodir(TEST_DIR );
38
39   sat::Pool pool(sat::Pool::instance());
40
41   TestSetup test( Arch_x86_64 );
42   test.loadRepo(repodir.absolutename().asDirUrl(), "updates");
43
44   Repository repo = pool.reposFind("updates");
45
46   BOOST_CHECK_EQUAL( repo.generatedTimestamp(), Date(1227279057) );
47   BOOST_CHECK_EQUAL( repo.suggestedExpirationTimestamp(), Date(1227279057 + 3600) );
48
49   // check that the attributes of product compatibility are ok
50   int count = 0;
51   vector<CpeId> cpeids;
52   vector<string> labels;
53
54   for_( it,
55         repo.compatibleWithProductBegin(),
56         repo.compatibleWithProductEnd() )
57   {
58       cpeids.push_back(it.cpeId());
59       labels.push_back(it.label());
60       count++;
61   }
62
63   // there were 2 compatible products
64   BOOST_CHECK_EQUAL( count, 2 );
65   BOOST_CHECK_EQUAL( cpeids[0], "cpe:/o:opensuse" );
66   BOOST_CHECK_EQUAL( cpeids[1], "cpe:/o:sle" );
67
68   BOOST_CHECK_EQUAL( labels[0], "openSUSE 11.0" );
69   BOOST_CHECK_EQUAL( labels[1], "SLE 11.0" );
70
71   cpeids.clear();
72   labels.clear();
73   count = 0;
74
75   for_( it,
76         repo.updatesProductBegin(),
77         repo.updatesProductEnd() )
78   {
79       cpeids.push_back(it.cpeId());
80       labels.push_back(it.label());
81       count++;
82   }
83
84   // the repo updates one product
85   BOOST_CHECK_EQUAL( count, 1 );
86   BOOST_CHECK_EQUAL( cpeids[0], "cpe:/o:sle" );
87   BOOST_CHECK_EQUAL( labels[0], "SLE 11.0" );
88
89   // because this product updates something, it _is_ an update repo
90   BOOST_CHECK( repo.isUpdateRepo() );
91
92   BOOST_CHECK( repo.providesUpdatesFor(CpeId("cpe:/o:sle")) );
93   BOOST_CHECK( ! repo.providesUpdatesFor(CpeId("cpe:/o:windows")) );
94   // reuse to count solvables
95   count = 0;
96
97   /**
98    * Now check for the extended metadata of the packages
99    */
100   for_( it, repo.solvablesBegin(), repo.solvablesEnd() )
101   {
102       sat::Solvable s = *it;
103       MIL << s << endl;
104       MIL << s.kind() << endl;
105       if ( s.ident() == "wt" )
106       {
107           count++;
108           Package::Ptr p = asKind<Package>(makeResObject(s));
109           BOOST_CHECK(p);
110           BOOST_CHECK(p->maybeUnsupported() );
111           BOOST_CHECK_EQUAL(p->vendorSupport(), VendorSupportUnknown );
112
113       }
114       else if ( s.ident() == "foobar" )
115       {
116             count++;
117             Package::Ptr p = asKind<Package>(makeResObject(s));
118             BOOST_CHECK(p);
119             BOOST_CHECK_EQUAL(p->vendorSupport(), VendorSupportUnsupported );
120             BOOST_CHECK(p->maybeUnsupported() );
121       }
122       else if ( s.ident() == "foofoo" )
123       {
124           count++;
125           Package::Ptr p = asKind<Package>(makeResObject(s));
126           BOOST_CHECK(p);
127           // if it is level 3 support it cant be unsupported
128           BOOST_CHECK_EQUAL(p->vendorSupport(), VendorSupportLevel3 );
129           BOOST_CHECK(! p->maybeUnsupported() );
130
131       }
132       else
133       {
134           BOOST_FAIL(str::form("Repo has package not contemplated in test: %s", s.ident().c_str()).c_str());
135       }
136
137     }
138
139     // check that we actually found all testeable
140     // resolvables
141     BOOST_CHECK_EQUAL(count, 3);
142
143 }