Changeset 594
- Timestamp:
- Apr 14, 2008, 5:24:02 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/copyright.cc
r592 r594 31 31 #include <fstream> 32 32 #include <string> 33 #include <vector> 34 35 std::vector<std::string> copyright_lines(std::istream&); 33 36 34 37 int main( int argc, char* argv[]) … … 36 39 using namespace theplu::svndigest; 37 40 bool verbose=false; 41 bool ok=true; 38 42 if (argc>1 && argv[1]==std::string("-v") ) 39 43 verbose=true; 40 44 41 45 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 42 72 if (verbose) 43 73 std::cout << "Create SVN instance" << std::endl; … … 52 82 if (verbose) 53 83 std::cout << "Create File object" << std::endl; 54 File file(0, root+"/README","");84 File file(0,filename,""); 55 85 56 86 if (verbose) … … 63 93 file.print_copyright(alias, verbose); 64 94 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 } 65 105 if (verbose) 66 std::cout << " Done!" << std::endl;67 return 0;106 std::cout << "Test failed." << std::endl; 107 return 1; 68 108 } 69 109 110 std::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.