Browse Source

- added testcases for has_/get_/set_* functions

master
Andreas Romeyke 2 years ago
parent
commit
2337f58c1b
1 changed files with 289 additions and 20 deletions
  1. +289
    -20
      test/test_bagmetadata.cpp

+ 289
- 20
test/test_bagmetadata.cpp View File

@@ -10,18 +10,18 @@
using namespace std;

bool check_constructor(string dir) {
try {
Bagmetadata p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
}
try {
Bagmetadata p( std::move(dir) );
return true;
} catch (exception &e) {
return false;
}
}

bool check_validation(string dir) {
Bagmetadata p( std::move(dir) );
bool res = p.validate();
return res;
Bagmetadata p( std::move(dir) );
bool res = p.validate();
return res;
}

bool check_get_metadata(string dir) {
@@ -52,19 +52,21 @@ bool check_get_metadata(string dir) {
}

bool check_has_metadata(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_metadata();
Bagmetadata p( std::move(dir) );
return p.has_metadata();
}

/*
bool check_has_PayloadOxum(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_PayloadOxum();
Bagmetadata p( std::move(dir) );
return p.has_PayloadOxum();
}

oxum_t check_get_PayloadOxum(string dir) {
Bagmetadata p( std::move(dir) );
return p.get_PayloadOxum();
Bagmetadata p( std::move(dir) );
return p.get_PayloadOxum();
}
*/

bool check_store( string dir_load_from, string dir_store_to ) {
Bagmetadata p( std::move(dir_load_from) );
@@ -72,6 +74,225 @@ bool check_store( string dir_load_from, string dir_store_to ) {
return result;
}

//


bool check_set_SourceOrganization(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_SourceOrganization( expected );
string result = p.get_SourceOrganization();
return (0 == expected.compare( result ) );
}
bool check_set_OrganizationAddress(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_OrganizationAddress( expected );
string result = p.get_OrganizationAddress();
return (0 == expected.compare( result ) );
}
bool check_set_ContactName(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_ContactName( expected );
string result = p.get_ContactName();
return (0 == expected.compare( result ) );
}
bool check_set_ContactPhone(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_ContactPhone( expected );
string result = p.get_ContactPhone();
return (0 == expected.compare( result ) );
}
bool check_set_ContactEmail(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_ContactEmail( expected );
string result = p.get_ContactEmail();
return (0 == expected.compare( result ) );
}
bool check_set_ExternalDescription(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_ExternalDescription( expected );
string result = p.get_ExternalDescription();
return (0 == expected.compare( result ) );
}
bool check_set_BaggingDate(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_BaggingDate( expected );
string result = p.get_BaggingDate();
return (0 == expected.compare( result ) );
}
bool check_set_ExternalIdentifier(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_ExternalIdentifier( expected );
string result = p.get_ExternalIdentifier();
return (0 == expected.compare( result ) );
}
bool check_set_BagSize(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_BagSize( expected );
string result = p.get_BagSize();
return (0 == expected.compare( result ) );
}
bool check_set_PayloadOxum(string dir, oxum_t expected) {
Bagmetadata p( std::move(dir) );
p.set_PayloadOxum( expected );
oxum_t result = p.get_PayloadOxum();

return (expected.octetcount == result.octetcount
&& expected.streamcount == result.streamcount
);
}
bool check_set_BagGroupIdentifier(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_BagGroupIdentifier( expected );
string result = p.get_BagGroupIdentifier();
return (0 == expected.compare( result ) );
}
bool check_set_BagCount(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_BagCount( expected );
string result = p.get_BagCount();
return (0 == expected.compare( result ) );
}
bool check_set_InternalSenderIdentifier(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_InternalSenderIdentifier( expected );
string result = p.get_InternalSenderIdentifier();
return (0 == expected.compare( result ) );
}
bool check_set_InternalSenderDescription(string dir, string expected) {
Bagmetadata p( std::move(dir) );
p.set_InternalSenderDescription( expected );
string result = p.get_InternalSenderDescription();
return (0 == expected.compare( result ) );
}

//

bool check_has_SourceOrganization(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_SourceOrganization();
}
bool check_has_OrganizationAddress(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_OrganizationAddress();
}
bool check_has_ContactName(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_ContactName();
}
bool check_has_ContactPhone(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_ContactPhone();
}
bool check_has_ContactEmail(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_ContactEmail();
}
bool check_has_ExternalDescription(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_ExternalDescription();
}
bool check_has_BaggingDate(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_BaggingDate();
}
bool check_has_ExternalIdentifier(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_ExternalIdentifier();
}
bool check_has_BagSize(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_BagSize();
}
bool check_has_PayloadOxum(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_PayloadOxum();
}
bool check_has_BagGroupIdentifier(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_BagGroupIdentifier();
}
bool check_has_BagCount(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_BagCount();
}
bool check_has_InternalSenderIdentifier(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_InternalSenderIdentifier();
}
bool check_has_InternalSenderDescription(string dir) {
Bagmetadata p( std::move(dir) );
return p.has_InternalSenderDescription();
}

//
//
//

bool check_get_SourceOrganization(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_SourceOrganization() ));
}
bool check_get_OrganizationAddress(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_OrganizationAddress() ));
}
bool check_get_ContactName(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_ContactName() ));
}
bool check_get_ContactPhone(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_ContactPhone() ));
}
bool check_get_ContactEmail(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_ContactEmail() ));
}
bool check_get_ExternalDescription(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_ExternalDescription() ));
}
bool check_get_BaggingDate(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_BaggingDate() ));
}
bool check_get_ExternalIdentifier(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_ExternalIdentifier() ));
}
bool check_get_BagSize(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_BagSize() ));
}
bool check_get_PayloadOxum(string dir, oxum_t expected) {
Bagmetadata p ( std::move(dir) );
oxum_t result = p.get_PayloadOxum();
return (
result.octetcount == expected.octetcount
&& result.streamcount == expected.streamcount
);
}
bool check_get_BagGroupIdentifier(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_BagGroupIdentifier() ));
}
bool check_get_BagCount(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_BagCount() ));
}
bool check_get_InternalSenderIdentifier(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_InternalSenderIdentifier() ));
}
bool check_get_InternalSenderDescription(string dir, string expected) {
Bagmetadata p ( std::move(dir) );
return (0== expected.compare( p.get_InternalSenderDescription() ));
}

