Branch data Line data Source code
1 : : /* GLIB - Library of useful routines for C programming
2 : : * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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 Public
17 : : * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 : : */
19 : :
20 : : /*
21 : : * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 : : * file for a list of people on the GLib Team. See the ChangeLog
23 : : * files for a list of changes. These files are distributed with
24 : : * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 : : */
26 : :
27 : : /* We are testing some deprecated APIs here */
28 : : #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
29 : : #define GLIB_DISABLE_DEPRECATION_WARNINGS
30 : : #endif
31 : :
32 : : #include <string.h>
33 : :
34 : : #include "glib.h"
35 : :
36 : : static void
37 : 1 : test_completion (void)
38 : : {
39 : : static const char *const a1 = "a\302\243";
40 : : static const char *const a2 = "a\302\244";
41 : : static const char *const bb = "bb";
42 : : static const char *const bc = "bc";
43 : :
44 : : GCompletion *cmp;
45 : : GList *items;
46 : : gchar *prefix;
47 : :
48 : 1 : cmp = g_completion_new (NULL);
49 : 1 : g_completion_set_compare (cmp, strncmp);
50 : :
51 : 1 : items = NULL;
52 : 1 : items = g_list_append (items, (gpointer) a1);
53 : 1 : items = g_list_append (items, (gpointer) a2);
54 : 1 : items = g_list_append (items, (gpointer) bb);
55 : 1 : items = g_list_append (items, (gpointer) bc);
56 : 1 : g_completion_add_items (cmp, items);
57 : 1 : g_list_free (items);
58 : :
59 : 1 : items = g_completion_complete (cmp, "a", &prefix);
60 : 1 : g_assert_cmpstr (prefix, ==, "a\302");
61 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
62 : 1 : g_free (prefix);
63 : :
64 : 1 : items = g_completion_complete_utf8 (cmp, "a", &prefix);
65 : 1 : g_assert_cmpstr (prefix, ==, "a");
66 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
67 : 1 : g_free (prefix);
68 : :
69 : 1 : items = g_completion_complete (cmp, "b", &prefix);
70 : 1 : g_assert_cmpstr (prefix, ==, "b");
71 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
72 : 1 : g_free (prefix);
73 : :
74 : 1 : items = g_completion_complete_utf8 (cmp, "b", &prefix);
75 : 1 : g_assert_cmpstr (prefix, ==, "b");
76 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
77 : 1 : g_free (prefix);
78 : :
79 : 1 : items = g_completion_complete (cmp, "a", NULL);
80 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
81 : :
82 : 1 : items = g_completion_complete_utf8 (cmp, "a", NULL);
83 : 1 : g_assert_cmpint (g_list_length (items), ==, 2);
84 : :
85 : 1 : items = g_list_append (NULL, (gpointer) bb);
86 : 1 : g_completion_remove_items (cmp, items);
87 : 1 : g_list_free (items);
88 : :
89 : 1 : items = g_completion_complete_utf8 (cmp, "b", &prefix);
90 : 1 : g_assert_cmpint (g_list_length (items), ==, 1);
91 : 1 : g_free (prefix);
92 : :
93 : 1 : g_completion_free (cmp);
94 : 1 : }
95 : :
96 : : int
97 : 1 : main (int argc,
98 : : char *argv[])
99 : : {
100 : 1 : g_test_init (&argc, &argv, NULL);
101 : 1 : g_test_add_func ("/completion/test-completion", test_completion);
102 : :
103 : 1 : return g_test_run ();
104 : : }
|