Update tester wrapper

parent 4ff6165a
......@@ -75,7 +75,18 @@ if(POLARSSL_FOUND)
endif()
if (ENABLE_TESTS)
find_package(CUnit REQUIRED)
find_package(CUnit)
if(CUNIT_FOUND)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
check_symbol_exists("CU_get_suite" "CUnit/CUnit.h" HAVE_CU_GET_SUITE)
check_symbol_exists("CU_curses_run_tests" "CUnit/CUnit.h" HAVE_CU_CURSES)
cmake_pop_check_state()
else()
message(WARNING "Could not find the cunit library!")
set(ENABLE_UNIT_TESTS OFF CACHE BOOL "Enable compilation of unit tests." FORCE)
endif()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bctoolbox.pc.in ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc)
......
......@@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TESTER_UTILS_H
#define TESTER_UTILS_H
#ifndef BCTOOLBOX_TESTER_H
#define BCTOOLBOX_TESTER_H
#include <stdio.h>
#include <stdarg.h>
......@@ -63,7 +63,7 @@ typedef struct {
before_all; /*function invoked before running the suite. If not returning 0, suite is not launched. */
pre_post_function_t after_all; /*function invoked at the end of the suite, even if some tests failed. */
test_function_t before_each; /*function invoked before each test within this suite. */
test_function_t after_each; /*function invoked after each test within this suite, even if it failed. */
pre_post_function_t after_each; /*function invoked after each test within this suite, even if it failed. */
int nb_tests; /* number of tests */
test_t *tests; /* tests within this suite */
} test_suite_t;
......@@ -103,6 +103,7 @@ int bc_tester_run_tests(const char *suite_name, const char *test_name, const cha
int bc_tester_suite_index(const char *suite_name);
const char * bc_tester_current_suite_name(void);
const char * bc_tester_current_test_name(void);
const char ** bc_tester_current_test_tags(void);
char* bc_sprintfva(const char* format, va_list args);
char* bc_sprintf(const char* format, ...);
......
......@@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bctoolbox/tester.h>
#include <stdlib.h>
......@@ -80,10 +79,10 @@ int xml_enabled = 0;
char * suite_name = NULL;
char * test_name = NULL;
char * tag_name = NULL;
char * expected_res = NULL;
static long max_vm_kb = 0;
void (*tester_printf_va)(int level, const char *format, va_list args);
char * expected_res = NULL;
void bc_tester_printf(int level, const char *format, ...) {
va_list args;
......@@ -147,6 +146,19 @@ int bc_tester_suite_index(const char *suite_name) {
return -1;
}
int bc_tester_test_index(test_suite_t *suite, const char *test_name) {
int i;
for (i = 0; i < suite->nb_tests; i++) {
if (strcmp(test_name, suite->tests[i].name) == 0) {
return i;
}
}
return -1;
}
int bc_tester_nb_suites(void) {
return nb_test_suites;
}
......@@ -245,7 +257,11 @@ static void test_complete_message_handler(const CU_pTest pTest, const CU_pSuite
free(result);
if (test_suite[suite_index]->after_each) {
test_suite[suite_index]->after_each();
int err = test_suite[suite_index]->after_each();
//if test passed but not after_each, count it as failure
if (err && !pFailure) {
CU_get_run_summary()->nTestsFailed++;
}
}
//insert empty line
bc_tester_printf(bc_printf_verbosity_info,"");
......@@ -702,3 +718,12 @@ const char * bc_tester_current_suite_name(void) {
const char * bc_tester_current_test_name(void) {
return bc_current_test_name;
}
const char ** bc_tester_current_test_tags(void) {
if (bc_current_suite_name && bc_current_test_name) {
int suite_index = bc_tester_suite_index(bc_current_suite_name);
int test_index = bc_tester_test_index(test_suite[suite_index], bc_current_test_name);
return test_suite[suite_index]->tests[test_index].tags;
}
return NULL;
}
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