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

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

DEFINITIONS

This source file includes following definitions.
  1. bad_input
  2. good_input
  3. overflow

   1 /*
   2  * Copyright 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 <crm/common/unittest_internal.h>
  13 
  14 static void
  15 bad_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  16     assert_int_equal(crm_get_msec(NULL), PCMK__PARSE_INT_DEFAULT);
  17     assert_int_equal(crm_get_msec("     "), PCMK__PARSE_INT_DEFAULT);
  18     assert_int_equal(crm_get_msec("abcxyz"), PCMK__PARSE_INT_DEFAULT);
  19     assert_int_equal(crm_get_msec("100xs"), PCMK__PARSE_INT_DEFAULT);
  20     assert_int_equal(crm_get_msec(" 100 xs "), PCMK__PARSE_INT_DEFAULT);
  21     assert_int_equal(crm_get_msec("-100ms"), PCMK__PARSE_INT_DEFAULT);
  22 }
  23 
  24 static void
  25 good_input(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  26     assert_int_equal(crm_get_msec("100"), 100000);
  27     assert_int_equal(crm_get_msec(" 100 "), 100000);
  28     assert_int_equal(crm_get_msec("\t100\n"), 100000);
  29 
  30     assert_int_equal(crm_get_msec("100ms"), 100);
  31     assert_int_equal(crm_get_msec("100 MSEC"), 100);
  32     assert_int_equal(crm_get_msec("1000US"), 1);
  33     assert_int_equal(crm_get_msec("1000usec"), 1);
  34     assert_int_equal(crm_get_msec("12s"), 12000);
  35     assert_int_equal(crm_get_msec("12 sec"), 12000);
  36     assert_int_equal(crm_get_msec("1m"), 60000);
  37     assert_int_equal(crm_get_msec("13 min"), 780000);
  38     assert_int_equal(crm_get_msec("2\th"), 7200000);
  39     assert_int_equal(crm_get_msec("1 hr"), 3600000);
  40 }
  41 
  42 static void
  43 overflow(void **state) {
     /* [previous][next][first][last][top][bottom][index][help] */
  44     assert_int_equal(crm_get_msec("9223372036854775807s"), LLONG_MAX);
  45 }
  46 
  47 PCMK__UNIT_TEST(NULL, NULL,
  48                 cmocka_unit_test(bad_input),
  49                 cmocka_unit_test(good_input),
  50                 cmocka_unit_test(overflow))

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