File: test_ui.c

package info (click to toggle)
lilv 0.26.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,336 kB
  • sloc: ansic: 11,764; python: 1,698; cpp: 349; makefile: 160; sh: 70
file content (172 lines) | stat: -rw-r--r-- 4,867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2007-2020 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC

#undef NDEBUG

#include "lilv_test_utils.h"

#include <lilv/lilv.h>

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static const char* const plugin_ttl = "\
@prefix lv2ui: <http://lv2plug.in/ns/extensions/ui#> .\n\
:plug a lv2:Plugin ;\n\
	a lv2:CompressorPlugin ;\n\
	doap:name \"Test plugin\" ;\n\
	lv2:optionalFeature lv2:hardRTCapable ;\n\
	lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ;\n\
	lv2ui:ui :ui , :ui2 , :ui3 , :ui4 ;\n\
	doap:maintainer [\n\
		foaf:name \"David Robillard\" ;\n\
		foaf:homepage <http://drobilla.net> ;\n\
		foaf:mbox <mailto:d@drobilla.net>\n\
	] ;\n\
	lv2:port [\n\
		a lv2:ControlPort ;\n\
		a lv2:InputPort ;\n\
		lv2:index 0 ;\n\
		lv2:symbol \"foo\" ;\n\
		lv2:name \"bar\" ;\n\
		lv2:minimum -1.0 ;\n\
		lv2:maximum 1.0 ;\n\
		lv2:default 0.5\n\
	] , [\n\
		a lv2:ControlPort ;\n\
		a lv2:InputPort ;\n\
		lv2:index 1 ;\n\
		lv2:symbol \"bar\" ;\n\
		lv2:name \"Baz\" ;\n\
		lv2:minimum -2.0 ;\n\
		lv2:maximum 2.0 ;\n\
		lv2:default 1.0\n\
	] , [\n\
		a lv2:ControlPort ;\n\
		a lv2:OutputPort ;\n\
		lv2:index 2 ;\n\
		lv2:symbol \"latency\" ;\n\
		lv2:name \"Latency\" ;\n\
		lv2:portProperty lv2:reportsLatency\n\
	] .\n\
\n\
	:ui\n\
		a lv2ui:GtkUI ;\n\
		lv2ui:requiredFeature lv2ui:makeResident ;\n\
		lv2ui:binary <ui" SHLIB_EXT "> ;\n\
		lv2ui:optionalFeature lv2ui:ext_presets .\n\
\n\
	:ui2\n\
		a lv2ui:GtkUI ;\n\
		lv2ui:binary <ui2" SHLIB_EXT "> .\n\
\n\
	:ui3\n\
		a lv2ui:GtkUI ;\n\
		lv2ui:binary <ui3" SHLIB_EXT "> .\n\
\n\
	:ui4\n\
		a lv2ui:GtkUI ;\n\
		lv2ui:binary <ui4" SHLIB_EXT "> .\n";

static unsigned
ui_supported(const char* container_type_uri, const char* ui_type_uri)
{
  return !strcmp(container_type_uri, ui_type_uri);
}

int
main(void)
{
  LilvTestEnv* const env   = lilv_test_env_new();
  LilvWorld* const   world = env->world;

  if (create_bundle(env, "ui.lv2", SIMPLE_MANIFEST_TTL, plugin_ttl)) {
    return 1;
  }

  lilv_world_load_specifications(env->world);
  lilv_world_load_bundle(env->world, env->test_bundle_uri);

  const LilvPlugins* plugins = lilv_world_get_all_plugins(world);
  const LilvPlugin*  plug = lilv_plugins_get_by_uri(plugins, env->plugin1_uri);
  assert(plug);

  LilvUIs* uis = lilv_plugin_get_uis(plug);
  assert(lilv_uis_size(uis) == 4);

  const LilvUI* ui0 = lilv_uis_get(uis, lilv_uis_begin(uis));
  assert(ui0);

  LilvNode* ui_uri   = lilv_new_uri(world, "http://example.org/ui");
  LilvNode* ui2_uri  = lilv_new_uri(world, "http://example.org/ui3");
  LilvNode* ui3_uri  = lilv_new_uri(world, "http://example.org/ui4");
  LilvNode* noui_uri = lilv_new_uri(world, "http://example.org/notaui");

  const LilvUI* ui0_2 = lilv_uis_get_by_uri(uis, ui_uri);
  assert(ui0 == ui0_2);
  assert(lilv_node_equals(lilv_ui_get_uri(ui0_2), ui_uri));

  const LilvUI* ui2 = lilv_uis_get_by_uri(uis, ui2_uri);
  assert(ui2 != ui0);

  const LilvUI* ui3 = lilv_uis_get_by_uri(uis, ui3_uri);
  assert(ui3 != ui0);

  const LilvUI* noui = lilv_uis_get_by_uri(uis, noui_uri);
  assert(noui == NULL);

  const LilvNodes* classes = lilv_ui_get_classes(ui0);
  assert(lilv_nodes_size(classes) == 1);

  LilvNode* ui_class_uri =
    lilv_new_uri(world, "http://lv2plug.in/ns/extensions/ui#GtkUI");

  LilvNode* unknown_ui_class_uri =
    lilv_new_uri(world, "http://example.org/mysteryUI");

  assert(lilv_node_equals(lilv_nodes_get_first(classes), ui_class_uri));
  assert(lilv_ui_is_a(ui0, ui_class_uri));

  const LilvNode* ui_type = NULL;
  assert(lilv_ui_is_supported(ui0, ui_supported, ui_class_uri, &ui_type));
  assert(
    !lilv_ui_is_supported(ui0, ui_supported, unknown_ui_class_uri, &ui_type));
  assert(lilv_node_equals(ui_type, ui_class_uri));

  const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
  const LilvNode* ui_bundle_uri   = lilv_ui_get_bundle_uri(ui0);
  assert(lilv_node_equals(plug_bundle_uri, ui_bundle_uri));

  const size_t ui_binary_uri_str_len =
    strlen(lilv_node_as_string(plug_bundle_uri)) + strlen("ui" SHLIB_EXT);

  char* ui_binary_uri_str = (char*)calloc(1, ui_binary_uri_str_len + 1);
  assert(ui_binary_uri_str);
  snprintf(ui_binary_uri_str,
           ui_binary_uri_str_len + 1,
           "%s%s",
           lilv_node_as_string(plug_bundle_uri),
           "ui" SHLIB_EXT);

  const LilvNode* ui_binary_uri = lilv_ui_get_binary_uri(ui0);

  LilvNode* expected_uri = lilv_new_uri(world, ui_binary_uri_str);
  assert(lilv_node_equals(expected_uri, ui_binary_uri));

  free(ui_binary_uri_str);
  lilv_node_free(unknown_ui_class_uri);
  lilv_node_free(ui_class_uri);
  lilv_node_free(ui_uri);
  lilv_node_free(ui2_uri);
  lilv_node_free(ui3_uri);
  lilv_node_free(noui_uri);
  lilv_node_free(expected_uri);
  lilv_uis_free(uis);

  delete_bundle(env);
  lilv_test_env_free(env);

  return 0;
}