Ticket #4217: remove OS/distro-specific stuff.
[midnight-commander.git] / tests / lib / vfs / tempdir.c
blob971dbd4f60782b03cbe2ddec88ed2e7f48c85176
1 /*
2 lib/vfs - manipulations with temp files and dirs
4 Copyright (C) 2012-2021
5 Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2012, 2013
10 This file is part of the Midnight Commander.
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.
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.
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/>.
26 #define TEST_SUITE_NAME "/lib/vfs"
28 #include "tests/mctest.h"
30 #ifndef HAVE_CHARSET
31 #define HAVE_CHARSET 1
32 #endif
34 #include "lib/charsets.h"
36 #include "lib/strutil.h"
37 #include "lib/vfs/xdirentry.h"
38 #include "lib/vfs/path.h"
40 #include "src/vfs/local/local.c"
42 /* --------------------------------------------------------------------------------------------- */
44 /* @Before */
45 static void
46 setup (void)
48 str_init_strings (NULL);
50 vfs_init ();
51 vfs_init_localfs ();
52 vfs_setup_work_dir ();
55 /* --------------------------------------------------------------------------------------------- */
57 /* @After */
58 static void
59 teardown (void)
61 vfs_shut ();
62 str_uninit_strings ();
65 /* --------------------------------------------------------------------------------------------- */
67 /* @Test */
68 /* *INDENT-OFF* */
69 START_TEST (test_mc_tmpdir)
70 /* *INDENT-ON* */
72 /* given */
73 const char *tmpdir;
74 const char *env_tmpdir;
76 /* when */
77 tmpdir = mc_tmpdir ();
78 env_tmpdir = g_getenv ("MC_TMPDIR");
80 /* then */
81 ck_assert_msg (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
82 "\nNo such directory: %s\n", tmpdir);
83 mctest_assert_str_eq (env_tmpdir, tmpdir);
85 /* *INDENT-OFF* */
86 END_TEST
87 /* *INDENT-ON* */
89 /* --------------------------------------------------------------------------------------------- */
91 /* @Test */
92 /* *INDENT-OFF* */
93 START_TEST (test_mc_mkstemps)
94 /* *INDENT-ON* */
96 /* given */
97 vfs_path_t *pname_vpath = NULL;
98 char *begin_pname;
99 int fd;
101 /* when */
102 fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
103 begin_pname = g_build_filename (mc_tmpdir (), "mctest-", (char *) NULL);
105 /* then */
106 close (fd);
107 mctest_assert_int_ne (fd, -1);
108 ck_assert_msg (g_file_test
109 (vfs_path_as_str (pname_vpath), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
110 "\nNo such file: %s\n", vfs_path_as_str (pname_vpath));
111 unlink (vfs_path_as_str (pname_vpath));
112 ck_assert_msg (strncmp (vfs_path_as_str (pname_vpath), begin_pname, strlen (begin_pname)) == 0,
113 "\nstart of %s should be equal to %s\n", vfs_path_as_str (pname_vpath),
114 begin_pname);
115 vfs_path_free (pname_vpath, TRUE);
117 /* *INDENT-OFF* */
118 END_TEST
119 /* *INDENT-ON* */
121 /* --------------------------------------------------------------------------------------------- */
124 main (void)
126 TCase *tc_core;
128 tc_core = tcase_create ("Core");
130 tcase_add_checked_fixture (tc_core, setup, teardown);
132 /* Add new tests here: *************** */
133 tcase_add_test (tc_core, test_mc_tmpdir);
134 tcase_add_test (tc_core, test_mc_mkstemps);
135 /* *********************************** */
137 return mctest_run_all (tc_core);
140 /* --------------------------------------------------------------------------------------------- */