Browse Source

- added fixture for target dir

master
Andreas Romeyke 2 years ago
parent
commit
ae8223f927
1 changed files with 67 additions and 37 deletions
  1. +67
    -37
      test/testbag.cpp

+ 67
- 37
test/testbag.cpp View File

@@ -6,55 +6,85 @@
#include "bag.hpp"

using namespace std;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;

struct TARGETFIXTURE {
TARGETFIXTURE() : targetdir("/tmp/testdir") { BOOST_TEST_MESSAGE("setup targetdir"); }
~TARGETFIXTURE() {
fs::path f { targetdir };
fs::remove_all( f );
BOOST_TEST_MESSAGE("teardown targetdir");
}
string targetdir;
};


bool check_constructor(string dir) {
try {
Bag p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
}
try {
Bag p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
}
}

bool check_validation(string dir) {
Bag p( std::move(dir) );
return p.validate();
Bag p( std::move(dir) );
return p.validate();
}

bool check_store( string dir_load_from, string dir_store_to ) {
Bag p( std::move(dir_load_from) );
bool result = p.store ( std::move(dir_store_to) );
return result;
Bag p( std::move(dir_load_from) );
bool result = p.store ( std::move(dir_store_to) );
// clean dir_store_to
fs::path f { dir_store_to };
fs::remove_all( f );
return result;
}

bool check_get_all_bag_files(string dir) {
Bag p( std::move(dir) );
list<string> results = p.get_all_bag_files();
list<string> expected {
"bagit.txt",
"bag-info.txt"
};
bool is_valid = true;
list<string>::iterator i;
list<string>::iterator j;
for (i=results.begin(), j=expected.begin(); i!=results.end() && j!=expected.end(); i++, j++) {
if ((*i) != (*j)) {
cout << "Expected: "<< (*j) << " Result:"<< (*i) << endl;
is_valid = false;
break;
}
}
return is_valid;
Bag p( std::move(dir) );
list<string> results = p.get_all_bag_files();
list<string> expected {
"bagit.txt",
"bag-info.txt"
};
bool is_valid = true;
list<string>::iterator i;
list<string>::iterator j;
for (i=results.begin(), j=expected.begin(); i!=results.end() && j!=expected.end(); i++, j++) {
if ((*i) != (*j)) {
cout << "Expected: "<< (*j) << " Result:"<< (*i) << endl;
is_valid = false;
break;
}
}
return is_valid;
}


/*
BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
BOOST_AUTO_TEST_CASE(constructor3) {BOOST_TEST(check_constructor("../testbags/bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_validation_buggy) {BOOST_TEST(check_validation("../testbags/1008_buggy/"));};
BOOST_AUTO_TEST_CASE(check_get_all_bag_files_ok) {BOOST_TEST(check_get_all_bag_files("../testbags/bag_minimal_ok"));};
*/
BOOST_AUTO_TEST_CASE(check_store_ok) {BOOST_TEST(check_store("../testbags/bag_minimal_ok/", "/tmp/testbag/"));};

BOOST_AUTO_TEST_CASE(constructor1) {
BOOST_TEST(check_constructor(""));
};
BOOST_AUTO_TEST_CASE(constructor2) {
BOOST_TEST(check_constructor("./"));
};
BOOST_AUTO_TEST_CASE(constructor3) {
BOOST_TEST(check_constructor("../testbags/bag_minimal_ok/"));
};
BOOST_AUTO_TEST_CASE(check_validation_ok) {
BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));
};
BOOST_AUTO_TEST_CASE(check_validation_buggy) {
BOOST_TEST(!check_validation("../testbags/1008_buggy/"));
};
BOOST_AUTO_TEST_CASE(check_get_all_bag_files_ok) {
BOOST_TEST(check_get_all_bag_files("../testbags/bag_minimal_ok"));
};

BOOST_FIXTURE_TEST_CASE(check_store_ok, TARGETFIXTURE) {
BOOST_TEST(check_store("../testbags/bag_minimal_ok/", targetdir));
};


Loading…
Cancel
Save