Add a unit tests for enforce()

This commit is contained in:
Dan Čermák 2018-03-11 23:47:43 +01:00
parent 5de9a7b562
commit 842dd4cecc
2 changed files with 25 additions and 0 deletions

View File

@ -3,6 +3,7 @@ add_executable(unit_tests mainTestRunner.cpp
test_types.cpp
test_tiffheader.cpp
test_futils.cpp
test_enforce.cpp
test_safe_op.cpp
)

View File

@ -0,0 +1,24 @@
#include <enforce.hpp>
#include "gtestwrapper.h"
TEST(enforce, errMessage)
{
try {
enforce(false, Exiv2::kerErrorMessage, "an error occurred");
} catch (const Exiv2::Error& e) {
ASSERT_STREQ(e.what(), "an error occurred");
}
}
TEST(enforce, exceptionThrown)
{
ASSERT_NO_THROW(enforce(true, Exiv2::kerErrorMessage));
ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage), Exiv2::Error);
ASSERT_THROW(enforce<std::overflow_error>(false, "error message"), std::overflow_error);
ASSERT_THROW(enforce(false, Exiv2::kerMallocFailed), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerErrorMessage, "error message"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerDataSourceOpenFailed, "path", "strerror"), Exiv2::Error);
ASSERT_THROW(enforce(false, Exiv2::kerCallFailed, "path", "strerror", "function"), Exiv2::Error);
}