source: branches/0.9-stable/test/config.cc @ 1368

Last change on this file since 1368 was 1368, checked in by Peter Johansson, 10 years ago

updating copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1// $Id: config.cc 1368 2011-06-10 02:27:10Z peter $
2
3/*
4  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010, 2011 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "Suite.h"
24
25#include "lib/Configuration.h"
26
27#include <sstream>
28
29namespace theplu{
30namespace svndigest{
31  void test_codon(test::Suite&);
32  void test_read_write(test::Suite&);
33  void test_props(test::Suite&);
34}} // end of namespace svndigest and theplu
35
36
37int main( int argc, char* argv[])
38{
39  using namespace theplu::svndigest;
40  test::Suite suite(argc, argv, false);
41
42  test_codon(suite);
43  test_read_write(suite);
44  test_props(suite);
45                                                                               
46  return suite.exit_status();
47}
48
49
50namespace theplu{
51namespace svndigest{
52
53  void test_codon(test::Suite& suite)
54  {
55    suite.out() << "test codons" << std::endl;
56    const Configuration& c(Configuration::instance());
57    if (!c.codon("foo.h")){
58      suite.out() << "No codon for foo.h\n";
59      suite.add(false);
60    }
61    if (!c.codon("/dir/test.cc")){
62      suite.out() << "No codon for test.cc\n";
63      suite.add(false);
64    }
65    if (!c.codon("bootstrap")){
66      suite.out() << "No codon for bootstrap\n";
67      suite.add(false);
68    }
69  }
70 
71  void test_props(test::Suite& suite)
72  {
73    suite.out() << "test props" << std::endl;
74    Configuration& conf(Configuration::instance());
75    std::stringstream ss;
76    ss << "[svn-props]\n"
77       << "foo* = svndigest:ignore\n"
78       << "bar* = svn:eol-style=native;svncopyright:ignore\n";
79    conf.load(ss);
80    const std::map<std::string, std::string>& props =
81      conf.svn_properties("foo_bla_bla");
82    if (props.find("svndigest:ignore")==props.end()) {
83        suite.out() << "property svndigest:ignore not set for foo_bla_bla\n";
84        suite.add(false);
85    }
86    const std::map<std::string, std::string>& props2 =
87      conf.svn_properties("bar_bla_bla");
88    std::map<std::string, std::string>::const_iterator it =
89      props2.find("svn:eol-style");
90    if (!suite.add(it != props2.end()))
91      suite.out() <<"expected property 'svn:eol-style' set for bar_bla_bla\n";
92    else if (!suite.add(it->second == "native"))
93      suite.out() << "expected 'svn:eol-style' set to 'native' "
94                  << "for bar_bla_bla\n";
95    // checking that we return empty map for files not mentioned in config
96    suite.out() << "props3" << std::endl;
97    const std::map<std::string, std::string>& props3 =
98      conf.svn_properties("nothing-nothing");
99    suite.add(props3.empty());
100  }
101
102  void test_read_write(test::Suite& suite)
103  {
104    Configuration& config = Configuration::instance();
105    std::stringstream ss;
106    ss << config;
107    config.load(ss);
108    std::stringstream ss2;
109    ss2 << config;
110    if (ss2.str() != ss.str()) {
111      suite.out() << "error: configuration output not equal\n";
112      suite.out() << "defalt output:\n" << ss.str() << "\n";
113      suite.out() << "second output:\n" << ss2.str() << "\n";
114      suite.add(false);
115    }
116  }
117
118}} // end of namespace svndigest and theplu
Note: See TracBrowser for help on using the repository browser.