C++ Library to handle BagIt structures. BagIt is a standard format to create transfer packages for digital preservation purposes. See https://en.wikipedia.org/wiki/BagIt for details http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB

  1. #define BOOST_TEST_MODULE TestTagManifest
  2. #include <boost/test/unit_test.hpp>
  3. #include <iostream>
  4. #include <string>
  5. #include <utility>
  6. #include "tagmanifest.hpp"
  7. BOOST_AUTO_TEST_SUITE(testbag_suite);
  8. using namespace std;
  9. bool check_constructor(string dir) {
  10. try {
  11. Tagmanifest p( std::move(dir) );
  12. return true;
  13. } catch (exception &e) {
  14. return false;
  15. }
  16. }
  17. bool check_validation(string dir) {
  18. Tagmanifest p( std::move(dir) );
  19. bool res = p.validate();
  20. return res;
  21. }
  22. bool check_get_checksum_file_pairs() {
  23. Tagmanifest p( "../testbags/bag_minimal_ok/" );
  24. multimap<checksum_string_t,filename_t> results = p.get_checksum_file_pairs( md5 );
  25. multimap<checksum_string_t,filename_t> expected = {
  26. {"939f3a18385ca2975ed6a02f4a180758", "manifest-md5.txt"},
  27. {"eaa2c609ff6371712f623f5531945b44", "bagit.txt"},
  28. };
  29. multimap<string,string>::iterator i;
  30. bool is_valid = true;
  31. for (i=expected.begin(); i!=expected.end() ; i++) {
  32. cout << "Expected: (" << (i->first) << "," << (i->second) << ")" << endl;
  33. auto idx_first_match = results.find(i->first );
  34. if (idx_first_match != results.end()) { // file found
  35. if (idx_first_match->first != i->first) {
  36. cout << "Results: (" << (idx_first_match->first) << "," << (idx_first_match->second) << ")" << endl;
  37. is_valid=false; break;
  38. }
  39. } else {
  40. cout << "Results: not found" << endl;
  41. is_valid=false; break;
  42. }
  43. }
  44. return is_valid;
  45. }
  46. bool check_get_checksummed_files() {
  47. Tagmanifest p( "../testbags/bag_minimal_ok/" );
  48. list<string> results = p.get_checksummed_files();
  49. list<string> expected {
  50. "../testbags/bag_minimal_ok/bag-info.txt"
  51. };
  52. results.sort();
  53. expected.sort();
  54. list<string>::iterator i;
  55. list<string>::iterator j;
  56. bool is_valid = true;
  57. for (i=results.begin(), j=expected.begin(); i!=results.end() && j!=expected.end(); i++, j++) {
  58. if ((*i) != (*j)) {
  59. cout << "Expected: "<< (*j) << " Result:"<< (*i) << endl;
  60. is_valid = false;
  61. break;
  62. }
  63. }
  64. return is_valid;
  65. }
  66. bool check_has_tagmanifest(string dir) {
  67. Tagmanifest p( std::move(dir) );
  68. return p.has_tagmanifest();
  69. }
  70. BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
  71. BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
  72. BOOST_AUTO_TEST_CASE(constructor3) {BOOST_TEST(check_constructor("/tmp/"));};
  73. BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
  74. BOOST_AUTO_TEST_CASE(check_checksum_file_pairs) {BOOST_TEST( check_get_checksum_file_pairs()); };
  75. BOOST_AUTO_TEST_CASE(check_checksummed_files) { BOOST_TEST(check_get_checksummed_files()); };
  76. BOOST_AUTO_TEST_CASE(check_tag_manifest) {BOOST_TEST(check_has_tagmanifest("../testbags/bag_minimal_ok/"));};
  77. BOOST_AUTO_TEST_SUITE_END();
  78. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab