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-2020
   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     mc_global.timer = mc_timer_new ();
  49     str_init_strings (NULL);
  50 
  51     vfs_init ();
  52     vfs_init_localfs ();
  53     vfs_setup_work_dir ();
  54 }
  55 
  56 /* --------------------------------------------------------------------------------------------- */
  57 
  58 /* @After */
  59 static void
  60 teardown (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  61 {
  62     vfs_shut ();
  63     str_uninit_strings ();
  64     mc_timer_destroy (mc_global.timer);
  65 }
  66 
  67 /* --------------------------------------------------------------------------------------------- */
  68 
  69 /* @Test */
  70 /* *INDENT-OFF* */
  71 START_TEST (test_mc_tmpdir)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 /* *INDENT-ON* */
  73 {
  74     /* given */
  75     const char *tmpdir;
  76     const char *env_tmpdir;
  77 
  78     /* when */
  79     tmpdir = mc_tmpdir ();
  80     env_tmpdir = g_getenv ("MC_TMPDIR");
  81 
  82     /* then */
  83     fail_unless (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
  84                  "\nNo such directory: %s\n", tmpdir);
  85     mctest_assert_str_eq (env_tmpdir, tmpdir);
  86 }
  87 /* *INDENT-OFF* */
  88 END_TEST
  89 /* *INDENT-ON* */
  90 
  91 /* --------------------------------------------------------------------------------------------- */
  92 
  93 /* @Test */
  94 /* *INDENT-OFF* */
  95 START_TEST (test_mc_mkstemps)
     /* [previous][next][first][last][top][bottom][index][help]  */
  96 /* *INDENT-ON* */
  97 {
  98     /* given */
  99     vfs_path_t *pname_vpath = NULL;
 100     char *begin_pname;
 101     int fd;
 102 
 103     /* when */
 104     fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
 105     begin_pname = g_build_filename (mc_tmpdir (), "mctest-", (char *) NULL);
 106 
 107     /* then */
 108     close (fd);
 109     mctest_assert_int_ne (fd, -1);
 110     fail_unless (g_file_test
 111                  (vfs_path_as_str (pname_vpath), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
 112                  "\nNo such file: %s\n", vfs_path_as_str (pname_vpath));
 113     unlink (vfs_path_as_str (pname_vpath));
 114     fail_unless (strncmp (vfs_path_as_str (pname_vpath), begin_pname, strlen (begin_pname)) == 0,
 115                  "\nstart of %s should be equal to %s\n", vfs_path_as_str (pname_vpath),
 116                  begin_pname);
 117     vfs_path_free (pname_vpath);
 118 }
 119 /* *INDENT-OFF* */
 120 END_TEST
 121 /* *INDENT-ON* */
 122 
 123 /* --------------------------------------------------------------------------------------------- */
 124 
 125 int
 126 main (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 127 {
 128     int number_failed;
 129 
 130     Suite *s = suite_create (TEST_SUITE_NAME);
 131     TCase *tc_core = tcase_create ("Core");
 132     SRunner *sr;
 133 
 134     tcase_add_checked_fixture (tc_core, setup, teardown);
 135 
 136     /* Add new tests here: *************** */
 137     tcase_add_test (tc_core, test_mc_tmpdir);
 138     tcase_add_test (tc_core, test_mc_mkstemps);
 139     /* *********************************** */
 140 
 141     suite_add_tcase (s, tc_core);
 142     sr = srunner_create (s);
 143     srunner_set_log (sr, "tempdir.log");
 144     srunner_run_all (sr, CK_ENV);
 145     number_failed = srunner_ntests_failed (sr);
 146     srunner_free (sr);
 147     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 148 }
 149 
 150 /* --------------------------------------------------------------------------------------------- */

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