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
  4. 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 <stdarg.h>
  13 #include <stddef.h>
  14 #include <stdint.h>
  15 #include <setjmp.h>
  16 #include <cmocka.h>
  17 
  18 static void
  19 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  20     assert_false(pcmk__ends_with(NULL, "xyz"));
  21 
  22     assert_true(pcmk__ends_with(NULL, NULL));
  23     assert_true(pcmk__ends_with(NULL, ""));
  24     assert_true(pcmk__ends_with("", NULL));
  25     assert_true(pcmk__ends_with("", ""));
  26     assert_true(pcmk__ends_with("abc", NULL));
  27     assert_true(pcmk__ends_with("abc", ""));
  28 }
  29 
  30 static void
  31 ends_with(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  32     assert_true(pcmk__ends_with("abc", "abc"));
  33     assert_true(pcmk__ends_with("abc", "bc"));
  34     assert_true(pcmk__ends_with("abc", "c"));
  35     assert_true(pcmk__ends_with("abcbc", "bc"));
  36 
  37     assert_false(pcmk__ends_with("abc", "def"));
  38     assert_false(pcmk__ends_with("abc", "defg"));
  39     assert_false(pcmk__ends_with("abc", "bcd"));
  40     assert_false(pcmk__ends_with("abc", "ab"));
  41 
  42     assert_false(pcmk__ends_with("abc", "BC"));
  43 }
  44 
  45 static void
  46 ends_with_ext(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  47     assert_true(pcmk__ends_with_ext("ab.c", ".c"));
  48     assert_true(pcmk__ends_with_ext("ab.cb.c", ".c"));
  49 
  50     assert_false(pcmk__ends_with_ext("ab.c", ".def"));
  51     assert_false(pcmk__ends_with_ext("ab.c", ".defg"));
  52     assert_false(pcmk__ends_with_ext("ab.c", ".cd"));
  53     assert_false(pcmk__ends_with_ext("ab.c", "ab"));
  54 
  55     assert_false(pcmk__ends_with_ext("ab.c", ".C"));
  56 }
  57 
  58 int
  59 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     const struct CMUnitTest tests[] = {
  62         cmocka_unit_test(bad_input),
  63         cmocka_unit_test(ends_with),
  64         cmocka_unit_test(ends_with_ext),
  65     };
  66 
  67     cmocka_set_message_output(CM_OUTPUT_TAP);
  68     return cmocka_run_group_tests(tests, NULL, NULL);
  69 }

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