source: trunk/test/stats_test.cc @ 596

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

added testlib to share code between different tests

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