Browse Source

- added testsuite for bagmetadata

- added testsuite for tagmanifest
master
parent
commit
30a20386bb
4 changed files with 196 additions and 4 deletions
  1. +3
    -1
      CMakeLists.txt
  2. +7
    -3
      test/CMakeLists.txt
  3. +94
    -0
      test/test_bagmetadata.cpp
  4. +92
    -0
      test/test_tagmanifest.cpp

+ 3
- 1
CMakeLists.txt View File

@@ -4,6 +4,8 @@ add_subdirectory(src)
# TESTS
add_subdirectory(test)
enable_testing()
add_test(NAME Mytest COMMAND Mytest)
add_test(NAME TestPayload COMMAND TestPayload)
add_test(NAME TestPayloadManifest COMMAND TestPayloadManifest)
add_test(NAME TestTagManifest COMMAND TestTagManifest)
add_test(NAME TestBagMetadata COMMAND TestBagMetadata)
add_test(NAME TestBag COMMAND TestBag)

+ 7
- 3
test/CMakeLists.txt View File

@@ -14,11 +14,15 @@ message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR})
link_directories(${OPENSSL_LIBRARIES})
add_definitions(-DBOOST_TEST_DYN_LINK)
add_executable(Mytest test.cpp)
add_executable(TestBag testbag.cpp)
add_executable(TestPayload test_payload.cpp)
add_executable(TestPayloadManifest test_payloadmanifest.cpp)
target_link_libraries(Mytest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
target_link_libraries(TestPayload ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} libcbag)
add_executable(TestTagManifest test_tagmanifest.cpp)
add_executable(TestBagMetadata test_bagmetadata.cpp)
target_link_libraries(TestBag ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
target_link_libraries(TestPayload ${Boost_LIBRARIES} libcbag)
target_link_libraries(TestPayloadManifest ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} libcbag)
target_link_libraries(TestTagManifest ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} libcbag)
target_link_libraries(TestBagMetadata ${Boost_LIBRARIES} libcbag)



+ 94
- 0
test/test_bagmetadata.cpp View File

@@ -0,0 +1,94 @@
#define BOOST_TEST_MODULE TestBagMetadata
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;

#include "bagmetadata.hpp"
#include "checksum.hpp"

using namespace std;

bool check_constructor(string dir) {
try {
Bagmetadata p( dir );
return true;
} catch (exception &e) {
return false;
}
}

bool check_validation(string dir) {
list<string> log;
Bagmetadata p( dir );
bool res = p.validate( log);
list<string>::iterator i;
for (i=log.begin(); i!=log.end(); i++) {
cout << (*i) << endl;
}
return res;
}

bool check_get_metadata(string dir) {
Bagmetadata p( dir );
map<string,string> results = p.get_metadata();
map<string,string> expected = {
{"External-Identifier", "testbag-01"},
{"Payload-Oxum", "38.4"},
{"Bagging-Date", "2015-12-28"},
{"Bag-Size", "16 B"},
{"External-Description", "3.dat"},
{"Foo", "bar baz\n blurp"},
};
map<string, string>::iterator i;
map<string, string>::iterator j;
bool is_valid = true;
for (i=expected.begin(), j=results.begin(); i!=expected.end() && j!=results.end(); i++,j++) {
if (
( i->first != j-> first) ||
( i->second != j->second)
) {
cout << "Expected: (" << (i->first) << ";" << (i->second) << ")" << endl;
cout << "Result: ("<< j->first << ";" << j->second << ")" << endl;
is_valid=false; break;
}
}
return is_valid;
}

bool check_has_metadata(string dir) {
Bagmetadata p( dir );
return p.has_bagmetadata();
}

bool check_has_oxum(string dir) {
Bagmetadata p( dir );
return p.has_oxum();
}

oxum_t check_get_oxum(string dir) {
Bagmetadata p( dir );
return p.get_oxum();
}


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("/tmp/"));};
BOOST_AUTO_TEST_CASE(check_metadata_exists) {BOOST_TEST( check_has_metadata("../testbags/bag_minimal_ok/")); };

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;
expected.octetcount=38;
expected.streamcount=4;
oxum_t result = check_get_oxum("../testbags/bag_minimal_ok/");
BOOST_TEST( expected.octetcount == result.octetcount);
BOOST_TEST( expected.streamcount == result.streamcount);
};
BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};



// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 92
- 0
test/test_tagmanifest.cpp View File

@@ -0,0 +1,92 @@
#define BOOST_TEST_MODULE TestTagManifest
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>
namespace utf = boost::unit_test;

#include "tagmanifest.hpp"

using namespace std;



bool check_constructor(string dir) {
try {
Tagmanifest p( dir );
return true;
} catch (exception &e) {
return false;
}
}

bool check_validation(string dir) {
list<string> log;
Tagmanifest p( dir );
bool res = p.validate( log);
list<string>::iterator i;
for (i=log.begin(); i!=log.end(); i++) {
cout << (*i) << endl;
}
return res;
}

bool check_get_checksum_file_pairs() {
Tagmanifest p( "../testbags/bag_minimal_ok/" );
multimap<checksum_string_t,filename_t> results = p.get_checksum_file_pairs( md5 );
multimap<checksum_string_t,filename_t> expected = {
{"939f3a18385ca2975ed6a02f4a180758", "manifest-md5.txt"},
{"9e5ad981e0d29adc278f6a294b8c2aca", "bagit.txt"}
};

multimap<string,string>::iterator i;
multimap<string,string>::iterator j;
bool is_valid = true;
for (i=expected.begin(), j=results.begin(); i!=expected.end() && j!=results.end(); i++,j++) {
if (
( i->first != j-> first) ||
( i->second != j->second)
) {
cout << "Expected: (" << (i->first) << "," << (i->second) << ") Result: ("<< j->first << "," << j->second << ")" << endl;
is_valid=false; break;
}
}
return is_valid;
}

bool check_get_checksummed_files() {
Tagmanifest p( "../testbags/bag_minimal_ok/" );
list<string> results = p.get_checksummed_files();
list<string> expected {
"../testbags/bag_minimal_ok/bag-info.txt"
};
results.sort();
expected.sort();
list<string>::iterator i;
list<string>::iterator j;
bool is_valid = true;
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;
}

bool check_has_tagmanifest(string dir) {
Tagmanifest p( dir );
return p.has_tagmanifest();
}


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("/tmp/"));};
BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_checksum_file_pairs) {BOOST_TEST( check_get_checksum_file_pairs()); };
BOOST_AUTO_TEST_CASE(check_checksummed_files) { BOOST_TEST(check_get_checksummed_files()); };
BOOST_AUTO_TEST_CASE(check_tag_manifest) {BOOST_TEST(check_has_tagmanifest("../testbags/bag_minimal_ok/"));};


// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

Loading…
Cancel
Save