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
  7. main

   1 /*
   2  * Copyright 2020 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 <stdio.h>
  11 #include <string.h>
  12 #include <sys/types.h>
  13 #include <crm_internal.h>
  14 
  15 static void
  16 add_words(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18     char *list = NULL;
  19     size_t list_len = 0;
  20 
  21     pcmk__add_word(&list, &list_len, "hello");
  22     pcmk__add_word(&list, &list_len, "world");
  23     g_assert_cmpint(strcmp(list, "hello world"), ==, 0);
  24 }
  25 
  26 static void
  27 add_with_no_len(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29     char *list = NULL;
  30 
  31     pcmk__add_word(&list, NULL, "hello");
  32     pcmk__add_word(&list, NULL, "world");
  33     g_assert_cmpint(strcmp(list, "hello world"), ==, 0);
  34 }
  35 
  36 static void
  37 add_nothing(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     char *list = NULL;
  40 
  41     pcmk__add_word(&list, NULL, "hello");
  42     pcmk__add_word(&list, NULL, NULL);
  43     pcmk__add_word(&list, NULL, "");
  44     g_assert_cmpint(strcmp(list, "hello"), ==, 0);
  45 }
  46 
  47 static void
  48 add_with_null(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50     char *list = NULL;
  51     size_t list_len = 0;
  52 
  53     pcmk__add_separated_word(&list, &list_len, "hello", NULL);
  54     pcmk__add_separated_word(&list, &list_len, "world", NULL);
  55     pcmk__add_separated_word(&list, &list_len, "I am a unit test", NULL);
  56     g_assert_cmpint(strcmp(list, "hello world I am a unit test"), ==, 0);
  57 }
  58 
  59 static void
  60 add_with_comma(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62     char *list = NULL;
  63     size_t list_len = 0;
  64 
  65     pcmk__add_separated_word(&list, &list_len, "hello", ",");
  66     pcmk__add_separated_word(&list, &list_len, "world", ",");
  67     pcmk__add_separated_word(&list, &list_len, "I am a unit test", ",");
  68     g_assert_cmpint(strcmp(list, "hello,world,I am a unit test"), ==, 0);
  69 }
  70 
  71 static void
  72 add_with_comma_and_space(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74     char *list = NULL;
  75     size_t list_len = 0;
  76 
  77     pcmk__add_separated_word(&list, &list_len, "hello", ", ");
  78     pcmk__add_separated_word(&list, &list_len, "world", ", ");
  79     pcmk__add_separated_word(&list, &list_len, "I am a unit test", ", ");
  80     g_assert_cmpint(strcmp(list, "hello, world, I am a unit test"), ==, 0);
  81 }
  82 
  83 int
  84 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86     g_test_init(&argc, &argv, NULL);
  87 
  88     g_test_add_func("/common/strings/add_word/add_words", add_words);
  89     g_test_add_func("/common/strings/add_word/add_with_no_len",
  90                     add_with_no_len);
  91     g_test_add_func("/common/strings/add_word/add_nothing", add_nothing);
  92     g_test_add_func("/common/strings/add_word/add_with_null", add_with_null);
  93     g_test_add_func("/common/strings/add_word/add_with_comma", add_with_comma);
  94     g_test_add_func("/common/strings/add_word/add_with_comma_and_space",
  95                     add_with_comma_and_space);
  96 
  97     return g_test_run();
  98 }

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