first unit test programs

This commit is contained in:
Asbjørn Pettersen 1999-09-20 16:33:43 +00:00
parent f6b782fdea
commit dae8fd9d6d
8 changed files with 659 additions and 0 deletions

View File

@ -1,3 +1,14 @@
Mon Sep 20 18:23:18 1999 ape@gandalf.spacetec.no (Asbjorn Pettersen)
* configure.in: Add app/unittest/Makefile
* app/unittest/unittest.h: Common include file for unit tests.
* app/unittest/globals.c: Global data for unit test programs.
* app/unittest/README:
* app/unittest/gimpparse.c: Parse test program
* app/unittest/gimppath.c: Show GIMP paths.
First unit test programs for GIMP. Useful for porting and testing.
Mon Sep 20 10:11:18 MEST 1999 Sven Neumann <sven@gimp.org>
* README.i18n: Daniel Egger sent me some corrections for this one

130
app/unittest/Makefile.am Normal file
View File

@ -0,0 +1,130 @@
## Process this file with automake to produce Makefile.in
scriptdata =
INTLLIBS=-lintl
bin_PROGRAMS = gimppath gimpparse
#bin_PROGRAMS = testplugin gimppath gimpparse plugshow plugdir
OFILES=../about_dialog.o ../disp_callbacks.o ../gimpunit.o \
../pattern_select.o \
../actionarea.o ../docindex.o ../global_edit.o \
../pattern_select_cmds.o \
../airbrush.o ../docindexif.o ../gradient.o ../patterns.o\
../draw_core.o ../gradient_cmds.o ../patterns_cmds.o \
../asupsample.o ../drawable.o ../gradient_select.o ../pencil.o\
../batch.o ../drawable_cmds.o ../gradient_select_cmds.o ../perspective_tool.o\
../bezier_select.o ../edit_cmds.o ../guides_cmds.o ../pixel_processor.o\
../blend.o ../edit_selection.o ../gximage.o ../pixel_region.o\
../blob.o ../ellipse_select.o ../histogram_tool.o \
../boundary.o ../equalize.o ../histogramwidget.o ../plug_in_cmds.o\
../brightness_contrast.o ../eraser.o ../hue_saturation.o ../posterize.o\
../brush_edit.o ../errorconsole.o ../image_map.o ../preferences_dialog.o\
../brush_select.o ../errors.o ../image_render.o ../procedural_db.o\
../brush_select_cmds.o ../file_new_dialog.o ../info_dialog.o ../procedural_db_cmds.o\
../brushes_cmds.o ../fileops.o ../info_window.o ../rect_select.o\
../bucket_fill.o ../fileops_cmds.o ../ink.o ../regex.o\
../buildmenu.o ../flip_tool.o ../install.o ../resize.o\
../by_color_select.o ../floating_sel.o ../interface.o ../rotate_tool.o\
../channel.o ../floating_sel_cmds.o ../interface_cmds.o ../scale.o\
../channel_cmds.o ../frac.o ../internal_procs.o ../scale_tool.o\
../channel_ops.o ../free_select.o ../invert.o ../scroll.o\
../channel_ops_cmds.o ../fuzzy_select.o ../iscissors.o ../selection.o\
../channels_dialog.o ../gdisplay.o ../layer.o ../session.o\
../clone.o ../gdisplay_cmds.o ../layer_cmds.o ../shear_tool.o\
../color_area.o ../gdisplay_ops.o ../layer_select.o ../temp_buf.o\
../color_balance.o ../general.o ../layers_dialog.o ../text_tool.o\
../color_cmds.o ../gimage.o ../levels.o ../text_tool_cmds.o\
../color_notebook.o ../gimage_cmds.o ../lut_funcs.o ../threshold.o\
../color_panel.o ../gimage_mask.o ../magnify.o ../tile.o\
../color_picker.o ../gimage_mask_cmds.o ../app_procs.o ../tile_cache.o\
../color_select.o ../gimpbrush.o ../menus.o ../tile_manager.o\
../color_transfer.o ../gimpbrushgenerated.o ../misc_cmds.o ../tile_swap.o\
../colormap_dialog.o ../gimpbrushlist.o ../module_db.o ../tips_dialog.o\
../colormaps.o ../gimpdrawable.o ../move.o ../tool_options.o\
../commands.o ../gimphistogram.o ../ops_buttons.o ../tools.o\
../convert.o ../gimpimage.o ../paint_core.o ../tools_cmds.o\
../convert_cmds.o ../gimplist.o ../paint_funcs.o ../transform_core.o\
../convolve.o ../gimplut.o ../paintbrush.o ../transform_tool.o\
../crop.o ../gimpobject.o ../palette.o ../undo.o\
../cursorutil.o ../gimpparasite.o ../palette_cmds.o ../undo_cmds.o\
../curves.o ../gimpprogress.o ../palette_select.o ../unit_cmds.o\
../datafiles.o ../parasite_cmds.o ../vector2d.o\
../desaturate.o ../gimprc_cmds.o ../parasitelist.o ../xcf.o\
../devices.o ../gimpset.o ../paths_cmds.o\
../dialog_handler.o ../gimpsignal.o ../paths_dialog.o \
../path_tool.o ../gimpbrushpipe.o ../gtkwrapbox.o ../gtkhwrapbox.o ../gtkvwrapbox.o \
../gimpdnd.o ../brush_scale.o ../measure.o ../xinput_airbrush.o \
../airbrush_blob.o ../gdisplay_color_ui.o \
../image_new.o ../nav_window.o ../smudge.o ../dodgeburn.o \
../indicator_area.o ../gdisplay_color.o ../gimpcontextpreview.o \
../qmask.o ../context_manager.o ../lc_dialog.o ../gimpcontext.o
testplugin_SOURCES = \
testplugin.c \
init.c
plugshow_SOURCES = \
plugshow.c
plugdir_SOURCES = \
plugdir.c
gimppath_SOURCES = \
gimppath.c
AM_CPPFLAGS = \
-DLIBDIR=\""$(gimpplugindir)"\" \
-DLOCALEDIR=\""$(localedir)"\" \
-DREGEX_MALLOC \
@GIMP_THREAD_FLAGS@
INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/intl \
$(GTK_CFLAGS) \
-I$(includedir)\
-I..
LDADD = $(OFILES) \
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a \
$(GTK_LIBS) \
$(GIMP_THREAD_LIBS) \
$(INTLLIBS)
plugshow_LDADD = $(OFILES) \
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a \
$(GTK_LIBS) \
$(GIMP_THREAD_LIBS) \
$(INTLLIBS)
plugdir_LDADD = $(OFILES) \
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a \
$(GTK_LIBS) \
$(GIMP_THREAD_LIBS) \
$(INTLLIBS)
gimppath_LDADD = $(OFILES) ../gimprc.o ../plug_in.o \
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a \
$(GTK_LIBS) \
$(GIMP_THREAD_LIBS) \
$(INTLLIBS)
gimpparse_LDADD = $(OFILES) ../plug_in.o\
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a \
$(GTK_LIBS) \
$(GIMP_THREAD_LIBS) \
$(INTLLIBS)
DEPS = \
../libgimpim.a \
$(top_builddir)/libgimp/libgimpi.a
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done

