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

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

DEFINITIONS

This source file includes following definitions.
  1. same_pointer
  2. one_is_null
  3. case_matters
  4. case_insensitive
  5. regex

   1 /*
   2  * Copyright 2020-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 <crm/common/unittest_internal.h>
  13 
  14 static void
  15 same_pointer(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  16     const char *s1 = "abcd";
  17     const char *s2 = "wxyz";
  18 
  19     assert_int_equal(pcmk__strcmp(s1, s1, pcmk__str_none), 0);
  20     assert_true(pcmk__str_eq(s1, s1, pcmk__str_none));
  21     assert_int_not_equal(pcmk__strcmp(s1, s2, pcmk__str_none), 0);
  22     assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
  23     assert_int_equal(pcmk__strcmp(NULL, NULL, pcmk__str_none), 0);
  24 }
  25 
  26 static void
  27 one_is_null(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  28     const char *s1 = "abcd";
  29 
  30     assert_int_equal(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), 0);
  31     assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches));
  32     assert_int_equal(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), 0);
  33     assert_true(pcmk__strcmp(s1, NULL, pcmk__str_none) > 0);
  34     assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none));
  35     assert_true(pcmk__strcmp(NULL, s1, pcmk__str_none) < 0);
  36 }
  37 
  38 static void
  39 case_matters(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  40     const char *s1 = "abcd";
  41     const char *s2 = "ABCD";
  42 
  43     assert_true(pcmk__strcmp(s1, s2, pcmk__str_none) > 0);
  44     assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
  45     assert_true(pcmk__strcmp(s2, s1, pcmk__str_none) < 0);
  46 }
  47 
  48 static void
  49 case_insensitive(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  50     const char *s1 = "abcd";
  51     const char *s2 = "ABCD";
  52 
  53     assert_int_equal(pcmk__strcmp(s1, s2, pcmk__str_casei), 0);
  54     assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei));
  55 }
  56 
  57 static void
  58 regex(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  59     const char *s1 = "abcd";
  60     const char *s2 = "ABCD";
  61 
  62     assert_true(pcmk__strcmp(NULL, "a..d", pcmk__str_regex) > 0);
  63     assert_true(pcmk__strcmp(s1, NULL, pcmk__str_regex) > 0);
  64     assert_int_equal(pcmk__strcmp(s1, "a..d", pcmk__str_regex), 0);
  65     assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex));
  66     assert_int_not_equal(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), 0);
  67     assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex));
  68     assert_int_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), 0);
  69     assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei));
  70     assert_int_not_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex), 0);
  71     assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex));
  72     assert_true(pcmk__strcmp(s2, "*ab", pcmk__str_regex) > 0);
  73 }
  74 
  75 PCMK__UNIT_TEST(NULL, NULL,
  76                 cmocka_unit_test(same_pointer),
  77                 cmocka_unit_test(one_is_null),
  78                 cmocka_unit_test(case_matters),
  79                 cmocka_unit_test(case_insensitive),
  80                 cmocka_unit_test(regex))

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