source: trunk/test/stats_test.cc @ 556

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

Fixing statistics bugs and links on first page

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1// $Id: stats_test.cc 556 2008-01-16 13:35:00Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of svndigest, http://trac.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 "AddStats.h"
25#include "BlameStats.h"
26#include "ClassicStats.h"
27#include "Configuration.h"
28#include "Stats.h"
29#include "SVN.h"
30
31#include <algorithm>
32#include <cassert>
33#include <iterator>
34#include <iostream>
35#include <numeric>
36#include <string>
37
38namespace theplu{
39namespace svndigest{
40
41  /**
42     \param path is path relaive to srcdir
43     \return absolute path
44  */
45  std::string abs_path(std::string path);
46 
47  bool test_add(void);
48  bool test_blame(void);
49  bool test_classic(void);
50 
51}} // end of namespace svndigest and theplu
52
53
54int main( int argc, char* argv[])
55{
56  using namespace theplu::svndigest;
57  bool ok=true;
58  SVN* svn=SVN::instance(abs_path("toy_project"));
59  if (!svn){
60    std::cerr << "error: cannot create SVN instance\n";
61    return 1;
62  }
63
64  ok &= test_add();
65  ok &= test_blame();
66  ok &= test_classic();
67                                                                               
68  if (ok)
69    return 0;
70  return 1;
71}
72
73
74namespace theplu{
75namespace svndigest{
76
77  std::string abs_path(std::string path)
78  {
79    std::string srcdir(getenv("srcdir"));
80    if (path.empty())
81      return srcdir;
82    if (path[path.size()-1]!='/')
83      srcdir.append("/");
84    return srcdir + path;
85  }
86 
87 
88  bool test_add(void)
89  {
90   
91    return true;
92  }
93 
94 
95  bool test_blame(void)
96  {
97    return true;
98  }
99
100 
101  bool test_classic(void)
102  {
103    bool ok =true;
104    std::string path = abs_path("toy_project/bin/svnstat.cc");
105    ClassicStats cs(path);
106    cs.parse(path);
107   
108    if (cs.code()+cs.comments()+cs.empty()!=cs.lines()){
109      std::cerr << "Code plus comments plus empty do not add up to lines\n";
110      std::cerr << "code: " << cs.code() << "\n";
111      std::cerr << "comment: " << cs.comments() << "\n";
112      std::cerr << "empty: " << cs.empty() << "\n";
113      std::cerr << "lines: " << cs.lines() << "\n";
114      return ok = false;
115    }
116
117    // testing copyright lines for peter
118    std::vector<size_t> correct(48);
119    correct[47]=2;
120   
121    std::partial_sum(correct.begin(), correct.end(), correct.begin());
122    for (size_t rev=0; rev<correct.size(); ++rev)
123      if (cs(LineTypeParser::copyright, "peter", rev)!=correct[rev]){
124        std::cerr << "error: copyright peter rev:" << rev << ": found " 
125                  << cs(LineTypeParser::copyright, "peter", rev)
126                  << " expected " << correct[rev] << "\n";
127        ok = false;
128      }
129
130    // testing code lines for jari
131    correct = std::vector<size_t>(48,0);
132    correct[15]=20;
133    correct[16]=1;
134    correct[17]=1;
135    correct[28]=8;
136    correct[30]=54;
137   
138    std::partial_sum(correct.begin(), correct.end(), correct.begin());
139    for (size_t rev=0; rev<correct.size(); ++rev)
140      if (cs(LineTypeParser::code, "jari", rev)!=correct[rev]){
141        std::cerr << "error: code jari rev:" << rev << ": found " 
142                  << cs(LineTypeParser::code, "jari", rev)
143                  << " expected " << correct[rev] << "\n";
144        ok = false;
145      }
146
147    // testing comment lines for jari
148    correct = std::vector<size_t>(48,0);
149    correct[15]=1;
150    correct[28]=13;
151    correct[30]=7;
152   
153    std::partial_sum(correct.begin(), correct.end(), correct.begin());
154    for (size_t rev=0; rev<correct.size(); ++rev)
155      if (cs(LineTypeParser::comment, "jari", rev)!=correct[rev]){
156        std::cerr << "error: comment jari rev:" << rev << ": found " 
157                  << cs(LineTypeParser::comment, "jari", rev)
158                  << " expected " << correct[rev] << "\n";
159        ok = false;
160      }
161
162    // testing blank lines for jari
163    correct = std::vector<size_t>(48,0);
164    correct[15]=10;
165    correct[28]=10;
166    correct[30]=2;
167   
168    std::partial_sum(correct.begin(), correct.end(), correct.begin());
169    for (size_t rev=0; rev<correct.size(); ++rev)
170      if (cs(LineTypeParser::other, "jari", rev)!=correct[rev]){
171        std::cerr << "error: other jari rev:" << rev << ": found " 
172                  << cs(LineTypeParser::other, "jari", rev)
173                  << " expected " << correct[rev] << "\n";
174        ok = false;
175      }
176
177    // testing code all lines for total
178    correct = std::vector<size_t>(48,0);
179    correct[15]=31;
180    correct[16]=1;
181    correct[17]=1;
182    correct[28]=31;
183    correct[30]=63;
184    correct[47]=2;
185
186    std::partial_sum(correct.begin(), correct.end(), correct.begin());
187    for (size_t rev=0; rev<correct.size(); ++rev)
188      if (cs(LineTypeParser::total, "all", rev)!=correct[rev]){
189        std::cerr << "error: total all rev:" << rev << ": found " 
190                  << cs(LineTypeParser::total, "all", rev)
191                  << " expected " << correct[rev] << "\n";
192        ok = false;
193      }
194
195    return ok;
196  }
197 
198}} // end of namespace svndigest and theplu
Note: See TracBrowser for help on using the repository browser.