source: trunk/test/cache_partial.cc @ 1321

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

updating includes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: cache_partial.cc 1321 2010-11-28 23:41:31Z 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 <fstream>
34#include <iostream>
35
36using namespace theplu::svndigest;
37
38int main( int argc, char* argv[])
39{
40  test::Suite suite(argc, argv, true);
41
42  mkdir_p("toy_project/.svndigest");
43  std::string root="toy_project";
44  std::string filename = root + "/AUTHORS";
45  suite.out() << "Create SVN instance" << std::endl;
46  SVN* svn=SVN::instance(root);
47  if (!svn)
48    return 1;
49  // Extract repository location
50  suite.out() << "Extract repository location" << std::endl;
51  std::string repo=SVNinfo(root).repos_root_url();
52
53  // create file ignoring cache file
54  std::string cache_file = "toy_project/.svndigest/AUTHORS.svndigest-cache";
55  File file(0,filename,"");
56  const StatsCollection& stats1 = file.parse(suite.verbose(), true);
57  suite.add(test::consistent(stats1, suite));
58
59  // create file using partial cache
60  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
61  File file2(0,filename,"");
62  const StatsCollection& stats2 = file2.parse(suite.verbose(), false);
63  suite.add(test::consistent(stats2, suite));
64
65  suite.add(equal(stats1, stats2, suite));
66
67  // test that load of partial cache is successful
68  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
69  AddStats cstats(filename);
70  std::ifstream is(cache_file.c_str());
71  bool cache_ok=true;
72  cstats.load_cache(is, cache_ok);
73  cstats.load_cache(is, cache_ok);
74  svn_revnum_t rev = cstats.load_cache(is, cache_ok);
75  if (!cache_ok) {
76    suite.out() << "error: seems cache file " << cache_file << " is old\n";
77    suite.add(false);
78  }
79  if (rev!=48) {
80    suite.out() << "load cache: " << cache_file << " returned " << rev << "\n"
81                << " expected 48\n";
82    suite.add(false);
83  }
84  is.close();
85
86  return suite.exit_status();
87}
88
89
90
91
Note: See TracBrowser for help on using the repository browser.