794 |
27 Jun 09 |
peter |
// $Id$ |
794 |
27 Jun 09 |
peter |
2 |
|
794 |
27 Jun 09 |
peter |
3 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2010, 2012, 2023 Peter Johansson |
794 |
27 Jun 09 |
peter |
5 |
|
794 |
27 Jun 09 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
794 |
27 Jun 09 |
peter |
7 |
|
794 |
27 Jun 09 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
794 |
27 Jun 09 |
peter |
under the terms of the GNU General Public License as published by |
794 |
27 Jun 09 |
peter |
the Free Software Foundation; either version 3 of the License, or |
794 |
27 Jun 09 |
peter |
(at your option) any later version. |
794 |
27 Jun 09 |
peter |
12 |
|
794 |
27 Jun 09 |
peter |
svndigest is distributed in the hope that it will be useful, but |
794 |
27 Jun 09 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
794 |
27 Jun 09 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
794 |
27 Jun 09 |
peter |
General Public License for more details. |
794 |
27 Jun 09 |
peter |
17 |
|
794 |
27 Jun 09 |
peter |
You should have received a copy of the GNU General Public License |
794 |
27 Jun 09 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
794 |
27 Jun 09 |
peter |
20 |
*/ |
794 |
27 Jun 09 |
peter |
21 |
|
794 |
27 Jun 09 |
peter |
// Testing that partial cache works fine, ticket #338. |
794 |
27 Jun 09 |
peter |
23 |
|
1619 |
12 Mar 23 |
peter |
24 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
25 |
|
794 |
27 Jun 09 |
peter |
26 |
#include "Suite.h" |
794 |
27 Jun 09 |
peter |
27 |
|
1124 |
07 Jul 10 |
peter |
28 |
#include "lib/AddStats.h" |
1119 |
04 Jul 10 |
peter |
29 |
#include "lib/File.h" |
1119 |
04 Jul 10 |
peter |
30 |
#include "lib/SVN.h" |
1119 |
04 Jul 10 |
peter |
31 |
#include "lib/SVNinfo.h" |
1124 |
07 Jul 10 |
peter |
32 |
#include "lib/StatsCollection.h" |
1119 |
04 Jul 10 |
peter |
33 |
#include "lib/utility.h" |
801 |
06 Jul 09 |
peter |
34 |
|
1321 |
28 Nov 10 |
peter |
35 |
#include <fstream> |
794 |
27 Jun 09 |
peter |
36 |
#include <iostream> |
794 |
27 Jun 09 |
peter |
37 |
|
801 |
06 Jul 09 |
peter |
38 |
using namespace theplu::svndigest; |
801 |
06 Jul 09 |
peter |
39 |
|
794 |
27 Jun 09 |
peter |
40 |
int main( int argc, char* argv[]) |
794 |
27 Jun 09 |
peter |
41 |
{ |
794 |
27 Jun 09 |
peter |
42 |
test::Suite suite(argc, argv, true); |
794 |
27 Jun 09 |
peter |
43 |
|
1092 |
12 Jun 10 |
peter |
44 |
mkdir_p("toy_project/.svndigest"); |
1092 |
12 Jun 10 |
peter |
45 |
std::string root="toy_project"; |
801 |
06 Jul 09 |
peter |
46 |
std::string filename = root + "/AUTHORS"; |
801 |
06 Jul 09 |
peter |
47 |
suite.out() << "Create SVN instance" << std::endl; |
801 |
06 Jul 09 |
peter |
48 |
SVN* svn=SVN::instance(root); |
801 |
06 Jul 09 |
peter |
49 |
if (!svn) |
801 |
06 Jul 09 |
peter |
50 |
return 1; |
801 |
06 Jul 09 |
peter |
// Extract repository location |
801 |
06 Jul 09 |
peter |
52 |
suite.out() << "Extract repository location" << std::endl; |
801 |
06 Jul 09 |
peter |
53 |
std::string repo=SVNinfo(root).repos_root_url(); |
794 |
27 Jun 09 |
peter |
54 |
|
801 |
06 Jul 09 |
peter |
// create file ignoring cache file |
1104 |
15 Jun 10 |
peter |
56 |
std::string cache_file = "toy_project/.svndigest/AUTHORS.svndigest-cache"; |
801 |
06 Jul 09 |
peter |
57 |
File file(0,filename,""); |
1478 |
29 May 12 |
peter |
58 |
const StatsCollection& stats1 = file.parse(suite.verbose(), true, 0); |
803 |
10 Jul 09 |
peter |
59 |
suite.add(test::consistent(stats1, suite)); |
801 |
06 Jul 09 |
peter |
60 |
|
801 |
06 Jul 09 |
peter |
// create file using partial cache |
801 |
06 Jul 09 |
peter |
62 |
copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file); |
801 |
06 Jul 09 |
peter |
63 |
File file2(0,filename,""); |
1478 |
29 May 12 |
peter |
64 |
const StatsCollection& stats2 = file2.parse(suite.verbose(), false, 0); |
803 |
10 Jul 09 |
peter |
65 |
suite.add(test::consistent(stats2, suite)); |
801 |
06 Jul 09 |
peter |
66 |
|
801 |
06 Jul 09 |
peter |
67 |
suite.add(equal(stats1, stats2, suite)); |
801 |
06 Jul 09 |
peter |
68 |
|
1122 |
07 Jul 10 |
peter |
// test that load of partial cache is successful |
1122 |
07 Jul 10 |
peter |
70 |
copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file); |
1124 |
07 Jul 10 |
peter |
71 |
AddStats cstats(filename); |
1122 |
07 Jul 10 |
peter |
72 |
std::ifstream is(cache_file.c_str()); |
1124 |
07 Jul 10 |
peter |
73 |
bool cache_ok=true; |
1611 |
12 Feb 23 |
peter |
74 |
suite.out() << "===\n"; |
1124 |
07 Jul 10 |
peter |
75 |
cstats.load_cache(is, cache_ok); |
1611 |
12 Feb 23 |
peter |
76 |
suite.out() << "beta \n"; |
1124 |
07 Jul 10 |
peter |
77 |
cstats.load_cache(is, cache_ok); |
1124 |
07 Jul 10 |
peter |
78 |
svn_revnum_t rev = cstats.load_cache(is, cache_ok); |
1611 |
12 Feb 23 |
peter |
79 |
suite.out() << "rev " << rev << "\n"; |
1124 |
07 Jul 10 |
peter |
80 |
if (!cache_ok) { |
1124 |
07 Jul 10 |
peter |
81 |
suite.out() << "error: seems cache file " << cache_file << " is old\n"; |
1124 |
07 Jul 10 |
peter |
82 |
suite.add(false); |
1124 |
07 Jul 10 |
peter |
83 |
} |
1122 |
07 Jul 10 |
peter |
84 |
if (rev!=48) { |
1122 |
07 Jul 10 |
peter |
85 |
suite.out() << "load cache: " << cache_file << " returned " << rev << "\n" |
1122 |
07 Jul 10 |
peter |
86 |
<< " expected 48\n"; |
1122 |
07 Jul 10 |
peter |
87 |
suite.add(false); |
1122 |
07 Jul 10 |
peter |
88 |
} |
1122 |
07 Jul 10 |
peter |
89 |
is.close(); |
1122 |
07 Jul 10 |
peter |
90 |
|
1611 |
12 Feb 23 |
peter |
91 |
suite.out() << "return\n"; |
1162 |
13 Aug 10 |
peter |
92 |
return suite.exit_status(); |
794 |
27 Jun 09 |
peter |
93 |
} |
794 |
27 Jun 09 |
peter |
94 |
|
794 |
27 Jun 09 |
peter |
95 |
|
801 |
06 Jul 09 |
peter |
96 |
|
801 |
06 Jul 09 |
peter |
97 |
|