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.

58 lines
1.7 KiB

  1. #define BOOST_TEST_MODULE TestPayload
  2. #include <boost/test/unit_test.hpp>
  3. #include <iostream>
  4. #include <string>
  5. #include <utility>
  6. #include "payload.hpp"
  7. BOOST_AUTO_TEST_SUITE(testbag_suite);
  8. using namespace std;
  9. bool check_constructor(string dir) {
  10. try {
  11. Payload p( std::move(dir) );
  12. return true;
  13. } catch (exception &e) {
  14. return false;
  15. }
  16. }
  17. bool check_validation(string dir) {
  18. Payload p( std::move(dir) );
  19. return p.validate();
  20. }
  21. bool check_relative_paths() {
  22. Payload p( "../testbags/bag_minimal_ok/" );
  23. list<string> results = p.get_all_relative_paths();
  24. list<string> expected {
  25. "data/1.txt",
  26. "data/3.dat",
  27. "data/subdir/2.dat",
  28. "data/subdir/2.md5",
  29. };
  30. results.sort();
  31. expected.sort();
  32. list<string>::iterator i;
  33. list<string>::iterator j;
  34. bool is_valid = true;
  35. for (i=results.begin(), j=expected.begin(); i!=results.end() && j!=expected.end(); i++, j++) {
  36. if ((*i) != (*j)) {
  37. cout << "Expected: "<< (*j) << " Result:"<< (*i) << endl;
  38. is_valid = false;
  39. break;
  40. }
  41. }
  42. return is_valid;
  43. }
  44. BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
  45. BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
  46. BOOST_AUTO_TEST_CASE(constructor3) {BOOST_TEST(check_constructor("/tmp/"));};
  47. BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
  48. BOOST_AUTO_TEST_CASE(check_validation_buggy) {BOOST_TEST(!check_validation("../testbags/1008_buggy/"));};
  49. BOOST_AUTO_TEST_CASE(check_rel_paths) { BOOST_TEST(check_relative_paths()); };
  50. BOOST_AUTO_TEST_SUITE_END();
  51. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab