source: trunk/test/trac.cc @ 373

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

fixing truncation issue in log message. fixes #188

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: trac.cc 317 2007-05-17 18:49:09Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://lev.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&new_path=trunk&old=12&old_path=trunk", 
56             my_out);
57  ok &= test("diff:tags/1.0", conf.trac_root()+
58             "changeset?new_path=tags/1.0&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&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&new_path=trunk&old=123&old_path=tags/1.0", 
65             my_out);
66  ok &= test("r123:236", conf.trac_root()+"log/?rev=236&stop_rev=123", my_out);
67  ok &= test("[123:236]",conf.trac_root()+"log/?rev=236&stop_rev=123", my_out);
68  ok &= test("log:trunk@123:236", 
69             conf.trac_root()+"log/trunk?rev=236&stop_rev=123", my_out);
70  ok &= test("milestone:1.0", conf.trac_root()+"milestone/1.0", my_out);
71  ok &= test("source:trunk", conf.trac_root()+"browser/trunk", my_out);
72  ok &= test("source:trunk@123", conf.trac_root()+"browser/trunk?rev=123", 
73             my_out);
74  ok &= test("source:trunk@123#L3", 
75             conf.trac_root()+"browser/trunk?rev=123#L3", my_out);
76  ok &= test("#65", conf.trac_root()+"ticket/65", my_out);
77  ok &= test("ticket:65", conf.trac_root()+"ticket/65", my_out);
78
79  if (ok)
80    return 0;
81  return -1;
82}
83
84bool test(std::string mess, std::string href, std::ostream& out)
85{
86  using namespace theplu::svndigest;
87  std::stringstream ss;
88  HtmlStream html(ss);
89  Trac trac(html);
90  trac.print(mess,80);
91  if (ss.str()==anchor(href, mess))
92    return true;
93  out << "error:\n";
94  out << "  message: " << mess << std::endl;
95  out << "  trac generates output:\n     " << ss.str() << std::endl;
96  out << "  expected:\n     " << anchor(href, mess) << std::endl;
97  return false;
98}
99
Note: See TracBrowser for help on using the repository browser.