source: trunk/test/trac.cc @ 444

Last change on this file since 444 was 439, checked in by Peter Johansson, 16 years ago

Merged patch release 0.6.1 to the trunk. Delta 0.6.1 - 0.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1// $Id: trac.cc 439 2007-07-09 21:04:52Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://trac.thep.lu.se/trac/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&);
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
83  if (ok)
84    return 0;
85  return -1;
86}
87
88bool test(std::string mess, std::string href, std::ostream& out)
89{
90  using namespace theplu::svndigest;
91  std::stringstream ss;
92  HtmlStream html(ss);
93  Trac trac(html);
94  trac.print(mess,80);
95  if (ss.str()==anchor(href, mess))
96    return true;
97  out << "error:\n";
98  out << "  message: " << mess << std::endl;
99  out << "  trac generates output:\n     " << ss.str() << std::endl;
100  out << "  expected:\n     " << anchor(href, mess) << std::endl;
101  return false;
102}
103
Note: See TracBrowser for help on using the repository browser.