source: trunk/test/trac_test.cc @ 1119

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

move lib/yat to yat. close #461

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1// $Id: trac_test.cc 1119 2010-07-04 18:34:07Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009 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  bool ok=true;
40  std::ostream& my_out(std::cout);
41
42  // faking a config file
43  Configuration& conf = Configuration::instance();
44  std::stringstream ss;
45  ss << "[trac]\ntrac-root = http://trac.domain.org/\n";
46  conf.load(ss);
47
48 
49  ok &= test("r123", conf.trac_root()+"changeset/123", my_out);
50  ok &= test("[123]", conf.trac_root()+"changeset/123", my_out);
51  ok &= test("changeset:123", conf.trac_root()+"changeset/123", my_out);
52  ok &= test("comment:ticket:123:1", 
53             conf.trac_root()+"ticket/123#comment:1", my_out);
54  ok &= test("diff:trunk@12:123", conf.trac_root()+
55             "changeset?new=123&amp;new_path=trunk&amp;"+
56             "old=12&amp;old_path=trunk", 
57             my_out);
58  ok &= test("diff:tags/1.0", conf.trac_root()+
59             "changeset?new_path=tags/1.0&amp;old_path=tags/1.0", 
60             my_out);
61  ok &= test("diff:tags/1.0//tags/1.0.1", conf.trac_root()+
62             "changeset?new_path=tags/1.0.1&amp;old_path=tags/1.0", 
63             my_out);
64  ok &= test("diff:tags/1.0@123//trunk@236", conf.trac_root()+
65             "changeset?new=236&amp;new_path=trunk&amp;"+
66             "old=123&amp;old_path=tags/1.0", 
67             my_out);
68  ok &= test("r123:236", conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
69             my_out);
70  ok &= test("[123:236]",conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
71             my_out);
72  ok &= test("log:trunk@123:236", 
73             conf.trac_root()+"log/trunk?rev=236&amp;stop_rev=123", my_out);
74  ok &= test("milestone:1.0", conf.trac_root()+"milestone/1.0", my_out);
75  ok &= test("source:trunk", conf.trac_root()+"browser/trunk", my_out);
76  ok &= test("source:trunk@123", conf.trac_root()+"browser/trunk?rev=123", 
77             my_out);
78  ok &= test("source:trunk@123#L3", 
79             conf.trac_root()+"browser/trunk?rev=123#L3", my_out);
80  ok &= test("#65", conf.trac_root()+"ticket/65", my_out);
81  ok &= test("ticket:65", conf.trac_root()+"ticket/65", my_out);
82  ok &= test_no_anchor("Container2D", my_out);
83  ok &= test_no_anchor("r2b", my_out);
84  ok &= test_no_anchor("ar2", my_out);
85  ok &= test_no_anchor("2r2", my_out);
86  ok &= test_no_anchor("r2r3", my_out);
87  ok &= test_no_anchor("ar2:3", my_out);
88  ok &= test_no_anchor("r2:3a", my_out);
89
90  if (ok)
91    return 0;
92  return -1;
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.