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

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

DEFINITIONS

This source file includes following definitions.
  1. bad_input
  2. ends_with
  3. ends_with_ext

   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 <crm/common/unittest_internal.h>
  13 
  14 static void
  15 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  16     assert_false(pcmk__ends_with(NULL, "xyz"));
  17 
  18     assert_true(pcmk__ends_with(NULL, NULL));
  19     assert_true(pcmk__ends_with(NULL, ""));
  20     assert_true(pcmk__ends_with("", NULL));
  21     assert_true(pcmk__ends_with("", ""));
  22     assert_true(pcmk__ends_with("abc", NULL));
  23     assert_true(pcmk__ends_with("abc", ""));
  24 }
  25 
  26 static void
  27 ends_with(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  28     assert_true(pcmk__ends_with("abc", "abc"));
  29     assert_true(pcmk__ends_with("abc", "bc"));
  30     assert_true(pcmk__ends_with("abc", "c"));
  31     assert_true(pcmk__ends_with("abcbc", "bc"));
  32 
  33     assert_false(pcmk__ends_with("abc", "def"));
  34     assert_false(pcmk__ends_with("abc", "defg"));
  35     assert_false(pcmk__ends_with("abc", "bcd"));
  36     assert_false(pcmk__ends_with("abc", "ab"));
  37 
  38     assert_false(pcmk__ends_with("abc", "BC"));
  39 }
  40 
  41 static void
  42 ends_with_ext(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  43     assert_true(pcmk__ends_with_ext("ab.c", ".c"));
  44     assert_true(pcmk__ends_with_ext("ab.cb.c", ".c"));
  45 
  46     assert_false(pcmk__ends_with_ext("ab.c", ".def"));
  47     assert_false(pcmk__ends_with_ext("ab.c", ".defg"));
  48     assert_false(pcmk__ends_with_ext("ab.c", ".cd"));
  49     assert_false(pcmk__ends_with_ext("ab.c", "ab"));
  50 
  51     assert_false(pcmk__ends_with_ext("ab.c", ".C"));
  52 }
  53 
  54 PCMK__UNIT_TEST(NULL, NULL,
  55                 cmocka_unit_test(bad_input),
  56                 cmocka_unit_test(ends_with),
  57                 cmocka_unit_test(ends_with_ext))

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