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.

78 lines
2.4 KiB

  1. #define BOOST_TEST_MODULE TestFetchFile
  2. #include <boost/test/unit_test.hpp>
  3. #include <iostream>
  4. #include <string>
  5. #include <list>
  6. #include <utility>
  7. #include <boost/filesystem.hpp>
  8. namespace fs = boost::filesystem;
  9. #include "fetchfile.hpp"
  10. BOOST_AUTO_TEST_SUITE(testbag_suite);
  11. using namespace std;
  12. bool check_constructor(string dir) {
  13. try {
  14. Fetchfile p( std::move(dir) );
  15. return true;
  16. } catch (exception &e) {
  17. return false;
  18. }
  19. }
  20. bool check_validation(string dir) {
  21. Fetchfile p( std::move(dir) );
  22. return p.validate();
  23. }
  24. bool check_store( string dir_load_from, string dir_store_to ) {
  25. Fetchfile p( std::move(dir_load_from) );
  26. fs::path f{ dir_store_to };
  27. fs::create_directory(f);
  28. bool result = p.store( std::move(dir_store_to) );
  29. fs::remove_all( f );
  30. return result;
  31. }
  32. bool check_get_fetchfile(string dir) {
  33. Fetchfile p( std::move(dir) );
  34. list<fetch_t> results = p.get_entries();
  35. list<fetch_t> expected;
  36. list<fetch_t>::iterator i;
  37. list<fetch_t>::iterator j;
  38. bool is_valid = true;
  39. for (i=expected.begin(), j=results.begin(); i!=expected.end() && j!=results.end(); i++,j++) {
  40. if (
  41. ( i->url != j-> url) ||
  42. ( i->size != j->size) ||
  43. ( i->filename != j->filename)
  44. ) {
  45. cout << "Expected: (" << (i->url) << ";" << (i->size) << ";"<< (i->filename)<< ")" << endl;
  46. cout << "Result: ("<< (j->url) << ";" << (j->size) << ";" << (j->filename)<< ")" << endl;
  47. is_valid=false; break;
  48. }
  49. }
  50. return is_valid;
  51. }
  52. bool check_has_fetchfile(string dir) {
  53. Fetchfile p( std::move(dir) );
  54. return p.has_fetchfile();
  55. }
  56. BOOST_AUTO_TEST_CASE(constructor1) {BOOST_TEST(check_constructor(""));};
  57. BOOST_AUTO_TEST_CASE(constructor2) {BOOST_TEST(check_constructor("./"));};
  58. BOOST_AUTO_TEST_CASE(constructor3) {BOOST_TEST(check_constructor("/tmp/"));};
  59. BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
  60. BOOST_AUTO_TEST_CASE(check_validation_buggy) {BOOST_TEST(check_validation("../testbags/1008_buggy/"));};
  61. BOOST_AUTO_TEST_CASE(check_fetchfile_exists) {BOOST_TEST(! check_has_fetchfile("../testbags/bag_minimal_ok/")); };
  62. BOOST_AUTO_TEST_CASE(check_fetchfile) {BOOST_TEST( check_get_fetchfile("../testbags/bag_minimal_ok/")); };
  63. BOOST_AUTO_TEST_CASE(check_store_ok) {BOOST_TEST(check_store("../testbags/bag_minimal_ok/", "/tmp/testbag/"));};
  64. BOOST_AUTO_TEST_SUITE_END();
  65. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab