Zero struct stat tv_nsec (if supported) whenever st is filled manually
[midnight-commander.git] / tests / lib / vfs / tempdir.c
blob338b3a710a0026d174b075e15a3c7e4a11263344
1 /*
2 lib/vfs - manipulations with temp files and dirs
4 Copyright (C) 2012-2017
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"
43 struct vfs_s_subclass test_subclass1, test_subclass2, test_subclass3;
44 struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
46 /* --------------------------------------------------------------------------------------------- */
48 /* @Before */
49 static void
50 setup (void)
52 str_init_strings (NULL);
54 vfs_init ();
55 init_localfs ();
56 vfs_setup_work_dir ();
59 /* --------------------------------------------------------------------------------------------- */
61 /* @After */
62 static void
63 teardown (void)
65 vfs_shut ();
66 str_uninit_strings ();
69 /* --------------------------------------------------------------------------------------------- */
71 /* @Test */
72 /* *INDENT-OFF* */
73 START_TEST (test_mc_tmpdir)
74 /* *INDENT-ON* */
76 /* given */
77 const char *tmpdir;
78 const char *env_tmpdir;
80 /* when */
81 tmpdir = mc_tmpdir ();
82 env_tmpdir = g_getenv ("MC_TMPDIR");
84 /* then */
85 fail_unless (g_file_test (tmpdir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR),
86 "\nNo such directory: %s\n", tmpdir);
87 mctest_assert_str_eq (env_tmpdir, tmpdir);
89 /* *INDENT-OFF* */
90 END_TEST
91 /* *INDENT-ON* */
93 /* --------------------------------------------------------------------------------------------- */
95 /* @Test */
96 /* *INDENT-OFF* */
97 START_TEST (test_mc_mkstemps)
98 /* *INDENT-ON* */
100 /* given */
101 vfs_path_t *pname_vpath = NULL;
102 char *begin_pname;
103 int fd;
105 /* when */
106 fd = mc_mkstemps (&pname_vpath, "mctest-", NULL);
107 begin_pname = g_build_filename (mc_tmpdir (), "mctest-", (char *) NULL);
109 /* then */
110 close (fd);
111 mctest_assert_int_ne (fd, -1);
112 fail_unless (g_file_test
113 (vfs_path_as_str (pname_vpath), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR),
114 "\nNo such file: %s\n", vfs_path_as_str (pname_vpath));
115 unlink (vfs_path_as_str (pname_vpath));
116 fail_unless (strncmp (vfs_path_as_str (pname_vpath), begin_pname, strlen (begin_pname)) == 0,
117 "\nstart of %s should be equal to %s\n", vfs_path_as_str (pname_vpath),
118 begin_pname);
119 vfs_path_free (pname_vpath);
121 /* *INDENT-OFF* */
122 END_TEST
123 /* *INDENT-ON* */
125 /* --------------------------------------------------------------------------------------------- */
128 main (void)
130 int number_failed;
132 Suite *s = suite_create (TEST_SUITE_NAME);
133 TCase *tc_core = tcase_create ("Core");
134 SRunner *sr;
136 tcase_add_checked_fixture (tc_core, setup, teardown);
138 /* Add new tests here: *************** */
139 tcase_add_test (tc_core, test_mc_tmpdir);
140 tcase_add_test (tc_core, test_mc_mkstemps);
141 /* *********************************** */
143 suite_add_tcase (s, tc_core);
144 sr = srunner_create (s);
145 srunner_set_log (sr, "tempdir.log");
146 srunner_run_all (sr, CK_ENV);
147 number_failed = srunner_ntests_failed (sr);
148 srunner_free (sr);
149 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
152 /* --------------------------------------------------------------------------------------------- */