Move test/gio-test.c to glib/test/io-channel-basic.c

Helps issue #1434
This commit is contained in:
Emmanuel Fleury 2022-03-13 10:57:32 +01:00
parent 38e0781ba7
commit 4589ff080d
3 changed files with 25 additions and 20 deletions

View File

@ -19,6 +19,11 @@
* Just run it. Optional parameter is number of sub-processes. * Just run it. Optional parameter is number of sub-processes.
*/ */
/* We are using g_io_channel_read() which is deprecated */
#ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#endif
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
@ -74,7 +79,7 @@ read_all (int fd,
if (error != G_IO_ERROR_NONE) if (error != G_IO_ERROR_NONE)
{ {
g_print ("gio-test: ...from %d: %d\n", fd, error); g_print ("io-channel-basic: ...from %d: %d\n", fd, error);
if (error == G_IO_ERROR_AGAIN) if (error == G_IO_ERROR_AGAIN)
continue; continue;
break; break;
@ -107,7 +112,7 @@ recv_message (GIOChannel *channel,
gint fd = g_io_channel_unix_get_fd (channel); gint fd = g_io_channel_unix_get_fd (channel);
gboolean retval = TRUE; gboolean retval = TRUE;
g_debug ("gio-test: ...from %d:%s%s%s%s", fd, g_debug ("io-channel-basic: ...from %d:%s%s%s%s", fd,
(cond & G_IO_ERR) ? " ERR" : "", (cond & G_IO_ERR) ? " ERR" : "",
(cond & G_IO_HUP) ? " HUP" : "", (cond & G_IO_HUP) ? " HUP" : "",
(cond & G_IO_IN) ? " IN" : "", (cond & G_IO_IN) ? " IN" : "",
@ -133,7 +138,7 @@ recv_message (GIOChannel *channel,
{ {
if (nb == 0) if (nb == 0)
{ {
g_debug ("gio-test: ...from %d: EOF", fd); g_debug ("io-channel-basic: ...from %d: EOF", fd);
shutdown_source (data); shutdown_source (data);
return FALSE; return FALSE;
} }
@ -156,14 +161,14 @@ recv_message (GIOChannel *channel,
if (nb == 0) if (nb == 0)
{ {
g_debug ("gio-test: ...from %d: EOF", fd); g_debug ("io-channel-basic: ...from %d: EOF", fd);
shutdown_source (data); shutdown_source (data);
return FALSE; return FALSE;
} }
g_assert_cmpuint (nb, ==, sizeof (nbytes)); g_assert_cmpuint (nb, ==, sizeof (nbytes));
g_assert_cmpuint (nbytes, <, BUFSIZE); g_assert_cmpuint (nbytes, <, BUFSIZE);
g_debug ("gio-test: ...from %d: %d bytes", fd, nbytes); g_debug ("io-channel-basic: ...from %d: %d bytes", fd, nbytes);
if (nbytes > 0) if (nbytes > 0)
{ {
error = read_all (fd, channel, buf, nbytes, &nb); error = read_all (fd, channel, buf, nbytes, &nb);
@ -173,14 +178,14 @@ recv_message (GIOChannel *channel,
if (nb == 0) if (nb == 0)
{ {
g_debug ("gio-test: ...from %d: EOF", fd); g_debug ("io-channel-basic: ...from %d: EOF", fd);
shutdown_source (data); shutdown_source (data);
return FALSE; return FALSE;
} }
for (j = 0; j < nbytes; j++) for (j = 0; j < nbytes; j++)
g_assert_cmpint (buf[j], ==, ' ' + (char) ((nbytes + j) % 95)); g_assert_cmpint (buf[j], ==, ' ' + (char) ((nbytes + j) % 95));
g_debug ("gio-test: ...from %d: OK", fd); g_debug ("io-channel-basic: ...from %d: OK", fd);
} }
} }
return retval; return retval;
@ -202,7 +207,7 @@ recv_windows_message (GIOChannel *channel,
if (error != G_IO_ERROR_NONE) if (error != G_IO_ERROR_NONE)
{ {
g_print ("gio-test: ...reading Windows message: G_IO_ERROR_%s\n", g_print ("io-channel-basic: ...reading Windows message: G_IO_ERROR_%s\n",
(error == G_IO_ERROR_AGAIN ? "AGAIN" : (error == G_IO_ERROR_AGAIN ? "AGAIN" :
(error == G_IO_ERROR_INVAL ? "INVAL" : (error == G_IO_ERROR_INVAL ? "INVAL" :
(error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???")))); (error == G_IO_ERROR_UNKNOWN ? "UNKNOWN" : "???"))));
@ -212,7 +217,7 @@ recv_windows_message (GIOChannel *channel,
break; break;
} }
g_print ("gio-test: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", g_print ("io-channel-basic: ...Windows message for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n",
msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam); msg.hwnd, msg.message, msg.wParam, (gintptr) msg.lParam);
return TRUE; return TRUE;
@ -229,7 +234,7 @@ window_procedure (HWND hwnd,
WPARAM wparam, WPARAM wparam,
LPARAM lparam) LPARAM lparam)
{ {
g_print ("gio-test: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n", g_print ("io-channel-basic: window_procedure for 0x%p: %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT "\n",
hwnd, message, wparam, (gintptr) lparam); hwnd, message, wparam, (gintptr) lparam);
return DefWindowProc (hwnd, message, wparam, lparam); return DefWindowProc (hwnd, message, wparam, lparam);
} }
@ -260,21 +265,21 @@ spawn_process (int children_nb)
wcl.hCursor = NULL; wcl.hCursor = NULL;
wcl.hbrBackground = NULL; wcl.hbrBackground = NULL;
wcl.lpszMenuName = NULL; wcl.lpszMenuName = NULL;
wcl.lpszClassName = "gio-test"; wcl.lpszClassName = "io-channel-basic";
klass = RegisterClass (&wcl); klass = RegisterClass (&wcl);
if (!klass) if (!klass)
{ {
g_print ("gio-test: RegisterClass failed\n"); g_print ("io-channel-basic: RegisterClass failed\n");
exit (1); exit (1);
} }
hwnd = CreateWindow (MAKEINTATOM(klass), "gio-test", 0, 0, 0, 10, 10, hwnd = CreateWindow (MAKEINTATOM(klass), "io-channel-basic", 0, 0, 0, 10, 10,
NULL, NULL, wcl.hInstance, NULL); NULL, NULL, wcl.hInstance, NULL);
if (!hwnd) if (!hwnd)
{ {
g_print ("gio-test: CreateWindow failed\n"); g_print ("io-channel-basic: CreateWindow failed\n");
exit (1); exit (1);
} }
@ -333,8 +338,8 @@ spawn_process (int children_nb)
pollresult = g_io_channel_win32_poll (&pollfd, 1, 100); pollresult = g_io_channel_win32_poll (&pollfd, 1, 100);
end = g_get_monotonic_time(); end = g_get_monotonic_time();
g_print ("gio-test: had to wait %" G_GINT64_FORMAT "s, result:%d\n", g_print ("io-channel-basic: had to wait %" G_GINT64_FORMAT "s, result:%d\n",
(end - start) / 1000000, pollresult); g_date_time_difference (end, start) / 1000000, pollresult);
#endif #endif
g_io_channel_unref (my_read_channel); g_io_channel_unref (my_read_channel);
} }
@ -372,7 +377,7 @@ run_process (int argc, char *argv[])
buflen = rand () % BUFSIZE; buflen = rand () % BUFSIZE;
for (j = 0; j < buflen; j++) for (j = 0; j < buflen; j++)
buf[j] = ' ' + ((buflen + j) % 95); buf[j] = ' ' + ((buflen + j) % 95);
g_debug ("gio-test: 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)); write (writefd, &i, sizeof (i));
write (writefd, &buflen, sizeof (buflen)); write (writefd, &buflen, sizeof (buflen));
@ -384,13 +389,13 @@ run_process (int argc, char *argv[])
int msg = WM_USER + (rand () % 100); int msg = WM_USER + (rand () % 100);
WPARAM wparam = rand (); WPARAM wparam = rand ();
LPARAM lparam = rand (); LPARAM lparam = rand ();
g_print ("gio-test: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n", g_print ("io-channel-basic: child posting message %d,%" G_GUINTPTR_FORMAT ",%" G_GINTPTR_FORMAT " to 0x%p\n",
msg, wparam, (gintptr) lparam, hwnd); msg, wparam, (gintptr) lparam, hwnd);
PostMessage (hwnd, msg, wparam, lparam); PostMessage (hwnd, msg, wparam, lparam);
} }
#endif #endif
} }
g_debug ("gio-test: child exiting, closing %d", writefd); g_debug ("io-channel-basic: child exiting, closing %d", writefd);
close (writefd); close (writefd);
} }

View File

@ -45,6 +45,7 @@ glib_tests = {
'hmac' : {}, 'hmac' : {},
'hook' : {}, 'hook' : {},
'hostutils' : {}, 'hostutils' : {},
'io-channel-basic' : {},
'io-channel' : {}, 'io-channel' : {},
'keyfile' : {}, 'keyfile' : {},
'list' : {}, 'list' : {},

View File

@ -16,7 +16,6 @@ subdir('gobject')
subdir('refcount') subdir('refcount')
tests = { tests = {
'gio-test' : {},
'slice-threadinit' : { 'slice-threadinit' : {
'dependencies' : [libgthread_dep], 'dependencies' : [libgthread_dep],
}, },