Browse Source

- added unit tests for payloadmanifest

master
parent
commit
143336abf9
3 changed files with 99 additions and 0 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +7
    -0
      test/CMakeLists.txt
  3. +91
    -0
      test/test_payloadmanifest.cpp

+ 1
- 0
CMakeLists.txt View File

@@ -6,3 +6,4 @@ add_subdirectory(test)
enable_testing()
add_test(NAME Mytest COMMAND Mytest)
add_test(NAME TestPayload COMMAND TestPayload)
add_test(NAME TestPayloadManifest COMMAND TestPayloadManifest)

+ 7
- 0
test/CMakeLists.txt View File

@@ -8,10 +8,17 @@ include_directories("${libcbag_dir}/src/include")
message(status "** libcbag Include: ${libcbag_dir}")
message(status "** libcbag Libraries: ${libcbag_BINARY_DIR}")
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
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(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)
target_link_libraries(TestPayloadManifest ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} libcbag)



+ 91
- 0
test/test_payloadmanifest.cpp View File

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

#include "payloadmanifest.hpp"

using namespace std;



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

bool check_validation(string dir) {
list<string> log;
Payloadmanifest 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() {
Payloadmanifest 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 = {
{"e1cbb0c3879af8347246f12c559a86b5", "data/1.txt"},
{"d41d8cd98f00b204e9800998ecf8427e", "data/3.dat"},
{"d41d8cd98f00b204e9800998ecf8427e", "data/subdir/2.dat"},
{"227bc609651f929e367c3b2b79e09d5b", "data/subdir/2.md5"}
};

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() {
Payloadmanifest p( "../testbags/bag_minimal_ok/" );
list<string> results = p.get_checksummed_files();
list<string> expected {
"../testbags/bag_minimal_ok/data/1.txt",
"../testbags/bag_minimal_ok/data/3.dat",
"../testbags/bag_minimal_ok/data/subdir/2.dat",
"../testbags/bag_minimal_ok/data/subdir/2.md5",
};
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;
}


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_validation_buggy) {BOOST_TEST(!check_validation("../testbags/1008_buggy/"));};
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()); };

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

Loading…
Cancel
Save