Changeset 801


Ignore:
Timestamp:
Jul 6, 2009, 4:07:42 AM (12 years ago)
Author:
Peter Johansson
Message:

working on the test for partial cache. refs #338

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/StatsCollection.h

    r693 r801  
    6060
    6161    /**
    62        reset everything
    6362     */
    6463    void print(std::ostream&);
  • trunk/test/Makefile.am

    r795 r801  
    44
    55# Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    6 # Copyright (C) 2009 Peter Johansson
    7 # Copyright (C) 2008 Peter Johansson
     6# Copyright (C) 2008, 2009 Peter Johansson
    87#
    98# This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    3130
    3231# tests not yet passing are listed here
    33 XFAIL_TESTS = cache_partial_test
     32XFAIL_TESTS =
    3433
    3534noinst_HEADERS = Suite.h
  • trunk/test/Suite.cc

    r744 r801  
    2525#include "environment.h"
    2626
    27 #include "utility.h"
     27#include "Stats.h"
     28#include "StatsCollection.h"
     29#include "../lib/utility.h"
    2830
    2931#include <cassert>
     
    9092
    9193
     94  bool equal(const StatsCollection& a, const StatsCollection& b,
     95             Suite& suite)
     96  {
     97    if (a.stats().size() != b.stats().size()) {
     98      suite.out() << "size mismatch\n";
     99      return false;
     100    }
     101    std::map<std::string, Stats*>::const_iterator iter1 = a.stats().begin();
     102    std::map<std::string, Stats*>::const_iterator iter2 = b.stats().begin();
     103    while (iter1 != a.stats().end()) {
     104      if (iter1->first != iter2->first) {
     105        suite.out() << "key mismatch\n";
     106        suite.out() << iter1->first << " vs " << iter2->first << "\n";
     107        return false;
     108      }
     109      if (!equal(*iter1->second, *iter2->second, suite)) {
     110        suite.out() << "error in " << iter1->first << "\n";
     111        return false;
     112      }
     113      ++iter1;
     114      ++iter2;
     115    }
     116    return true;
     117  }
     118 
     119
     120  bool equal(const Stats& a, const Stats& b, test::Suite& suite)
     121  {
     122    if (a.authors() != b.authors()) {
     123      suite.out() << "authors are not equal\n";
     124      return false;
     125    }
     126    if (a.revision() != b.revision()) {
     127      suite.out() << "revision mismatch\n";
     128      return false;
     129    }
     130    std::vector<std::string> authors;
     131    authors.reserve(a.authors().size()+1);
     132    std::copy(a.authors().begin(), a.authors().end(),
     133              std::back_inserter(authors));
     134    authors.push_back("all");
     135    for (int linetype=0; linetype <= LineTypeParser::total; ++linetype) {
     136      for (std::vector<std::string>::const_iterator author=authors.begin();
     137           author!=authors.end(); ++author) {
     138        for (svn_revnum_t rev=0; rev<a.revision(); ++rev) {
     139          size_t ax = a(linetype, *author, rev);
     140          size_t bx = b(linetype, *author, rev);
     141          if (ax != bx) {
     142            suite.out() << "error: linetype: " << linetype
     143                        << " author " << *author 
     144                        << " rev " << rev << "\n"
     145                        << "   a: " << ax << "\n"
     146                        << "   b: " << bx << "\n";
     147            return false;
     148          }
     149        }
     150      }
     151    }
     152    return true;
     153  }
     154
     155
    92156  void Suite::update_test_wc(void) const
    93157  {
     
    114178
    115179
     180  std::string src_filename(const std::string& path)
     181  {
     182    return abs_srcdir()+"/"+path;
     183  }
     184
     185
    116186}}}
  • trunk/test/Suite.h

    r744 r801  
    2929namespace theplu {
    3030namespace svndigest {
     31  class Stats;
     32  class StatsCollection;
     33
    3134namespace test {
    3235
     
    6568  };
    6669
     70  bool equal(const StatsCollection& a, const StatsCollection& b,
     71             test::Suite& suite);
     72
     73  bool equal(const Stats& a, const Stats& b, test::Suite& suite);
     74
    6775  /**
    6876     \return absolute path to file
    69      \param local_path path relative to srcdir
     77     \param local_path path relative to builddir
    7078   */
    7179  std::string filename(const std::string& local_path);
    7280
     81  /**
     82     \return absolute path to file
     83     \param path path relative to srcdir
     84   */
     85  std::string src_filename(const std::string& path);
    7386}}}
    7487
  • trunk/test/cache_partial_test.cc

    r794 r801  
    2424#include "Suite.h"
    2525
     26#include "File.h"
     27#include "SVN.h"
     28#include "SVNinfo.h"
     29
     30#include "../lib/utility.h"
     31
    2632#include <iostream>
     33
     34using namespace theplu::svndigest;
    2735
    2836int main( int argc, char* argv[])
    2937{
    30   using namespace theplu::svndigest;
    3138  test::Suite suite(argc, argv, true);
    3239
    33   suite.add(false);
     40  mkdir_p(test::filename("toy_project/.svndigest"));
     41  std::string root=test::filename("toy_project");
     42  std::string filename = root + "/AUTHORS";
     43  suite.out() << "Create SVN instance" << std::endl;
     44  SVN* svn=SVN::instance(root);
     45  if (!svn)
     46    return 1;
     47  // Extract repository location
     48  suite.out() << "Extract repository location" << std::endl;
     49  std::string repo=SVNinfo(root).repos_root_url();
     50
     51  // create file ignoring cache file
     52  std::string cache_file =
     53    test::filename("toy_project/.svndigest/AUTHORS.svndigest-cache");
     54  File file(0,filename,"");
     55  const StatsCollection& stats1 = file.parse(suite.verbose(), true);
     56
     57  // create file using partial cache
     58  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
     59  File file2(0,filename,"");
     60  const StatsCollection& stats2 = file2.parse(suite.verbose(), false);
     61
     62  suite.add(equal(stats1, stats2, suite));
    3463
    3564  if (suite.ok()) {
     
    4271
    4372
     73
     74
Note: See TracChangeset for help on using the changeset viewer.