summaryrefslogtreecommitdiff
path: root/utils/services/qname-test.c
blob: 5d0cd220eb5957e76d619602c43e5c4ff9ca04cb (plain)
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
/*
 * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include <glib.h>
#include <qname.h>

static void
srcdir_qname_init (const gchar *luri, const gchar *lprefix)
{
	gchar *class_location;

	class_location = g_build_filename (TOP_SRCDIR, "utils", "services", "file-class.cache.test", NULL);

	qname_init (luri, lprefix, class_location);

	g_free (class_location);
}

static void
test_qname_to_shortname (void)
{
	gchar *result = NULL;

	srcdir_qname_init ("test://local_uri#", "local");

	result = qname_to_shortname ("http://purl.org/dc/elements/1.1/source");
	g_assert_cmpstr (result, ==, "dc:source");
	g_free (result);

	result = qname_to_shortname ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement");
	g_assert_cmpstr (result, ==, "nie:InformationElement");
	g_free (result);

	result = qname_to_shortname ("test://local_uri#Class");
	g_assert_cmpstr (result, ==, "local:Class");
	g_free (result);

	result = qname_to_shortname ("test://doesnt_exists#Class");
	g_assert_cmpstr (result, ==, "test://doesnt_exists#Class");
	g_free (result);

	qname_shutdown ();
}

static void
test_qname_to_classname (void)
{
	gchar *result = NULL;

	srcdir_qname_init ("test://local_uri#", "local");

	result = qname_to_classname ("http://purl.org/dc/elements/1.1/source");
	g_assert_cmpstr (result, ==, "source");
	g_free (result);

	result = qname_to_classname ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement");
	g_assert_cmpstr (result, ==, "InformationElement");
	g_free (result);

	result = qname_to_classname ("test://local_uri#Class");
	g_assert_cmpstr (result, ==, "Class");
	g_free (result);

	result = qname_to_classname ("test://doesnt_exists#Class");
	g_assert_cmpstr (result, ==, "test://doesnt_exists#Class");
	g_free (result);

	qname_shutdown ();
}

static void
test_qname_to_link (void)
{
	gchar *result = NULL;

	srcdir_qname_init ("test://local_uri#", "local");

	result = qname_to_link ("test://local_uri#Class");
	g_assert_cmpstr (result, ==, "#Class");
	g_free (result);

	result = qname_to_link ("http://www.semanticdesktop.org/ontologies/2007/01/19/nie#InformationElement");
	g_assert_cmpstr (result, ==, "../nie/index.html#InformationElement");
	g_free (result);

	/* This is one of the special cases, where the prefix of the class
	 * doesn't match with the prefix of the file where it is defined
	 */
	result = qname_to_link ("http://www.tracker-project.org/ontologies/tracker#Namespace");
	g_assert_cmpstr (result, ==, "../rdf/index.html#Namespace");
	g_free (result);

	qname_shutdown ();
}

static void
test_process_dc (void)
{
	/* DC is the only ontology namespaces without '#' at the end
	   This force us to handle it as special case in a lot of places
	*/

	gchar *result = NULL;

	srcdir_qname_init ("test://dc_style/", "local");

	/* local */
	result = qname_to_link ("test://dc_style/Class");
	g_assert_cmpstr (result, ==, "#Class");
	g_free (result);

	/* out of this file */
	result = qname_to_link ("http://purl.org/dc/elements/1.1/creator");
	g_assert_cmpstr (result, ==, "../dc/index.html#creator");
	g_free (result);

	result = qname_to_shortname ("http://purl.org/dc/elements/1.1/creator");
	g_assert_cmpstr (result, ==, "dc:creator");
	g_free (result);

	result = qname_to_classname ("http://purl.org/dc/elements/1.1/creator");
	g_assert_cmpstr (result, ==, "creator");
	g_free (result);

	qname_shutdown ();
}

int
main (int argc, char **argv)
{
	int result;

	g_type_init ();
	g_test_init (&argc, &argv, NULL);

	g_test_add_func ("/html_generator/qname/qname_to_shortname",
	                 test_qname_to_shortname);

	g_test_add_func ("/html_generator/qname/qname_to_classname",
	                 test_qname_to_classname);

	g_test_add_func ("/html_generator/qname/qname_to_link",
	                 test_qname_to_link);

	g_test_add_func ("/html_generator/qname/dc_alike_namespaces",
	                 test_process_dc);

	result = g_test_run ();

	return result;
}