From 2bc328f237880d2ba2b580ca18a00ba0b5b7c0b2 Mon Sep 17 00:00:00 2001 From: Ruben Laguna Date: Fri, 6 Feb 2015 18:15:29 +0100 Subject: [PATCH] Add example g_add_test Now it should be easier to start adding tests --- tests/test.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/test.c b/tests/test.c index 0cff184..aa6b318 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,11 +1,30 @@ #include #include #include +#include + +typedef struct { + int a; /* usually some other data structure that you + * need for your tests */ +} dfixture; + +void my_setup(dfixture *df, gconstpointer test_data) { + /* here goes the code to setup fixture */ +} + +void my_teardown(dfixture *df, gconstpointer test_data) { + /* here goes the code to free/cleanup fixture */ +} + +void my_first_test(dfixture *df, gconstpointer ignored) { + /* g_assert(false); */ + g_assert(true); +} int main(int argc, char *argv[]) { + /* https://developer.gnome.org/glib/stable/glib-Testing.html */ g_test_init(&argc, &argv, NULL); - printf("Write some tests!!! Failing!\n"); - exit(EXIT_FAILURE); - return 0; + g_test_add("/set0/my first test", /* type fixture*/ dfixture, /*tdata*/NULL, /*fsetup*/ my_setup, my_first_test, my_teardown); + return g_test_run(); }