root/lib/common/tests/strings/pcmk__str_in_list_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. empty_input_list
  2. empty_string
  3. star_matches
  4. star_doesnt_match
  5. in_list
  6. not_in_list
  7. main

   1 /*
   2  * Copyright 2021 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>
  13 #include <stdbool.h>
  14 #include <glib.h>
  15 
  16 static void
  17 empty_input_list(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  18     g_assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_none));
  19     g_assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_null_matches));
  20     g_assert_false(pcmk__str_in_list(NULL, "xxx", pcmk__str_none));
  21     g_assert_false(pcmk__str_in_list(NULL, "", pcmk__str_none));
  22 }
  23 
  24 static void
  25 empty_string(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  26     GList *list = NULL;
  27 
  28     list = g_list_prepend(list, (gpointer) "xxx");
  29 
  30     g_assert_false(pcmk__str_in_list(list, NULL, pcmk__str_none));
  31     g_assert_true(pcmk__str_in_list(list, NULL, pcmk__str_null_matches));
  32     g_assert_false(pcmk__str_in_list(list, "", pcmk__str_none));
  33     g_assert_false(pcmk__str_in_list(list, "", pcmk__str_null_matches));
  34 
  35     g_list_free(list);
  36 }
  37 
  38 static void
  39 star_matches(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  40     GList *list = NULL;
  41 
  42     list = g_list_prepend(list, (gpointer) "*");
  43 
  44     g_assert_true(pcmk__str_in_list(list, "xxx", pcmk__str_none));
  45     g_assert_true(pcmk__str_in_list(list, "yyy", pcmk__str_none));
  46     g_assert_true(pcmk__str_in_list(list, "XXX", pcmk__str_casei));
  47     g_assert_true(pcmk__str_in_list(list, "", pcmk__str_none));
  48     g_assert_true(pcmk__str_in_list(list, NULL, pcmk__str_none));
  49     g_assert_true(pcmk__str_in_list(list, NULL, pcmk__str_null_matches));
  50 
  51     g_list_free(list);
  52 }
  53 
  54 static void
  55 star_doesnt_match(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  56     GList *list = NULL;
  57 
  58     list = g_list_prepend(list, (gpointer) "*");
  59     list = g_list_append(list, (gpointer) "more");
  60 
  61     g_assert_false(pcmk__str_in_list(list, "xxx", pcmk__str_none));
  62     g_assert_false(pcmk__str_in_list(list, "yyy", pcmk__str_none));
  63     g_assert_false(pcmk__str_in_list(list, "XXX", pcmk__str_casei));
  64     g_assert_false(pcmk__str_in_list(list, "", pcmk__str_none));
  65 
  66     g_list_free(list);
  67 }
  68 
  69 static void
  70 in_list(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  71     GList *list = NULL;
  72 
  73     list = g_list_prepend(list, (gpointer) "xxx");
  74     list = g_list_prepend(list, (gpointer) "yyy");
  75     list = g_list_prepend(list, (gpointer) "zzz");
  76 
  77     g_assert_true(pcmk__str_in_list(list, "xxx", pcmk__str_none));
  78     g_assert_true(pcmk__str_in_list(list, "XXX", pcmk__str_casei));
  79     g_assert_true(pcmk__str_in_list(list, "yyy", pcmk__str_none));
  80     g_assert_true(pcmk__str_in_list(list, "YYY", pcmk__str_casei));
  81     g_assert_true(pcmk__str_in_list(list, "zzz", pcmk__str_none));
  82     g_assert_true(pcmk__str_in_list(list, "ZZZ", pcmk__str_casei));
  83 
  84     g_list_free(list);
  85 }
  86 
  87 static void
  88 not_in_list(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  89     GList *list = NULL;
  90 
  91     list = g_list_prepend(list, (gpointer) "xxx");
  92     list = g_list_prepend(list, (gpointer) "yyy");
  93 
  94     g_assert_false(pcmk__str_in_list(list, "xx", pcmk__str_none));
  95     g_assert_false(pcmk__str_in_list(list, "XXX", pcmk__str_none));
  96     g_assert_false(pcmk__str_in_list(list, "zzz", pcmk__str_none));
  97     g_assert_false(pcmk__str_in_list(list, "zzz", pcmk__str_casei));
  98 
  99     g_list_free(list);
 100 }
 101 
 102 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104     g_test_init(&argc, &argv, NULL);
 105 
 106     g_test_add_func("/common/strings/in_list/empty_list", empty_input_list);
 107     g_test_add_func("/common/strings/in_list/empty_string", empty_string);
 108     g_test_add_func("/common/strings/in_list/star_matches", star_matches);
 109     g_test_add_func("/common/strings/in_list/star_doesnt_match", star_doesnt_match);
 110     g_test_add_func("/common/strings/in_list/in", in_list);
 111     g_test_add_func("/common/strings/in_list/not_in", not_in_list);
 112 
 113     return g_test_run();
 114 }

/* [previous][next][first][last][top][bottom][index][help] */