2001-12-10 00:31:30 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* Test suite for GimpConfig.
|
2002-03-24 01:58:57 +08:00
|
|
|
* Copyright (C) 2001-2002 Sven Neumann <sven@gimp.org>
|
2003-10-11 22:30:18 +08:00
|
|
|
*
|
2001-12-10 00:31:30 +08:00
|
|
|
* 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 "config.h"
|
|
|
|
|
2002-05-06 19:04:39 +08:00
|
|
|
#include "stdlib.h"
|
|
|
|
#include "string.h"
|
|
|
|
|
2001-12-10 00:31:30 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-12-17 00:33:18 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
#include "core/core-types.h"
|
|
|
|
#include "core/gimpgrid.h"
|
2001-12-17 00:33:18 +08:00
|
|
|
|
2005-01-25 06:05:02 +08:00
|
|
|
#include "gimprc-unknown.h"
|
2001-12-10 00:31:30 +08:00
|
|
|
|
|
|
|
|
2001-12-10 20:32:28 +08:00
|
|
|
static void notify_callback (GObject *object,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void output_unknown_token (const gchar *key,
|
|
|
|
const gchar *value,
|
|
|
|
gpointer data);
|
2001-12-10 00:31:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
2003-10-19 08:33:25 +08:00
|
|
|
GimpConfig *grid;
|
|
|
|
GimpConfig *grid2;
|
2001-12-13 09:55:37 +08:00
|
|
|
const gchar *filename = "foorc";
|
|
|
|
gchar *header;
|
2002-05-06 06:11:34 +08:00
|
|
|
gchar *result;
|
2004-03-02 03:50:18 +08:00
|
|
|
GList *list;
|
2001-12-13 09:55:37 +08:00
|
|
|
gint i;
|
2002-03-24 01:58:57 +08:00
|
|
|
GError *error = NULL;
|
2001-12-13 09:55:37 +08:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (strcmp (argv[i], "--g-fatal-warnings") == 0)
|
|
|
|
{
|
|
|
|
GLogLevelFlags fatal_mask;
|
2003-10-11 22:30:18 +08:00
|
|
|
|
2001-12-13 09:55:37 +08:00
|
|
|
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
|
|
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
|
|
g_log_set_always_fatal (fatal_mask);
|
|
|
|
}
|
|
|
|
}
|
2001-12-10 00:31:30 +08:00
|
|
|
|
|
|
|
g_type_init ();
|
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print ("\nTesting GimpConfig ...\n");
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Creating a new Grid object ...");
|
|
|
|
grid = g_object_new (GIMP_TYPE_GRID, NULL);
|
|
|
|
g_print (" done.\n");
|
2003-10-11 22:30:18 +08:00
|
|
|
|
|
|
|
g_print (" Adding the unknown token (foobar \"hadjaha\") ...");
|
2005-01-25 06:05:02 +08:00
|
|
|
gimp_rc_add_unknown_token (grid, "foobar", "hadjaha");
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" done.\n");
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_print (" Serializing %s to '%s' ...",
|
2003-10-19 08:33:25 +08:00
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (grid)), filename);
|
2002-03-24 01:58:57 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
if (! gimp_config_serialize_to_file (grid,
|
2006-04-12 20:49:29 +08:00
|
|
|
filename,
|
|
|
|
"foorc", "end of foorc",
|
|
|
|
NULL, &error))
|
2002-03-24 01:58:57 +08:00
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
2002-05-06 19:04:39 +08:00
|
|
|
return EXIT_FAILURE;
|
2002-03-24 01:58:57 +08:00
|
|
|
}
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" done.\n");
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_signal_connect (grid, "notify",
|
2001-12-13 09:55:37 +08:00
|
|
|
G_CALLBACK (notify_callback),
|
|
|
|
NULL);
|
2001-12-11 04:43:51 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Deserializing from '%s' ...\n", filename);
|
|
|
|
if (! gimp_config_deserialize_file (grid, filename, NULL, &error))
|
2002-03-24 01:58:57 +08:00
|
|
|
{
|
|
|
|
g_print ("%s\n", error->message);
|
2002-05-06 19:04:39 +08:00
|
|
|
return EXIT_FAILURE;
|
2002-03-24 01:58:57 +08:00
|
|
|
}
|
2003-10-19 08:33:25 +08:00
|
|
|
header = " Unknown string tokens:\n";
|
2005-01-25 06:05:02 +08:00
|
|
|
gimp_rc_foreach_unknown_token (grid, output_unknown_token, &header);
|
2004-03-02 03:50:18 +08:00
|
|
|
g_print (" done.\n\n");
|
2001-12-10 20:32:28 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Changing a property ...");
|
|
|
|
g_object_set (grid, "style", GIMP_GRID_DOTS, NULL);
|
2001-12-29 00:26:54 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Testing gimp_config_duplicate() ...");
|
|
|
|
grid2 = gimp_config_duplicate (grid);
|
2002-03-24 01:58:57 +08:00
|
|
|
g_print (" done.\n");
|
2002-02-08 22:05:10 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_signal_connect (grid2, "notify",
|
2002-03-24 01:58:57 +08:00
|
|
|
G_CALLBACK (notify_callback),
|
|
|
|
NULL);
|
2001-12-29 00:26:54 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Changing a property in the duplicate ...");
|
|
|
|
g_object_set (grid2, "xspacing", 20.0, NULL);
|
2002-05-06 06:11:34 +08:00
|
|
|
|
2004-03-02 03:50:18 +08:00
|
|
|
g_print (" Creating a diff between the two ...");
|
2005-05-20 07:43:08 +08:00
|
|
|
for (list = gimp_config_diff (G_OBJECT (grid), G_OBJECT (grid2), 0);
|
|
|
|
list;
|
|
|
|
list = list->next)
|
2004-03-02 03:50:18 +08:00
|
|
|
{
|
|
|
|
GParamSpec *pspec = list->data;
|
|
|
|
|
|
|
|
g_print ("%c%s", (list->prev ? ',' : ' '), pspec->name);
|
|
|
|
}
|
|
|
|
g_print ("\n\n");
|
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_object_unref (grid2);
|
2002-05-15 19:59:51 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Deserializing from gimpconfig.c (should fail) ...");
|
|
|
|
if (! gimp_config_deserialize_file (grid, "gimpconfig.c", NULL, &error))
|
2002-05-15 19:59:51 +08:00
|
|
|
{
|
|
|
|
g_print (" OK, failed. The error was:\n %s\n", error->message);
|
2002-05-29 02:49:45 +08:00
|
|
|
g_error_free (error);
|
2003-06-24 06:02:56 +08:00
|
|
|
error = NULL;
|
2002-05-15 19:59:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_print ("This test should have failed :-(\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
g_print (" Serializing to a string and back ... ");
|
2003-06-24 06:02:56 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
result = gimp_config_serialize_to_string (grid, NULL);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
grid2 = g_object_new (GIMP_TYPE_GRID, NULL);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
2003-10-19 08:33:25 +08:00
|
|
|
if (! gimp_config_deserialize_string (grid2, result, -1, NULL, &error))
|
2003-06-24 06:02:56 +08:00
|
|
|
{
|
|
|
|
g_print ("failed!\nThe error was:\n %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-20 07:43:08 +08:00
|
|
|
GList *diff = gimp_config_diff (G_OBJECT (grid), G_OBJECT (grid2), 0);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
if (diff)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
g_print ("succeeded but properties differ:\n");
|
|
|
|
for (list = diff; list; list = list->next)
|
|
|
|
{
|
|
|
|
GParamSpec *pspec = list->data;
|
|
|
|
g_print (" %s\n", pspec->name);
|
|
|
|
}
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2003-11-02 04:06:01 +08:00
|
|
|
g_print ("OK (%u bytes)\n", result ? (guint) strlen (result) : 0);
|
2003-06-24 06:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (result);
|
2003-10-19 08:33:25 +08:00
|
|
|
g_object_unref (grid2);
|
|
|
|
g_object_unref (grid);
|
2003-10-11 22:30:18 +08:00
|
|
|
|
2004-03-02 03:50:18 +08:00
|
|
|
g_print ("\nFinished test of GimpConfig.\n\n");
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2002-05-06 19:04:39 +08:00
|
|
|
return EXIT_SUCCESS;
|
2001-12-10 00:31:30 +08:00
|
|
|
}
|
|
|
|
|
2002-05-29 01:53:51 +08:00
|
|
|
static void
|
2001-12-10 00:31:30 +08:00
|
|
|
notify_callback (GObject *object,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2002-05-29 01:53:51 +08:00
|
|
|
GString *str;
|
|
|
|
GValue value = { 0, };
|
|
|
|
|
2001-12-10 00:31:30 +08:00
|
|
|
g_return_if_fail (G_IS_OBJECT (object));
|
|
|
|
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
|
|
|
|
|
2002-05-29 01:53:51 +08:00
|
|
|
g_value_init (&value, pspec->value_type);
|
|
|
|
g_object_get_property (object, pspec->name, &value);
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2002-05-29 01:53:51 +08:00
|
|
|
str = g_string_new (NULL);
|
2001-12-10 00:31:30 +08:00
|
|
|
|
2002-05-29 01:53:51 +08:00
|
|
|
if (gimp_config_serialize_value (&value, str, TRUE))
|
|
|
|
{
|
|
|
|
g_print (" %s -> %s\n", pspec->name, str->str);
|
2001-12-10 00:31:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
g_print (" %s changed but we failed to serialize its value!\n",
|
2002-05-29 01:53:51 +08:00
|
|
|
pspec->name);
|
2001-12-10 00:31:30 +08:00
|
|
|
}
|
2002-05-29 01:53:51 +08:00
|
|
|
|
|
|
|
g_string_free (str, TRUE);
|
|
|
|
g_value_unset (&value);
|
2001-12-10 00:31:30 +08:00
|
|
|
}
|
2001-12-10 20:32:28 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
output_unknown_token (const gchar *key,
|
|
|
|
const gchar *value,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2001-12-13 09:55:37 +08:00
|
|
|
gchar **header = (gchar **) data;
|
|
|
|
gchar *escaped = g_strescape (value, NULL);
|
2001-12-10 20:32:28 +08:00
|
|
|
|
|
|
|
if (*header)
|
|
|
|
{
|
2001-12-13 09:55:37 +08:00
|
|
|
g_print (*header);
|
|
|
|
*header = NULL;
|
2001-12-10 20:32:28 +08:00
|
|
|
}
|
|
|
|
|
2003-03-17 22:23:42 +08:00
|
|
|
g_print (" %s \"%s\"\n", key, escaped);
|
|
|
|
|
2001-12-10 20:32:28 +08:00
|
|
|
g_free (escaped);
|
|
|
|
}
|
2001-12-17 00:33:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* some dummy funcs so we can properly link this beast */
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_unit_get_identifier (GimpUnit unit)
|
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case GIMP_UNIT_PIXEL:
|
|
|
|
return "pixels";
|
|
|
|
case GIMP_UNIT_INCH:
|
|
|
|
return "inches";
|
|
|
|
case GIMP_UNIT_MM:
|
|
|
|
return "millimeters";
|
|
|
|
case GIMP_UNIT_POINT:
|
|
|
|
return "points";
|
|
|
|
case GIMP_UNIT_PICA:
|
|
|
|
return "picas";
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
gimp_unit_get_number_of_units (void)
|
|
|
|
{
|
|
|
|
return GIMP_UNIT_END;
|
|
|
|
}
|