(root)/
glib-2.79.0/
glib/
tests/
completion.c
       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  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    cmp = g_completion_new (NULL);
      49    g_completion_set_compare (cmp, strncmp);
      50  
      51    items = NULL;
      52    items = g_list_append (items, (gpointer) a1);
      53    items = g_list_append (items, (gpointer) a2);
      54    items = g_list_append (items, (gpointer) bb);
      55    items = g_list_append (items, (gpointer) bc);
      56    g_completion_add_items (cmp, items);
      57    g_list_free (items);
      58  
      59    items = g_completion_complete (cmp, "a", &prefix);
      60    g_assert_cmpstr (prefix, ==, "a\302");
      61    g_assert_cmpint (g_list_length (items), ==, 2);
      62    g_free (prefix);
      63  
      64    items = g_completion_complete_utf8 (cmp, "a", &prefix);
      65    g_assert_cmpstr (prefix, ==, "a");
      66    g_assert_cmpint (g_list_length (items), ==, 2);
      67    g_free (prefix);
      68  
      69    items = g_completion_complete (cmp, "b", &prefix);
      70    g_assert_cmpstr (prefix, ==, "b");
      71    g_assert_cmpint (g_list_length (items), ==, 2);
      72    g_free (prefix);
      73  
      74    items = g_completion_complete_utf8 (cmp, "b", &prefix);
      75    g_assert_cmpstr (prefix, ==, "b");
      76    g_assert_cmpint (g_list_length (items), ==, 2);
      77    g_free (prefix);
      78  
      79    items = g_completion_complete (cmp, "a", NULL);
      80    g_assert_cmpint (g_list_length (items), ==, 2);
      81  
      82    items = g_completion_complete_utf8 (cmp, "a", NULL);
      83    g_assert_cmpint (g_list_length (items), ==, 2);
      84  
      85    items = g_list_append (NULL, (gpointer) bb);
      86    g_completion_remove_items (cmp, items);
      87    g_list_free (items);
      88  
      89    items = g_completion_complete_utf8 (cmp, "b", &prefix);
      90    g_assert_cmpint (g_list_length (items), ==, 1);
      91    g_free (prefix);
      92  
      93    g_completion_free (cmp);
      94  }
      95  
      96  int
      97  main (int argc,
      98        char *argv[])
      99  {
     100    g_test_init (&argc, &argv, NULL);
     101    g_test_add_func ("/completion/test-completion", test_completion);
     102  
     103    return g_test_run ();
     104  }