source: trunk/test/cache_partial_test.cc @ 1124

Last change on this file since 1124 was 1124, checked in by Peter Johansson, 11 years ago

detecting old cache files and re-writing them in new format (version 8). closes #443 and #289

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: cache_partial_test.cc 1124 2010-07-07 05:35:17Z peter $
2
3/*
4  Copyright (C) 2009, 2010 Peter Johansson
5
6  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22// Testing that partial cache works fine, ticket #338.
23
24#include "Suite.h"
25
26#include "lib/AddStats.h"
27#include "lib/File.h"
28#include "lib/SVN.h"
29#include "lib/SVNinfo.h"
30#include "lib/StatsCollection.h"
31#include "lib/utility.h"
32
33#include <iostream>
34
35using namespace theplu::svndigest;
36
37int main( int argc, char* argv[])
38{
39  test::Suite suite(argc, argv, true);
40
41  mkdir_p("toy_project/.svndigest");
42  std::string root="toy_project";
43  std::string filename = root + "/AUTHORS";
44  suite.out() << "Create SVN instance" << std::endl;
45  SVN* svn=SVN::instance(root);
46  if (!svn)
47    return 1;
48  // Extract repository location
49  suite.out() << "Extract repository location" << std::endl;
50  std::string repo=SVNinfo(root).repos_root_url();
51
52  // create file ignoring cache file
53  std::string cache_file = "toy_project/.svndigest/AUTHORS.svndigest-cache";
54  File file(0,filename,"");
55  const StatsCollection& stats1 = file.parse(suite.verbose(), true);
56  suite.add(test::consistent(stats1, suite));
57
58  // create file using partial cache
59  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
60  File file2(0,filename,"");
61  const StatsCollection& stats2 = file2.parse(suite.verbose(), false);
62  suite.add(test::consistent(stats2, suite));
63
64  suite.add(equal(stats1, stats2, suite));
65
66  // test that load of partial cache is successful
67  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
68  AddStats cstats(filename);
69  std::ifstream is(cache_file.c_str());
70  bool cache_ok=true;
71  cstats.load_cache(is, cache_ok);
72  cstats.load_cache(is, cache_ok);
73  svn_revnum_t rev = cstats.load_cache(is, cache_ok);
74  if (!cache_ok) {
75    suite.out() << "error: seems cache file " << cache_file << " is old\n";
76    suite.add(false);
77  }
78  if (rev!=48) {
79    suite.out() << "load cache: " << cache_file << " returned " << rev << "\n"
80                << " expected 48\n";
81    suite.add(false);
82  }
83  is.close();
84
85  if (suite.ok()) {
86    suite.out() << "Test is OK\n";
87    return 0;
88  }
89  suite.out() << "Test failed\n";
90  return 1;
91}
92
93
94
95
Note: See TracBrowser for help on using the repository browser.