From edbffff51f8769c58b977e6d860501928d234f80 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 13 Dec 2008 18:50:07 +0000 Subject: Complete test coverage for UI stuff: 93.5% coverage git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@1866 a436a847-0d15-0410-975c-d299462d15a1 --- test/slv2_test.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/slv2_test.c b/test/slv2_test.c index 5c8d6a4..d3324df 100644 --- a/test/slv2_test.c +++ b/test/slv2_test.c @@ -162,9 +162,10 @@ struct TestCase { TestFunc func; }; -#define PREFIX_LINE "@prefix : .\n" +#define PREFIX_LINE "@prefix : .\n" #define PREFIX_LV2 "@prefix lv2: .\n" #define PREFIX_LV2EV "@prefix lv2ev: . \n" +#define PREFIX_LV2UI "@prefix lv2ui: .\n" #define PREFIX_RDFS "@prefix rdfs: .\n" #define PREFIX_FOAF "@prefix foaf: .\n" #define PREFIX_DOAP "@prefix doap: .\n" @@ -174,7 +175,7 @@ struct TestCase { #define PLUGIN_NAME(name) "doap:name \"" name "\"" #define LICENSE_GPL "doap:license " -static char *uris_plugin = "http://example.com/plug"; +static char *uris_plugin = "http://example.org/plug"; static SLV2Value plugin_uri_value, plugin2_uri_value; /*****************************************************************************/ @@ -183,7 +184,7 @@ void init_uris() { plugin_uri_value = slv2_value_new_uri(world, uris_plugin); - plugin2_uri_value = slv2_value_new_uri(world, "http://example.com/foobar"); + plugin2_uri_value = slv2_value_new_uri(world, "http://example.org/foobar"); TEST_ASSERT(plugin_uri_value); TEST_ASSERT(plugin2_uri_value); } @@ -203,8 +204,8 @@ int test_utils() { 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")); + TEST_ASSERT(!slv2_uri_to_path("file:/example.org/blah")); + TEST_ASSERT(!slv2_uri_to_path("http://example.org/blah")); return 1; } @@ -314,7 +315,7 @@ int test_values() { init_world(); - SLV2Value v0 = slv2_value_new_uri(world, "http://example.com/"); + SLV2Value v0 = slv2_value_new_uri(world, "http://example.org/"); SLV2Values vs1 = slv2_values_new(); TEST_ASSERT(vs1); TEST_ASSERT(!slv2_values_size(vs1)); @@ -840,6 +841,107 @@ test_port() /*****************************************************************************/ +int +test_ui() +{ + if (!start_bundle(MANIFEST_PREFIXES + ":plug a lv2:Plugin ; lv2:binary ; rdfs:seeAlso .\n", + BUNDLE_PREFIXES PREFIX_LV2UI + ":plug a lv2:Plugin ; a lv2:CompressorPlugin ; " + PLUGIN_NAME("Test plugin") " ; " + LICENSE_GPL " ; " + "lv2:optionalFeature lv2:hardRtCapable ; " + "lv2:requiredFeature ; " + "lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ; " + "doap:maintainer [ foaf:name \"David Robillard\" ; " + " foaf:homepage ; foaf:mbox ] ; " + "lv2:port [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 0 ; lv2:symbol \"foo\" ; lv2:name \"bar\" ; " + " lv2:minimum -1.0 ; lv2:maximum 1.0 ; lv2:default 0.5 " + "] , [ " + " a lv2:ControlPort ; a lv2:InputPort ; " + " lv2:index 1 ; lv2:symbol \"bar\" ; lv2:name \"Baz\" ; " + " lv2:minimum -2.0 ; lv2:maximum 2.0 ; lv2:default 1.0 " + "] , [ " + " a lv2:ControlPort ; a lv2:OutputPort ; " + " lv2:index 2 ; lv2:symbol \"latency\" ; lv2:name \"Latency\" ; " + " lv2:portProperty lv2:reportsLatency " + "] .\n" + ":ui a lv2ui:GtkUI ; " + " lv2ui:requiredFeature lv2ui:makeResident ; " + " lv2ui:binary ; " + " lv2ui:optionalFeature lv2ui:ext_presets . " + ":ui2 a lv2ui:GtkUI ; lv2ui:binary . " + ":ui3 a lv2ui:GtkUI ; lv2ui:binary . " + ":ui4 a lv2ui:GtkUI ; lv2ui:binary . ", + 1)) + return 0; + + init_uris(); + SLV2Plugins plugins = slv2_world_get_all_plugins(world); + SLV2Plugin plug = slv2_plugins_get_by_uri(plugins, plugin_uri_value); + TEST_ASSERT(plug); + + SLV2UIs uis = slv2_plugin_get_uis(plug); + TEST_ASSERT(slv2_uis_size(uis) == 4); + + TEST_ASSERT(slv2_uis_get_at(uis, (unsigned)INT_MAX + 1) == NULL); + + SLV2UI ui0 = slv2_uis_get_at(uis, 0); + TEST_ASSERT(ui0); + + SLV2Value ui_uri = slv2_value_new_uri(world, "http://example.org/ui"); + SLV2Value ui2_uri = slv2_value_new_uri(world, "http://example.org/ui3"); + SLV2Value ui3_uri = slv2_value_new_uri(world, "http://example.org/ui4"); + SLV2Value noui_uri = slv2_value_new_uri(world, "http://example.org/notaui"); + + SLV2UI ui0_2 = slv2_uis_get_by_uri(uis, ui_uri); + TEST_ASSERT(ui0 == ui0_2); + + SLV2UI ui2 = slv2_uis_get_by_uri(uis, ui2_uri); + TEST_ASSERT(ui2 != ui0); + + SLV2UI ui3 = slv2_uis_get_by_uri(uis, ui3_uri); + TEST_ASSERT(ui3 != ui0); + + SLV2UI noui = slv2_uis_get_by_uri(uis, noui_uri); + TEST_ASSERT(noui == NULL); + + SLV2Values classes = slv2_ui_get_classes(ui0); + TEST_ASSERT(slv2_values_size(classes) == 1); + + SLV2Value ui_class_uri = slv2_value_new_uri(world, + "http://lv2plug.in/ns/extensions/ui#GtkUI"); + + TEST_ASSERT(slv2_value_equals(slv2_values_get_at(classes, 0), ui_class_uri)); + TEST_ASSERT(slv2_ui_is_a(ui0, ui_class_uri)); + + SLV2Value plug_bundle_uri = slv2_plugin_get_bundle_uri(plug); + SLV2Value ui_bundle_uri = slv2_ui_get_bundle_uri(ui0); + TEST_ASSERT(slv2_value_equals(plug_bundle_uri, ui_bundle_uri)); + + char* ui_binary_uri_str = (char*)malloc(TEST_PATH_MAX); + snprintf(ui_binary_uri_str, TEST_PATH_MAX, "%s%s", + slv2_value_as_string(plug_bundle_uri), "ui.so"); + + SLV2Value ui_binary_uri = slv2_ui_get_binary_uri(ui0); + + SLV2Value expected_uri = slv2_value_new_uri(world, ui_binary_uri_str); + TEST_ASSERT(slv2_value_equals(expected_uri, ui_binary_uri)); + + slv2_value_free(ui_uri); + slv2_value_free(ui2_uri); + slv2_value_free(noui_uri); + slv2_value_free(expected_uri); + slv2_uis_free(uis); + + cleanup_uris(); + return 1; +} + +/*****************************************************************************/ + /* add tests here */ static struct TestCase tests[] = { TEST_CASE(utils), @@ -853,6 +955,7 @@ static struct TestCase tests[] = { TEST_CASE(plugin), TEST_CASE(port), TEST_CASE(plugin), + TEST_CASE(ui), { NULL, NULL } }; -- cgit v1.2.1