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.

87 lines
2.9 KiB

  1. #define BOOST_TEST_MODULE TestPayloadManifest
  2. #include <boost/test/unit_test.hpp>
  3. #include <iostream>
  4. #include <string>
  5. #include <utility>
  6. #include "payloadmanifest.hpp"
  7. BOOST_AUTO_TEST_SUITE(testbag_suite);
  8. using namespace std;
  9. bool check_constructor(string dir) {
  10. try {
  11. Payloadmanifest p( std::move(dir) );
  12. return true;
  13. } catch (exception &e) {
  14. return false;
  15. }
  16. }
  17. bool check_validation(string dir) {
  18. Payloadmanifest p( std::move(dir) );
  19. bool res = p.validate();
  20. return res;
  21. }
  22. bool check_get_checksum_file_pairs() {
  23. Payloadmanifest 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. {"e1cbb0c3879af8347246f12c559a86b5", "data/1.txt"},
  27. {"d41d8cd98f00b204e9800998ecf8427e", "data/3.dat"},
  28. {"d41d8cd98f00b204e9800998ecf8427e", "data/subdir/2.dat"},
  29. {"227bc609651f929e367c3b2b79e09d5b", "data/subdir/2.md5"}
  30. };
  31. multimap<string,string>::iterator i;
  32. multimap<string,string>::iterator j;
  33. bool is_valid = true;
  34. for (i=expected.begin(), j=results.begin(); i!=expected.end() && j!=results.end(); i++,j++) {
  35. if (
  36. ( i->first != j-> first) ||
  37. ( i->second != j->second)
  38. ) {
  39. cout << "Expected: (" << (i->first) << "," << (i->second) << ") Result: ("<< j->first << "," << j->second << ")" << endl;
  40. is_valid=false; break;
  41. }
  42. }
  43. return is_valid;
  44. }
  45. bool check_get_checksummed_files() {
  46. Payloadmanifest p( "../testbags/bag_minimal_ok/" );
  47. list<string> results = p.get_checksummed_files();
  48. list<string> expected {
  49. "../testbags/bag_minimal_ok/data/1.txt",
  50. "../testbags/bag_minimal_ok/data/3.dat",
  51. "../testbags/bag_minimal_ok/data/subdir/2.dat",
  52. "../testbags/bag_minimal_ok/data/subdir/2.md5",
  53. };
  54. results.sort();
  55. expected.sort();
  56. list<string>::iterator i;
  57. list<string>::iterator j;
  58. bool is_valid = true;
  59. for (i=results.begin(), j=expected.begin(); i!=results.end() && j!=expected.end(); i++, j++) {
  60. if ((*i) != (*j)) {
  61. cout << "Expected: "<< (*j) << " Result:"<< (*i) << endl;
  62. is_valid = false;
  63. break;
  64. }
  65. }
  66. return is_valid;
  67. }
  68. BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
  69. BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
  70. BOOST_AUTO_TEST_CASE(constructor3) {BOOST_TEST(check_constructor("/tmp/"));};
  71. BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
  72. BOOST_AUTO_TEST_CASE(check_validation_buggy) {BOOST_TEST(!check_validation("../testbags/1008_buggy/"));};
  73. BOOST_AUTO_TEST_CASE(check_checksum_file_pairs) {BOOST_TEST( check_get_checksum_file_pairs()); };
  74. BOOST_AUTO_TEST_CASE(check_checksummed_files) { BOOST_TEST(check_get_checksummed_files()); };
  75. BOOST_AUTO_TEST_SUITE_END();
  76. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab