From 740ce08c86a34836cc3875f3c803f53a2b058cba Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 13 Dec 2008 01:38:54 +0000 Subject: Better failed test reporting. Comment out some unused code. git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1853 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 6 ++- src/port.c | 2 + src/slv2_internal.h | 2 +- test/slv2_test.c | 145 ++++++++++++++++++++++++++-------------------------- 4 files changed, 80 insertions(+), 75 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 497d4bd..7a9b32e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -88,7 +88,8 @@ slv2_plugin_free(SLV2Plugin p) /** comparator for sorting */ -/*static int +#if 0 +static int slv2_port_compare_by_index(const void* a, const void* b) { SLV2Port port_a = *(SLV2Port*)a; @@ -100,7 +101,8 @@ slv2_port_compare_by_index(const void* a, const void* b) return 0; else //if (port_a->index > port_b->index) return 1; -}*/ +} +#endif void diff --git a/src/port.c b/src/port.c index 7fd3ede..27cc297 100644 --- a/src/port.c +++ b/src/port.c @@ -54,6 +54,7 @@ slv2_port_free(SLV2Port port) /* private */ +#if 0 SLV2Port slv2_port_duplicate(SLV2Port port) { @@ -62,6 +63,7 @@ slv2_port_duplicate(SLV2Port port) ret->symbol = slv2_value_duplicate(port->symbol); return ret; } +#endif bool diff --git a/src/slv2_internal.h b/src/slv2_internal.h index f5c0ace..48193c7 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -45,7 +45,7 @@ struct _SLV2Port { SLV2Port slv2_port_new(SLV2World world, uint32_t index, const char* symbol); -SLV2Port slv2_port_duplicate(SLV2Port port); +//SLV2Port slv2_port_duplicate(SLV2Port port); void slv2_port_free(SLV2Port port); diff --git a/test/slv2_test.c b/test/slv2_test.c index 64a6f66..039a148 100644 --- a/test/slv2_test.c +++ b/test/slv2_test.c @@ -1,4 +1,4 @@ -/* SLV2 +/* SLV2 Tests * Copyright (C) 2008 Dave Robillard * Copyright (C) 2008 Krzysztof Foltman * @@ -141,10 +141,16 @@ cleanup() /*****************************************************************************/ -#define TESTCASE(name) { #name, test_##name } -#define TESTITEM(check) do { test_count++; if (!(check)) { error_count++; fprintf(stderr, "Failed: %s\n", #check); } } while(0); +#define TEST_CASE(name) { #name, test_##name } +#define TEST_ASSERT(check) do {\ + test_count++;\ + if (!(check)) {\ + error_count++;\ + fprintf(stderr, "Failure at slv2_test.c:%d: %s\n", __LINE__, #check);\ + }\ +} while (0); -typedef int (*TestFunc) (); +typedef int (*TestFunc)(); struct TestCase { const char *title; @@ -172,8 +178,8 @@ init_uris() { plugin_uri_value = slv2_value_new_uri(world, uris_plugin); plugin2_uri_value = slv2_value_new_uri(world, "http://example.com/foobar"); - TESTITEM(plugin_uri_value); - TESTITEM(plugin2_uri_value); + TEST_ASSERT(plugin_uri_value); + TEST_ASSERT(plugin2_uri_value); } void @@ -190,9 +196,9 @@ cleanup_uris() int test_utils() { - TESTITEM(!strcmp(slv2_uri_to_path("file:///tmp/blah"), "/tmp/blah")); - TESTITEM(!slv2_uri_to_path("file:/example.com/blah")); - TESTITEM(!slv2_uri_to_path("http://example.com/blah")); + TEST_ASSERT(!strcmp(slv2_uri_to_path("file:///tmp/blah"), "/tmp/blah")); + TEST_ASSERT(!slv2_uri_to_path("file:/example.com/blah")); + TEST_ASSERT(!slv2_uri_to_path("http://example.com/blah")); return 1; } @@ -207,38 +213,38 @@ test_value() init_world(); v1 = slv2_value_new_uri(world, "http://example.com/"); - TESTITEM(v1); - TESTITEM(slv2_value_is_uri(v1)); - TESTITEM(!strcmp(slv2_value_as_uri(v1), uri)); - TESTITEM(!slv2_value_is_literal(v1)); - TESTITEM(!slv2_value_is_string(v1)); - TESTITEM(!slv2_value_is_float(v1)); - TESTITEM(!slv2_value_is_int(v1)); + TEST_ASSERT(v1); + TEST_ASSERT(slv2_value_is_uri(v1)); + TEST_ASSERT(!strcmp(slv2_value_as_uri(v1), uri)); + TEST_ASSERT(!slv2_value_is_literal(v1)); + TEST_ASSERT(!slv2_value_is_string(v1)); + TEST_ASSERT(!slv2_value_is_float(v1)); + TEST_ASSERT(!slv2_value_is_int(v1)); res = slv2_value_get_turtle_token(v1); - TESTITEM(!strcmp(res, "")); + TEST_ASSERT(!strcmp(res, "")); v2 = slv2_value_new_uri(world, uri); - TESTITEM(v2); - TESTITEM(slv2_value_is_uri(v2)); - TESTITEM(!strcmp(slv2_value_as_uri(v2), uri)); + TEST_ASSERT(v2); + TEST_ASSERT(slv2_value_is_uri(v2)); + TEST_ASSERT(!strcmp(slv2_value_as_uri(v2), uri)); - TESTITEM(slv2_value_equals(v1, v2)); + TEST_ASSERT(slv2_value_equals(v1, v2)); v3 = slv2_value_new_uri(world, "http://example.com/another"); - TESTITEM(v3); - TESTITEM(slv2_value_is_uri(v3)); - TESTITEM(!strcmp(slv2_value_as_uri(v3), "http://example.com/another")); - TESTITEM(!slv2_value_equals(v1, v3)); + TEST_ASSERT(v3); + TEST_ASSERT(slv2_value_is_uri(v3)); + TEST_ASSERT(!strcmp(slv2_value_as_uri(v3), "http://example.com/another")); + TEST_ASSERT(!slv2_value_equals(v1, v3)); slv2_value_free(v2); v2 = slv2_value_duplicate(v1); - TESTITEM(slv2_value_equals(v1, v2)); - TESTITEM(slv2_value_is_uri(v2)); - TESTITEM(!strcmp(slv2_value_as_uri(v2), uri)); - TESTITEM(!slv2_value_is_literal(v2)); - TESTITEM(!slv2_value_is_string(v2)); - TESTITEM(!slv2_value_is_float(v2)); - TESTITEM(!slv2_value_is_int(v2)); + TEST_ASSERT(slv2_value_equals(v1, v2)); + TEST_ASSERT(slv2_value_is_uri(v2)); + TEST_ASSERT(!strcmp(slv2_value_as_uri(v2), uri)); + TEST_ASSERT(!slv2_value_is_literal(v2)); + TEST_ASSERT(!slv2_value_is_string(v2)); + TEST_ASSERT(!slv2_value_is_float(v2)); + TEST_ASSERT(!slv2_value_is_int(v2)); slv2_value_free(v3); slv2_value_free(v2); @@ -257,9 +263,9 @@ test_values() init_world(); v0 = slv2_value_new_uri(world, "http://example.com/"); vs1 = slv2_values_new(); - TESTITEM(vs1); - TESTITEM(!slv2_values_size(vs1)); - TESTITEM(!slv2_values_contains(vs1, v0)); + TEST_ASSERT(vs1); + TEST_ASSERT(!slv2_values_size(vs1)); + TEST_ASSERT(!slv2_values_contains(vs1, v0)); slv2_values_free(vs1); slv2_value_free(v0); return 1; @@ -299,16 +305,16 @@ discovery_verify_plugin(SLV2Plugin plugin) SLV2Value value = slv2_plugin_get_uri(plugin); if (slv2_value_equals(value, plugin_uri_value)) { SLV2Value lib_uri = NULL; - TESTITEM(!slv2_value_equals(value, plugin2_uri_value)); + TEST_ASSERT(!slv2_value_equals(value, plugin2_uri_value)); discovery_plugin_found = 1; lib_uri = slv2_plugin_get_library_uri(plugin); - TESTITEM(lib_uri); - TESTITEM(slv2_value_is_uri(lib_uri)); - TESTITEM(slv2_value_as_uri(lib_uri)); - TESTITEM(strstr(slv2_value_as_uri(lib_uri), "foo.so")); + TEST_ASSERT(lib_uri); + TEST_ASSERT(slv2_value_is_uri(lib_uri)); + TEST_ASSERT(slv2_value_as_uri(lib_uri)); + TEST_ASSERT(strstr(slv2_value_as_uri(lib_uri), "foo.so")); /* this is already being tested as ticket291, but the discovery and ticket291 * may diverge at some point, so I'm duplicating it here */ - TESTITEM(slv2_plugin_verify(plugin)); + TEST_ASSERT(slv2_plugin_verify(plugin)); } } @@ -338,58 +344,53 @@ test_discovery_variant(int load_all) * lookup 5: no plugins (get_plugins_by_filter, non-existing plugin) */ for (int lookup = 1; lookup <= 5; lookup++) { - printf("Lookup variant %d\n", lookup); + //printf("Lookup variant %d\n", lookup); int expect_found = 0; switch (lookup) { case 1: plugins = slv2_world_get_all_plugins(world); - TESTITEM(slv2_plugins_size(plugins) > 0); + TEST_ASSERT(slv2_plugins_size(plugins) > 0); expect_found = 1; break; case 2: - plugins = - slv2_world_get_plugins_by_filter(world, - discovery_plugin_filter_all); - TESTITEM(slv2_plugins_size(plugins) > 0); + plugins = slv2_world_get_plugins_by_filter(world, + discovery_plugin_filter_all); + TEST_ASSERT(slv2_plugins_size(plugins) > 0); expect_found = 1; break; case 3: - plugins = - slv2_world_get_plugins_by_filter(world, - discovery_plugin_filter_none); - TESTITEM(slv2_plugins_size(plugins) == 0); + plugins = slv2_world_get_plugins_by_filter(world, + discovery_plugin_filter_none); + TEST_ASSERT(slv2_plugins_size(plugins) == 0); break; case 4: - plugins = - slv2_world_get_plugins_by_filter(world, - discovery_plugin_filter_ours); - TESTITEM(slv2_plugins_size(plugins) == 1); + plugins = slv2_world_get_plugins_by_filter(world, + discovery_plugin_filter_ours); + TEST_ASSERT(slv2_plugins_size(plugins) == 1); expect_found = 1; break; case 5: - plugins = - slv2_world_get_plugins_by_filter(world, - discovery_plugin_filter_fake); - TESTITEM(slv2_plugins_size(plugins) == 0); + plugins = slv2_world_get_plugins_by_filter(world, + discovery_plugin_filter_fake); + TEST_ASSERT(slv2_plugins_size(plugins) == 0); break; } explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TESTITEM((explug != NULL) == expect_found); + TEST_ASSERT((explug != NULL) == expect_found); explug2 = slv2_plugins_get_by_uri(plugins, plugin2_uri_value); - TESTITEM(explug2 == NULL); + TEST_ASSERT(explug2 == NULL); if (explug && expect_found) { - TESTITEM(!strcmp - (slv2_value_as_string(slv2_plugin_get_name(explug)), - "Test plugin")); + TEST_ASSERT(!strcmp(slv2_value_as_string(slv2_plugin_get_name(explug)), + "Test plugin")); } discovery_plugin_found = 0; for (size_t i = 0; i < slv2_plugins_size(plugins); i++) discovery_verify_plugin(slv2_plugins_get_at(plugins, i)); - TESTITEM(discovery_plugin_found == expect_found); + TEST_ASSERT(discovery_plugin_found == expect_found); slv2_plugins_free(world, plugins); plugins = NULL; } @@ -433,7 +434,7 @@ test_verify() init_uris(); plugins = slv2_world_get_all_plugins(world); explug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); - TESTITEM(explug); + TEST_ASSERT(explug); slv2_plugin_verify(explug); slv2_plugins_free(world, plugins); cleanup_uris(); @@ -444,12 +445,12 @@ test_verify() /* add tests here */ static struct TestCase tests[] = { - TESTCASE(utils), - TESTCASE(value), - TESTCASE(values), - /* TESTCASE(discovery_load_bundle), */ - TESTCASE(verify), - TESTCASE(discovery_load_all), + TEST_CASE(utils), + TEST_CASE(value), + TEST_CASE(values), + /* TEST_CASE(discovery_load_bundle), */ + TEST_CASE(verify), + TEST_CASE(discovery_load_all), { NULL, NULL } }; -- cgit v1.2.1