source: trunk/test/trac_test.cc @ 768

Last change on this file since 768 was 768, checked in by Peter Johansson, 12 years ago

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1// $Id: trac_test.cc 768 2009-01-31 21:30:37Z peter $
2
3/*
4  Copyright (C) 2007, 2008, 2009 Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Configuration.h"
23#include "HtmlStream.h"
24#include "html_utility.h"
25#include "Trac.h"
26
27#include <fstream>
28#include <iostream>
29#include <sstream>
30#include <string>
31
32bool test(std::string mess, std::string href, std::ostream&);
33bool test_no_anchor(std::string str, std::ostream&);
34
35int main(const int argc,const char* argv[])
36{
37  using namespace theplu::svndigest;
38  bool ok=true;
39  std::ostream& my_out(std::cout);
40
41  // faking a config file
42  Configuration& conf = Configuration::instance();
43  std::stringstream ss;
44  ss << "[trac]\ntrac-root = http://trac.domain.org/\n";
45  conf.load(ss);
46
47 
48  ok &= test("r123", conf.trac_root()+"changeset/123", my_out);
49  ok &= test("[123]", conf.trac_root()+"changeset/123", my_out);
50  ok &= test("changeset:123", conf.trac_root()+"changeset/123", my_out);
51  ok &= test("comment:ticket:123:1", 
52             conf.trac_root()+"ticket/123#comment:1", my_out);
53  ok &= test("diff:trunk@12:123", conf.trac_root()+
54             "changeset?new=123&amp;new_path=trunk&amp;"+
55             "old=12&amp;old_path=trunk", 
56             my_out);
57  ok &= test("diff:tags/1.0", conf.trac_root()+
58             "changeset?new_path=tags/1.0&amp;old_path=tags/1.0", 
59             my_out);
60  ok &= test("diff:tags/1.0//tags/1.0.1", conf.trac_root()+
61             "changeset?new_path=tags/1.0.1&amp;old_path=tags/1.0", 
62             my_out);
63  ok &= test("diff:tags/1.0@123//trunk@236", conf.trac_root()+
64             "changeset?new=236&amp;new_path=trunk&amp;"+
65             "old=123&amp;old_path=tags/1.0", 
66             my_out);
67  ok &= test("r123:236", conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
68             my_out);
69  ok &= test("[123:236]",conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
70             my_out);
71  ok &= test("log:trunk@123:236", 
72             conf.trac_root()+"log/trunk?rev=236&amp;stop_rev=123", my_out);
73  ok &= test("milestone:1.0", conf.trac_root()+"milestone/1.0", my_out);
74  ok &= test("source:trunk", conf.trac_root()+"browser/trunk", my_out);
75  ok &= test("source:trunk@123", conf.trac_root()+"browser/trunk?rev=123", 
76             my_out);
77  ok &= test("source:trunk@123#L3", 
78             conf.trac_root()+"browser/trunk?rev=123#L3", my_out);
79  ok &= test("#65", conf.trac_root()+"ticket/65", my_out);
80  ok &= test("ticket:65", conf.trac_root()+"ticket/65", my_out);
81  ok &= test_no_anchor("Container2D", my_out);
82  ok &= test_no_anchor("r2b", my_out);
83  ok &= test_no_anchor("ar2", my_out);
84  ok &= test_no_anchor("2r2", my_out);
85  ok &= test_no_anchor("r2r3", my_out);
86  ok &= test_no_anchor("ar2:3", my_out);
87  ok &= test_no_anchor("r2:3a", my_out);
88
89  if (ok)
90    return 0;
91  return -1;
92}
93
94bool test(std::string mess, std::string href, std::ostream& out)
95{
96  using namespace theplu::svndigest;
97  std::stringstream ss;
98  HtmlStream html(ss);
99  Trac trac(html);
100  trac.print(mess,80);
101  if (ss.str()==anchor(href, mess))
102    return true;
103  out << "error:\n";
104  out << "  message: " << mess << std::endl;
105  out << "  trac generates output:\n     " << ss.str() << std::endl;
106  out << "  expected:\n     " << anchor(href, mess) << std::endl;
107  return false;
108}
109
110bool test_no_anchor(std::string str, std::ostream& os)
111{
112  using namespace theplu::svndigest;
113  std::stringstream ss;
114  HtmlStream html(ss);
115  Trac trac(html);
116  trac.print(str,80);
117  if (ss.str()!=str) {
118    os << "error:\n";
119    os << "  message: " << str << std::endl;
120    os << "  trac generates output:\n     " << ss.str() << std::endl;
121    os << "  expected:\n     " << str << std::endl;
122    return false;
123  }
124  return true;
125}
Note: See TracBrowser for help on using the repository browser.