source: trunk/test/trac_test.cc @ 693

Last change on this file since 693 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: trac_test.cc 693 2008-09-11 20:42:56Z jari $
2
3/*
4  Copyright (C) 2007 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&);
33
34int main(const int argc,const char* argv[])
35{
36  using namespace theplu::svndigest;
37  bool ok=true;
38  std::ostream& my_out(std::cout);
39
40  // faking a config file
41  Configuration& conf = Configuration::instance();
42  std::stringstream ss;
43  ss << "[trac]\ntrac-root = http://trac.domain.org/\n";
44  conf.load(ss);
45
46 
47  ok &= test("r123", conf.trac_root()+"changeset/123", my_out);
48  ok &= test("[123]", conf.trac_root()+"changeset/123", my_out);
49  ok &= test("changeset:123", conf.trac_root()+"changeset/123", my_out);
50  ok &= test("comment:ticket:123:1", 
51             conf.trac_root()+"ticket/123#comment:1", my_out);
52  ok &= test("diff:trunk@12:123", conf.trac_root()+
53             "changeset?new=123&amp;new_path=trunk&amp;"+
54             "old=12&amp;old_path=trunk", 
55             my_out);
56  ok &= test("diff:tags/1.0", conf.trac_root()+
57             "changeset?new_path=tags/1.0&amp;old_path=tags/1.0", 
58             my_out);
59  ok &= test("diff:tags/1.0//tags/1.0.1", conf.trac_root()+
60             "changeset?new_path=tags/1.0.1&amp;old_path=tags/1.0", 
61             my_out);
62  ok &= test("diff:tags/1.0@123//trunk@236", conf.trac_root()+
63             "changeset?new=236&amp;new_path=trunk&amp;"+
64             "old=123&amp;old_path=tags/1.0", 
65             my_out);
66  ok &= test("r123:236", conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
67             my_out);
68  ok &= test("[123:236]",conf.trac_root()+"log/?rev=236&amp;stop_rev=123", 
69             my_out);
70  ok &= test("log:trunk@123:236", 
71             conf.trac_root()+"log/trunk?rev=236&amp;stop_rev=123", my_out);
72  ok &= test("milestone:1.0", conf.trac_root()+"milestone/1.0", my_out);
73  ok &= test("source:trunk", conf.trac_root()+"browser/trunk", my_out);
74  ok &= test("source:trunk@123", conf.trac_root()+"browser/trunk?rev=123", 
75             my_out);
76  ok &= test("source:trunk@123#L3", 
77             conf.trac_root()+"browser/trunk?rev=123#L3", my_out);
78  ok &= test("#65", conf.trac_root()+"ticket/65", my_out);
79  ok &= test("ticket:65", conf.trac_root()+"ticket/65", my_out);
80
81  if (ok)
82    return 0;
83  return -1;
84}
85
86bool test(std::string mess, std::string href, std::ostream& out)
87{
88  using namespace theplu::svndigest;
89  std::stringstream ss;
90  HtmlStream html(ss);
91  Trac trac(html);
92  trac.print(mess,80);
93  if (ss.str()==anchor(href, mess))
94    return true;
95  out << "error:\n";
96  out << "  message: " << mess << std::endl;
97  out << "  trac generates output:\n     " << ss.str() << std::endl;
98  out << "  expected:\n     " << anchor(href, mess) << std::endl;
99  return false;
100}
101
Note: See TracBrowser for help on using the repository browser.