Add assertion function to TestConnections

The TestConnections::assert behaves much like the normal assert function
by simply inverting the check for add_result.
This commit is contained in:
Markus Mäkelä 2017-12-04 10:12:50 +02:00
parent 74e781a3c3
commit 277ece53d0
2 changed files with 33 additions and 11 deletions

View File

@ -322,28 +322,44 @@ TestConnections::~TestConnections()
}
}
void TestConnections::add_result(int result, const char *format, ...)
void TestConnections::report_result(const char *format, va_list argp)
{
timeval t2;
gettimeofday(&t2, NULL);
double elapsedTime = (t2.tv_sec - start_time.tv_sec);
elapsedTime += (double) (t2.tv_usec - start_time.tv_usec) / 1000000.0;
if (result != 0)
global_result += 1;
printf("%04f: TEST_FAILED! ", elapsedTime);
vprintf(format, argp);
if (format[strlen(format) - 1] != '\n')
{
global_result += result;
printf("%04f: TEST_FAILED! ", elapsedTime);
printf("\n");
}
}
void TestConnections::add_result(bool result, const char *format, ...)
{
if (result)
{
va_list argp;
va_start(argp, format);
vprintf(format, argp);
report_result(format, argp);
va_end(argp);
}
}
if (format[strlen(format) - 1] != '\n')
{
printf("\n");
}
void TestConnections::assert(bool result, const char *format, ...)
{
if (!result)
{
va_list argp;
va_start(argp, format);
report_result(format, argp);
va_end(argp);
}
}

View File

@ -322,7 +322,10 @@ public:
* @param result 0 if step PASSED
* @param format ... message to pring if result is not 0
*/
void add_result(int result, const char *format, ...);
void add_result(bool result, const char *format, ...);
/** Same as add_result() but inverted */
void assert(bool result, const char *format, ...);
/**
* @brief ReadEnv Reads all Maxscale and Master/Slave and Galera setups info from environmental variables
@ -716,6 +719,9 @@ public:
* @param dest Destination file name for actual configuration file
*/
void process_template(const char *src, const char *dest = "/etc/maxscale.cnf");
private:
void report_result(const char *format, va_list argp);
};
/**