root/lib/common/tests/scores/score2char_stack_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. invalid_params
  2. outside_limits
  3. inside_limits
  4. main

   1 /*
   2  * Copyright 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 <stdarg.h>
  13 #include <stddef.h>
  14 #include <stdint.h>
  15 #include <setjmp.h>
  16 #include <cmocka.h>
  17 
  18 static void
  19 invalid_params(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     char *buf = malloc(9);
  22 
  23     assert_null(score2char_stack(100, NULL, 9));
  24     assert_null(score2char_stack(100, buf, 9));
  25 
  26     free(buf);
  27 }
  28 
  29 static void
  30 outside_limits(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32     char *buf = malloc(10);
  33 
  34     buf = score2char_stack(CRM_SCORE_INFINITY * 2, buf, 10);
  35     assert_string_equal(buf, CRM_INFINITY_S);
  36 
  37     buf = score2char_stack(-CRM_SCORE_INFINITY * 2, buf, 10);
  38     assert_string_equal(buf, CRM_MINUS_INFINITY_S);
  39 
  40     free(buf);
  41 }
  42 
  43 static void
  44 inside_limits(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46     char *buf = malloc(10);
  47 
  48     buf = score2char_stack(0, buf, 10);
  49     assert_string_equal(buf, "0");
  50 
  51     buf = score2char_stack(1024, buf, 10);
  52     assert_string_equal(buf, "1024");
  53 
  54     buf = score2char_stack(-1024, buf, 10);
  55     assert_string_equal(buf, "-1024");
  56 
  57     free(buf);
  58 }
  59 
  60 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62     const struct CMUnitTest tests[] = {
  63         cmocka_unit_test(invalid_params),
  64         cmocka_unit_test(outside_limits),
  65         cmocka_unit_test(inside_limits),
  66     };
  67 
  68     cmocka_set_message_output(CM_OUTPUT_TAP);
  69     return cmocka_run_group_tests(tests, NULL, NULL);
  70 }

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