Push/pop dirstack: changed type of saved items to vfs_path_t type.
[midnight-commander.git] / tests / lib / vfs / tempdir.c
blob2a23d973aec647af6316fbdbf03cd66370ec83a0
1 /*
2 lib/vfs - manipulations with temp files and dirs
4 Copyright (C) 2012
5 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2012
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 <config.h>
30 #include <check.h>
32 #include "lib/global.c"
34 #ifndef HAVE_CHARSET
35 #define HAVE_CHARSET 1
36 #endif
38 #include "lib/charsets.h"
40 #include "lib/strutil.h"
41 #include "lib/vfs/xdirentry.h"
42 #include "lib/vfs/path.h"
44 #include "src/vfs/local/local.c"
47 struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
48 struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
50 static void
51 setup (void)
53 str_init_strings (NULL);
55 vfs_init ();
56 init_localfs ();
57 vfs_setup_work_dir ();
60 static void
61 teardown (void)
63 vfs_shut ();
64 str_uninit_strings ();
67 /* --------------------------------------------------------------------------------------------- */
68 START_TEST (test_mc_tmpdir)
70 const char *tmpdir;
71 const char *env_tmpdir;
73 tmpdir = mc_tmpdir();
74 fail_unless (
75 g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
76 "\nNo such directory: %s\n", tmpdir
79 env_tmpdir = g_getenv ("MC_TMPDIR");
80 fail_unless (
81 strcmp (env_tmpdir, tmpdir) == 0,
82 "\nenv_tmpdir=%s\n tmpdir=%s\n", env_tmpdir, tmpdir
85 END_TEST
87 START_TEST (test_mc_mkstemps)
89 vfs_path_t *pname_vpath = NULL;
90 char *pname;
91 char *begin_pname;
92 int fd;
94 fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
95 if (fd == -1)
97 fail ("\nerror creating temp file!\n");
99 pname = vfs_path_to_str (pname_vpath);
100 vfs_path_free (pname_vpath);
101 close (fd);
103 fail_unless (
104 g_file_test (pname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
105 "\nNo such file: %s\n", pname
107 unlink(pname);
109 begin_pname = g_build_filename (mc_tmpdir(), "mctest-", NULL);
110 fail_unless (
111 strncmp(pname, begin_pname, strlen(begin_pname)) == 0,
112 "\nstart of %s should be equal to %s\n", pname, begin_pname
114 g_free (pname);
116 END_TEST
118 /* --------------------------------------------------------------------------------------------- */
121 main (void)
123 int number_failed;
125 Suite *s = suite_create (TEST_SUITE_NAME);
126 TCase *tc_core = tcase_create ("Core");
127 SRunner *sr;
129 tcase_add_checked_fixture (tc_core, setup, teardown);
131 /* Add new tests here: *************** */
132 tcase_add_test (tc_core, test_mc_tmpdir);
133 tcase_add_test (tc_core, test_mc_mkstemps);
134 /* *********************************** */
136 suite_add_tcase (s, tc_core);
137 sr = srunner_create (s);
138 srunner_set_log (sr, "tempdir.log");
139 srunner_run_all (sr, CK_NORMAL);
140 number_failed = srunner_ntests_failed (sr);
141 srunner_free (sr);
142 return (number_failed == 0) ? 0 : 1;
145 /* --------------------------------------------------------------------------------------------- */