Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Gnome/testsuite/gtk/   (Gnome Linux Desktop Version 4.23.2©)  Datei vom 30.5.2026 mit Größe 5 kB image not shown  

Quelle  fnmatch.c

  Sprache: C
 

#include <gtk/gtk.h>
#include "gtk/gtkprivate.h"

#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
#define DO_ESCAPE 1
#endif

typedef struct {
  const char *pat;
  const char *str;
  gboolean no_leading_period;
  gboolean ci;
  gboolean result;
} TestCase;

static TestCase tests[] = {
  { "[a-]""-"TRUEFALSETRUE },

  { "a""a"TRUEFALSETRUE },
  { "a""b"TRUEFALSEFALSE },

  /* Test what ? matches */
  { "?""a"TRUEFALSETRUE },
  { "?""."TRUEFALSEFALSE },
  { "a?""a."TRUEFALSETRUE },
  { "a" G_DIR_SEPARATOR_S "?""a" G_DIR_SEPARATOR_S "b"TRUEFALSETRUE },
  { "a" G_DIR_SEPARATOR_S "?""a" G_DIR_SEPARATOR_S "."TRUEFALSEFALSE },
  { "?""" G_DIR_SEPARATOR_S ""TRUEFALSEFALSE },

  /* Test what * matches */
  { "*""a"TRUEFALSETRUE },
  { "*""."TRUEFALSEFALSE },
  { "a*""a."TRUEFALSETRUE },
  { "a" G_DIR_SEPARATOR_S "*""a" G_DIR_SEPARATOR_S "b"TRUEFALSETRUE },
  { "a" G_DIR_SEPARATOR_S "*""a" G_DIR_SEPARATOR_S "."TRUEFALSEFALSE },
  { "*""" G_DIR_SEPARATOR_S ""TRUEFALSEFALSE },

  /* Range tests */
  { "[ab]""a"TRUEFALSETRUE },
  { "[ab]""c"TRUEFALSEFALSE },
  { "[^ab]""a"TRUEFALSEFALSE },
  { "[!ab]""a"TRUEFALSEFALSE },
  { "[^ab]""c"TRUEFALSETRUE },
  { "[!ab]""c"TRUEFALSETRUE },
  { "[a-c]""b"TRUEFALSETRUE },
  { "[a-c]""d"TRUEFALSEFALSE },
  { "[a-]""-"TRUEFALSETRUE },
  { "[]]""]"TRUEFALSETRUE },
  { "[^]]""a"TRUEFALSETRUE },
  { "[!]]""a"TRUEFALSETRUE },

  /* Various unclosed ranges */
  { "[ab""a"TRUEFALSEFALSE },
  { "[a-""a"TRUEFALSEFALSE },
  { "[ab""c"TRUEFALSEFALSE },
  { "[a-""c"TRUEFALSEFALSE },
  { "[^]""a"TRUEFALSEFALSE },

  /* Ranges and special no-wildcard matches */
  { "[.]""."TRUEFALSEFALSE },
  { "a[.]""a."TRUEFALSETRUE },
  { "a" G_DIR_SEPARATOR_S "[.]""a" G_DIR_SEPARATOR_S "."TRUEFALSEFALSE },
  { "[" G_DIR_SEPARATOR_S "]""" G_DIR_SEPARATOR_S ""TRUEFALSEFALSE },
  { "[^" G_DIR_SEPARATOR_S "]""a"TRUEFALSETRUE },
  
  /* Basic tests of * (and combinations of * and ?) */
  { "a*b""ab"TRUEFALSETRUE },
  { "a*b""axb"TRUEFALSETRUE },
  { "a*b""axxb"TRUEFALSETRUE },
  { "a**b""ab"TRUEFALSETRUE },
  { "a**b""axb"TRUEFALSETRUE },
  { "a**b""axxb"TRUEFALSETRUE },
  { "a*?*b""ab"TRUEFALSEFALSE },
  { "a*?*b""axb"TRUEFALSETRUE },
  { "a*?*b""axxb"TRUEFALSETRUE },

  /* Test of  *[range] */
  { "a*[cd]""ac"TRUEFALSETRUE },
  { "a*[cd]""axc"TRUEFALSETRUE },
  { "a*[cd]""axx"TRUEFALSEFALSE },

  { "a" G_DIR_SEPARATOR_S "[.]""a" G_DIR_SEPARATOR_S "."TRUEFALSEFALSE },
  { "a*[.]""a" G_DIR_SEPARATOR_S "."TRUEFALSEFALSE },


  /* Test of UTF-8 */

  { "ä""ä"TRUEFALSETRUE },
  { "?""ä"TRUEFALSETRUE },
  { "*ö""äö"TRUEFALSETRUE },
  { "*ö""ääö"TRUEFALSETRUE },
  { "[ä]""ä"TRUEFALSETRUE },
  { "[ä-ö]""é"TRUEFALSETRUE },
  { "[ä-ö]""a"TRUEFALSEFALSE },

  /* ci patterns */
  { "*.txt""a.TXT"TRUETRUETRUE },
  { "*.txt""a.TxT"TRUETRUETRUE },
  { "*.txt""a.txT"TRUETRUETRUE },
  { "*ö""äÖ"TRUETRUETRUE },

#ifdef DO_ESCAPE
  /* Tests of escaping */
  { "\\\\""\\"TRUEFALSETRUE },
  { "\\?""?"TRUEFALSETRUE },
  { "\\?""a"TRUEFALSEFALSE },
  { "\\*""*"TRUEFALSETRUE },
  { "\\*""a"TRUEFALSEFALSE },
  { "\\[a-b]""[a-b]"TRUEFALSETRUE },
  { "[\\\\]""\\"TRUEFALSETRUE },
  { "[\\^a]""a"TRUEFALSETRUE },
  { "[a\\-c]""b"TRUEFALSEFALSE },
  { "[a\\-c]""-"TRUEFALSETRUE },
  { "[a\\]""a"TRUEFALSEFALSE },
#endif /* DO_ESCAPE */
};

