root/lib/common/tests/operations/parse_op_key_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. basic
  2. colon_in_rsc
  3. dashes_in_rsc
  4. migrate_to_from
  5. pre_post
  6. skip_rsc
  7. skip_ty
  8. skip_ms
  9. empty_input
  10. malformed_input
  11. main

   1 /*
   2  * Copyright 2020-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 <stdio.h>
  13 #include <glib.h>
  14 
  15 static void
  16 basic(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18     char *rsc = NULL;
  19     char *ty = NULL;
  20     guint ms = 0;
  21 
  22     g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms));
  23     g_assert_cmpstr(rsc, ==, "Fencing");
  24     g_assert_cmpstr(ty, ==, "monitor");
  25     g_assert_cmpint(ms, ==, 60000);
  26     free(rsc);
  27     free(ty);
  28 }
  29 
  30 static void
  31 colon_in_rsc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  32 {
  33     char *rsc = NULL;
  34     char *ty = NULL;
  35     guint ms = 0;
  36 
  37     g_assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms));
  38     g_assert_cmpstr(rsc, ==, "ClusterIP:0");
  39     g_assert_cmpstr(ty, ==, "start");
  40     g_assert_cmpint(ms, ==, 0);
  41     free(rsc);
  42     free(ty);
  43 
  44     g_assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms));
  45     g_assert_cmpstr(rsc, ==, "imagestoreclone:1");
  46     g_assert_cmpstr(ty, ==, "post_notify_stop");
  47     g_assert_cmpint(ms, ==, 0);
  48     free(rsc);
  49     free(ty);
  50 }
  51 
  52 static void
  53 dashes_in_rsc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55     char *rsc = NULL;
  56     char *ty = NULL;
  57     guint ms = 0;
  58 
  59     g_assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms));
  60     g_assert_cmpstr(rsc, ==, "httpd-bundle-0");
  61     g_assert_cmpstr(ty, ==, "monitor");
  62     g_assert_cmpint(ms, ==, 30000);
  63     free(rsc);
  64     free(ty);
  65 
  66     g_assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms));
  67     g_assert_cmpstr(rsc, ==, "httpd-bundle-ip-192.168.122.132");
  68     g_assert_cmpstr(ty, ==, "start");
  69     g_assert_cmpint(ms, ==, 0);
  70     free(rsc);
  71     free(ty);
  72 }
  73 
  74 static void
  75 migrate_to_from(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77     char *rsc = NULL;
  78     char *ty = NULL;
  79     guint ms = 0;
  80 
  81     g_assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms));
  82     g_assert_cmpstr(rsc, ==, "vm");
  83     g_assert_cmpstr(ty, ==, "migrate_from");
  84     g_assert_cmpint(ms, ==, 0);
  85     free(rsc);
  86     free(ty);
  87 
  88     g_assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms));
  89     g_assert_cmpstr(rsc, ==, "vm");
  90     g_assert_cmpstr(ty, ==, "migrate_to");
  91     g_assert_cmpint(ms, ==, 0);
  92     free(rsc);
  93     free(ty);
  94 
  95     g_assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms));
  96     g_assert_cmpstr(rsc, ==, "vm_idcc_devel");
  97     g_assert_cmpstr(ty, ==, "migrate_to");
  98     g_assert_cmpint(ms, ==, 0);
  99     free(rsc);
 100     free(ty);
 101 }
 102 
 103 static void
 104 pre_post(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106     char *rsc = NULL;
 107     char *ty = NULL;
 108     guint ms = 0;
 109 
 110     g_assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms));
 111     g_assert_cmpstr(rsc, ==, "rsc_drbd_7788:1");
 112     g_assert_cmpstr(ty, ==, "post_notify_start");
 113     g_assert_cmpint(ms, ==, 0);
 114     free(rsc);
 115     free(ty);
 116 
 117     g_assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms));
 118     g_assert_cmpstr(rsc, ==, "rabbitmq-bundle-clone");
 119     g_assert_cmpstr(ty, ==, "pre_notify_stop");
 120     g_assert_cmpint(ms, ==, 0);
 121     free(rsc);
 122     free(ty);
 123 
 124     g_assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms));
 125     g_assert_cmpstr(rsc, ==, "post_notify");
 126     g_assert_cmpstr(ty, ==, "start");
 127     g_assert_cmpint(ms, ==, 0);
 128     free(rsc);
 129     free(ty);
 130 }
 131 
 132 static void
 133 skip_rsc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135     char *ty = NULL;
 136     guint ms = 0;
 137 
 138     g_assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms));
 139     g_assert_cmpstr(ty, ==, "monitor");
 140     g_assert_cmpint(ms, ==, 60000);
 141     free(ty);
 142 }
 143 
 144 static void
 145 skip_ty(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147     char *rsc = NULL;
 148     guint ms = 0;
 149 
 150     g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms));
 151     g_assert_cmpstr(rsc, ==, "Fencing");
 152     g_assert_cmpint(ms, ==, 60000);
 153     free(rsc);
 154 }
 155 
 156 static void
 157 skip_ms(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159     char *rsc = NULL;
 160     char *ty = NULL;
 161 
 162     g_assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL));
 163     g_assert_cmpstr(rsc, ==, "Fencing");
 164     g_assert_cmpstr(ty, ==, "monitor");
 165     free(rsc);
 166     free(ty);
 167 }
 168 
 169 static void
 170 empty_input(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 171 {
 172     char *rsc = NULL;
 173     char *ty = NULL;
 174     guint ms = 0;
 175 
 176     g_assert_false(parse_op_key("", &rsc, &ty, &ms));
 177     g_assert_null(rsc);
 178     g_assert_null(ty);
 179     g_assert_cmpint(ms, ==, 0);
 180 
 181     g_assert_false(parse_op_key(NULL, &rsc, &ty, &ms));
 182     g_assert_null(rsc);
 183     g_assert_null(ty);
 184     g_assert_cmpint(ms, ==, 0);
 185 }
 186 
 187 static void
 188 malformed_input(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 189 {
 190     char *rsc = NULL;
 191     char *ty = NULL;
 192     guint ms = 0;
 193 
 194     g_assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms));
 195     g_assert_null(rsc);
 196     g_assert_null(ty);
 197     g_assert_cmpint(ms, ==, 0);
 198 
 199     g_assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms));
 200     g_assert_null(rsc);
 201     g_assert_null(ty);
 202     g_assert_cmpint(ms, ==, 0);
 203 
 204     g_assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms));
 205     g_assert_null(rsc);
 206     g_assert_null(ty);
 207     g_assert_cmpint(ms, ==, 0);
 208 }
 209 
 210 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
 211 {
 212     g_test_init(&argc, &argv, NULL);
 213 
 214     g_test_add_func("/common/utils/parse_op_key/basic", basic);
 215     g_test_add_func("/common/utils/parse_op_key/colon_in_rsc", colon_in_rsc);
 216     g_test_add_func("/common/utils/parse_op_key/dashes_in_rsc", dashes_in_rsc);
 217     g_test_add_func("/common/utils/parse_op_key/migrate_to_from", migrate_to_from);
 218     g_test_add_func("/common/utils/parse_op_key/pre_post", pre_post);
 219 
 220     g_test_add_func("/common/utils/parse_op_key/skip_rsc", skip_rsc);
 221     g_test_add_func("/common/utils/parse_op_key/skip_ty", skip_ty);
 222     g_test_add_func("/common/utils/parse_op_key/skip_ms", skip_ms);
 223 
 224     g_test_add_func("/common/utils/parse_op_key/empty_input", empty_input);
 225     g_test_add_func("/common/utils/parse_op_key/malformed_input", malformed_input);
 226 
 227     return g_test_run();
 228 }

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