Integrated gtester program into build process.

* Makefile.am: build and install gtester binary.

* gtester.c: fixed up coding style and removed hard wired test coded.

svn path=/trunk/; revision=5894
This commit is contained in:
Tim Janik 2007-11-20 15:00:40 +00:00
parent bf51c15b89
commit 39cf400cdf
2 changed files with 70 additions and 68 deletions

View File

@ -282,18 +282,26 @@ libglib_2_0_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-export-dynamic $(no_undefined) $(export_symbols) -export-dynamic $(no_undefined) $(export_symbols)
INSTALL_PROGS=
if OS_WIN32 if OS_WIN32
bin_PROGRAMS = gspawn-win32-helper gspawn-win32-helper-console INSTALL_PROGS += gspawn-win32-helper gspawn-win32-helper-console
gspawn_win32_helper_LDADD = libglib-2.0.la gspawn_win32_helper_LDADD = libglib-2.0.la
gspawn_win32_helper_LDFLAGS = -mwindows gspawn_win32_helper_LDFLAGS = -mwindows
gspawn_win32_helper_console_LDADD = libglib-2.0.la gspawn_win32_helper_console_LDADD = libglib-2.0.la
gspawn-win32-helper-console.c:
echo '#include "gspawn-win32-helper.c"' >$@
glib-win32-res.o: glib.rc glib-win32-res.o: glib.rc
$(WINDRES) glib.rc $@ $(WINDRES) glib.rc $@
endif endif
gspawn-win32-helper-console.c: bin_PROGRAMS = ${INSTALL_PROGS}
echo '#include "gspawn-win32-helper.c"' >$@
INSTALL_PROGS += gtester
gtester_SOURCES = gtester.c
gtester_LDADD = libglib-2.0.la
glib-2.0.lib: libglib-2.0.la glib.def glib-2.0.lib: libglib-2.0.la glib.def
lib -name:libglib-2.0-$(LT_CURRENT_MINUS_AGE).dll -def:glib.def -out:$@ lib -name:libglib-2.0-$(LT_CURRENT_MINUS_AGE).dll -def:glib.def -out:$@

View File

@ -1,64 +1,63 @@
/* This file is part of gtester /* GLib testing framework runner
* Copyright (C) 2007 Sven Herzberg
* Copyright (C) 2007 Tim Janik
* *
* AUTHORS * This library is free software; you can redistribute it and/or
* Sven Herzberg <herzi@gnome-de.org> * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* *
* Copyright (C) 2007 Sven Herzberg * This library is distributed in the hope that it will be useful,
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public
* along with this program; if not, write to the Free Software * License along with this library; if not, write to the
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* USA * Boston, MA 02111-1307, USA.
*/ */
#include <glib.h> #include <glib.h>
/* the read buffer size in bytes */ /* the read buffer size in bytes */
#define READ_BUFFER_SIZE 1024 #define READ_BUFFER_SIZE 1024
/* --- variables --- */
static GIOChannel* out = NULL; static GIOChannel* out = NULL;
/* --- functions --- */
static gboolean static gboolean
child_out_cb (GIOChannel * source, child_out_cb (GIOChannel *source,
GIOCondition condition, GIOCondition condition,
gpointer data) gpointer data)
{ {
GError* error = NULL; GError *error = NULL;
gsize length = 0; gsize length = 0;
gchar buffer[READ_BUFFER_SIZE]; gchar buffer[READ_BUFFER_SIZE];
GIOStatus status = G_IO_STATUS_NORMAL; GIOStatus status = G_IO_STATUS_NORMAL;
while (status == G_IO_STATUS_NORMAL) { while (status == G_IO_STATUS_NORMAL)
status = g_io_channel_read_chars (source, buffer, sizeof (buffer), &length, &error); {
status = g_io_channel_read_chars (source, buffer, sizeof (buffer), &length, &error);
switch (status) { switch (status)
case G_IO_STATUS_NORMAL: {
// FIXME: this is where the parsing happens case G_IO_STATUS_NORMAL:
g_print ("%d\n", length); // FIXME: this is where the parsing happens
break; g_print ("read output bytes: %d\n", length);
case G_IO_STATUS_AGAIN: break;
/* retry later */ case G_IO_STATUS_AGAIN:
break; /* retry later */
case G_IO_STATUS_ERROR: break;
/* fall through into EOF */ case G_IO_STATUS_ERROR:
g_warning ("Error while reading data: %s", /* fall through into EOF */
error->message); g_warning ("Error while reading data: %s",
g_error_free (error); error->message);
case G_IO_STATUS_EOF: g_error_free (error);
return FALSE; case G_IO_STATUS_EOF:
return FALSE;
}
} }
}
return TRUE; return TRUE;
} }
@ -67,7 +66,7 @@ child_watch_cb (GPid pid,
gint status, gint status,
gpointer data) gpointer data)
{ {
GMainLoop* loop = data; GMainLoop *loop = data;
g_spawn_close_pid (pid); g_spawn_close_pid (pid);
@ -77,31 +76,29 @@ child_watch_cb (GPid pid,
} }
int int
main (int argc, main (int argc,
char**argv) char **argv)
{ {
GMainLoop* loop; GMainLoop *loop;
GError * error = NULL; GError *error = NULL;
GPid pid = 0; GPid pid = 0;
gchar * working_folder; gchar *working_folder;
gchar * child_argv[] = { gchar *child_argv[] = {
"git-annotate", "/bin/ls",
"--incremental",
"ChangeLog",
NULL NULL
}; };
gint child_out; gint child_out;
working_folder = g_strdup ("/home/herzi/Hacking/Imendio/WebKit/WebCore"); //g_get_current_dir (); working_folder = g_strdup ("."); // g_get_current_dir ();
g_spawn_async_with_pipes (working_folder, g_spawn_async_with_pipes (working_folder,
child_argv, NULL /* envp */, child_argv, NULL /* envp */,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, NULL,
&pid, &pid,
NULL, NULL,
&child_out, &child_out,
NULL, NULL,
&error); &error);
g_free (working_folder); g_free (working_folder);
if (error) if (error)
@ -112,14 +109,11 @@ main (int argc,
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
g_child_watch_add (pid, g_child_watch_add (pid, child_watch_cb, loop);
child_watch_cb,
loop);
out = g_io_channel_unix_new (child_out); out = g_io_channel_unix_new (child_out);
g_io_channel_set_flags (out, G_IO_FLAG_NONBLOCK, NULL); // FIXME: GError g_io_channel_set_flags (out, G_IO_FLAG_NONBLOCK, NULL); // FIXME: GError
g_io_add_watch (out, G_IO_IN, g_io_add_watch (out, G_IO_IN, child_out_cb, loop);
child_out_cb, loop);
g_main_loop_run (loop); g_main_loop_run (loop);
g_main_loop_unref (loop); g_main_loop_unref (loop);