1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <boost/test/auto_unit_test.hpp>
#include "zypp/base/Logger.h"
#include "zypp/base/InputStream.h"
#include "zypp/parser/IniParser.h"
#include "zypp/Url.h"
#include "zypp/PathInfo.h"
using std::cout;
using std::endl;
using std::string;
using namespace zypp;
using namespace zypp::parser;
using namespace boost::unit_test;
#define DATADIR (Pathname(TESTS_SRC_DIR) + "/parser/inifile/data")
class IniTest : public IniParser
{
virtual void consume( const std::string §ion )
{
MIL << section << endl;
}
virtual void consume( const std::string §ion, const std::string &key, const std::string &value )
{
MIL << "'" << section << "'" << " | " << "'" << key << "'" << " | " << "'" << value << "'" << endl;
if (section == "base" && key == "gpgcheck")
BOOST_CHECK_EQUAL(value, "1");
}
};
class WithSpacesTest : public IniParser
{
virtual void consume( const std::string §ion )
{
MIL << section << endl;
BOOST_CHECK(section == "base" || section == "equal" || section == "te]st");
}
virtual void consume( const std::string §ion, const std::string &key, const std::string &value )
{
MIL << "'" << section << "'" << " | " << "'" << key << "'" << " | " << "'" << value << "'" << endl;
if ( section == "base")
{
if ( key == "name" )
BOOST_CHECK_EQUAL( value, "foo" );
}
else if ( section == "equal" )
{
if ( key == "name1" )
BOOST_CHECK_EQUAL( value, "=foo" );
else if ( key == "name2" )
BOOST_CHECK_EQUAL( value, "f=oo" );
else if ( key == "name3" )
BOOST_CHECK_EQUAL( value, "foo=" );
else
{
cout << "'" << section << "'" << " | " << "'" << key << "'" << " | " << "'" << value << "'" << endl;
BOOST_CHECK_MESSAGE( false, "Unhandled key" );
}
}
}
};
BOOST_AUTO_TEST_CASE(ini_read)
{
InputStream is((DATADIR+"/1.ini"));
IniTest parser;
parser.parse(is);
}
BOOST_AUTO_TEST_CASE(ini_spaces_test)
{
InputStream is((DATADIR+"/2.ini"));
WithSpacesTest parser;
parser.parse(is);
}
|