Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / tests / zypp / Deltarpm_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/TmpPath.h"
12 #include "zypp/PathInfo.h"
13 #include "zypp/RepoManager.h"
14 #include "zypp/sat/Pool.h"
15 #include "zypp/repo/DeltaCandidates.h"
16 #include "zypp/repo/PackageDelta.h"
17 #include "KeyRingTestReceiver.h"
18
19 using boost::unit_test::test_case;
20
21 using namespace std;
22 using namespace zypp;
23 using namespace zypp::repo;
24 using namespace zypp::filesystem;
25
26 #define TEST_DIR TESTS_SRC_DIR "/zypp/data/Delta"
27
28 BOOST_AUTO_TEST_CASE(delta)
29 {
30   KeyRing::setDefaultAccept( KeyRing::ACCEPT_UNKNOWNKEY | KeyRing::ACCEPT_UNSIGNED_FILE );
31
32   TmpDir rootdir;
33   RepoManager rm( RepoManagerOptions::makeTestSetup( rootdir ) );
34
35   RepoInfo updates;
36   updates.setAlias("updates");
37   updates.addBaseUrl( Pathname(TEST_DIR).asUrl() );
38
39   try
40   {
41     rm.buildCache(updates);
42     rm.loadFromCache(updates);
43   }
44   catch (const Exception & e)
45   {
46     BOOST_FAIL( string("Problem getting the data: ")+ e.msg()) ;
47   }
48   sat::Pool pool(sat::Pool::instance());
49
50   repo::DeltaCandidates dc(list<Repository>(pool.reposBegin(),pool.reposEnd()), "libzypp");
51
52   std::list<packagedelta::DeltaRpm> deltas = dc.deltaRpms(0);
53   for_ (it,deltas.begin(),deltas.end())
54   {
55     BOOST_CHECK(it->name() == "libzypp");
56     BOOST_CHECK(it->edition() == Edition("4.21.3-2"));
57     BOOST_CHECK(it->arch() == "i386");
58     BOOST_CHECK(it->baseversion().edition().match(Edition("4.21.3-1"))
59       ||it->baseversion().edition().match(Edition("4.21.2-3")));
60
61     cout << it->name() << " - " << it->edition() << " - " <<  it->arch()
62       << " base: " << it->baseversion().edition() << endl;
63
64     cout << (it->edition() == "4.21.3-2") << endl;              // fine
65     cout << (it->edition() == Edition("4.21.3-2")) << endl;     // fine
66     cout << (it->edition().match(Edition("4.21.3-2")) == 0) << endl; // match returns -1,0,1
67     cout << (it->edition().match("4.21.3-2") == 0) << endl;          // match returns -1,0,1
68   }
69 }