Browse Source

- log is now stringstream and not list<string>

master
Andreas Romeyke 3 years ago
parent
commit
c9944088ca
  1. 7
      src/examples/test_bag.cpp
  2. 2
      src/include/bag.hpp
  3. 4
      src/include/bagmetadata.hpp
  4. 4
      src/include/manifest.hpp
  5. 4
      src/include/payload.hpp
  6. 2
      src/include/payloadmanifest.hpp
  7. 2
      src/lib/bagmetadata.cpp
  8. 8
      src/lib/manifest.cpp
  9. 2
      src/lib/payload.cpp
  10. 4
      src/lib/payloadmanifest.cpp
  11. 21
      src/lib/validate_bag.cpp
  12. 7
      test/test_bagmetadata.cpp
  13. 2
      test/test_payload.cpp
  14. 7
      test/test_payloadmanifest.cpp
  15. 7
      test/test_tagmanifest.cpp
  16. 2
      test/testbag.cpp

7
src/examples/test_bag.cpp

@ -11,13 +11,10 @@ int main(int argc, const char *argv[]) {
}
const string dir = argv[1];
Bag bag( dir );
list<string> log;
stringstream log;
bool is_valid = bag.validate(log);
cout << "The bag '"<< dir <<"' is " << (is_valid ? "valid" : "invalid") << endl;
list<string>::const_iterator iterator;
for (iterator = log.begin(); iterator != log.end(); ++iterator) {
std::cout << *iterator << endl;
}
std::cout << log.str() << endl;
return 0;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

2
src/include/bag.hpp

@ -31,7 +31,7 @@ class Bag {
Bag();
Bag(string dfname);
bool store( string dfname);
bool validate( list<string> & log );
bool validate( stringstream & log );
};
#endif
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

4
src/include/bagmetadata.hpp

