source: trunk/test/config_test.cc @ 1152

Last change on this file since 1152 was 1152, checked in by Peter Johansson, 11 years ago

allow config file to override svn property (fixes #326). Adding two new files (split.h and split.cc) from yat.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: config_test.cc 1152 2010-08-07 14:31:18Z peter $
2
3/*
4  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010 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
27namespace theplu{
28namespace svndigest{
29  void test_codon(test::Suite&);
30  void test_read_write(test::Suite&);
31  void test_props(test::Suite&);
32}} // end of namespace svndigest and theplu
33
34
35int main( int argc, char* argv[])
36{
37  using namespace theplu::svndigest;
38  test::Suite suite(argc, argv, false);
39
40  test_codon(suite);
41  test_read_write(suite);
42  test_props(suite);
43                                                                               
44  if (suite.ok()) {
45    suite.out() << "Test is Ok!" << std::endl;
46    return 0;
47  }
48  suite.out() << "Test failed." << std::endl;
49  return 1;
50}
51
52
53namespace theplu{
54namespace svndigest{
55
56  void test_codon(test::Suite& suite)
57  {
58    suite.out() << "test codons" << std::endl;
59    const Configuration& c(Configuration::instance());
60    if (!c.codon("foo.h")){
61      suite.out() << "No codon for foo.h\n";
62      suite.add(false);
63    }
64    if (!c.codon("/dir/test.cc")){
65      suite.out() << "No codon for test.cc\n";
66      suite.add(false);
67    }
68    if (!c.codon("bootstrap")){
69      suite.out() << "No codon for bootstrap\n";
70      suite.add(false);
71    }
72  }
73 
74  void test_props(test::Suite& suite)
75  {
76    suite.out() << "test props" << std::endl;
77    Configuration& conf(Configuration::instance());
78    std::stringstream ss;
79    ss << "[svn_props]\n"
80       << "foo* = svndigest:ignore\n"
81       << "bar* = svn:eol-style=native;svncopyright:ignore\n";
82    conf.load(ss);
83    const std::map<std::string, std::string>& props =
84      conf.svn_properties("foo_bla_bla");
85    if (props.find("svndigest:ignore")==props.end()) {
86        suite.out() << "property svndigest:ignore not set for foo_bla_bla\n";
87        suite.add(false);
88    }
89    const std::map<std::string, std::string>& props2 =
90      conf.svn_properties("bar_bla_bla");
91    std::map<std::string, std::string>::const_iterator it =
92      props2.find("svn:eol-style");
93    if (!suite.add(it != props2.end()))
94      suite.out() <<"expected property 'svn:eol-style' set for bar_bla_bla\n";
95    else if (!suite.add(it->second == "native"))
96      suite.out() << "expected 'svn:eol-style' set to 'native' "
97                  << "for bar_bla_bla\n";
98    // checking that we return empty map for files not mentioned in config
99    suite.out() << "props3" << std::endl;
100    const std::map<std::string, std::string>& props3 =
101      conf.svn_properties("nothing-nothing");
102    suite.add(props3.empty());
103  }
104
105  void test_read_write(test::Suite& suite)
106  {
107    Configuration& config = Configuration::instance();
108    std::stringstream ss;
109    ss << config;
110    config.load(ss);
111    std::stringstream ss2;
112    ss2 << config;
113    if (ss2.str() != ss.str()) {
114      suite.out() << "error: configuration output not equal\n";
115      suite.out() << "defalt output:\n" << ss.str() << "\n";
116      suite.out() << "second output:\n" << ss2.str() << "\n";
117      suite.add(false);
118    }
119  }
120
121}} // end of namespace svndigest and theplu
Note: See TracBrowser for help on using the repository browser.