//
//
//
//
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/"));};
@@ -81,15 +302,63 @@ BOOST_AUTO_TEST_CASE(check_metadata) {BOOST_TEST( check_get_metadata("../testbag
BOOST_AUTO_TEST_CASE(check_oxum_exists) {BOOST_TEST( check_has_PayloadOxum("../testbags/bag_minimal_ok/")); };
BOOST_AUTO_TEST_CASE(check_oxum) {
oxum_t expected{};
expected.octetcount=38;
expected.streamcount=4;
oxum_t result = check_get_PayloadOxum("../testbags/bag_minimal_ok/");
BOOST_TEST( expected.octetcount == result.octetcount);
BOOST_TEST( expected.streamcount == result.streamcount);
expected.octetcount=38;
expected.streamcount=4;
BOOST_TEST( check_get_PayloadOxum("../testbags/bag_minimal_ok/", expected));
};




BOOST_AUTO_TEST_CASE(check_validation_ok) {BOOST_TEST(check_validation("../testbags/bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_store_ok) {BOOST_TEST(check_store("../testbags/bag_minimal_ok/", "/tmp/testbag/"));};



//BOOST_AUTO_TEST_CASE(check_has_PayloadOxum_ok) {BOOST_TEST(check_has_PayloadOxum("../testbags_bag_minimal_ok/"));};
//BOOST_AUTO_TEST_CASE(check_get_PayloadOxum_ok) {BOOST_TEST(check_get_PayloadOxum("../testbags_bag_minimal_ok/"));};
//BOOST_AUTO_TEST_CASE(check_store_ok) {BOOST_TEST(check_store("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_set_SourceOrganization_ok) {BOOST_TEST(check_set_SourceOrganization("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_OrganizationAddress_ok) {BOOST_TEST(check_set_OrganizationAddress("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_ContactName_ok) {BOOST_TEST(check_set_ContactName("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_ContactPhone_ok) {BOOST_TEST(check_set_ContactPhone("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_ContactEmail_ok) {BOOST_TEST(check_set_ContactEmail("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_ExternalDescription_ok) {BOOST_TEST(check_set_ExternalDescription("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_BaggingDate_ok) {BOOST_TEST(check_set_BaggingDate("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_ExternalIdentifier_ok) {BOOST_TEST(check_set_ExternalIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_BagSize_ok) {BOOST_TEST(check_set_BagSize("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_PayloadOxum_ok) {BOOST_TEST(check_set_PayloadOxum("../testbags_bag_minimal_ok/", {2,1}));};
BOOST_AUTO_TEST_CASE(check_set_BagGroupIdentifier_ok) {BOOST_TEST(check_set_BagGroupIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_BagCount_ok) {BOOST_TEST(check_set_BagCount("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_InternalSenderIdentifier_ok) {BOOST_TEST(check_set_InternalSenderIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_set_InternalSenderDescription_ok) {BOOST_TEST(check_set_InternalSenderDescription("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_has_SourceOrganization_ok) {BOOST_TEST(check_has_SourceOrganization("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_OrganizationAddress_ok) {BOOST_TEST(check_has_OrganizationAddress("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_ContactName_ok) {BOOST_TEST(check_has_ContactName("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_ContactPhone_ok) {BOOST_TEST(check_has_ContactPhone("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_ContactEmail_ok) {BOOST_TEST(check_has_ContactEmail("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_ExternalDescription_ok) {BOOST_TEST(check_has_ExternalDescription("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_BaggingDate_ok) {BOOST_TEST(check_has_BaggingDate("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_ExternalIdentifier_ok) {BOOST_TEST(check_has_ExternalIdentifier("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_BagSize_ok) {BOOST_TEST(check_has_BagSize("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_PayloadOxum_ok) {BOOST_TEST(check_has_PayloadOxum("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_BagGroupIdentifier_ok) {BOOST_TEST(check_has_BagGroupIdentifier("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_BagCount_ok) {BOOST_TEST(check_has_BagCount("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_InternalSenderIdentifier_ok) {BOOST_TEST(check_has_InternalSenderIdentifier("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_has_InternalSenderDescription_ok) {BOOST_TEST(check_has_InternalSenderDescription("../testbags_bag_minimal_ok/"));};
BOOST_AUTO_TEST_CASE(check_get_SourceOrganization_ok) {BOOST_TEST(check_get_SourceOrganization("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_OrganizationAddress_ok) {BOOST_TEST(check_get_OrganizationAddress("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_ContactName_ok) {BOOST_TEST(check_get_ContactName("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_ContactPhone_ok) {BOOST_TEST(check_get_ContactPhone("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_ContactEmail_ok) {BOOST_TEST(check_get_ContactEmail("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_ExternalDescription_ok) {BOOST_TEST(check_get_ExternalDescription("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_BaggingDate_ok) {BOOST_TEST(check_get_BaggingDate("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_ExternalIdentifier_ok) {BOOST_TEST(check_get_ExternalIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_BagSize_ok) {BOOST_TEST(check_get_BagSize("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_PayloadOxum_ok) {BOOST_TEST(check_get_PayloadOxum("../testbags_bag_minimal_ok/", {2, 1}));};
BOOST_AUTO_TEST_CASE(check_get_BagGroupIdentifier_ok) {BOOST_TEST(check_get_BagGroupIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_BagCount_ok) {BOOST_TEST(check_get_BagCount("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_InternalSenderIdentifier_ok) {BOOST_TEST(check_get_InternalSenderIdentifier("../testbags_bag_minimal_ok/", "test"));};
BOOST_AUTO_TEST_CASE(check_get_InternalSenderDescription_ok) {BOOST_TEST(check_get_InternalSenderDescription("../testbags_bag_minimal_ok/", "test"));};

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

Loading…
Cancel
Save