Ignore:
Timestamp:
Apr 14, 2008, 5:24:02 AM (13 years ago)
Author:
Peter Johansson
Message:

working on copyright test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/copyright.cc

    r592 r594  
    3131#include <fstream>
    3232#include <string>
     33#include <vector>
     34
     35std::vector<std::string> copyright_lines(std::istream&);
    3336
    3437int main( int argc, char* argv[])
     
    3639  using namespace theplu::svndigest;
    3740  bool verbose=false;
     41  bool ok=true;
    3842  if (argc>1 && argv[1]==std::string("-v") )
    3943    verbose=true;
    4044
    4145  std::string root("toy_project");
     46  std::string filename = root + "/README";
     47
     48  // Saving original file
     49  std::ifstream is(filename.c_str());
     50  assert(is.good());
     51  std::string original_file;
     52  std::getline(is, original_file, '\0');
     53  is.close();
     54  is.clear(std::ios::goodbit);
     55
     56  is.open(filename.c_str());
     57  std::vector<std::string> copyrights=copyright_lines(is);
     58  is.close();
     59  is.clear(std::ios::goodbit);
     60
     61  if (copyrights.size()!=1) {
     62    if (verbose){
     63      std::cout << copyrights.size() << " Copyright lines\n";
     64      for (size_t i=0; i<copyrights.size(); ++i)
     65        std::cout << copyrights[i] << "\n";
     66    }
     67    ok = false;
     68  }
     69  else if (verbose)
     70    std::cout << "File containes 1 copyright line.\n";
     71
    4272  if (verbose)
    4373    std::cout << "Create SVN instance" << std::endl;
     
    5282  if (verbose)
    5383    std::cout << "Create File object" << std::endl;
    54   File file(0,root+"/README","");
     84  File file(0,filename,"");
    5585 
    5686  if (verbose)
     
    6393  file.print_copyright(alias, verbose);
    6494
     95  // Restoring file
     96  std::ofstream os(filename.c_str());
     97  assert(os.good());
     98  os << original_file;
     99
     100  if (ok) {
     101    if (verbose)
     102      std::cout << "Test is Ok!" << std::endl;
     103    return 0;
     104  }
    65105  if (verbose)
    66     std::cout << "Done!" << std::endl;
    67   return 0;
     106    std::cout << "Test failed." << std::endl;
     107  return 1;
    68108}
    69109
     110std::vector<std::string> copyright_lines(std::istream& is)
     111{
     112  using namespace theplu::svndigest;
     113  std::vector<std::string> res;
     114  std::string line;
     115  while (std::getline(is, line)){
     116    if (match_begin(line.begin(), line.end(), "Copyright (C)"))
     117      res.push_back(line);
     118  }
     119 
     120  return res;
     121}
     122
Note: See TracChangeset for help on using the changeset viewer.