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

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

DEFINITIONS

This source file includes following definitions.
  1. add_words
  2. add_with_no_len
  3. add_nothing
  4. add_with_null
  5. add_with_comma
  6. add_with_comma_and_space

   1 /*
   2  * Copyright 2020-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 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 add_words(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17     GString *list = NULL;
  18 
  19     pcmk__add_word(&list, 16, "hello");
  20     pcmk__add_word(&list, 16, "world");
  21     assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
  22     g_string_free(list, TRUE);
  23 }
  24 
  25 static void
  26 add_with_no_len(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     GString *list = NULL;
  29 
  30     pcmk__add_word(&list, 0, "hello");
  31     pcmk__add_word(&list, 0, "world");
  32     assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
  33     g_string_free(list, TRUE);
  34 }
  35 
  36 static void
  37 add_nothing(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     GString *list = NULL;
  40 
  41     pcmk__add_word(&list, 0, "hello");
  42     pcmk__add_word(&list, 0, NULL);
  43     pcmk__add_word(&list, 0, "");
  44     assert_int_equal(strcmp((const char *) list->str, "hello"), 0);
  45     g_string_free(list, TRUE);
  46 }
  47 
  48 static void
  49 add_with_null(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51     GString *list = NULL;
  52 
  53     pcmk__add_separated_word(&list, 32, "hello", NULL);
  54     pcmk__add_separated_word(&list, 32, "world", NULL);
  55     pcmk__add_separated_word(&list, 32, "I am a unit test", NULL);
  56     assert_int_equal(strcmp((const char *) list->str,
  57                             "hello world I am a unit test"), 0);
  58     g_string_free(list, TRUE);
  59 }
  60 
  61 static void
  62 add_with_comma(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64     GString *list = NULL;
  65 
  66     pcmk__add_separated_word(&list, 32, "hello", ",");
  67     pcmk__add_separated_word(&list, 32, "world", ",");
  68     pcmk__add_separated_word(&list, 32, "I am a unit test", ",");
  69     assert_int_equal(strcmp((const char *) list->str,
  70                             "hello,world,I am a unit test"), 0);
  71     g_string_free(list, TRUE);
  72 }
  73 
  74 static void
  75 add_with_comma_and_space(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77     GString *list = NULL;
  78 
  79     pcmk__add_separated_word(&list, 32, "hello", ", ");
  80     pcmk__add_separated_word(&list, 32, "world", ", ");
  81     pcmk__add_separated_word(&list, 32, "I am a unit test", ", ");
  82     assert_int_equal(strcmp((const char *) list->str,
  83                             "hello, world, I am a unit test"), 0);
  84     g_string_free(list, TRUE);
  85 }
  86 
  87 PCMK__UNIT_TEST(NULL, NULL,
  88                 cmocka_unit_test(add_words),
  89                 cmocka_unit_test(add_with_no_len),
  90                 cmocka_unit_test(add_nothing),
  91                 cmocka_unit_test(add_with_null),
  92                 cmocka_unit_test(add_with_comma),
  93                 cmocka_unit_test(add_with_comma_and_space))

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