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:
Marco Trevisan (Treviño) 2022-07-06 16:06:12 +02:00
parent a5390002fc
commit 7a382438aa
5 changed files with 17 additions and 17 deletions

View File

@ -1469,7 +1469,7 @@ test_file_test (void)
fd = g_file_open_tmp (NULL, &name, &error); fd = g_file_open_tmp (NULL, &name, &error);
g_assert_no_error (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); g_assert_cmpint (g_fsync (fd), ==, 0);
close (fd); close (fd);
@ -1477,7 +1477,7 @@ test_file_test (void)
result = g_file_test (name, G_FILE_TEST_IS_SYMLINK); result = g_file_test (name, G_FILE_TEST_IS_SYMLINK);
g_assert_false (result); g_assert_false (result);
symlink (name, "symlink"); g_assert_no_errno (symlink (name, "symlink"));
result = g_file_test ("symlink", G_FILE_TEST_IS_SYMLINK); result = g_file_test ("symlink", G_FILE_TEST_IS_SYMLINK);
g_assert_true (result); g_assert_true (result);
unlink ("symlink"); unlink ("symlink");
@ -1500,7 +1500,7 @@ test_set_contents (void)
fd = g_file_open_tmp (NULL, &name, &error); fd = g_file_open_tmp (NULL, &name, &error);
g_assert_no_error (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); g_assert_cmpint (g_fsync (fd), ==, 0);
close (fd); close (fd);
@ -1593,7 +1593,7 @@ test_set_contents_full (void)
fd = g_file_open_tmp (NULL, &file_name, &error); fd = g_file_open_tmp (NULL, &file_name, &error);
g_assert_no_error (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)); g_assert_no_errno (g_fsync (fd));
close (fd); close (fd);
@ -1726,7 +1726,7 @@ test_set_contents_full_read_only_file (void)
* existing file permissions. */ * existing file permissions. */
fd = g_file_open_tmp (NULL, &file_name, &error); fd = g_file_open_tmp (NULL, &file_name, &error);
g_assert_no_error (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)); g_assert_no_errno (g_fsync (fd));
close (fd); close (fd);
g_assert_no_errno (g_chmod (file_name, 0400)); /* S_IREAD */ 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); file_name = g_build_filename (dir_name, "file", NULL);
fd = g_open (file_name, O_CREAT | O_RDWR, 0644); fd = g_open (file_name, O_CREAT | O_RDWR, 0644);
g_assert_cmpint (fd, >=, 0); g_assert_cmpint (fd, >=, 0);
write (fd, "a", 1); g_assert_cmpint (write (fd, "a", 1), ==, 1);
g_assert_no_errno (g_fsync (fd)); g_assert_no_errno (g_fsync (fd));
close (fd); close (fd);

View File

@ -320,7 +320,7 @@ spawn_process (int children_nb)
/* Spawn new Unix process */ /* Spawn new Unix process */
cmdline = g_strdup_printf ("%s --child %d:%d &", cmdline = g_strdup_printf ("%s --child %d:%d &",
exec_name, pipe_to_sub[0], pipe_from_sub[1]); exec_name, pipe_to_sub[0], pipe_from_sub[1]);
system (cmdline); g_assert_no_errno (system (cmdline));
#endif #endif
g_free (cmdline); g_free (cmdline);
@ -375,9 +375,9 @@ run_process (int argc, char *argv[])
buf[j] = ' ' + ((buflen + j) % 95); buf[j] = ' ' + ((buflen + j) % 95);
g_debug ("io-channel-basic: child writing %d+%d bytes to %d", g_debug ("io-channel-basic: child writing %d+%d bytes to %d",
(int) (sizeof (i) + sizeof (buflen)), buflen, writefd); (int) (sizeof (i) + sizeof (buflen)), buflen, writefd);
write (writefd, &i, sizeof (i)); g_assert_cmpint (write (writefd, &i, sizeof (i)), ==, sizeof (i));
write (writefd, &buflen, sizeof (buflen)); g_assert_cmpint (write (writefd, &buflen, sizeof (buflen)), ==, sizeof (buflen));
write (writefd, buf, buflen); g_assert_cmpint (write (writefd, buf, buflen), ==, buflen);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (i % 10 == 0) if (i % 10 == 0)

View File

@ -1467,8 +1467,8 @@ test_source_unix_fd_api (void)
gint fds_a[2]; gint fds_a[2];
gint fds_b[2]; gint fds_b[2];
pipe (fds_a); g_assert_cmpint (pipe (fds_a), ==, 0);
pipe (fds_b); g_assert_cmpint (pipe (fds_b), ==, 0);
source_a = g_source_new (&no_funcs, sizeof (FlagSource)); source_a = g_source_new (&no_funcs, sizeof (FlagSource));
source_b = g_source_new (&no_funcs, sizeof (FlagSource)); source_b = g_source_new (&no_funcs, sizeof (FlagSource));

View File

@ -157,9 +157,9 @@ test_spawn_childs (void)
main_loop = g_main_loop_new (NULL, FALSE); main_loop = g_main_loop_new (NULL, FALSE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
system ("cd ."); g_assert_no_errno (system ("cd ."));
#else #else
system ("true"); g_assert_no_errno (system ("true"));
#endif #endif
n_alive = 2; n_alive = 2;
@ -200,9 +200,9 @@ test_spawn_childs_threads (void)
main_loop = g_main_loop_new (NULL, FALSE); main_loop = g_main_loop_new (NULL, FALSE);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
system ("cd ."); g_assert_no_errno (system ("cd ."));
#else #else
system ("true"); g_assert_no_errno (system ("true"));
#endif #endif
n_alive = 2; n_alive = 2;

View File

@ -40,7 +40,7 @@ test_pipe (void)
g_assert (res); g_assert (res);
g_assert_no_error (error); 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)); memset (buf, 0, sizeof (buf));
bytes_read = read (pipefd[0], buf, sizeof(buf) - 1); bytes_read = read (pipefd[0], buf, sizeof(buf) - 1);
g_assert_cmpint (bytes_read, >, 0); g_assert_cmpint (bytes_read, >, 0);