root/lib/common/tests/utils/compare_version_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. empty_params
  2. equal_versions
  3. unequal_versions
  4. shorter_versions
  5. 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 empty_params(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21     assert_int_equal(compare_version(NULL, NULL), 0);
  22     assert_int_equal(compare_version(NULL, "abc"), -1);
  23     assert_int_equal(compare_version(NULL, "1.0.1"), -1);
  24     assert_int_equal(compare_version("abc", NULL), 1);
  25     assert_int_equal(compare_version("1.0.1", NULL), 1);
  26 }
  27 
  28 static void
  29 equal_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31     assert_int_equal(compare_version("0.4.7", "0.4.7"), 0);
  32     assert_int_equal(compare_version("1.0", "1.0"), 0);
  33 }
  34 
  35 static void
  36 unequal_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38     assert_int_equal(compare_version("0.4.7", "0.4.8"), -1);
  39     assert_int_equal(compare_version("0.4.8", "0.4.7"), 1);
  40 
  41     assert_int_equal(compare_version("0.2.3", "0.3"), -1);
  42     assert_int_equal(compare_version("0.3", "0.2.3"), 1);
  43 
  44     assert_int_equal(compare_version("0.99", "1.0"), -1);
  45     assert_int_equal(compare_version("1.0", "0.99"), 1);
  46 }
  47 
  48 static void
  49 shorter_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51     assert_int_equal(compare_version("1.0", "1.0.1"), -1);
  52     assert_int_equal(compare_version("1.0.1", "1.0"), 1);
  53 }
  54 
  55 int main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57     const struct CMUnitTest tests[] = {
  58         cmocka_unit_test(empty_params),
  59         cmocka_unit_test(equal_versions),
  60         cmocka_unit_test(unequal_versions),
  61         cmocka_unit_test(shorter_versions),
  62     };
  63 
  64     cmocka_set_message_output(CM_OUTPUT_TAP);
  65     return cmocka_run_group_tests(tests, NULL, NULL);
  66 }

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