root/tests/lib/vfs/tempdir.c

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

DEFINITIONS

This source file includes following definitions.
  1. setup
  2. teardown
  3. START_TEST
  4. START_TEST
  5. main

   1 /*
   2    lib/vfs - manipulations with temp files and  dirs
   3 
   4    Copyright (C) 2012-2024
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Slava Zanko <slavazanko@gmail.com>, 2012, 2013
   9 
  10    This file is part of the Midnight Commander.
  11 
  12    The Midnight Commander is free software: you can redistribute it
  13    and/or modify it under the terms of the GNU General Public License as
  14    published by the Free Software Foundation, either version 3 of the License,
  15    or (at your option) any later version.
  16 
  17    The Midnight Commander is distributed in the hope that it will be useful,
  18    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20    GNU General Public License for more details.
  21 
  22    You should have received a copy of the GNU General Public License
  23    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  24  */
  25 
  26 #define TEST_SUITE_NAME "/lib/vfs"
  27 
  28 #include "tests/mctest.h"
  29 
  30 #ifndef HAVE_CHARSET
  31 #define HAVE_CHARSET 1
  32 #endif
  33 
  34 #include "lib/charsets.h"
  35 
  36 #include "lib/strutil.h"
  37 #include "lib/vfs/xdirentry.h"
  38 #include "lib/vfs/path.h"
  39 
  40 #include "src/vfs/local/local.c"
  41 
  42 /* --------------------------------------------------------------------------------------------- */
  43 
  44 /* @Before */
  45 static void
  46 setup (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  47 {
  48     /* Ensure that tests behave consistently irrespectively of the environment */
  49     g_unsetenv ("MC_TMPDIR");
  50 
  51     str_init_strings (NULL);
  52 
  53     vfs_init ();
  54     vfs_init_localfs ();
  55     vfs_setup_work_dir ();
  56 }
  57 
  58 /* --------------------------------------------------------------------------------------------- */
  59 
  60 /* @After */
  61 static void
  62 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  63 {
  64     vfs_shut ();
  65     str_uninit_strings ();
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 /* @Test */
  71 /* *INDENT-OFF* */
  72 START_TEST (test_mc_tmpdir)
     /* [previous][next][first][last][top][bottom][index][help]  */
  73 /* *INDENT-ON* */
  74 {
  75     /* given */
  76     const char *tmpdir;
  77     const char *env_tmpdir;
  78 
  79     /* when */
  80     tmpdir = mc_tmpdir ();
  81     env_tmpdir = g_getenv ("MC_TMPDIR");
  82 
  83     /* then */
  84     ck_assert_msg (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
  85                    "\nNo such directory: %s\n", tmpdir);
  86     mctest_assert_str_eq (env_tmpdir, tmpdir);
  87 }
  88 /* *INDENT-OFF* */
  89 END_TEST
  90 /* *INDENT-ON* */
  91 
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 /* @Test */
  95 /* *INDENT-OFF* */
  96 START_TEST (test_mc_mkstemps)
     /* [previous][next][first][last][top][bottom][index][help]  */
  97 /* *INDENT-ON* */
  98 {
  99     /* given */
 100     vfs_path_t *pname_vpath = NULL;
 101     char *begin_pname;
 102     int fd;
 103 
 104     /* when */
 105     fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
 106     begin_pname = g_build_filename (mc_tmpdir (), "mctest-", (char *) NULL);
 107 
 108     /* then */
 109     close (fd);
 110     ck_assert_int_ne (fd, -1);
 111     ck_assert_msg (g_file_test
 112                    (vfs_path_as_str (pname_vpath), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
 113                    "\nNo such file: %s\n", vfs_path_as_str (pname_vpath));
 114     unlink (vfs_path_as_str (pname_vpath));
 115     ck_assert_msg (strncmp (vfs_path_as_str (pname_vpath), begin_pname, strlen (begin_pname)) == 0,
 116                    "\nstart of %s should be equal to %s\n", vfs_path_as_str (pname_vpath),
 117                    begin_pname);
 118     vfs_path_free (pname_vpath, TRUE);
 119 }
 120 /* *INDENT-OFF* */
 121 END_TEST
 122 /* *INDENT-ON* */
 123 
 124 /* --------------------------------------------------------------------------------------------- */
 125 
 126 int
 127 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 128 {
 129     TCase *tc_core;
 130 
 131     tc_core = tcase_create ("Core");
 132 
 133     tcase_add_checked_fixture (tc_core, setup, teardown);
 134 
 135     /* Add new tests here: *************** */
 136     tcase_add_test (tc_core, test_mc_tmpdir);
 137     tcase_add_test (tc_core, test_mc_mkstemps);
 138     /* *********************************** */
 139 
 140     return mctest_run_all (tc_core);
 141 }
 142 
 143 /* --------------------------------------------------------------------------------------------- */

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