Commit 3309bbf0 authored by Davis King's avatar Davis King

Updated the unit test application so that it prints the number of

individual testing statements which were executed.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%404270
parent 52f2a0ff
......@@ -185,8 +185,10 @@ int main (int argc, char** argv)
if (be_verbose)
{
cout << "\n\nTesting Finished\n";
cout << "Total number of individual testing statements executed: "<< number_of_testing_statements_executed() << endl;
cout << "All tests completed successfully\n\n";
}
dlog << LINFO << "Total number of individual testing statements executed: "<< number_of_testing_statements_executed();
dlog << LINFO << "All tests completed successfully";
}
else
......@@ -194,9 +196,11 @@ int main (int argc, char** argv)
if (be_verbose)
{
cout << "\n\nTesting Finished\n";
cout << "Total number of individual testing statements executed: "<< number_of_testing_statements_executed() << endl;
cout << "Number of failed tests: " << num_of_failed_tests << "\n";
cout << "Number of passed tests: " << num_of_passed_tests << "\n\n";
}
dlog << LINFO << "Total number of individual testing statements executed: "<< number_of_testing_statements_executed();
dlog << LWARN << "Number of failed tests: " << num_of_failed_tests;
dlog << LWARN << "Number of passed tests: " << num_of_passed_tests;
}
......
......@@ -15,6 +15,17 @@ namespace test
// -----------------------------------------------------------------------------
static dlib::mutex spinner_mutex;
static dlib::mutex test_count_mutex;
dlib::uint64 test_count = 0;
// -----------------------------------------------------------------------------
dlib::uint64 number_of_testing_statements_executed (
)
{
dlib::auto_mutex lock(test_count_mutex);
return test_count;
}
// -----------------------------------------------------------------------------
......@@ -25,13 +36,40 @@ namespace test
const char* _exp_str
)
{
test_count_mutex.lock();
++test_count;
test_count_mutex.unlock();
if ( !(_exp) )
{
std::ostringstream dlib__out;
dlib__out << "\n\nError occurred at line " << line << ".\n";
dlib__out << "Error occurred in file " << file << ".\n";
dlib__out << "Failing expression was " << _exp_str << ".\n";
throw dlib::error(dlib__out.str());
}
}
// -----------------------------------------------------------------------------
void check_test_msg (
bool _exp,
long line,
const char* file,
const char* _exp_str,
const char* _msg
)
{
test_count_mutex.lock();
++test_count;
test_count_mutex.unlock();
if ( !(_exp) )
{
std::ostringstream dlib__out;
dlib__out << "\n\nError occurred at line " << line << ".\n";
dlib__out << "Error occurred in file " << file << ".\n";
dlib__out << "Failing expression was " << _exp_str << ".\n";
throw dlib::error(dlib__out.str());
dlib__out << "\n\nError occurred at line " << line << ".\n";
dlib__out << "Error occurred in file " << file << ".\n";
dlib__out << "Failing expression was " << _exp_str << ".\n";
dlib__out << _msg << "\n";
throw dlib::error(dlib__out.str());
}
}
......
......@@ -18,17 +18,7 @@
#define DLIB_TEST(_exp) check_test(_exp, __LINE__, __FILE__, #_exp);
#define DLIB_TEST_MSG(_exp,_message) \
{if ( !(_exp) ) \
{ \
std::ostringstream dlib__out; \
dlib__out << "\n\nError occurred at line " << __LINE__ << ".\n"; \
dlib__out << "Error occurred in file " << __FILE__ << ".\n"; \
dlib__out << "Failing expression was " << #_exp << ".\n"; \
dlib__out << _message << "\n"; \
throw dlib::error(dlib__out.str()); \
}}
#define DLIB_TEST_MSG(_exp,_message) check_test_msg(_exp, __LINE__, __FILE__, #_exp, #_message);
namespace test
{
......@@ -47,12 +37,30 @@ namespace test
const char* _exp_str
);
void check_test_msg (
bool _exp,
long line,
const char* file,
const char* _exp_str,
const char* _msg
);
// -----------------------------------------------------------------------------
// This bool controls any cout statements in this program. Only print to
// standard out if we should be verbose. The default is true
extern bool be_verbose;
// -----------------------------------------------------------------------------
dlib::uint64 number_of_testing_statements_executed (
);
/*!
ensures
- returns the total number of DLIB_TEST and DLIB_TEST_MSG
statements executed since program startup.
!*/
// -----------------------------------------------------------------------------
void print_spinner (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment