2 * Copyright (c) 2005 Zmanda, Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 #include "glib-util.h"
25 #include "testutils.h"
27 /* Global state set up for the tests */
28 static char *device_path = NULL;
35 cleanup_vtape_dir(char *device_path)
37 char *quoted = g_shell_quote(device_path);
38 char *cmd = vstralloc("rm -rf ", quoted, NULL);
40 /* would you rather write 'rm -rf' here? */
41 if (system(cmd) == -1) {
52 char *cwd = g_get_current_dir();
53 char *device_path = NULL;
54 char *data_dir = NULL;
56 device_path = vstralloc(cwd, "/vfs-test-XXXXXX", NULL);
59 if (mkdtemp(device_path) == NULL) {
60 fprintf(stderr, "Could not create temporary directory in %s\n", cwd);
64 /* append "/data/" to that for the VFS device*/
65 data_dir = vstralloc(device_path, "/data/", NULL);
66 if (mkdir(data_dir, 0777) == -1) {
67 fprintf(stderr, "Could not create %s: %s\n", cwd, strerror(errno));
80 char *device_name = NULL;
82 device_name = vstralloc("file:", device_path, NULL);
83 device = device_open(device_name);
84 if (device->status != DEVICE_STATUS_SUCCESS) {
85 g_critical("Could not open device %s: %s\n", device_name, device_error(device));
97 test_vfs_free_space(void)
99 Device *device = NULL;
103 device = setup_device();
107 bzero(&value, sizeof(value));
108 if (!device_property_get(device, PROPERTY_FREE_SPACE, &value)) {
109 g_debug("Could not get property_free_space\n");
113 qsize = *(QualifiedSize*)g_value_get_boxed(&value);
114 g_value_unset(&value);
116 if (qsize.accuracy != SIZE_ACCURACY_REAL) {
117 g_debug("property_free_space accuracy is not SIZE_ACCURACY_REAL\n");
121 if (qsize.bytes == 0) {
122 g_debug("property_free_space returned bytes=0\n");
126 g_object_unref(device);
136 main(int argc, char **argv)
139 static TestUtilsTest tests[] = {
140 TU_TEST(test_vfs_free_space, 5),
145 config_init(0, NULL);
148 /* TODO: if more tests are added, we'll need a setup/cleanup hook
150 device_path = setup_vtape_dir();
152 result = testutils_run_tests(argc, argv, tests);
154 cleanup_vtape_dir(device_path);