mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-28 00:16:15 +01:00
glib/tests: Ensure that calls to write, system, symlink and pipe are checked
Assert that calls to such system calls are returning the expected values
This commit is contained in:
parent
a5390002fc
commit
7a382438aa
@ -1469,7 +1469,7 @@ test_file_test (void)
|
||||
|
||||
fd = g_file_open_tmp (NULL, &name, &error);
|
||||
g_assert_no_error (error);
|
||||
write (fd, "a", 1);
|
||||
g_assert_cmpint (write (fd, "a", 1), ==, 1);
|
||||
g_assert_cmpint (g_fsync (fd), ==, 0);
|
||||
close (fd);
|
||||
|
||||
@ -1477,7 +1477,7 @@ test_file_test (void)
|
||||
result = g_file_test (name, G_FILE_TEST_IS_SYMLINK);
|
||||
g_assert_false (result);
|
||||
|
||||
symlink (name, "symlink");
|
||||
g_assert_no_errno (symlink (name, "symlink"));
|
||||
result = g_file_test ("symlink", G_FILE_TEST_IS_SYMLINK);
|
||||
g_assert_true (result);
|
||||
unlink ("symlink");
|
||||
@ -1500,7 +1500,7 @@ test_set_contents (void)
|
||||
|
||||
fd = g_file_open_tmp (NULL, &name, &error);
|
||||
g_assert_no_error (error);
|
||||
write (fd, "a", 1);
|
||||
g_assert_cmpint (write (fd, "a", 1), ==, 1);
|
||||
g_assert_cmpint (g_fsync (fd), ==, 0);
|
||||
close (fd);
|
||||
|
||||
@ -1593,7 +1593,7 @@ test_set_contents_full (void)
|
||||
|
||||
fd = g_file_open_tmp (NULL, &file_name, &error);
|
||||
g_assert_no_error (error);
|
||||
write (fd, "a", 1);
|
||||
g_assert_cmpint (write (fd, "a", 1), ==, 1);
|
||||
g_assert_no_errno (g_fsync (fd));
|
||||
close (fd);
|
||||
|
||||
@ -1726,7 +1726,7 @@ test_set_contents_full_read_only_file (void)
|
||||
* existing file permissions. */
|
||||
fd = g_file_open_tmp (NULL, &file_name, &error);
|
||||
g_assert_no_error (error);
|
||||
write (fd, "a", 1);
|
||||
g_assert_cmpint (write (fd, "a", 1), ==, 1);
|
||||
g_assert_no_errno (g_fsync (fd));
|
||||
close (fd);
|
||||
g_assert_no_errno (g_chmod (file_name, 0400)); /* S_IREAD */
|
||||
@ -1800,7 +1800,7 @@ test_set_contents_full_read_only_directory (void)
|
||||
file_name = g_build_filename (dir_name, "file", NULL);
|
||||
fd = g_open (file_name, O_CREAT | O_RDWR, 0644);
|
||||
g_assert_cmpint (fd, >=, 0);
|
||||
write (fd, "a", 1);
|
||||
g_assert_cmpint (write (fd, "a", 1), ==, 1);
|
||||
g_assert_no_errno (g_fsync (fd));
|
||||
close (fd);
|
||||
|
||||
|
@ -320,7 +320,7 @@ spawn_process (int children_nb)
|
||||
/* Spawn new Unix process */
|
||||
cmdline = g_strdup_printf ("%s --child %d:%d &",
|
||||
exec_name, pipe_to_sub[0], pipe_from_sub[1]);
|
||||
system (cmdline);
|
||||
g_assert_no_errno (system (cmdline));
|
||||
#endif
|
||||
g_free (cmdline);
|
||||
|
||||
@ -375,9 +375,9 @@ run_process (int argc, char *argv[])
|
||||
buf[j] = ' ' + ((buflen + j) % 95);
|
||||
g_debug ("io-channel-basic: child writing %d+%d bytes to %d",
|
||||
(int) (sizeof (i) + sizeof (buflen)), buflen, writefd);
|
||||
write (writefd, &i, sizeof (i));
|
||||
write (writefd, &buflen, sizeof (buflen));
|
||||
write (writefd, buf, buflen);
|
||||
g_assert_cmpint (write (writefd, &i, sizeof (i)), ==, sizeof (i));
|
||||
g_assert_cmpint (write (writefd, &buflen, sizeof (buflen)), ==, sizeof (buflen));
|
||||
g_assert_cmpint (write (writefd, buf, buflen), ==, buflen);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
if (i % 10 == 0)
|
||||
|
@ -1467,8 +1467,8 @@ test_source_unix_fd_api (void)
|
||||
gint fds_a[2];
|
||||
gint fds_b[2];
|
||||
|
||||
pipe (fds_a);
|
||||
pipe (fds_b);
|
||||
g_assert_cmpint (pipe (fds_a), ==, 0);
|
||||
g_assert_cmpint (pipe (fds_b), ==, 0);
|
||||
|
||||
source_a = g_source_new (&no_funcs, sizeof (FlagSource));
|
||||
source_b = g_source_new (&no_funcs, sizeof (FlagSource));
|
||||
|
@ -157,9 +157,9 @@ test_spawn_childs (void)
|
||||
main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
system ("cd .");
|
||||
g_assert_no_errno (system ("cd ."));
|
||||
#else
|
||||
system ("true");
|
||||
g_assert_no_errno (system ("true"));
|
||||
#endif
|
||||
|
||||
n_alive = 2;
|
||||
@ -200,9 +200,9 @@ test_spawn_childs_threads (void)
|
||||
main_loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
system ("cd .");
|
||||
g_assert_no_errno (system ("cd ."));
|
||||
#else
|
||||
system ("true");
|
||||
g_assert_no_errno (system ("true"));
|
||||
#endif
|
||||
|
||||
n_alive = 2;
|
||||
|
@ -40,7 +40,7 @@ test_pipe (void)
|
||||
g_assert (res);
|
||||
g_assert_no_error (error);
|
||||
|
||||
write (pipefd[1], "hello", sizeof ("hello"));
|
||||
g_assert_cmpint (write (pipefd[1], "hello", sizeof ("hello")), ==, sizeof ("hello"));
|
||||
memset (buf, 0, sizeof (buf));
|
||||
bytes_read = read (pipefd[0], buf, sizeof(buf) - 1);
|
||||
g_assert_cmpint (bytes_read, >, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user