Branch data Line data Source code
1 : : /*
2 : : * Copyright 2025 GNOME Foundation, Inc.
3 : : *
4 : : * SPDX-License-Identifier: LGPL-2.1-or-later
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License as published by the Free Software Foundation; either
9 : : * version 2.1 of the License, or (at your option) any later version.
10 : : *
11 : : * This library is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * Lesser General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU Lesser General
17 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 : : *
19 : : * Authors:
20 : : * - Philip Withnall <pwithnall@gnome.org>
21 : : */
22 : :
23 : : #include "config.h"
24 : :
25 : : #include "girepository.h"
26 : : #include "girparser-private.h"
27 : :
28 : : static void
29 : 1 : test_type_parsing (void)
30 : : {
31 : 1 : const char *buffer_template = "<?xml version='1.0'?>"
32 : : "<repository version='1.2'"
33 : : " xmlns='http://www.gtk.org/introspection/core/1.0'"
34 : : " xmlns:c='http://www.gtk.org/introspection/c/1.0'>"
35 : : "<package name='TestNamespace-1.0'/>"
36 : : "<namespace name='TestNamespace' version='1.0'"
37 : : " c:identifier-prefixes='test'"
38 : : " c:symbol-prefixes='test'>"
39 : : "<function name='dummy' c:identifier='dummy'>"
40 : : "<return-value transfer-ownership='none'>"
41 : : "<type name='%s'/>"
42 : : "</return-value>"
43 : : "<parameters>"
44 : : "</parameters>"
45 : : "</function>"
46 : : "</namespace>"
47 : : "</repository>";
48 : : const struct
49 : : {
50 : : const char *type;
51 : : gboolean expected_success;
52 : : }
53 : 1 : vectors[] =
54 : : {
55 : : { "GLib.Error", TRUE },
56 : : { "GLib.Error<IOError,FileError>", TRUE },
57 : : { "GLib.Error<IOError", FALSE },
58 : : };
59 : :
60 : 1 : g_test_summary ("Test parsing different valid and invalid types");
61 : :
62 : 4 : for (size_t i = 0; i < G_N_ELEMENTS (vectors); i++)
63 : : {
64 : 3 : GIIrParser *parser = NULL;
65 : : GIIrModule *module;
66 : 3 : GError *local_error = NULL;
67 : 3 : char *buffer = NULL;
68 : :
69 : : #pragma GCC diagnostic push
70 : : #pragma GCC diagnostic ignored "-Wformat-nonliteral"
71 : 3 : buffer = g_strdup_printf (buffer_template, vectors[i].type);
72 : : #pragma GCC diagnostic pop
73 : :
74 : 3 : parser = gi_ir_parser_new ();
75 : 3 : module = gi_ir_parser_parse_string (parser, "TestNamespace",
76 : : "TestNamespace-1.0.gir",
77 : : buffer, -1,
78 : : &local_error);
79 : :
80 : 3 : if (vectors[i].expected_success)
81 : : {
82 : 2 : g_assert_no_error (local_error);
83 : 2 : g_assert_nonnull (module);
84 : : }
85 : : else
86 : : {
87 : 1 : g_assert_error (local_error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT);
88 : 1 : g_assert_null (module);
89 : : }
90 : :
91 : 3 : g_clear_error (&local_error);
92 : 3 : g_clear_pointer (&parser, gi_ir_parser_free);
93 : 3 : g_free (buffer);
94 : : }
95 : 1 : }
96 : :
97 : : int
98 : 1 : main (int argc,
99 : : char *argv[])
100 : : {
101 : 1 : g_test_init (&argc, &argv, NULL);
102 : :
103 : 1 : g_test_add_func ("/ir-parser/type-parsing", test_type_parsing);
104 : :
105 : 1 : return g_test_run ();
106 : : }
|