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

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

DEFINITIONS

This source file includes following definitions.
  1. empty_input
  2. leading_newline
  3. middle_newline
  4. trailing_newline
  5. other_whitespace

   1 /*
   2  * Copyright 2022 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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 #include <string.h>
  15 
  16 static void
  17 empty_input(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19     char *s = strdup("");
  20 
  21     assert_null(pcmk__trim(NULL));
  22     assert_string_equal(pcmk__trim(s), "");
  23 
  24     free(s);
  25 }
  26 
  27 static void
  28 leading_newline(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30     char *s = strdup("\nabcd");
  31 
  32     assert_string_equal(pcmk__trim(s), "\nabcd");
  33     free(s);
  34 }
  35 
  36 static void
  37 middle_newline(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     char *s = strdup("ab\ncd");
  40 
  41     assert_string_equal(pcmk__trim(s), "ab\ncd");
  42     free(s);
  43 }
  44 
  45 static void
  46 trailing_newline(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48     char *s = strdup("abcd\n\n");
  49 
  50     assert_string_equal(pcmk__trim(s), "abcd");
  51     free(s);
  52 
  53     s = strdup("abcd\n ");
  54     assert_string_equal(pcmk__trim(s), "abcd\n ");
  55     free(s);
  56 }
  57 
  58 static void
  59 other_whitespace(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61     char *s = strdup("  ab\t\ncd  \t");
  62 
  63     assert_string_equal(pcmk__trim(s), "  ab\t\ncd  \t");
  64     free(s);
  65 }
  66 
  67 PCMK__UNIT_TEST(NULL, NULL,
  68                 cmocka_unit_test(empty_input),
  69                 cmocka_unit_test(leading_newline),
  70                 cmocka_unit_test(middle_newline),
  71                 cmocka_unit_test(trailing_newline),
  72                 cmocka_unit_test(other_whitespace))

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