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

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

DEFINITIONS

This source file includes following definitions.
  1. score1_minus_inf
  2. score2_minus_inf
  3. score1_pos_inf
  4. score2_pos_inf
  5. result_infinite
  6. result_finite
  7. 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 score1_minus_inf(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  22     assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, -1), -CRM_SCORE_INFINITY);
  23     assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 0), -CRM_SCORE_INFINITY);
  24     assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, 1), -CRM_SCORE_INFINITY);
  25     assert_int_equal(pcmk__add_scores(-CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  26 }
  27 
  28 static void
  29 score2_minus_inf(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31     assert_int_equal(pcmk__add_scores(-1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  32     assert_int_equal(pcmk__add_scores(0, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  33     assert_int_equal(pcmk__add_scores(1, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  34     assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -CRM_SCORE_INFINITY), -CRM_SCORE_INFINITY);
  35 }
  36 
  37 static void
  38 score1_pos_inf(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40     assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
  41     assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, -1), CRM_SCORE_INFINITY);
  42     assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 0), CRM_SCORE_INFINITY);
  43     assert_int_equal(pcmk__add_scores(CRM_SCORE_INFINITY, 1), CRM_SCORE_INFINITY);
  44 }
  45 
  46 static void
  47 score2_pos_inf(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     assert_int_equal(pcmk__add_scores(-1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
  50     assert_int_equal(pcmk__add_scores(0, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
  51     assert_int_equal(pcmk__add_scores(1, CRM_SCORE_INFINITY), CRM_SCORE_INFINITY);
  52 }
  53 
  54 static void
  55 result_infinite(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57     assert_int_equal(pcmk__add_scores(INT_MAX, INT_MAX), CRM_SCORE_INFINITY);
  58     assert_int_equal(pcmk__add_scores(INT_MIN, INT_MIN), -CRM_SCORE_INFINITY);
  59     assert_int_equal(pcmk__add_scores(2000000, 50), CRM_SCORE_INFINITY);
  60     assert_int_equal(pcmk__add_scores(-4000000, 50), -CRM_SCORE_INFINITY);
  61 }
  62 
  63 static void
  64 result_finite(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66     assert_int_equal(pcmk__add_scores(0, 0), 0);
  67     assert_int_equal(pcmk__add_scores(0, 100), 100);
  68     assert_int_equal(pcmk__add_scores(200, 0), 200);
  69     assert_int_equal(pcmk__add_scores(200, -50), 150);
  70 }
  71 
  72 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  73 {
  74     const struct CMUnitTest tests[] = {
  75         cmocka_unit_test(score1_minus_inf),
  76         cmocka_unit_test(score2_minus_inf),
  77         cmocka_unit_test(score1_pos_inf),
  78         cmocka_unit_test(score2_pos_inf),
  79         cmocka_unit_test(result_infinite),
  80         cmocka_unit_test(result_finite),
  81     };
  82 
  83     cmocka_set_message_output(CM_OUTPUT_TAP);
  84     return cmocka_run_group_tests(tests, NULL, NULL);
  85 }

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