Imported Upstream version 17.22.1
[platform/upstream/libzypp.git] / tests / parser / yum / RepomdFileReader_test.cc
1 #include <stdio.h>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <list>
6 #include <boost/test/unit_test.hpp>
7
8 #include "zypp/parser/yum/RepomdFileReader.h"
9 #include "zypp/Url.h"
10 #include "zypp/PathInfo.h"
11
12 using namespace std;
13 using namespace zypp;
14 using namespace boost::unit_test;
15
16 using namespace zypp::parser::yum;
17
18 #define DATADIR (Pathname(TESTS_SRC_DIR) + "parser/yum/data")
19
20 class Collector
21 {
22 public:
23   Collector()
24   {}
25
26   bool operator()( OnMediaLocation &&loc, const std::string &t )
27   {
28     items.push_back( make_pair( t, std::move(loc) ) );
29     return true;
30   }
31   
32   vector<pair<std::string, OnMediaLocation> > items;
33 };
34
35 BOOST_AUTO_TEST_CASE(repomd_read)
36 {
37   list<Pathname> entries;
38   if ( filesystem::readdir( entries, DATADIR, false ) != 0 )
39     ZYPP_THROW(Exception("failed to read directory"));
40     
41   for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
42   {
43     Pathname file = *it;
44     if ( ( file.basename().substr(0, 6) == "repomd" ) && (file.extension() == ".xml" ) )
45     {
46       cout << *it << endl;
47
48       Collector collect;
49       RepomdFileReader( file, std::ref(collect) );
50
51       std::ifstream ifs( file.extend(".solution").asString().c_str() );
52
53       unsigned int count = 0;
54       while ( ifs && !ifs.eof() )
55       {
56         string dtype;
57         getline(ifs, dtype);
58         if ( dtype.empty() )
59           break;
60         BOOST_REQUIRE( count < collect.items.size() );
61         BOOST_CHECK_EQUAL( collect.items[count].first, dtype );
62
63         string checksum_type;
64         string checksum;
65         getline(ifs, checksum_type);
66         getline(ifs, checksum);
67         BOOST_CHECK_EQUAL( collect.items[count].second.checksum(), CheckSum(checksum_type, checksum) );
68
69         string loc;
70         getline(ifs, loc);
71         BOOST_CHECK_EQUAL( collect.items[count].second.filename(), Pathname(loc) );
72
73         count++;
74       }
75       BOOST_CHECK_EQUAL( collect.items.size(), count );
76     }
77   }
78 }
79
80
81 // vim: set ts=2 sts=2 sw=2 ai et: