source: branches/0.6-stable/test/trac.cc @ 761

Last change on this file since 761 was 761, checked in by Peter Johansson, 14 years ago

fixes #353

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1// $Id: trac.cc 761 2009-01-29 12:46:49Z peter $
2
3/*
4  Copyright (C) 2007, 2008 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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Configuration.h"
25#include "HtmlStream.h"
26#include "html_utility.h"
27#include "Trac.h"
28
29#include <fstream>
30#include <iostream>
31#include <sstream>
32#include <string>
33
34bool test(std::string mess, std::string href, std::ostream&);
35bool test_no_anchor(std::string str, std::ostream&);
36
37int main(const int argc,const char* argv[])
38{
39  using namespace theplu::svndigest;
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  if (ok)
92    return 0;
93  return -1;
94}
95
96bool test(std::string mess, std::string href, std::ostream& out)
97{
98  using namespace theplu::svndigest;
99  std::stringstream ss;
100  HtmlStream html(ss);
101  Trac trac(html);
102  trac.print(mess,80);
103  if (ss.str()==anchor(href, mess))
104    return true;
105  out << "error:\n";
106  out << "  message: " << mess << std::endl;
107  out << "  trac generates output:\n     " << ss.str() << std::endl;
108  out << "  expected:\n     " << anchor(href, mess) << std::endl;
109  return false;
110}
111
112bool test_no_anchor(std::string str, std::ostream& os)
113{
114  using namespace theplu::svndigest;
115  std::stringstream ss;
116  HtmlStream html(ss);
117  Trac trac(html);
118  trac.print(str,80);
119  if (ss.str()!=str) {
120    os << "error:\n";
121    os << "  message: " << str << std::endl;
122    os << "  trac generates output:\n     " << ss.str() << std::endl;
123    os << "  expected:\n     " << str << std::endl;
124    return false;
125  }
126  return true;
127}
Note: See TracBrowser for help on using the repository browser.