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. full_path

   1 /*
   2  * Copyright 2020-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 #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     pcmk__assert_asserts(
  23         {
  24             pcmk__mock_strdup = true;   // strdup() will return NULL
  25             expect_string(__wrap_strdup, s, "/full/path");
  26             pcmk__full_path("/full/path", "/dir");
  27             pcmk__mock_strdup = false;  // Use real strdup()
  28         }
  29     );
  30 }
  31 
  32 static void
  33 full_path(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     char *path = NULL;
  36 
  37     path = pcmk__full_path("file", "/dir");
  38     assert_int_equal(strcmp(path, "/dir/file"), 0);
  39     free(path);
  40 
  41     path = pcmk__full_path("/full/path", "/dir");
  42     assert_int_equal(strcmp(path, "/full/path"), 0);
  43     free(path);
  44 
  45     path = pcmk__full_path("../relative/path", "/dir");
  46     assert_int_equal(strcmp(path, "/dir/../relative/path"), 0);
  47     free(path);
  48 }
  49 
  50 PCMK__UNIT_TEST(NULL, NULL,
  51                 cmocka_unit_test(function_asserts),
  52                 cmocka_unit_test(full_path))

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