@ -2,7 +2,7 @@
#define LIBCBAG_BAGMETADATA
#include <string>
#include <map>
#include <list>
#include <sstream>
#include "checksum.hpp"
using namespace std;
@ -32,7 +32,7 @@ class Bagmetadata{
Bagmetadata( string basedir );
bool has_bagmetadata();
map<string,string> get_metadata();
bool validate( list<string> & log );
bool validate( stringstream & log );
bool has_oxum();
oxum_t get_oxum();
bool store( string basedir);

4
src/include/manifest.hpp

@ -2,7 +2,7 @@
#define LIBCBAG_MANIFEST
#include <string>
#include <map>
#include <list>
#include <sstream>
#include "checksum.hpp"
using namespace std;
typedef string filename_t;
@ -15,7 +15,7 @@ class Manifest{
public:
virtual multimap<checksum_string_t,filename_t> get_checksum_file_pairs(checksum_algorithms algorithm);
list<filename_t> get_checksummed_files();
virtual bool validate( list<string> & log );
virtual bool validate( stringstream & log );
void debug();
bool store( string basedir);
};

4
src/include/payload.hpp

@ -3,7 +3,7 @@
#include <string>
#include <list>
#include <boost/filesystem.hpp>
#include <list>
#include <sstream>
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
@ -16,7 +16,7 @@ class Payload{
Payload( string basedir );
list<string> get_all_relative_paths();
list<string> get_all_absolute_paths();
bool validate(list<string> & log);
bool validate(stringstream & log);
bool store( string basedir);
};
#endif

2
src/include/payloadmanifest.hpp

@ -10,7 +10,7 @@ using namespace std;
class Payloadmanifest : public Manifest {
public:
Payloadmanifest( string basedir );
bool validate(list<string> & log);
bool validate( stringstream & log);
};
#endif

2
src/lib/bagmetadata.cpp

@ -88,7 +88,7 @@ map <string,string> Bagmetadata::get_metadata() {
return this->metadata;
}
bool Bagmetadata::validate(list<string> & log ) {
bool Bagmetadata::validate(stringstream & log ) {
bool is_valid = true;
return is_valid;
}

8
src/lib/manifest.cpp

@ -33,7 +33,7 @@ multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksu
return checksum_file_pairs;
}
bool Manifest::validate( list<string> & log ) {
bool Manifest::validate( stringstream & log ) {
Checksum checksum;
bool is_valid = true;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
@ -45,18 +45,18 @@ bool Manifest::validate( list<string> & log ) {
string calc_checksum = checksum.checksum_of_file( file, it->first );
//cout << "\t" << "file="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
if (calc_checksum.empty()) {
log.push_back( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected by file '" + it->second +"', but file was not found");
log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but file was not found" << endl;
is_valid = false;
}
else if (0 != expected_checksum.compare( calc_checksum)) {
// cout << ( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected, but found: '" + calc_checksum + "'") << endl;
log.push_back( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected by file '" + it->second +"', but found: '" + calc_checksum + "'");
log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but found: '" << calc_checksum << "'" << endl;
is_valid = false;
}
fs::path p{ file };
fs::file_status s = fs::status( p );
if (! fs::is_regular_file( p )) {
log.push_back("Bagit file '" + file + "' does not exists in '" + this->basedir + "'");
log << "Bagit file '" << file << "' does not exists in '" << this->basedir << "'" << endl;
}
}
}

2
src/lib/payload.cpp

@ -55,7 +55,7 @@ list<string> Payload::get_all_absolute_paths() {
return strpaths;
}
bool Payload::validate( list<string> & log ) {
bool Payload::validate( stringstream & log ) {
return true;
}

4
src/lib/payloadmanifest.cpp

@ -37,14 +37,14 @@ Payloadmanifest::Payloadmanifest( string basedir ) {
//cout << "PAYLOADMANIFEST constructor, finished" << endl;
}
bool Payloadmanifest::validate( list<string> & log ) {
bool Payloadmanifest::validate( stringstream & log ) {
bool is_valid = true;
bool tmp = Manifest::validate( log );
if (false == tmp) { is_valid = false; }
// check if at least one payload file exist
//cout << "payload_manifest: " << this->manifest_algorithm_files.size() << endl;
if (0 == this->manifest_algorithm_files.size()) {
log.push_back("Bagit payloadmanifest count greater zero expected, but " + to_string(this->manifest_algorithm_files.size()) + " found");
log << "Bagit payloadmanifest count greater zero expected, but " << to_string(this->manifest_algorithm_files.size()) << " found" << endl;
is_valid = false;
}
//cout << "PAYLOADMANIFEST validate, calling debug()" << endl;

21
src/lib/validate_bag.cpp

@ -1,24 +1,25 @@
#include "bag.hpp"
#include <iostream>
#include <sstream>
bool Bag::validate( list<string> & log ) {
bool Bag::validate( stringstream & log ) {
bool is_valid = true;
if (this->bagit_version_major != 0) {
log.push_back( "Bagit major version 0 is expected, but got: " + to_string(this->bagit_version_major));
log << "Bagit major version 0 is expected, but got: " << to_string(this->bagit_version_major) << endl;
is_valid = false;
}
if (this->bagit_version_minor != 97) {
log.push_back( "Bagit minor version 97 is expected, but got: " + to_string(this->bagit_version_minor));
log << "Bagit minor version 97 is expected, but got: " << to_string(this->bagit_version_minor) << endl;
is_valid = false;
}
if (0 != tag_file_character_encoding.compare( "UTF-8" )) {
log.push_back( "Bagit character encoding UTF-8 is expected, but got: " + this->tag_file_character_encoding);
log << "Bagit character encoding UTF-8 is expected, but got: " << this->tag_file_character_encoding << endl;
is_valid = false;
}
if (NULL == this->payload_p) {
log.push_back( "Bagit payload directory 'data/' is expected, but could not found");
log << "Bagit payload directory 'data/' is expected, but could not found" << endl;
is_valid = false;
} else {
bool ret = this->payload_p->validate( log );
@ -30,7 +31,7 @@ bool Bag::validate( list<string> & log ) {
is_valid = false;
} else {
// checksums check
log.push_back( "Bagit payload manifest");
log << "Bagit payload manifest" << endl;
bool ret = this->payloadmanifest_p->validate( log );
if (ret == false) {
is_valid = false;
@ -61,7 +62,7 @@ bool Bag::validate( list<string> & log ) {
int cmp_res = (*it1).compare( *it2);
//cout << "COMP: "<<cmp_res<<" file='"<< (*it1) << "' checksummed file='" << (*it2) << "'" << endl;
if ( cmp_res < 0) {
log.push_back("Bagit warning, file '" + (*it1) + "' in payload has no checksum entry in payload manifest");
log << "Bagit warning, file '" << (*it1) << "' in payload has no checksum entry in payload manifest" << endl;
it1++;
} else if ( cmp_res > 0) {
it2++;
@ -75,7 +76,7 @@ bool Bag::validate( list<string> & log ) {
// next elements are optional
if (NULL == this->tagmanifest_p) {
} else {
log.push_back( "Bagit tag manifest");
log << "Bagit tag manifest" << endl;
bool ret = this->tagmanifest_p->validate( log );
if (ret == false) {
is_valid = false;
@ -94,11 +95,11 @@ bool Bag::validate( list<string> & log ) {
oxum_t expected_oxum = this->bagmetadata_p->get_oxum();
oxum_t calculated_oxum = c.oxum_of_filelist( files );
if (expected_oxum.octetcount != calculated_oxum.octetcount) {
log.push_back("Bagit payload oxum octectcount=" + to_string(expected_oxum.octetcount) + " expected, but " + to_string(calculated_oxum.octetcount) + " found");
log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl;
is_valid = false;
}
if (expected_oxum.streamcount != calculated_oxum.streamcount) {
log.push_back("Bagit payload oxum streamcount=" + to_string(expected_oxum.streamcount) + " expected, but " + to_string(calculated_oxum.streamcount) + " found");
log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl;
is_valid = false;
}

7
test/test_bagmetadata.cpp

@ -19,13 +19,10 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
stringstream log;
Bagmetadata p( dir );
bool res = p.validate( log);
list<string>::iterator i;
for (i=log.begin(); i!=log.end(); i++) {
cout << (*i) << endl;
}
cout << log.str() << endl;
return res;
}

2
test/test_payload.cpp

@ -18,7 +18,7 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
stringstream log;
Payload p( dir );
return p.validate( log);
}

7
test/test_payloadmanifest.cpp

@ -20,13 +20,10 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
stringstream log;
Payloadmanifest p( dir );
bool res = p.validate( log);
list<string>::iterator i;
for (i=log.begin(); i!=log.end(); i++) {
cout << (*i) << endl;
}
cout << log.str() << endl;
return res;
}

7
test/test_tagmanifest.cpp

@ -20,13 +20,10 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
stringstream log;
Tagmanifest p( dir );
bool res = p.validate( log);
list<string>::iterator i;
for (i=log.begin(); i!=log.end(); i++) {
cout << (*i) << endl;
}
cout << log.str() << endl;
return res;
}

2
test/testbag.cpp

@ -16,7 +16,7 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
list<string> log;
stringstream log;
Bag p( dir );
return p.validate( log);
}

Loading…
Cancel
Save