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

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

DEFINITIONS

This source file includes following definitions.
  1. same_pointer
  2. one_is_null
  3. case_matters
  4. case_insensitive
  5. regex
  6. main

   1 #include <stdio.h>
   2 #include <stdbool.h>
   3 #include <glib.h>
   4 
   5 #include <crm_internal.h>
   6 
   7 static void
   8 same_pointer(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
   9     const char *s1 = "abcd";
  10     const char *s2 = "wxyz";
  11 
  12     g_assert_cmpint(pcmk__strcmp(s1, s1, pcmk__str_none), ==, 0);
  13     g_assert_cmpint(pcmk__str_eq(s1, s1, pcmk__str_none), ==, true);
  14     g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), !=, 0);
  15     g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false);
  16     g_assert_cmpint(pcmk__strcmp(NULL, NULL, pcmk__str_none), ==, 0);
  17 }
  18 
  19 static void
  20 one_is_null(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  21     const char *s1 = "abcd";
  22 
  23     g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), ==, 0);
  24     g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_null_matches), ==, true);
  25     g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), ==, 0);
  26     g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_none), >, 0);
  27     g_assert_cmpint(pcmk__str_eq(s1, NULL, pcmk__str_none), ==, false);
  28     g_assert_cmpint(pcmk__strcmp(NULL, s1, pcmk__str_none), <, 0);
  29 }
  30 
  31 static void
  32 case_matters(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  33     const char *s1 = "abcd";
  34     const char *s2 = "ABCD";
  35 
  36     g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_none), >, 0);
  37     g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_none), ==, false);
  38     g_assert_cmpint(pcmk__strcmp(s2, s1, pcmk__str_none), <, 0);
  39 }
  40 
  41 static void
  42 case_insensitive(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  43     const char *s1 = "abcd";
  44     const char *s2 = "ABCD";
  45 
  46     g_assert_cmpint(pcmk__strcmp(s1, s2, pcmk__str_casei), ==, 0);
  47     g_assert_cmpint(pcmk__str_eq(s1, s2, pcmk__str_casei), ==, true);
  48 }
  49 
  50 static void
  51 regex(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  52     const char *s1 = "abcd";
  53     const char *s2 = "ABCD";
  54 
  55     g_assert_cmpint(pcmk__strcmp(NULL, "a..d", pcmk__str_regex), ==, 1);
  56     g_assert_cmpint(pcmk__strcmp(s1, NULL, pcmk__str_regex), ==, 1);
  57     g_assert_cmpint(pcmk__strcmp(s1, "a..d", pcmk__str_regex), ==, 0);
  58     g_assert_cmpint(pcmk__str_eq(s1, "a..d", pcmk__str_regex), ==, true);
  59     g_assert_cmpint(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), !=, 0);
  60     g_assert_cmpint(pcmk__str_eq(s1, "xxyy", pcmk__str_regex), ==, false);
  61     g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, 0);
  62     g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei), ==, true);
  63     g_assert_cmpint(pcmk__strcmp(s2, "a..d", pcmk__str_regex), !=, 0);
  64     g_assert_cmpint(pcmk__str_eq(s2, "a..d", pcmk__str_regex), ==, false);
  65     g_assert_cmpint(pcmk__strcmp(s2, "*ab", pcmk__str_regex), ==, 1);
  66 }
  67 
  68 int main(int argc, char **argv) {
     /* [previous][next][first][last][top][bottom][index][help] */
  69     g_test_init(&argc, &argv, NULL);
  70 
  71     g_test_add_func("/common/strings/strcmp/same_pointer", same_pointer);
  72     g_test_add_func("/common/strings/strcmp/one_is_null", one_is_null);
  73     g_test_add_func("/common/strings/strcmp/case_matters", case_matters);
  74     g_test_add_func("/common/strings/strcmp/case_insensitive", case_insensitive);
  75     g_test_add_func("/common/strings/strcmp/regex", regex);
  76 
  77     return g_test_run();
  78 }

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