root/lib/common/tests/io/pcmk__full_path_test.c

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

DEFINITIONS

This source file includes following definitions.
  1. function_asserts
  2. function_exits
  3. full_path

   1 /*
   2  * Copyright 2020-2024 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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/common/unittest_internal.h>
  13 
  14 #include "mock_private.h"
  15 
  16 static void
  17 function_asserts(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19     pcmk__assert_asserts(pcmk__full_path(NULL, "/dir"));
  20     pcmk__assert_asserts(pcmk__full_path("file", NULL));
  21 }
  22 
  23 static void
  24 function_exits(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  25 {
  26     pcmk__assert_exits(
  27         CRM_EX_OSERR,
  28         {
  29             pcmk__mock_strdup = true;   // strdup() will return NULL
  30             expect_string(__wrap_strdup, s, "/full/path");
  31             pcmk__full_path("/full/path", "/dir");
  32             pcmk__mock_strdup = false;  // Use real strdup()
  33         }
  34     );
  35 }
  36 
  37 static void
  38 full_path(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40     char *path = NULL;
  41 
  42     path = pcmk__full_path("file", "/dir");
  43     assert_int_equal(strcmp(path, "/dir/file"), 0);
  44     free(path);
  45 
  46     path = pcmk__full_path("/full/path", "/dir");
  47     assert_int_equal(strcmp(path, "/full/path"), 0);
  48     free(path);
  49 
  50     path = pcmk__full_path("../relative/path", "/dir");
  51     assert_int_equal(strcmp(path, "/dir/../relative/path"), 0);
  52     free(path);
  53 }
  54 
  55 PCMK__UNIT_TEST(NULL, NULL,
  56                 cmocka_unit_test(function_asserts),
  57                 cmocka_unit_test(function_exits),
  58                 cmocka_unit_test(full_path))

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