imb / fctx

C unit testing in a header (works for C++ too!).
Other
36 stars 15 forks source link

Better "data" blocks for initialization and teardown #9

Open imb opened 14 years ago

imb commented 14 years ago

Sometimes the following pattern,

char _data; FCT_SUITE_BGN(xxx) { FCT_SETUP_BGN() { data = malloc(sizeof(char)_N); }FCT_SETUP_END(); FCT_TEARDOWN_BGN() { free(data); } FCT_TEARDOWN_END(); FCT_TEST_BGN() { /* do test */ } FCT_TEST_END(); FCT_SUITE_END();

is akward. It is especially akward when the "data" is a C++ object that lacks a default constructor. Perhaps you have an object you would like to do a one-time initialization on, for instance:

config_t config("name", 123);
config.add(some_object_t(someparam));
config.add(other_object_t(otherparam));

Those "add" commands can't be in the "global" space, but you don't really want to call them over and over again with the setup/teardown. Its a config object that is read-only for the test suite for example.