17 test_file_get_contents ()
24 const gchar
*filename
= "c:\\Windows\\system.ini";
26 const gchar
*filename
= "/etc/hosts";
31 ret = g_file_get_contents (NULL, NULL, NULL, NULL);
33 ret = g_file_get_contents ("", NULL, NULL, NULL);
34 error no such file and fails for 'error' not being null too
35 ret = g_file_get_contents ("", &content, NULL, &error);
39 ret
= g_file_get_contents ("", &content
, NULL
, &error
);
41 return FAILED ("HAH!");
43 return FAILED ("Got nothing as error.");
45 return FAILED ("Content is uninitialized");
49 ret
= g_file_get_contents (filename
, &content
, &length
, &error
);
51 return FAILED ("The error is %d %s\n", error
->code
, error
->message
);
53 return FAILED ("Got an error returning TRUE");
55 return FAILED ("Content is NULL");
56 if (strlen (content
) != length
)
57 return FAILED ("length is %d but the string is %d", length
, strlen (content
));
68 gchar
*name
= GINT_TO_POINTER (-1);
71 * Okay, this works, but creates a .xxx file in /tmp on every run. Disabled.
72 * fd = g_file_open_tmp (NULL, NULL, NULL);
74 * return FAILED ("Default failed.");
78 fd
= g_file_open_tmp ("invalidtemplate", NULL
, &error
);
80 return FAILED ("The template was invalid and accepted");
82 return FAILED ("No error returned.");
86 fd
= g_file_open_tmp ("i/nvalidtemplate", &name
, &error
);
88 return FAILED ("The template was invalid and accepted");
90 return FAILED ("No error returned.");
92 return FAILED ("'name' is not reset");
96 fd
= g_file_open_tmp ("valid-XXXXXX", &name
, &error
);
98 return FAILED ("This should be valid");
100 return FAILED ("No error returned.");
102 return FAILED ("No name returned.");
116 #ifndef G_OS_WIN32 /* FIXME */
121 res
= g_file_test (NULL
, 0);
123 return FAILED ("Should return FALSE HERE");
125 res
= g_file_test ("file.c", 0);
127 return FAILED ("Should return FALSE HERE");
129 tmp
= g_get_tmp_dir ();
130 res
= g_file_test (tmp
, G_FILE_TEST_EXISTS
);
132 return FAILED ("tmp does not exist.");
133 res
= g_file_test (tmp
, G_FILE_TEST_IS_REGULAR
);
135 return FAILED ("tmp is regular");
137 res
= g_file_test (tmp
, G_FILE_TEST_IS_DIR
);
139 return FAILED ("tmp is not a directory");
140 res
= g_file_test (tmp
, G_FILE_TEST_IS_EXECUTABLE
);
142 return FAILED ("tmp is not a executable");
144 res
= g_file_test (tmp
, G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_SYMLINK
);
146 return FAILED ("2 tmp does not exist.");
147 res
= g_file_test (tmp
, G_FILE_TEST_IS_REGULAR
| G_FILE_TEST_IS_SYMLINK
);
149 return FAILED ("2 tmp is regular");
151 res
= g_file_test (tmp
, G_FILE_TEST_IS_DIR
| G_FILE_TEST_IS_SYMLINK
);
153 return FAILED ("2 tmp is not a directory");
154 res
= g_file_test (tmp
, G_FILE_TEST_IS_EXECUTABLE
| G_FILE_TEST_IS_SYMLINK
);
156 return FAILED ("2 tmp is not a executable");
158 close (g_file_open_tmp (NULL
, &path
, NULL
)); /* create an empty file */
159 res
= g_file_test (path
, G_FILE_TEST_EXISTS
);
161 return FAILED ("3 %s should exist", path
);
162 res
= g_file_test (path
, G_FILE_TEST_IS_REGULAR
);
163 /* This is strange. Empty file is reported as not existing! */
165 return FAILED ("3 %s IS_REGULAR", path
);
166 res
= g_file_test (path
, G_FILE_TEST_IS_DIR
);
168 return FAILED ("3 %s should not be a directory", path
);
169 res
= g_file_test (path
, G_FILE_TEST_IS_EXECUTABLE
);
171 return FAILED ("3 %s should not be executable", path
);
172 res
= g_file_test (path
, G_FILE_TEST_IS_SYMLINK
);
174 return FAILED ("3 %s should not be a symlink", path
);
176 #ifndef G_OS_WIN32 /* FIXME */
177 sympath
= g_strconcat (path
, "-link", NULL
);
178 ignored
= symlink (path
, sympath
);
179 res
= g_file_test (sympath
, G_FILE_TEST_EXISTS
);
181 return FAILED ("4 %s should not exist", sympath
);
182 res
= g_file_test (sympath
, G_FILE_TEST_IS_REGULAR
);
184 return FAILED ("4 %s should not be a regular file", sympath
);
185 res
= g_file_test (sympath
, G_FILE_TEST_IS_DIR
);
187 return FAILED ("4 %s should not be a directory", sympath
);
188 res
= g_file_test (sympath
, G_FILE_TEST_IS_EXECUTABLE
);
190 return FAILED ("4 %s should not be executable", sympath
);
191 res
= g_file_test (sympath
, G_FILE_TEST_IS_SYMLINK
);
193 return FAILED ("4 %s should be a symlink", sympath
);
197 res
= g_file_test (sympath
, G_FILE_TEST_EXISTS
);
199 return FAILED ("5 %s should exist", sympath
);
200 res
= g_file_test (sympath
, G_FILE_TEST_IS_REGULAR
);
202 return FAILED ("5 %s should be a regular file", sympath
);
203 res
= g_file_test (sympath
, G_FILE_TEST_IS_DIR
);
205 return FAILED ("5 %s should not be a directory", sympath
);
206 res
= g_file_test (sympath
, G_FILE_TEST_IS_EXECUTABLE
);
208 return FAILED ("5 %s should not be executable", sympath
);
209 res
= g_file_test (sympath
, G_FILE_TEST_IS_SYMLINK
);
211 return FAILED ("5 %s should be a symlink", sympath
);
219 static Test file_tests
[] = {
220 {"g_file_get_contents", test_file_get_contents
},
221 {"g_file_open_tmp", test_open_tmp
},
222 {"g_file_test", test_file
},
226 DEFINE_TEST_GROUP_INIT(file_tests_init
, file_tests
)