18
app/unittest/README Normal file
View File

@ -0,0 +1,18 @@
Unit test programs for GIMP.
./gimppath - Display GIMP's paths and rc files.
./gimpparse <rc file> - Parse rc files.
Have fun.
Asbjorn Pettersen.

394
app/unittest/gimpparse.c Normal file
View File

@ -0,0 +1,394 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "unittest.h"
#include "globals.c"
#if 1
#include "../gimprc.c"
#endif
char * get_personal(const char *filename)
{
char *full_filename = gimp_personal_rc_file(filename);
g_print ("%-50s = gimp_personal_rc_file(\"%s\");\n",
full_filename, filename);
return (full_filename);
}
void dump_ParseInfo(ParseInfo *p)
{
printf("*** ParseInfo ***\n");
printf("fp=%p ",p->fp);
printf("linenum=%d ",p->linenum);
printf("charnum=%d ",p->charnum);
printf("position=%d\n",p->position);
printf("buffer_size=%d ",p->buffer_size);
printf("tokenbuf_size=%d\n",p->tokenbuf_size);
printf("buffer=>%s<\n",p->buffer);
printf("tokenbuf=>%s<\n",p->tokenbuf);
}
int
get_token2 (ParseInfo *info)
{
char *buffer;
char *tokenbuf;
int tokenpos = 0;
int state;
int count;
int slashed;
dump_ParseInfo(info);
printf("get_token2 %p\n",info);
state = 0;
buffer = info->buffer;
tokenbuf = info->tokenbuf;
slashed = FALSE;
while (1)
{
printf("get_token2 %p\n",info);
if (info->inc_charnum && info->charnum)
info->charnum += 1;
if (info->inc_linenum && info->linenum)
{
info->linenum += 1;
info->charnum = 1;
}
info->inc_linenum = FALSE;
info->inc_charnum = FALSE;
if (info->position >= (info->buffer_size - 1))
info->position = -1;
if ((info->position == -1) || (buffer[info->position] == '\0'))
{
count = fread (buffer, sizeof (char), info->buffer_size - 1, info->fp);
if ((count == 0) && feof (info->fp))
return TOKEN_EOF;
buffer[count] = '\0';
info->position = 0;
}
info->inc_charnum = TRUE;
if ((buffer[info->position] == '\n') ||
(buffer[info->position] == '\r'))
info->inc_linenum = TRUE;
switch (state)
{
case 0:
if (buffer[info->position] == '#')
{
info->position += 1;
state = 4;
}
else if (buffer[info->position] == '(')
{
info->position += 1;
return TOKEN_LEFT_PAREN;
}
else if (buffer[info->position] == ')')
{
info->position += 1;
return TOKEN_RIGHT_PAREN;
}
else if (buffer[info->position] == '"')
{
info->position += 1;
state = 1;
slashed = FALSE;
}
else if ((buffer[info->position] == '-') || isdigit (buffer[info->position]))
{
tokenbuf[tokenpos++] = buffer[info->position];
info->position += 1;
state = 3;
}
else if ((buffer[info->position] != ' ') &&
(buffer[info->position] != '\t') &&
(buffer[info->position] != '\n') &&
(buffer[info->position] != '\r'))
{
tokenbuf[tokenpos++] = buffer[info->position];
info->position += 1;
state = 2;
}
else if (buffer[info->position] == '\'')
{
info->position += 1;
state = 2;
}
else
{
info->position += 1;
}
break;
case 1:
if ((buffer[info->position] == '\\') && (!slashed))
{
slashed = TRUE;
info->position += 1;
}
else if (slashed || (buffer[info->position] != '"'))
{
if (slashed && buffer[info->position] == 'n')
tokenbuf[tokenpos++] = '\n';
else if (slashed && buffer[info->position] == 'r')
tokenbuf[tokenpos++] = '\r';
else if (slashed && buffer[info->position] == 'z') /* ^Z */
tokenbuf[tokenpos++] = '\032';
else if (slashed && buffer[info->position] == '0') /* \0 */
tokenbuf[tokenpos++] = '\0';
else if (slashed && buffer[info->position] == '"')
tokenbuf[tokenpos++] = '"';
else
tokenbuf[tokenpos++] = buffer[info->position];
slashed = FALSE;
info->position += 1;
}
else
{
tokenbuf[tokenpos] = '\0';
token_str = tokenbuf;
token_sym = tokenbuf;
token_int = tokenpos;
info->position += 1;
return TOKEN_STRING;
}
break;
case 2:
if ((buffer[info->position] != ' ') &&
(buffer[info->position] != '\t') &&
(buffer[info->position] != '\n') &&
(buffer[info->position] != '\r') &&
(buffer[info->position] != '"') &&
(buffer[info->position] != '(') &&
(buffer[info->position] != ')'))
{
tokenbuf[tokenpos++] = buffer[info->position];
info->position += 1;
}
else
{
tokenbuf[tokenpos] = '\0';
token_sym = tokenbuf;
return TOKEN_SYMBOL;
}
break;
case 3:
if (isdigit (buffer[info->position]) ||
(buffer[info->position] == '.'))
{
tokenbuf[tokenpos++] = buffer[info->position];
info->position += 1;
}
else if ((buffer[info->position] != ' ') &&
(buffer[info->position] != '\t') &&
(buffer[info->position] != '\n') &&
(buffer[info->position] != '\r') &&
(buffer[info->position] != '"') &&
(buffer[info->position] != '(') &&
(buffer[info->position] != ')'))
{
tokenbuf[tokenpos++] = buffer[info->position];
info->position += 1;
state = 2;
}
else
{
tokenbuf[tokenpos] = '\0';
token_sym = tokenbuf;
token_num = atof (tokenbuf);
token_int = atoi (tokenbuf);
return TOKEN_NUMBER;
}
break;
case 4:
if (buffer[info->position] == '\n')
state = 0;
info->position += 1;
break;
}
}
}
static int
peek_next_token2 ()
{
printf("peek_next_token next_token=%d\n",next_token);
if (next_token == -1)
next_token = get_token2 (&parse_info);
return next_token;
}
static int
parse_statement2 ()
{
int token;
int i;
printf(" parse_statement2\n");
token = peek_next_token2 ();
if (!token)
return DONE;
printf("token=%d\n",token);
if (token != TOKEN_LEFT_PAREN)
return ERROR;
token = get_next_token ();
printf("token=%d\n",token);
token = peek_next_token ();
if (!token || (token != TOKEN_SYMBOL))
return ERROR;
token = get_next_token ();
printf("token=%d\n",token);
for (i = 0; i < nfuncs; i++)
if (strcmp (funcs[i].name, token_sym) == 0)
switch (funcs[i].type)
{
case TT_STRING:
return parse_string (funcs[i].val1p, funcs[i].val2p);
case TT_PATH:
return parse_path (funcs[i].val1p, funcs[i].val2p);
case TT_DOUBLE:
return parse_double (funcs[i].val1p, funcs[i].val2p);
case TT_FLOAT:
return parse_float (funcs[i].val1p, funcs[i].val2p);
case TT_INT:
return parse_int (funcs[i].val1p, funcs[i].val2p);
case TT_BOOLEAN:
return parse_boolean (funcs[i].val1p, funcs[i].val2p);
case TT_POSITION:
return parse_position (funcs[i].val1p, funcs[i].val2p);
case TT_MEMSIZE:
return parse_mem_size (funcs[i].val1p, funcs[i].val2p);
case TT_IMAGETYPE:
return parse_image_type (funcs[i].val1p, funcs[i].val2p);
case TT_XCOLORCUBE:
return parse_color_cube (funcs[i].val1p, funcs[i].val2p);
case TT_XPREVSIZE:
return parse_preview_size (funcs[i].val1p, funcs[i].val2p);
case TT_XUNIT:
return parse_units (funcs[i].val1p, funcs[i].val2p);
case TT_XPLUGIN:
return parse_plug_in (funcs[i].val1p, funcs[i].val2p);
case TT_XPLUGINDEF:
return parse_plug_in_def (funcs[i].val1p, funcs[i].val2p);
case TT_XMENUPATH:
return parse_menu_path (funcs[i].val1p, funcs[i].val2p);
case TT_XDEVICE:
return parse_device (funcs[i].val1p, funcs[i].val2p);
case TT_XSESSIONINFO:
return parse_session_info (funcs[i].val1p, funcs[i].val2p);
case TT_XUNITINFO:
return parse_unit_info (funcs[i].val1p, funcs[i].val2p);
case TT_XPARASITE:
return parse_parasite (funcs[i].val1p, funcs[i].val2p);
}
return parse_unknown (token_sym);
}
void
parse_gimprc_file2 (char *filename)
{
int status;
char rfilename[MAXPATHLEN];
#if 1
char *gimp_dir;
gimp_dir = gimp_directory ();
printf(" SET GLOBAL variables !!!\n");
add_gimp_directory_token (gimp_dir);
parse_buffers_init();
/* next_token = -1;*/
#endif
printf("parse_gimprc_file2 %s\n",filename);
if (!g_path_is_absolute (filename))
{
g_snprintf (rfilename, MAXPATHLEN, "%s" G_DIR_SEPARATOR_S "%s",
g_get_home_dir (), filename);
filename = rfilename;
}
printf("parse_gimprc_file2 %s\n",filename);
parse_info.fp = fopen (filename, "rt");
printf("fp=%p\n",parse_info.fp);
if (!parse_info.fp)
{
g_print (_("error opening: \"%s\"\n"), filename);
return;
}
if ((be_verbose == TRUE) || (no_splash == TRUE))
g_print (_("parsing \"%s\"\n"), filename);
cur_token = -1;
next_token = -1;
printf("set parse_info\n");
parse_info.position = -1;
parse_info.linenum = 1;
parse_info.charnum = 1;
parse_info.inc_linenum = FALSE;
parse_info.inc_charnum = FALSE;
printf("set parse_info done\n");
dump_ParseInfo(&parse_info);
done = FALSE;
while ((status = parse_statement ()) == OK)
printf("status= %d\n",status);
dump_ParseInfo(&parse_info);
fclose (parse_info.fp);
if (status == ERROR)
{
g_print (_("error parsing: \"%s\"\n"), filename);
g_print (_(" at line %d column %d\n"), parse_info.linenum, parse_info.charnum);
g_print (_(" unexpected token: %s\n"), token_sym);
}
}
void parse_gimp_files(char *rcfile)
{
char *filename = get_personal(rcfile);
printf ("call parse_gimprc_file filename=%s\n",filename);
parse_gimprc_file2 (filename);
}
int
main (int argc, char **argv)
{
if (argc < 2)
{
printf ("%s <rc file>\n",argv[0]);
printf ("ex: %s gimprc\n",argv[0]);
printf ("ex: %s unitrc\n",argv[0]);
printf ("ex: %s menurc\n",argv[0]);
printf ("ex: %s pluginrc\n",argv[0]);
printf ("ex: %s sessionrc\n",argv[0]);
printf ("ex: %s devicerc\n",argv[0]);
printf ("ex: %s ideas\n",argv[0]);
exit (0);
}
parse_gimp_files(argv[1]);
}