static void
test_fnmatch (gconstpointer data)
{
  const TestCase *test = data;

  g_assert_true (_gtk_fnmatch (test->pat, test->str, test->no_leading_period, test->ci) == test->result);
}

typedef struct {
  const char *glob;
  const char *ci;
} CITest;

static CITest citests[] = {
  { "*.txt""*.[tT][xX][tT]" },
  { "*.TXT""*.[tT][xX][tT]" },
  { "*?[]-abc]t""*?[]-abc][tT]" },
#ifdef DO_ESCAPE
  /* Tests of escaping */
  { "\\\\""\\\\" },
  { "\\??""\\??" },
  { "\\**""\\**" },
  { "\\[""\\[" },
  { "\\[a-""\\[[aA]-" },
  { "\\[]""\\[]" },
#endif
};

static void
test_ci_glob (gconstpointer data)
{
  const CITest *test = data;
  char *ci;

  ci = _gtk_make_ci_glob_pattern (test->glob);
  g_assert_cmpstr (ci, ==, test->ci);
  g_free (ci);
}

int
main (int argc, char *argv[])
{
  (g_test_init) (&argc, &argv, NULL);

  for (int i = 0; i < G_N_ELEMENTS (tests); i++)
    {
      char *path = g_strdup_printf ("/fnmatch/test%d", i);
      g_test_add_data_func (path, &tests[i], test_fnmatch);
      g_free (path);
    }

  for (int i = 0; i < G_N_ELEMENTS (citests); i++)
    {
      char *path = g_strdup_printf ("/ci-glob/test%d", i);
      g_test_add_data_func (path, &citests[i], test_ci_glob);
      g_free (path);
    }

  return g_test_run ();
}

Messung V0.5 in Prozent
C=98 H=92 G=94

¤ Dauer der Verarbeitung: 0.9 Sekunden  (vorverarbeitet am  2026-07-03) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.