source: trunk/test/trac_test.cc @ 1163

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

Oops. Fix some mess up in previous commit

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