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

   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 <crm/common/unittest_internal.h>
  13 
  14 static void
  15 empty_params(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17     assert_int_equal(compare_version(NULL, NULL), 0);
  18     assert_int_equal(compare_version(NULL, "abc"), -1);
  19     assert_int_equal(compare_version(NULL, "1.0.1"), -1);
  20     assert_int_equal(compare_version("abc", NULL), 1);
  21     assert_int_equal(compare_version("1.0.1", NULL), 1);
  22 }
  23 
  24 static void
  25 equal_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27     assert_int_equal(compare_version("0.4.7", "0.4.7"), 0);
  28     assert_int_equal(compare_version("1.0", "1.0"), 0);
  29 }
  30 
  31 static void
  32 unequal_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34     assert_int_equal(compare_version("0.4.7", "0.4.8"), -1);
  35     assert_int_equal(compare_version("0.4.8", "0.4.7"), 1);
  36 
  37     assert_int_equal(compare_version("0.2.3", "0.3"), -1);
  38     assert_int_equal(compare_version("0.3", "0.2.3"), 1);
  39 
  40     assert_int_equal(compare_version("0.99", "1.0"), -1);
  41     assert_int_equal(compare_version("1.0", "0.99"), 1);
  42 }
  43 
  44 static void
  45 shorter_versions(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47     assert_int_equal(compare_version("1.0", "1.0.1"), -1);
  48     assert_int_equal(compare_version("1.0.1", "1.0"), 1);
  49 }
  50 
  51 PCMK__UNIT_TEST(NULL, NULL,
  52                 cmocka_unit_test(empty_params),
  53                 cmocka_unit_test(equal_versions),
  54                 cmocka_unit_test(unequal_versions),
  55                 cmocka_unit_test(shorter_versions))

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