Bug Summary

File:_build/../testsuite/test-file-saver.c
Warning:line 198, column 17
Using a fixed address is not portable because that address will probably not be valid in all environments or platforms

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test-file-saver.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/_build -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-19/lib/clang/19 -I testsuite/test-file-saver.p -I testsuite -I ../testsuite -I . -I .. -I ctksourceview -I /usr/include/fribidi -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/libxml2 -D _FILE_OFFSET_BITS=64 -D G_DISABLE_DEPRECATED -D CDK_DISABLE_DEPRECATED -D CTK_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -D CDK_VERSION_MIN_REQUIRED=CDK_VERSION_3_24 -D CDK_VERSION_MAX_ALLOWED=CDK_VERSION_3_24 -D GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_48 -D GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_48 -D G_LOG_DOMAIN="CtkSourceView" -D TOP_SRCDIR="/rootdir" -U G_DISABLE_ASSERT -U G_DISABLE_CAST_CHECKS -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-cast-function-type -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -std=gnu99 -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-07-24-143421-13989-1 -x c ../testsuite/test-file-saver.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
2/*
3 * This file is part of CtkSourceView
4 *
5 * Copyright (C) 2010 - Jesse van den Kieboom
6 * Copyright (C) 2014 - Sébastien Wilmet
7 *
8 * CtkSourceView is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * CtkSourceView is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <gio/gio.h>
23#include <ctk/ctk.h>
24#include <string.h>
25#include <sys/stat.h>
26#include <glib/gprintf.h>
27#include <ctksourceview/ctksource.h>
28
29#define ENABLE_REMOTE_TESTS(0) FALSE(0)
30
31/* linux/bsd has it. others such as Solaris, do not */
32#ifndef ACCESSPERMS((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|
0100) >> 3) >> 3))
33#define ACCESSPERMS((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|
0100) >> 3) >> 3))
(S_IRWXU(0400|0200|0100)|S_IRWXG((0400|0200|0100) >> 3)|S_IRWXO(((0400|0200|0100) >> 3) >> 3))
34#endif
35
36#define DEFAULT_REMOTE_URI_DIR"sftp://localhost/tmp/" "sftp://localhost/tmp/"
37#define DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt" "ctksourceview-file-saver-test.txt"
38#define DEFAULT_TEST_UNOWNED_TEXT_FILE"ctksourceview-file-saver-unowned-group.txt" "ctksourceview-file-saver-unowned-group.txt"
39#define DEFAULT_UNOWNED_DIR"ctksourceview-file-saver-unowned" "ctksourceview-file-saver-unowned"
40
41#define DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt" DEFAULT_REMOTE_URI_DIR"sftp://localhost/tmp/" DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt"
42#define DEFAULT_CONTENT"hello world!" "hello world!"
43#define DEFAULT_CONTENT_RESULT"hello world!\n" "hello world!\n"
44
45#define UNOWNED_REMOTE_DIRECTORY"sftp://localhost/tmp/" "ctksourceview-file-saver-unowned" DEFAULT_REMOTE_URI_DIR"sftp://localhost/tmp/" DEFAULT_UNOWNED_DIR"ctksourceview-file-saver-unowned"
46
47typedef struct _SaverTestData SaverTestData;
48typedef void (*SavedCallback) (SaverTestData *data);
49
50struct _SaverTestData
51{
52 CtkSourceFileSaver *saver;
53 GFile *location;
54 const gchar *expected_file_contents;
55 SavedCallback saved_callback;
56 gpointer userdata;
57
58 guint file_existed : 1;
59};
60
61static const gchar *
62read_file (GFile *location)
63{
64 /* TODO use g_file_load_contents() */
65 GError *error = NULL((void*)0);
66 static gchar buffer[4096];
67 gsize read;
68
69 GInputStream *stream = G_INPUT_STREAM (g_file_read (location, NULL, &error))((((GInputStream*) (void *) ((g_file_read (location, ((void*)
0), &error))))))
;
70
71 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 71, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
72
73 g_input_stream_read_all (stream, buffer, sizeof (buffer) - 1, &read, NULL((void*)0), &error);
74 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 74, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
75
76 buffer[read] = '\0';
77
78 g_input_stream_close (stream, NULL((void*)0), NULL((void*)0));
79
80 g_object_unref (stream);
81
82 return buffer;
83}
84
85static void
86save_file_cb (CtkSourceFileSaver *saver,
87 GAsyncResult *result,
88 SaverTestData *data)
89{
90 GError *error = NULL((void*)0);
91
92 ctk_source_file_saver_save_finish (saver, result, &error);
93
94 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 94, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
95
96 g_assert_cmpstr (data->expected_file_contents, ==, read_file (data->location))do { const char *__s1 = (data->expected_file_contents), *__s2
= (read_file (data->location)); if (g_strcmp0 (__s1, __s2
) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-file-saver.c"
, 96, ((const char*) (__func__)), "data->expected_file_contents"
" " "==" " " "read_file (data->location)", __s1, "==", __s2
); } while (0)
;
97
98 if (data->saved_callback != NULL((void*)0))
99 {
100 data->saved_callback (data);
101 }
102
103 if (!data->file_existed)
104 {
105 g_file_delete (data->location, NULL((void*)0), NULL((void*)0));
106 }
107
108 /* finished */
109 ctk_main_quit ();
110}
111
112static void
113save_file (SaverTestData *data)
114{
115 data->file_existed = g_file_query_exists (data->location, NULL((void*)0));
116
117 ctk_source_file_saver_save_async (data->saver,
118 G_PRIORITY_DEFAULT0,
119 NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0),
120 (GAsyncReadyCallback) save_file_cb,
121 data);
122}
123
124static void
125mount_cb (GFile *location,
126 GAsyncResult *result,
127 SaverTestData *data)
128{
129 GError *error = NULL((void*)0);
130
131 g_file_mount_enclosing_volume_finish (location, result, &error);
132
133 if (error != NULL((void*)0) && error->code == G_IO_ERROR_ALREADY_MOUNTED)
134 {
135 g_error_free (error);
136 }
137 else
138 {
139 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 139, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
140 }
141
142 save_file (data);
143}
144
145static void
146check_mounted (SaverTestData *data)
147{
148 GMountOperation *mount_operation;
149
150 if (g_file_is_native (data->location))
151 {
152 save_file (data);
153 return;
154 }
155
156 mount_operation = ctk_mount_operation_new (NULL((void*)0));
157
158 g_file_mount_enclosing_volume (data->location,
159 G_MOUNT_MOUNT_NONE,
160 mount_operation,
161 NULL((void*)0),
162 (GAsyncReadyCallback) mount_cb,
163 data);
164
165 g_object_unref (mount_operation);
166}
167
168static void
169test_saver (const gchar *filename_or_uri,
170 const gchar *buffer_contents,
171 const gchar *expected_file_contents,
172 CtkSourceNewlineType newline_type,
173 SavedCallback saved_callback,
174 gpointer userdata)
175{
176 GFile *location;
177 CtkSourceBuffer *buffer;
178 CtkSourceFile *file;
179 CtkSourceFileSaver *saver;
180 SaverTestData *data;
181
182 location = g_file_new_for_commandline_arg (filename_or_uri);
183
184 buffer = ctk_source_buffer_new (NULL((void*)0));
185 ctk_text_buffer_set_text (CTK_TEXT_BUFFER (buffer)((((CtkTextBuffer*) (void *) ((buffer))))), buffer_contents, -1);
186
187 file = ctk_source_file_new ();
188 saver = ctk_source_file_saver_new_with_target (buffer, file, location);
189
190 ctk_source_file_saver_set_newline_type (saver, newline_type);
191 ctk_source_file_saver_set_encoding (saver, ctk_source_encoding_get_utf8 ());
192
193 data = g_slice_new (SaverTestData)((SaverTestData*) g_slice_alloc (sizeof (SaverTestData)));
194 data->saver = saver;
195 data->location = location;
196 data->expected_file_contents = expected_file_contents;
197 data->saved_callback = saved_callback;
198 data->userdata = userdata;
12
Using a fixed address is not portable because that address will probably not be valid in all environments or platforms
199
200 check_mounted (data);
201 ctk_main ();
202
203 g_object_unref (location);
204 g_object_unref (buffer);
205 g_object_unref (file);
206 g_object_unref (saver);
207 g_slice_free (SaverTestData, data)do { if (1) g_slice_free1 (sizeof (SaverTestData), (data)); else
(void) ((SaverTestData*) 0 == (data)); } while (0)
;
208}
209
210typedef struct
211{
212 CtkSourceNewlineType type;
213 const gchar *text;
214 const gchar *result;
215} NewLineTestData;
216
217static NewLineTestData newline_test_data[] = {
218 {CTK_SOURCE_NEWLINE_TYPE_LF, "\nhello\nworld", "\nhello\nworld\n"},
219 {CTK_SOURCE_NEWLINE_TYPE_LF, "\nhello\nworld\n", "\nhello\nworld\n\n"},
220 {CTK_SOURCE_NEWLINE_TYPE_LF, "\nhello\nworld\n\n", "\nhello\nworld\n\n\n"},
221 {CTK_SOURCE_NEWLINE_TYPE_LF, "\r\nhello\r\nworld", "\nhello\nworld\n"},
222 {CTK_SOURCE_NEWLINE_TYPE_LF, "\r\nhello\r\nworld\r\n", "\nhello\nworld\n\n"},
223 {CTK_SOURCE_NEWLINE_TYPE_LF, "\rhello\rworld", "\nhello\nworld\n"},
224 {CTK_SOURCE_NEWLINE_TYPE_LF, "\rhello\rworld\r", "\nhello\nworld\n\n"},
225 {CTK_SOURCE_NEWLINE_TYPE_LF, "\nhello\r\nworld", "\nhello\nworld\n"},
226 {CTK_SOURCE_NEWLINE_TYPE_LF, "\nhello\r\nworld\r", "\nhello\nworld\n\n"},
227
228 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\nhello\nworld", "\r\nhello\r\nworld\r\n"},
229 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\nhello\nworld\n", "\r\nhello\r\nworld\r\n\r\n"},
230 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\nhello\nworld\n\n", "\r\nhello\r\nworld\r\n\r\n\r\n"},
231 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\r\nhello\r\nworld", "\r\nhello\r\nworld\r\n"},
232 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\r\nhello\r\nworld\r\n", "\r\nhello\r\nworld\r\n\r\n"},
233 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\rhello\rworld", "\r\nhello\r\nworld\r\n"},
234 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\rhello\rworld\r", "\r\nhello\r\nworld\r\n\r\n"},
235 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\nhello\r\nworld", "\r\nhello\r\nworld\r\n"},
236 {CTK_SOURCE_NEWLINE_TYPE_CR_LF, "\nhello\r\nworld\r", "\r\nhello\r\nworld\r\n\r\n"},
237
238 {CTK_SOURCE_NEWLINE_TYPE_CR, "\nhello\nworld", "\rhello\rworld\r"},
239 {CTK_SOURCE_NEWLINE_TYPE_CR, "\nhello\nworld\n", "\rhello\rworld\r\r"},
240 {CTK_SOURCE_NEWLINE_TYPE_CR, "\nhello\nworld\n\n", "\rhello\rworld\r\r\r"},
241 {CTK_SOURCE_NEWLINE_TYPE_CR, "\r\nhello\r\nworld", "\rhello\rworld\r"},
242 {CTK_SOURCE_NEWLINE_TYPE_CR, "\r\nhello\r\nworld\r\n", "\rhello\rworld\r\r"},
243 {CTK_SOURCE_NEWLINE_TYPE_CR, "\rhello\rworld", "\rhello\rworld\r"},
244 {CTK_SOURCE_NEWLINE_TYPE_CR, "\rhello\rworld\r", "\rhello\rworld\r\r"},
245 {CTK_SOURCE_NEWLINE_TYPE_CR, "\nhello\r\nworld", "\rhello\rworld\r"},
246 {CTK_SOURCE_NEWLINE_TYPE_CR, "\nhello\r\nworld\r", "\rhello\rworld\r\r"}
247};
248
249static void
250test_new_line (const gchar *filename)
251{
252 gint i;
253 gint num = sizeof (newline_test_data) / sizeof (NewLineTestData);
254
255 for (i = 0; i < num; ++i)
256 {
257 NewLineTestData *nt = &(newline_test_data[i]);
258
259 test_saver (filename,
260 nt->text,
261 nt->result,
262 nt->type,
263 NULL((void*)0),
264 NULL((void*)0));
265 }
266}
267
268static void
269test_local_newline (void)
270{
271 gchar *default_local_uri;
272
273 default_local_uri = g_build_filename (g_get_tmp_dir (),
274 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
275 NULL((void*)0));
276 test_new_line (default_local_uri);
277 g_free (default_local_uri);
278}
279
280static void
281test_local (void)
282{
283 gchar *default_local_uri;
284
285 default_local_uri = g_build_filename (g_get_tmp_dir (),
286 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
287 NULL((void*)0));
288 test_saver (default_local_uri,
289 "hello world",
290 "hello world\n",
291 CTK_SOURCE_NEWLINE_TYPE_LF,
292 NULL((void*)0),
293 NULL((void*)0));
294
295 test_saver (default_local_uri,
296 "hello world\r\n",
297 "hello world\n\n",
298 CTK_SOURCE_NEWLINE_TYPE_LF,
299 NULL((void*)0),
300 NULL((void*)0));
301
302 test_saver (default_local_uri,
303 "hello world\n",
304 "hello world\n\n",
305 CTK_SOURCE_NEWLINE_TYPE_LF,
306 NULL((void*)0),
307 NULL((void*)0));
308 g_free (default_local_uri);
309}
310
311static void
312test_remote_newline (void)
313{
314 test_new_line (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt");
315}
316
317static void
318test_remote (void)
319{
320 test_saver (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt",
321 "hello world",
322 "hello world\n",
323 CTK_SOURCE_NEWLINE_TYPE_LF,
324 NULL((void*)0),
325 NULL((void*)0));
326
327 test_saver (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt",
328 "hello world\r\n",
329 "hello world\n\n",
330 CTK_SOURCE_NEWLINE_TYPE_LF,
331 NULL((void*)0),
332 NULL((void*)0));
333
334 test_saver (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt",
335 "hello world\n",
336 "hello world\n\n",
337 CTK_SOURCE_NEWLINE_TYPE_LF,
338 NULL((void*)0),
339 NULL((void*)0));
340}
341
342#ifndef G_OS_WIN32
343static void
344check_permissions (GFile *location,
345 guint permissions)
346{
347 GError *error = NULL((void*)0);
348 GFileInfo *info;
349
350 info = g_file_query_info (location,
351 G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode",
352 G_FILE_QUERY_INFO_NONE,
353 NULL((void*)0),
354 &error);
355
356 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 356, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
357
358 g_assert_cmpint (permissions,do { gint64 __n1 = (permissions), __n2 = (g_file_info_get_attribute_uint32
(info, "unix::mode") & ((0400|0200|0100)|((0400|0200|0100
) >> 3)|(((0400|0200|0100) >> 3) >> 3))); if
(__n1 == __n2) ; else g_assertion_message_cmpnum ("CtkSourceView"
, "../testsuite/test-file-saver.c", 360, ((const char*) (__func__
)), "permissions" " " "==" " " "g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS"
, (long double) __n1, "==", (long double) __n2, 'i'); } while
(0)
359 ==,do { gint64 __n1 = (permissions), __n2 = (g_file_info_get_attribute_uint32
(info, "unix::mode") & ((0400|0200|0100)|((0400|0200|0100
) >> 3)|(((0400|0200|0100) >> 3) >> 3))); if
(__n1 == __n2) ; else g_assertion_message_cmpnum ("CtkSourceView"
, "../testsuite/test-file-saver.c", 360, ((const char*) (__func__
)), "permissions" " " "==" " " "g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS"
, (long double) __n1, "==", (long double) __n2, 'i'); } while
(0)
360 g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS)do { gint64 __n1 = (permissions), __n2 = (g_file_info_get_attribute_uint32
(info, "unix::mode") & ((0400|0200|0100)|((0400|0200|0100
) >> 3)|(((0400|0200|0100) >> 3) >> 3))); if
(__n1 == __n2) ; else g_assertion_message_cmpnum ("CtkSourceView"
, "../testsuite/test-file-saver.c", 360, ((const char*) (__func__
)), "permissions" " " "==" " " "g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE) & ACCESSPERMS"
, (long double) __n1, "==", (long double) __n2, 'i'); } while
(0)
;
361
362 g_object_unref (info);
363}
364
365static void
366check_permissions_saved (SaverTestData *data)
367{
368 guint permissions = (guint)GPOINTER_TO_INT (data->userdata)((gint) (glong) (data->userdata));
369
370 check_permissions (data->location, permissions);
371}
372
373static void
374test_permissions (const gchar *uri,
375 guint permissions)
376{
377 GError *error = NULL((void*)0);
378 GFile *location = g_file_new_for_commandline_arg (uri);
379 GFileOutputStream *stream;
380 GFileInfo *info;
381 guint mode;
382
383 g_file_delete (location, NULL((void*)0), NULL((void*)0));
384 stream = g_file_create (location, 0, NULL((void*)0), &error);
385
386 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 386, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
2
Assuming 'error' is null
3
Taking false branch
4
Loop condition is false. Exiting loop
387
388 g_output_stream_close (G_OUTPUT_STREAM (stream)((((GOutputStream*) (void *) ((stream))))), NULL((void*)0), NULL((void*)0));
389 g_object_unref (stream);
390
391 info = g_file_query_info (location,
392 G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode",
393 G_FILE_QUERY_INFO_NONE,
394 NULL((void*)0),
395 &error);
396
397 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 397, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
5
Assuming 'error' is null
6
Taking false branch
7
Loop condition is false. Exiting loop
398
399 mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode");
400 g_object_unref (info);
401
402 g_file_set_attribute_uint32 (location,
403 G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode",
404 (mode & ~ACCESSPERMS((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|
0100) >> 3) >> 3))
) | permissions,
405 G_FILE_QUERY_INFO_NONE,
406 NULL((void*)0),
407 &error);
408 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 408, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
8
Assuming 'error' is null
9
Taking false branch
10
Loop condition is false. Exiting loop
409
410 check_permissions (location, permissions);
411
412 test_saver (uri,
11
Calling 'test_saver'
413 DEFAULT_CONTENT"hello world!",
414 DEFAULT_CONTENT_RESULT"hello world!\n",
415 CTK_SOURCE_NEWLINE_TYPE_LF,
416 check_permissions_saved,
417 GINT_TO_POINTER ((gint)permissions)((gpointer) (glong) ((gint)permissions)));
418
419 g_file_delete (location, NULL((void*)0), NULL((void*)0));
420 g_object_unref (location);
421}
422
423static void
424test_local_permissions (void)
425{
426 gchar *default_local_uri;
427
428 default_local_uri = g_build_filename (g_get_tmp_dir (),
429 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
430 NULL((void*)0));
431 test_permissions (default_local_uri, 0600);
432 test_permissions (default_local_uri, 0660);
433 test_permissions (default_local_uri, 0666);
434 test_permissions (default_local_uri, 0760);
435 g_free (default_local_uri);
436}
437#endif
438
439static void
440test_local_unowned_directory (void)
441{
442 gchar *unowned_local_uri;
443
444 unowned_local_uri = g_build_filename (g_get_tmp_dir (),
445 DEFAULT_UNOWNED_DIR"ctksourceview-file-saver-unowned",
446 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
447 NULL((void*)0));
448 test_saver (unowned_local_uri,
449 DEFAULT_CONTENT"hello world!",
450 DEFAULT_CONTENT_RESULT"hello world!\n",
451 CTK_SOURCE_NEWLINE_TYPE_LF,
452 NULL((void*)0),
453 NULL((void*)0));
454 g_free (unowned_local_uri);
455}
456
457static void
458test_remote_unowned_directory (void)
459{
460 gchar *unowned_remote_uri;
461
462 unowned_remote_uri = g_strconcat (UNOWNED_REMOTE_DIRECTORY"sftp://localhost/tmp/" "ctksourceview-file-saver-unowned",
463 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
464 NULL((void*)0));
465 test_saver (unowned_remote_uri,
466 DEFAULT_CONTENT"hello world!",
467 DEFAULT_CONTENT_RESULT"hello world!\n",
468 CTK_SOURCE_NEWLINE_TYPE_LF,
469 NULL((void*)0),
470 NULL((void*)0));
471 g_free (unowned_remote_uri);
472}
473
474#ifndef G_OS_WIN32
475static void
476test_remote_permissions (void)
477{
478 test_permissions (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt", 0600);
1
Calling 'test_permissions'
479 test_permissions (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt", 0660);
480 test_permissions (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt", 0666);
481 test_permissions (DEFAULT_REMOTE_URI"sftp://localhost/tmp/" "ctksourceview-file-saver-test.txt", 0760);
482}
483
484static void
485test_unowned_group_permissions (SaverTestData *data)
486{
487 GError *error = NULL((void*)0);
488 const gchar *group;
489 guint32 mode;
490
491 GFileInfo *info = g_file_query_info (data->location,
492 G_FILE_ATTRIBUTE_OWNER_GROUP"owner::group" ","
493 G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode",
494 G_FILE_QUERY_INFO_NONE,
495 NULL((void*)0),
496 &error);
497
498 g_assert_no_error (error)do { if (error) g_assertion_message_error ("CtkSourceView", "../testsuite/test-file-saver.c"
, 498, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
499
500 group = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP"owner::group");
501 g_assert_cmpstr (group, ==, "root")do { const char *__s1 = (group), *__s2 = ("root"); if (g_strcmp0
(__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView"
, "../testsuite/test-file-saver.c", 501, ((const char*) (__func__
)), "group" " " "==" " " "\"root\"", __s1, "==", __s2); } while
(0)
;
502
503 mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode");
504
505 g_assert_cmpint (mode & ACCESSPERMS, ==, 0660)do { gint64 __n1 = (mode & ((0400|0200|0100)|((0400|0200|
0100) >> 3)|(((0400|0200|0100) >> 3) >> 3))
), __n2 = (0660); if (__n1 == __n2) ; else g_assertion_message_cmpnum
("CtkSourceView", "../testsuite/test-file-saver.c", 505, ((const
char*) (__func__)), "mode & ACCESSPERMS" " " "==" " " "0660"
, (long double) __n1, "==", (long double) __n2, 'i'); } while
(0)
;
506
507 g_object_unref (info);
508}
509
510static void
511test_unowned_group (const gchar *uri)
512{
513 test_saver (uri,
514 DEFAULT_CONTENT"hello world!",
515 DEFAULT_CONTENT_RESULT"hello world!\n",
516 CTK_SOURCE_NEWLINE_TYPE_LF,
517 test_unowned_group_permissions,
518 NULL((void*)0));
519}
520
521static void
522test_local_unowned_group (void)
523{
524 gchar *unowned_group_local_uri;
525
526 unowned_group_local_uri = g_build_filename (g_get_tmp_dir (),
527 DEFAULT_TEST_UNOWNED_TEXT_FILE"ctksourceview-file-saver-unowned-group.txt",
528 NULL((void*)0));
529 test_unowned_group (unowned_group_local_uri);
530 g_free (unowned_group_local_uri);
531}
532
533#if 0
534static void
535test_remote_unowned_group (void)
536{
537 g_char *unowned_group_remote_uri;
538
539 unowned_group_remote_uri = g_strconcat (DEFAULT_REMOTE_URI_DIR"sftp://localhost/tmp/",
540 DEFAULT_TEST_UNOWNED_TEXT_FILE"ctksourceview-file-saver-unowned-group.txt",
541 NULL((void*)0));
542 test_unowned_group ();
543 g_free (unowned_group_remote_uri);
544}
545#endif
546
547#endif
548
549static gboolean
550check_unowned_directory (void)
551{
552 gchar *unowned_local_directory, *unowned_local_uri;
553 GFile *unowned, *unowned_file;
554 GFileInfo *info;
555 GError *error = NULL((void*)0);
556
557 unowned_local_directory = g_build_filename (g_get_tmp_dir (),
558 DEFAULT_UNOWNED_DIR"ctksourceview-file-saver-unowned",
559 NULL((void*)0));
560 unowned = g_file_new_for_path (unowned_local_directory);
561 g_free (unowned_local_directory);
562 g_printf ("*** Checking for unowned directory test... ");
563
564 info = g_file_query_info (unowned,
565 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write",
566 G_FILE_QUERY_INFO_NONE,
567 NULL((void*)0),
568 &error);
569
570 if (error)
571 {
572 g_object_unref (unowned);
573 g_printf ("NO: directory does not exist\n");
574
575 g_error_free (error);
576 return FALSE(0);
577 }
578
579 if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write"))
580 {
581 g_object_unref (unowned);
582
583 g_printf ("NO: directory is writable\n");
584 g_object_unref (info);
585 return FALSE(0);
586 }
587
588 g_object_unref (info);
589 g_object_unref (unowned);
590 unowned_local_uri = g_build_filename (g_get_tmp_dir (),
591 DEFAULT_UNOWNED_DIR"ctksourceview-file-saver-unowned",
592 DEFAULT_TEST_TEXT_FILE"ctksourceview-file-saver-test.txt",
593 NULL((void*)0));
594 unowned_file = g_file_new_for_commandline_arg (unowned_local_uri);
595
596 info = g_file_query_info (unowned_file,
597 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write",
598 G_FILE_QUERY_INFO_NONE,
599 NULL((void*)0),
600 &error);
601 g_free (unowned_local_uri);
602
603 if (error)
604 {
605 g_object_unref (unowned_file);
606 g_error_free (error);
607
608 g_printf ("NO: file does not exist\n");
609 return FALSE(0);
610 }
611
612 if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write"))
613 {
614 g_object_unref (unowned_file);
615
616 g_printf ("NO: file is not writable\n");
617 g_object_unref (info);
618 return FALSE(0);
619 }
620
621 g_object_unref (info);
622 g_object_unref (unowned_file);
623
624 g_printf ("YES\n");
625 return TRUE(!(0));
626}
627
628static gboolean
629check_unowned_group (void)
630{
631 gchar *unowned_group_local_uri;
632 GFile *unowned;
633 GFileInfo *info;
634 GError *error = NULL((void*)0);
635
636 unowned_group_local_uri = g_build_filename (g_get_tmp_dir (),
637 DEFAULT_TEST_UNOWNED_TEXT_FILE"ctksourceview-file-saver-unowned-group.txt",
638 NULL((void*)0));
639 unowned = g_file_new_for_path (unowned_group_local_uri);
640
641 g_printf ("*** Checking for unowned group test... ");
642
643 info = g_file_query_info (unowned,
644 G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write" ","
645 G_FILE_ATTRIBUTE_OWNER_GROUP"owner::group" ","
646 G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode",
647 G_FILE_QUERY_INFO_NONE,
648 NULL((void*)0),
649 &error);
650 g_free (unowned_group_local_uri);
651
652 if (error)
653 {
654 g_object_unref (unowned);
655 g_printf ("NO: file does not exist\n");
656
657 g_error_free (error);
658 return FALSE(0);
659 }
660
661 if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE"access::can-write"))
662 {
663 g_object_unref (unowned);
664
665 g_printf ("NO: file is not writable\n");
666 g_object_unref (info);
667 return FALSE(0);
668 }
669
670 if (g_strcmp0 (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP"owner::group"),
671 "root") != 0)
672 {
673 g_object_unref (unowned);
674
675 g_printf ("NO: group is not root (%s)\n", g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP"owner::group"));
676 g_object_unref (info);
677 return FALSE(0);
678 }
679
680#ifndef G_OS_WIN32
681 if ((g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE"unix::mode") & ACCESSPERMS((0400|0200|0100)|((0400|0200|0100) >> 3)|(((0400|0200|
0100) >> 3) >> 3))
) != 0660)
682 {
683 g_object_unref (unowned);
684
685 g_printf ("NO: file has wrong permissions\n");
686 g_object_unref (info);
687 return FALSE(0);
688 }
689#endif
690
691 g_object_unref (info);
692 g_object_unref (unowned);
693
694 g_printf ("YES\n");
695 return TRUE(!(0));
696}
697
698static void
699all_tests (void)
700{
701 gboolean have_unowned;
702#ifndef G_OS_WIN32
703 gboolean have_unowned_group;
704#endif
705
706 g_printf ("\n***\n");
707 have_unowned = check_unowned_directory ();
708#ifndef G_OS_WIN32
709 have_unowned_group = check_unowned_group ();
710#endif
711 g_printf ("***\n\n");
712
713 g_test_trap_subprocess ("/file-saver/subprocess/local",
714 0,
715 G_TEST_SUBPROCESS_INHERIT_STDERR);
716 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 716, ((const char*) (__func__)), 0, 0)
;
717
718 g_test_trap_subprocess ("/file-saver/subprocess/local-new-line",
719 0,
720 G_TEST_SUBPROCESS_INHERIT_STDERR);
721 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 721, ((const char*) (__func__)), 0, 0)
;
722
723 if (have_unowned)
724 {
725 g_test_trap_subprocess ("/file-saver/subprocess/local-unowned-directory",
726 0,
727 G_TEST_SUBPROCESS_INHERIT_STDERR);
728 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 728, ((const char*) (__func__)), 0, 0)
;
729 }
730
731 if (ENABLE_REMOTE_TESTS(0))
732 {
733 g_test_trap_subprocess ("/file-saver/subprocess/remote",
734 0,
735 G_TEST_SUBPROCESS_INHERIT_STDERR);
736 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 736, ((const char*) (__func__)), 0, 0)
;
737
738 g_test_trap_subprocess ("/file-saver/subprocess/remote-new-line",
739 0,
740 G_TEST_SUBPROCESS_INHERIT_STDERR);
741 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 741, ((const char*) (__func__)), 0, 0)
;
742
743 if (have_unowned)
744 {
745 g_test_trap_subprocess ("/file-saver/subprocess/remote-unowned-directory",
746 0,
747 G_TEST_SUBPROCESS_INHERIT_STDERR);
748 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 748, ((const char*) (__func__)), 0, 0)
;
749 }
750
751 /*
752 if (have_unowned_group)
753 {
754 g_test_trap_subprocess ("/file-saver/subprocess/remote-unowned-group",
755 0,
756 G_TEST_SUBPROCESS_INHERIT_STDERR);
757 g_test_trap_assert_passed ();
758 }
759 */
760 }
761
762#ifndef G_OS_WIN32
763 g_test_trap_subprocess ("/file-saver/subprocess/local-permissions",
764 0,
765 G_TEST_SUBPROCESS_INHERIT_STDERR);
766 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 766, ((const char*) (__func__)), 0, 0)
;
767
768 if (have_unowned_group)
769 {
770 g_test_trap_subprocess ("/file-saver/subprocess/local-unowned-group",
771 0,
772 G_TEST_SUBPROCESS_INHERIT_STDERR);
773 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 773, ((const char*) (__func__)), 0, 0)
;
774 }
775
776 if (ENABLE_REMOTE_TESTS(0))
777 {
778 g_test_trap_subprocess ("/file-saver/subprocess/remote-permissions",
779 0,
780 G_TEST_SUBPROCESS_INHERIT_STDERR);
781 g_test_trap_assert_passed ()g_test_trap_assertions ("CtkSourceView", "../testsuite/test-file-saver.c"
, 781, ((const char*) (__func__)), 0, 0)
;
782 }
783#endif
784}
785
786gint
787main (gint argc,
788 gchar *argv[])
789{
790 ctk_test_init (&argc, &argv);
791
792 g_test_add_func ("/file-saver", all_tests);
793
794 g_test_add_func ("/file-saver/subprocess/local", test_local);
795 g_test_add_func ("/file-saver/subprocess/local-new-line", test_local_newline);
796 g_test_add_func ("/file-saver/subprocess/local-unowned-directory", test_local_unowned_directory);
797
798 if (ENABLE_REMOTE_TESTS(0))
799 {
800 g_test_add_func ("/file-saver/subprocess/remote", test_remote);
801 g_test_add_func ("/file-saver/subprocess/remote-new-line", test_remote_newline);
802 g_test_add_func ("/file-saver/subprocess/remote-unowned-directory", test_remote_unowned_directory);
803
804 /* FIXME: there is a bug in gvfs sftp which doesn't pass this test */
805 /* g_test_add_func ("/file-saver/subprocess/remote-unowned-group", test_remote_unowned_group); */
806 }
807
808#ifndef G_OS_WIN32
809 g_test_add_func ("/file-saver/subprocess/local-permissions", test_local_permissions);
810 g_test_add_func ("/file-saver/subprocess/local-unowned-group", test_local_unowned_group);
811
812 if (ENABLE_REMOTE_TESTS(0))
813 {
814 g_test_add_func ("/file-saver/subprocess/remote-permissions", test_remote_permissions);
815 }
816#endif
817
818 return g_test_run ();
819}