source: trunk/test/trac_test.cc @ 1162

Last change on this file since 1162 was 1162, checked in by Peter Johansson, 13 years ago

new function exit_status in Suite and use it in all C++ tests

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1// $Id: trac_test.cc 1162 2010-08-13 17:30:03Z peter $
2
3/*
4  Copyright (C) 2007, 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 "lib/Configuration.h"
24#include "lib/HtmlStream.h"
25#include "lib/html_utility.h"
26#include "lib/Trac.h"
27
28#include <fstream>
29#include <iostream>
30#include <sstream>
31#include <string>
32
33bool test(std::string mess, std::string href, std::ostream&);
34bool test_no_anchor(std::string str, std::ostream&);
35
36int main(const int argc,const char* argv[])
37{
38  using namespace theplu::svndigest;
39  test::Suite suite(argc, argv);
40  bool ok=true;
41  std::ostream& my_out(std::cout);
42
43  // faking a config file
44  Configuration& conf = Configuration::instance();
45  std::stringstream ss;
46  ss << "[trac]\ntrac-root = http://trac.domain.org/\n";
47  conf.load(ss);
48
49 
50  ok &= test("r123", conf.trac_root()+"changeset/123", my_out);
51  ok &= test("[123]", conf.trac_root()+"changeset/123", my_out);
52  ok &= test("changeset:123", conf.trac_root()+"changeset/123", my_out);
53  ok &= test("comment:ticket:123:1", 
54             conf.trac_root()+"ticket/123#comment:1", my_out);
55  ok &= test("diff:trunk@12:123", conf.trac_root()+
56             "changeset?new=123&amp;new_path=trunk&amp;"+
57             "old=12&amp;old_path=trunk", 
58             my_out);
59  ok &= test("diff:tags/1.0", conf.trac_root()+
60             "changeset?new_path=tags/1.0&amp;old_path=tags/1.0", 
61             my_out);
62  ok &= test("diff:tags/1.0//tags/1.0.1", conf.trac_root()+
63             "changeset?new_path=tags/1.0.1&amp;old_path=tags/1.0", 
64             my_out);
65  ok &= test("diff:tags/1.0@123//trunk@236", conf.trac_root()+
66             "changeset?new=236&amp;new_path=trunk&amp;"+
67             "old=123&amp;old_path=tags/1.0", 
68             my_out);
69  ok &= test("r123:236", conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
70             my_out);
71  ok &= test("[123:236]",conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
72             my_out);
73  ok &= test("log:trunk@123:236", 
74             conf.trac_root()+"log/trunk?rev=236&amp;stop_rev=123", my_out);
75  ok &= test("milestone:1.0", conf.trac_root()+"milestone/1.0", my_out);
76  ok &= test("source:trunk", conf.trac_root()+"browser/trunk", my_out);
77  ok &= test("source:trunk@123", conf.trac_root()+"browser/trunk?rev=123", 
78             my_out);
79  ok &= test("source:trunk@123#L3", 
80             conf.trac_root()+"browser/trunk?rev=123#L3", my_out);
81  ok &= test("#65", conf.trac_root()+"ticket/65", my_out);
82  ok &= test("ticket:65", conf.trac_root()+"ticket/65", my_out);
83  ok &= test_no_anchor("Container2D", my_out);
84  ok &= test_no_anchor("r2b", my_out);
85  ok &= test_no_anchor("ar2", my_out);
86  ok &= test_no_anchor("2r2", my_out);
87  ok &= test_no_anchor("r2r3", my_out);
88  ok &= test_no_anchor("ar2:3", my_out);
89  ok &= test_no_anchor("r2:3a", my_out);
90
91  suite.add(ok);
92  return suite.exit_status();
93}
94
95bool test(std::string mess, std::string href, std::ostream& out)
96{
97  using namespace theplu::svndigest;
98  std::stringstream ss;
99  HtmlStream html(ss);
100  Trac trac(html);
101  trac.print(mess,80);
102  if (ss.str()==anchor(href, mess))
103    return true;
104  out << "error:\n";
105  out << "  message: " << mess << std::endl;
106  out << "  trac generates output:\n     " << ss.str() << std::endl;
107  out << "  expected:\n     " << anchor(href, mess) << std::endl;
108  return false;
109}
110
111bool test_no_anchor(std::string str, std::ostream& os)
112{
113  using namespace theplu::svndigest;
114  std::stringstream ss;
115  HtmlStream html(ss);
116  Trac trac(html);
117  trac.print(str,80);
118  if (ss.str()!=str) {
119    os << "error:\n";
120    os << "  message: " << str << std::endl;
121    os << "  trac generates output:\n     " << ss.str() << std::endl;
122    os << "  expected:\n     " << str << std::endl;
123    return false;
124  }
125  return true;
126}
Note: See TracBrowser for help on using the repository browser.