Browse Source

- using auto for iterators

- using const for paths
master
Andreas Romeyke 2 years ago
parent
commit
43c0ffb120
15 changed files with 134 additions and 127 deletions
  1. +25
    -19
      src/lib/bag.cpp
  2. +9
    -8
      src/lib/bagmetadata.cpp
  3. +16
    -16
      src/lib/checksum.cpp
  4. +8
    -8
      src/lib/fetchfile.cpp
  5. +18
    -18
      src/lib/manifest.cpp
  6. +2
    -2
      src/lib/othertags.cpp
  7. +6
    -6
      src/lib/payload.cpp
  8. +5
    -5
      src/lib/payloadmanifest.cpp
  9. +8
    -8
      src/lib/tagmanifest.cpp
  10. +11
    -11
      test/test_bagmetadata.cpp
  11. +8
    -8
      test/test_fetchfile.cpp
  12. +4
    -4
      test/test_payload.cpp
  13. +4
    -4
      test/test_payloadmanifest.cpp
  14. +5
    -5
      test/test_tagmanifest.cpp
  15. +5
    -5
      test/testbag.cpp

+ 25
- 19
src/lib/bag.cpp View File

@ -80,10 +80,10 @@ Bag::Bag( string dfname ) {
list<string> Bag::get_all_bag_files() {
list<string> files;
files.push_back( "bagit.txt" );
files.push_back( "bag-info.txt" );
if (NULL != this->tagmanifest_p) {
// TODO: this->tagmanifest_p->get_all_checksum_files()
files.emplace_back("bagit.txt" );
files.emplace_back("bag-info.txt" );
if (nullptr != this->tagmanifest_p) {
// TODO(art1): this->tagmanifest_p->get_all_checksum_files()
}
return files;
}
@ -99,39 +99,45 @@ bool Bag::store( string basedir ) {
fs::create_directory(p);
// store payload
if (NULL == Bag::payload_p) {
if (nullptr == Bag::payload_p) {
Bag::log << "Payload object needed" << endl;
return false;
}
Bag::payload_p->store( basedir );
// store payload manifest
if (NULL == Bag::payloadmanifest_p) {
if (nullptr == Bag::payloadmanifest_p) {
Bag::log << "Payloadmanifest object needed" << endl;
return false;
}
list<string> payload_files =Bag::payload_p->get_all_relative_paths();
cout << "PAYLOAD" <<endl;
Bag::payloadmanifest_p->store( basedir, payload_files);
// store tagmanifest
if (NULL == Bag::tagmanifest_p) {
if (nullptr == Bag::tagmanifest_p) {
Bag::log << "Tagmanifest object needed" << endl;
return false;
}
list<string> bagfiles = Bag::get_all_bag_files();
cout << "TAGMANIFEST" << endl;
list<string>::iterator it;
for (it=bagfiles.begin(); it!= bagfiles.end(); ++it) {
cout << "TAGMANIFEST-file '" << *it << "'" << endl;
}
Bag::tagmanifest_p->store( basedir, bagfiles );
// store baginfo
if (NULL == Bag::bagmetadata_p) {
if (nullptr == Bag::bagmetadata_p) {
Bag::log << "Bagmetadata object needed" << endl;
return false;
}
Bag::bagmetadata_p->store( basedir );
// store fetchfile (if needed)
if (NULL == Bag::fetchfile_p) {
if (nullptr == Bag::fetchfile_p) {
Bag::log << "Fetchfile object needed" << endl;
return false;
}
Bag::fetchfile_p->store( basedir );
// store other
if (NULL == Bag::othertags_p) {
if (nullptr == Bag::othertags_p) {
Bag::log << "Othertags object needed" << endl;
return false;
}
@ -164,25 +170,25 @@ bool Bag::validate() {
this->log << "Bagit character encoding UTF-8 is expected, but got: " << this->tag_file_character_encoding << endl;
is_valid = false;
}
if (NULL == this->payload_p) {
if (nullptr == this->payload_p) {
this->log << "Bagit payload directory 'data/' is expected, but could not found" << endl;
is_valid = false;
} else {
bool ret = this->payload_p->validate();
if (ret == false) {
if (!ret) {
is_valid = false;
}
}
if (NULL == this->payloadmanifest_p) {
if (nullptr == this->payloadmanifest_p) {
is_valid = false;
} else {
// checksums check
this->log << "Bagit payload manifest" << endl;
bool ret = this->payloadmanifest_p->validate();
if (ret == false) {
if (!ret) {
is_valid = false;
}
if (NULL != this->payload_p) {
if (nullptr != this->payload_p) {
// check if payload checksums missed for payload files
// HINT: not requested by draft, therefore only a warning
list<string> payload_files = this->payload_p->get_all_relative_paths();
@ -220,18 +226,18 @@ bool Bag::validate() {
}
}
// next elements are optional
if (NULL == this->tagmanifest_p) {
if (nullptr == this->tagmanifest_p) {
} else {
this->log << "Bagit tag manifest" << endl;
bool ret = this->tagmanifest_p->validate();
if (ret == false) {
if (!ret) {
is_valid = false;
}
}
if (NULL == this->bagmetadata_p) {
if (nullptr == this->bagmetadata_p) {
} else {
bool ret = this->bagmetadata_p->validate();
if (ret == false) {
if (!ret) {
is_valid = false;
}
if (this->bagmetadata_p->has_oxum()) {


+ 9
- 8
src/lib/bagmetadata.cpp View File

@ -2,9 +2,9 @@
#include <iostream>
#include <fstream>
#include <regex>
#include <sstream>
#include <string>
#include <regex>
#include <tr1/regex>
#include <boost/filesystem.hpp>
//#include <filesystem> // c++17
@ -39,8 +39,8 @@ Bagmetadata::Bagmetadata( string basedir ) {
);
file.close();
// parse content using regex based split
regex rgx_line("\\n(?=\\S)"); // entry should not start with whitespace
regex key_value_separator(":\\s*");
regex rgx_line(R"(\n(?=\S))"); // entry should not start with whitespace
regex key_value_separator(R"(:\s*)");
// DEBUG: string repl = "|";
// DEBUG: string content2 = regex_replace(content, rgx, "|");
// DEBUG: cout << "REPL:(" << content2 << ")" << endl;
@ -58,14 +58,15 @@ Bagmetadata::Bagmetadata( string basedir ) {
-1);
string key;
string value;
// TODO: add check for results!
// TODO(art1): add check for results!
key = *(iter);
value = (*++iter);
// clean \n at the end of a multiline value
if (!value.empty())
{
if (value[value.length()-1] == '\n')
if (value[value.length()-1] == '\n') {
value.erase(value.length()-1);
}
}
Bagmetadata::metadata[ key ] = value;
@ -104,7 +105,7 @@ bool Bagmetadata::has_oxum() {
}
oxum_t Bagmetadata::get_oxum() {
oxum_t oxum;
oxum_t oxum{};
oxum.octetcount=0;
oxum.streamcount=0;
map<string, string>::iterator it;
@ -134,8 +135,8 @@ bool Bagmetadata::store( string basedir ) {
ofstream baginfo_txt_file;
baginfo_txt_file.open( filename );
if (baginfo_txt_file.is_open()) {
for (map<string, string>::iterator it=this->metadata.begin(); it!=this->metadata.end(); ++it) {
baginfo_txt_file << (it->first) << " : " << (it->second) << endl;
for (auto & it : this->metadata) {
baginfo_txt_file << (it.first) << " : " << (it.second) << endl;
}
baginfo_txt_file.close();
}


+ 16
- 16
src/lib/checksum.cpp View File

@ -2,8 +2,8 @@
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include "checksum.hpp"
#include <string>
string string_of_algorithm( checksum_algorithms alg) {
@ -14,7 +14,7 @@ string string_of_algorithm( checksum_algorithms alg) {
}
}
string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) {
string Checksum::checksum_of_file(const string& filepath, checksum_algorithms alg) {
ifstream file (filepath, ios::ate);
stringstream hex_result;
// cout << "processing file '" << filepath << "'" << endl;
@ -23,31 +23,31 @@ string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) {
char * memBlock;
fileSize = file.tellg();
memBlock = new char[fileSize];
if (NULL != memBlock) {
if (nullptr != memBlock) {
file.seekg(0,ios::beg);
file.read(memBlock, fileSize);
switch ( alg ) {
case md5: {
unsigned char result[MD5_DIGEST_LENGTH];
MD5((unsigned char*) memBlock, fileSize, result);
for (int i=0; i<MD5_DIGEST_LENGTH; i++) {
hex_result<< hex << setw(2) << setfill('0') << (int) result[i];
MD5(reinterpret_cast<unsigned char*>( memBlock), fileSize, result);
for (unsigned char i : result) {
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i);
}
break;
}
case sha1: {
unsigned char result[SHA_DIGEST_LENGTH];
SHA1((unsigned char*) memBlock, fileSize, result);
for (int i=0; i<SHA_DIGEST_LENGTH; i++) {
hex_result<< hex << setw(2) << setfill('0') << (int) result[i];
SHA1(reinterpret_cast<unsigned char*>( memBlock), fileSize, result);
for (unsigned char i : result) {
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i);
}
break;
}
case sha256: {
unsigned char result[SHA_DIGEST_LENGTH];
SHA256((unsigned char*) memBlock, fileSize, result);
for (int i=0; i<SHA_DIGEST_LENGTH; i++) {
hex_result<< hex << setw(2) << setfill('0') << (int) result[i];
SHA256(reinterpret_cast<unsigned char*>( memBlock), fileSize, result);
for (unsigned char i : result) {
hex_result<< hex << setw(2) << setfill('0') << static_cast<int>( i);
}
break;
}
@ -65,9 +65,9 @@ string Checksum::checksum_of_file(string filepath, checksum_algorithms alg) {
return hex_result.str();
}
oxum_t Checksum::oxum_of_file(string filepath) {
oxum_t Checksum::oxum_of_file(const string& filepath) {
ifstream file (filepath, ios::ate);
oxum_t oxum;
oxum_t oxum{};
//cout << "processing file '" << filepath << "'" << endl;
if (file.is_open() ) {
ifstream::pos_type fileSize;
@ -82,11 +82,11 @@ oxum_t Checksum::oxum_of_file(string filepath) {
}
oxum_t Checksum::oxum_of_filelist( list<string> files) {
oxum_t oxum;
oxum_t oxum{};
oxum.octetcount=0;
oxum.streamcount=0;
list<string>::iterator i;
for (i=files.begin(); i!= files.end(); i++) {
for (i=files.begin(); i!= files.end(); ++i) {
oxum_t tmp = this->oxum_of_file( *i );
oxum.octetcount+= tmp.octetcount;
oxum.streamcount+= tmp.streamcount;


+ 8
- 8
src/lib/fetchfile.cpp View File

@ -3,8 +3,8 @@
#include <memory>
#include <curl/curl.h>
#include "fetchfile.hpp"
#include <sstream>
#include <boost/filesystem.hpp>
#include <sstream>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
@ -59,7 +59,7 @@ bool Fetchfile::fetch( fetch_t fetch ) {
CURL *curl;
CURLcode result;
curl = curl_easy_init();
if (curl) {
if (curl != nullptr) {
FILE *fp;
fp = fopen( fetch.filename.c_str(), "wb");
curl_easy_setopt(curl, CURLOPT_URL, fetch.url.c_str());
@ -86,9 +86,9 @@ list<fetch_t> Fetchfile::get_entries() {
bool Fetchfile::fetch_all_entries() {
bool is_successful = true;
for (list<fetch_t>::iterator it=this->entries.begin(); it!=this->entries.end(); ++it) {
bool result = this->fetch( *it );
if (false == result) {
for (auto & entrie : this->entries) {
bool result = this->fetch( entrie );
if (!result) {
is_successful = false;
}
}
@ -99,7 +99,7 @@ bool Fetchfile::fetch_all_entries() {
bool Fetchfile::validate() {
bool is_valid = true;
if (this->has_fetchfile()) {
// TODO:
// TODO(art1):
}
return is_valid;
}
@ -116,8 +116,8 @@ bool Fetchfile::store( string basedir ) {
ofstream fetchfile_txt_file;
fetchfile_txt_file.open( filename );
if (fetchfile_txt_file.is_open()) {
for (list<fetch_t>::iterator it=this->entries.begin(); it!=this->entries.end(); ++it) {
fetchfile_txt_file << it->url << " " << it->size << " " << it->filename << endl;
for (auto & entrie : this->entries) {
fetchfile_txt_file << entrie.url << " " << entrie.size << " " << entrie.filename << endl;
}
fetchfile_txt_file.close();
}


+ 18
- 18
src/lib/manifest.cpp View File

@ -36,21 +36,21 @@ multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksu
bool Manifest::validate() {
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) {
for (auto & manifest_algorithm_file : this->manifest_algorithm_files) {
//cout << "validate using file '"<< (it->second) << "' (" << (it->first) << ")" <<endl;
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( it->first );
for (multimap<checksum_string_t,filename_t>::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) {
string expected_checksum = ch->first;
string file = this->basedir + ch->second;
string calc_checksum = checksum.checksum_of_file( file, it->first );
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( manifest_algorithm_file.first );
for (auto & checksum_file_pair : checksum_file_pairs) {
string expected_checksum = checksum_file_pair.first;
string file = this->basedir + checksum_file_pair.second;
string calc_checksum = checksum.checksum_of_file( file, manifest_algorithm_file.first );
//cout << "\t" << "file="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
if (calc_checksum.empty()) {
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but file was not found" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_algorithm_file.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;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << it->second << "', but found: '" << calc_checksum << "'" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_algorithm_file.second << "', but found: '" << calc_checksum << "'" << endl;
is_valid = false;
}
fs::path p{ file };
@ -69,7 +69,7 @@ bool Manifest::validate() {
void Manifest::debug() {
//cout << "DEBUG: basedir='"<<this->basedir<<"'"<<endl;
//cout << "DEBUG: list of manifest files:"<<endl;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
for (auto it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
// cout << "DEBUG:\tvalidate using file '"<< (it->second) << "' (" << (it->first) << ")" <<endl;
}
//cout << "DEBUG" << endl;
@ -77,10 +77,10 @@ void Manifest::debug() {
list<string> Manifest::get_checksummed_files() {
list<string> files;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( it->first );
for (multimap<checksum_string_t,filename_t>::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) {
string file = this->basedir + ch->second;
for (auto & manifest_algorithm_file : this->manifest_algorithm_files) {
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( manifest_algorithm_file.first );
for (auto & checksum_file_pair : checksum_file_pairs) {
string file = this->basedir + checksum_file_pair.second;
// cout << "MF: '" << file << "'" << endl;
files.push_back( file );
}
@ -88,13 +88,13 @@ list<string> Manifest::get_checksummed_files() {
return files;
}
bool Manifest::store( string basedir, list<string>& files ) {
bool Manifest::store( const string& basedir, list<string>& files ) {
Checksum checksum;
for (map<checksum_algorithms, string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
checksum_algorithms alg = it->first;
for (auto & manifest_algorithm_file : this->manifest_algorithm_files) {
checksum_algorithms alg = manifest_algorithm_file.first;
// test if file exists
string algfilename = basedir + it->second;
cout << "DEBUG manifest::store, file='"<<algfilename << "' (newbase='" << basedir << "', filename='" << it->second << "'" <<endl;
string algfilename = basedir + manifest_algorithm_file.second;
cout << "DEBUG manifest::store, file='"<<algfilename << "' (newbase='" << basedir << "', filename='" << manifest_algorithm_file.second << "'" <<endl;
ofstream alg_txt_file;
alg_txt_file.open( algfilename );
if (alg_txt_file.is_open()) {


+ 2
- 2
src/lib/othertags.cpp View File

@ -1,9 +1,9 @@
#include "othertags.hpp"
Othertags::Othertags( string basedir ) {
Othertags::Othertags( string /*basedir*/ ) {
}
bool Othertags::store( string basedir ) {
bool Othertags::store( string /*basedir*/ ) {
return false;
}


+ 6
- 6
src/lib/payload.cpp View File

@ -1,9 +1,9 @@
#include "payload.hpp"
#include <iostream>
#include <string>
#include <list>
#include <boost/filesystem.hpp>
#include <boost/filesystem/operations.hpp>
#include <list>
#include <string>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
@ -18,7 +18,7 @@ Payload::Payload( string basedir ) {
// cout << "exists: "<< fs::exists(s) << endl;
};
void Payload::scan_dir_recursively( fs::path directory, list<fs::path> &paths) {
void Payload::scan_dir_recursively( const fs::path& directory, list<fs::path> &paths) {
fs::recursive_directory_iterator iter(directory), end;
for (; iter != end; ++iter) {
fs::path subdir = iter->path();
@ -61,19 +61,19 @@ bool Payload::validate() {
}
bool Payload::store( string basedir ) {
bool Payload::store( const string& basedir ) {
string newbasedir = basedir + "data/";
fs::path p{ newbasedir };
fs::file_status s = fs::status( p );
if (fs::is_directory( s)) {
// TODO: Payload::log << "directory '" << newbasedir << "'already exists" << endl;
// TODO(art1): Payload::log << "directory '" << newbasedir << "'already exists" << endl;
cout << "directory '" << newbasedir << "'already exists" << endl;
return false;
}
fs::create_directory(p);
list<string> paths = Payload::get_all_relative_paths();
for (string relpath : paths) {
for (const string& relpath : paths) {
string sourcepath = Payload::basedir + relpath;
string targetpath = basedir + relpath;
cout << "map '" << sourcepath << "' to '" << targetpath << "'" <<endl;


+ 5
- 5
src/lib/payloadmanifest.cpp View File

@ -18,11 +18,11 @@ Payloadmanifest::Payloadmanifest( string basedir ) {
for (checksum_algorithms alg : checksum_algorithmsList) {
possible_manifest_files[alg] = "manifest-" + string_of_algorithm( alg ) + ".txt";
}
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
checksum_algorithms alg = it->first;
for (auto & possible_manifest_file : possible_manifest_files) {
checksum_algorithms alg = possible_manifest_file.first;
// test if file exists
//string filename = basedir + it->second;
string filename = it->second;
string filename = possible_manifest_file.second;
fs::path p{ basedir + filename };
fs::file_status s = fs::status( p );
if (fs::is_regular_file( s)) {
@ -34,9 +34,9 @@ Payloadmanifest::Payloadmanifest( string basedir ) {
bool Payloadmanifest::validate() {
bool is_valid = true;
bool tmp = Manifest::validate();
if (false == tmp) { is_valid = false; }
if (!tmp) { is_valid = false; }
// check if at least one payload file exist
if (0 == this->manifest_algorithm_files.size()) {
if (this->manifest_algorithm_files.empty()) {
this->log << "Bagit payloadmanifest count greater zero expected, but " << to_string(this->manifest_algorithm_files.size()) << " found" << endl;
is_valid = false;
}


+ 8
- 8
src/lib/tagmanifest.cpp View File

@ -18,17 +18,17 @@ Tagmanifest::Tagmanifest( string basedir ) {
for (checksum_algorithms alg : checksum_algorithmsList) {
possible_manifest_files[alg] = "tagmanifest-" + string_of_algorithm( alg ) + ".txt";
}
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
for (auto & possible_manifest_file : possible_manifest_files) {
// debug
// cout << it->first << " => " << it->second << endl;
// test if file exists
//string filename = basedir + it->second;
string filename = it->second;
checksum_algorithms alg = it->first;
string filename = possible_manifest_file.second;
checksum_algorithms alg = possible_manifest_file.first;
fs::path p{ filename };
fs::file_status s = fs::status( p );
//cout << "path "<< p.string() << endl;
//cout << "is file: "<< fs::is_regular_file( s) << endl;
cout << "path "<< p.string() << endl;
cout << "is file: "<< fs::is_regular_file( s) << endl;
if (fs::is_regular_file( s)) {
Tagmanifest::manifest_algorithm_files[alg] = filename;
// debug
@ -48,10 +48,10 @@ multimap<checksum_string_t,filename_t> Tagmanifest::get_checksum_file_pairs(chec
multimap<checksum_string_t,filename_t> checksum_file_pairs = Manifest::get_checksum_file_pairs(alg);
//cout << "DEBUG: called super->get_checksum_file_pairs" << endl;
for (multimap<checksum_string_t,filename_t>::iterator it=checksum_file_pairs.begin(); it!=checksum_file_pairs.end(); ++it) {
for (auto & checksum_file_pair : checksum_file_pairs) {
// cout << "DEBUG: TAGMANIFEST found 'data/' in the beginning of file '"<<it->second<<"' in tagmanifest file '"<< this->manifest_algorithm_files[ alg] << endl;
if (it->second.find( "data/" ) == 0) {
cout << "found 'data/' in the beginning of file '"<<it->second<<"' in tagmanifest file '"<< this->manifest_algorithm_files[ alg] << endl;
if (checksum_file_pair.second.find( "data/" ) == 0) {
cout << "found 'data/' in the beginning of file '"<<checksum_file_pair.second<<"' in tagmanifest file '"<< this->manifest_algorithm_files[ alg] << endl;
}
}
//cout << "TAGMANIFEST get_checksum_file_pairs, calling debug()" << endl;


+ 11
- 11
test/test_bagmetadata.cpp View File

@ -1,8 +1,8 @@
#define BOOST_TEST_MODULE TestBagMetadata
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;
#include <string>
#include <utility>
#include "bagmetadata.hpp"
#include "checksum.hpp"
@ -11,7 +11,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -19,13 +19,13 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
bool res = p.validate();
return res;
}
bool check_get_metadata(string dir) {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
map<string,string> results = p.get_metadata();
map<string,string> expected = {
{"External-Identifier", "testbag-01"},
@ -52,23 +52,23 @@ bool check_get_metadata(string dir) {
}
bool check_has_metadata(string dir) {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
return p.has_bagmetadata();
}
bool check_has_oxum(string dir) {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
return p.has_oxum();
}
oxum_t check_get_oxum(string dir) {
Bagmetadata p( dir );
Bagmetadata p( std::move(dir) );
return p.get_oxum();
}
bool check_store( string dir_load_from, string dir_store_to ) {
Bagmetadata p( dir_load_from );
bool result = p.store( dir_store_to );
Bagmetadata p( std::move(dir_load_from) );
bool result = p.store( std::move(dir_store_to) );
return result;
}
@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(check_metadata_exists) {BOOST_TEST( check_has_metadata("../
BOOST_AUTO_TEST_CASE(check_metadata) {BOOST_TEST( check_get_metadata("../testbags/bag_minimal_ok/")); };
BOOST_AUTO_TEST_CASE(check_oxum_exists) {BOOST_TEST( check_has_oxum("../testbags/bag_minimal_ok/")); };
BOOST_AUTO_TEST_CASE(check_oxum) {
oxum_t expected;
oxum_t expected{};
expected.octetcount=38;
expected.streamcount=4;
oxum_t result = check_get_oxum("../testbags/bag_minimal_ok/");


+ 8
- 8
test/test_fetchfile.cpp View File

@ -1,9 +1,9 @@
#define BOOST_TEST_MODULE TestFetchFile
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
#include <string>
#include <list>
namespace utf = boost::unit_test;
#include <utility>
#include "fetchfile.hpp"
@ -11,7 +11,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Fetchfile p( dir );
Fetchfile p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -19,18 +19,18 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Fetchfile p( dir );
Fetchfile p( std::move(dir) );
return p.validate();
}
bool check_store( string dir_load_from, string dir_store_to ) {
Fetchfile p( dir_load_from );
bool result = p.store( dir_store_to );
Fetchfile p( std::move(dir_load_from) );
bool result = p.store( std::move(dir_store_to) );
return result;
}
bool check_get_fetchfile(string dir) {
Fetchfile p( dir );
Fetchfile p( std::move(dir) );
list<fetch_t> results = p.get_entries();
list<fetch_t> expected;
list<fetch_t>::iterator i;
@ -52,7 +52,7 @@ bool check_get_fetchfile(string dir) {
bool check_has_fetchfile(string dir) {
Fetchfile p( dir );
Fetchfile p( std::move(dir) );
return p.has_fetchfile();
}


+ 4
- 4
test/test_payload.cpp View File

@ -1,8 +1,8 @@
#define BOOST_TEST_MODULE TestPayload
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;
#include <string>
#include <utility>
#include "payload.hpp"
@ -10,7 +10,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Payload p( dir );
Payload p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -18,7 +18,7 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Payload p( dir );
Payload p( std::move(dir) );
return p.validate();
}


+ 4
- 4
test/test_payloadmanifest.cpp View File

@ -1,8 +1,8 @@
#define BOOST_TEST_MODULE TestPayloadManifest
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;
#include <string>
#include <utility>
#include "payloadmanifest.hpp"
@ -12,7 +12,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Payloadmanifest p( dir );
Payloadmanifest p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -20,7 +20,7 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Payloadmanifest p( dir );
Payloadmanifest p( std::move(dir) );
bool res = p.validate();
return res;
}


+ 5
- 5
test/test_tagmanifest.cpp View File

@ -1,8 +1,8 @@
#define BOOST_TEST_MODULE TestTagManifest
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;
#include <string>
#include <utility>
#include "tagmanifest.hpp"
@ -12,7 +12,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Tagmanifest p( dir );
Tagmanifest p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -20,7 +20,7 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Tagmanifest p( dir );
Tagmanifest p( std::move(dir) );
bool res = p.validate();
return res;
}
@ -70,7 +70,7 @@ bool check_get_checksummed_files() {
}
bool check_has_tagmanifest(string dir) {
Tagmanifest p( dir );
Tagmanifest p( std::move(dir) );
return p.has_tagmanifest();
}


+ 5
- 5
test/testbag.cpp View File

@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE Mytest
#include <boost/test/unit_test.hpp>
namespace utf = boost::unit_test;
#include <utility>
#include "bag.hpp"
@ -8,7 +8,7 @@ using namespace std;
bool check_constructor(string dir) {
try {
Bag p( dir );
Bag p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
@ -16,13 +16,13 @@ bool check_constructor(string dir) {
}
bool check_validation(string dir) {
Bag p( dir );
Bag p( std::move(dir) );
return p.validate();
}
bool check_store( string dir_load_from, string dir_store_to ) {
Bag p( dir_load_from );
bool result = p.store ( dir_store_to );
Bag p( std::move(dir_load_from) );
bool result = p.store ( std::move(dir_store_to) );
return result;
}


Loading…
Cancel
Save