From d59aaa88c43507a8209e5a786b9278920b378b56 Mon Sep 17 00:00:00 2001 From: Davi de Castro Reis Date: Tue, 21 Aug 2012 18:07:46 +0200 Subject: [PATCH] Fixed initialization order of test framework. --- cxxmph/test.cc | 14 ++++++++++---- cxxmph/test.h | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cxxmph/test.cc b/cxxmph/test.cc index 366e39b..a20355d 100644 --- a/cxxmph/test.cc +++ b/cxxmph/test.cc @@ -2,13 +2,19 @@ #include "test.h" -Suite* global_suite = suite_create("cxxmph_test_suite"); -TCase* global_tc_core = tcase_create("Core"); +Suite* global_suite() { + static Suite* gs = suite_create("cxxmph_test_suite"); + return gs; +} +TCase* global_tc_core() { + static TCase* gtc = tcase_create("Core"); + return gtc; +} int main (void) { - suite_add_tcase(global_suite, global_tc_core); + suite_add_tcase(global_suite(), global_tc_core()); int number_failed; - SRunner *sr = srunner_create (global_suite); + SRunner *sr = srunner_create (global_suite()); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); diff --git a/cxxmph/test.h b/cxxmph/test.h index 3054b6f..31a854c 100644 --- a/cxxmph/test.h +++ b/cxxmph/test.h @@ -9,9 +9,10 @@ // included last. #include +#include -extern Suite* global_suite; -extern TCase* global_tc_core; +Suite* global_suite(); +TCase* global_tc_core(); // Creates a new test case calling boolean_function. Name must be a valid, // unique c identifier when prefixed with tc_. @@ -24,7 +25,7 @@ extern TCase* global_tc_core; struct TestCase { TestCase(void (*f)(int)) { - tcase_add_test(global_tc_core, f); + tcase_add_test(global_tc_core(), f); } };