From 4379641774f75cee5562c30b37272e1f87994e13 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sun, 21 Feb 2010 11:04:47 +0100 Subject: [PATCH] [tests] New adg_test_invalid_pointer() function Common code to get an invalid pointer, that is a pointer to some random memory. Using it in place of handcrafted "junk" array. It is not advisable to use naive junk pointers such as (void *) 1: this will likely point to read-only memory, hence breaking the tests because of this instead of checking the reaction with wrong pointers. --- tests/test-edges.c | 5 +---- tests/test-entity.c | 5 +---- tests/test-internal.c | 7 +++++++ tests/test-internal.h | 5 +++-- tests/test-model.c | 6 +----- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/test-edges.c b/tests/test-edges.c index 2c9766c1..cb1d6fec 100644 --- a/tests/test-edges.c +++ b/tests/test-edges.c @@ -21,9 +21,6 @@ #include "test-internal.h" -static int junk[10] = { 0 }; - - static void test_source(void) { @@ -33,7 +30,7 @@ test_source(void) edges = adg_edges_new(); valid_trail = ADG_TRAIL(adg_path_new()); - invalid_trail = (AdgTrail *) junk; + invalid_trail = adg_test_invalid_pointer(); /* Using the public APIs */ adg_edges_set_source(edges, valid_trail); diff --git a/tests/test-entity.c b/tests/test-entity.c index b8516aca..844a5128 100644 --- a/tests/test-entity.c +++ b/tests/test-entity.c @@ -21,9 +21,6 @@ #include "test-internal.h" -static int junk[10] = { 0 }; - - static void test_parent(void) { @@ -33,7 +30,7 @@ test_parent(void) entity = ADG_ENTITY(adg_logo_new()); valid_container = ADG_ENTITY(adg_container_new()); - invalid_container = (AdgEntity *) junk; + invalid_container = adg_test_invalid_pointer(); /* Using the public APIs */ adg_entity_set_parent(entity, valid_container); diff --git a/tests/test-internal.c b/tests/test-internal.c index 971a9f00..2f9b75cb 100644 --- a/tests/test-internal.c +++ b/tests/test-internal.c @@ -48,3 +48,10 @@ test_init(int *p_argc, char **p_argv[]) g_log_set_always_fatal(0); g_log_set_default_handler(null_handler, NULL); } + +gpointer +adg_test_invalid_pointer(void) +{ + static int junk[10] = { 0 }; + return junk; +} diff --git a/tests/test-internal.h b/tests/test-internal.h index e058a591..2a3d3d89 100644 --- a/tests/test-internal.h +++ b/tests/test-internal.h @@ -26,8 +26,9 @@ G_BEGIN_DECLS -void test_init (int *p_argc, - char **p_argv[]); +void test_init (int *p_argc, + char **p_argv[]); +gpointer adg_test_invalid_pointer (void) G_GNUC_CONST; G_END_DECLS diff --git a/tests/test-model.c b/tests/test-model.c index 08bd4629..34efc993 100644 --- a/tests/test-model.c +++ b/tests/test-model.c @@ -21,9 +21,6 @@ #include "test-internal.h" -static int junk[10] = { 0 }; - - static void test_named_pair(void) { @@ -31,7 +28,6 @@ test_named_pair(void) AdgPair pair; const AdgPair *got_pair; - model = ADG_MODEL(adg_path_new()); pair.x = -1234; pair.y = 4321; @@ -61,7 +57,7 @@ test_dependency(void) model = ADG_MODEL(adg_path_new()); valid_entity = ADG_ENTITY(adg_logo_new()); - invalid_entity = (AdgEntity *) junk; + invalid_entity = adg_test_invalid_pointer(); /* Using the public APIs */ adg_model_add_dependency(model, NULL); -- 2.11.4.GIT