59
app/unittest/gimppath.c Normal file
View File

@ -0,0 +1,59 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "unittest.h"
#include "globals.c"
void show_personal(const char *filename)
{
char *full_filename = gimp_personal_rc_file(filename);
g_print ("%-50s = gimp_personal_rc_file(\"%s\");\n",
full_filename, filename);
}
void show_personal_files(void)
{
show_personal("devicerc");
show_personal("ideas");
show_personal("parasiterc");
show_personal("gimprc");
show_personal("unitrc");
show_personal("menurc");
show_personal("pluginrc");
show_personal("sessionrc");
}
void show_gimp_dirs(void)
{
g_print ( "%s %s\n", _("GIMP version"), GIMP_VERSION);
g_print ("%-50s = g_get_home_dir();\n",g_get_home_dir ());
g_print ("%-50s = g_getenv(\"GIMP_DIRECTORY\");\n",g_getenv ("GIMP_DIRECTORY"));
g_print ("%-50s = g_getenv(\"GIMP_DATADIR\");\n",g_getenv ("GIMP_DATADIR"));
g_print ("%-50s = gimp_directory();\n",gimp_directory());
g_print ("%-50s = gimp_data_directory();\n",gimp_data_directory());
g_print ("%-50s = gimp_gtkrc();\n",gimp_gtkrc());
}
int
main (int argc, char **argv)
{
show_gimp_dirs();
show_personal_files();
}

19
app/unittest/globals.c Normal file
View File

@ -0,0 +1,19 @@
/* GLOBAL data */
int no_interface;
int no_data;
int no_splash;
int no_splash_image;
int be_verbose;
int use_shm;
int use_debug_handler;
int console_messages;
int restore_session;
GimpSet* image_context;
MessageHandlerType message_handler;
char *prog_name; /* The path name we are invoked with */
char *alternate_gimprc;
char *alternate_system_gimprc;
char **batch_cmds;

27
app/unittest/unittest.h Normal file
View File

@ -0,0 +1,27 @@
#include "config.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "libgimp/gserialize.h"
#ifndef WAIT_ANY
#define WAIT_ANY -1
#endif /* WAIT_ANY */
#include "libgimp/gimpfeatures.h"
#include "appenv.h"
#include "app_procs.h"
#include "errors.h"
#include "install.h"
#include "libgimp/gimpintl.h"

View File

@ -664,6 +664,7 @@ gimptool
libgimp/gimpfeatures.h
libgimp/Makefile
app/Makefile
app/unittest/Makefile
plug-ins/Makefile
plug-ins/perl/config.pl
plug-ins/libgck/Makefile