app: Add regression testing for sessionrc/docks

Add a regression test for sessionrc parsing, handing and writing. The
test work in the following way: GIMP starts so that sessionrc is
deserialized and stored internally, the UI is shown, and then the
internal data structure about windows is serialized to a new
sessionrc. The test makes sure that a new sessionrc actually has been
created, and then that the content of the new file is identical to the
old one.
This commit is contained in:
Martin Nordholts 2009-09-17 01:12:21 +02:00
parent dc51d81671
commit 6e0befa6ba
5 changed files with 254 additions and 6 deletions

View File

@ -3,4 +3,5 @@
/Makefile.in
/test-layer-grouping*
/test-layers*
/test-session-management*
/test-window-management*

View File

@ -3,15 +3,17 @@ TESTS_ENVIRONMENT = \
GIMP2_DIRECTORY=$(abs_top_srcdir)/app/tests/gimpdir
TESTS = \
test-layer-grouping \
test-layers \
test-window-management \
test-layer-grouping
test-session-management \
test-window-management
EXTRA_PROGRAMS = $(TESTS)
test_layers_SOURCES = test-layers.c
test_layer_grouping_SOURCES = test-layer-grouping.c
test_window_management_SOURCES = test-window-management.c
test_layers_SOURCES = test-layers.c
test_layer_grouping_SOURCES = test-layer-grouping.c
test_window_management_SOURCES = test-window-management.c
test_session_management_SOURCES = test-session-management.c
libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
libgimpconfig = $(top_builddir)/libgimpconfig/libgimpconfig-$(GIMP_API_VERSION).la

View File

@ -4,7 +4,6 @@
/menurc
/parasiterc
/pluginrc
/sessionrc
/templaterc
/themerc
/toolrc

View File

@ -0,0 +1,86 @@
# GIMP sessionrc
#
# This file takes session-specific info (that is info, you want to keep
# between two GIMP sessions). You are not supposed to edit it manually, but
# of course you can do. The sessionrc will be entirely rewritten every time
# you quit GIMP. If this file isn't found, defaults are used.
(session-info "dock" "dock"
(position 428 198)
(size 210 523)
(open-on-exit)
(aux-info
(show-image-menu "true")
(follow-active-image "true"))
(dock
(book
(current-page 1)
(dockable "gimp-layer-list"
(tab-style icon)
(preview-size 32))
(dockable "gimp-undo-history"
(tab-style icon)))
(book
(position 259)
(current-page 0)
(dockable "gimp-brush-grid"
(tab-style preview)))))
(session-info "dock" "dock"
(position 184 358)
(size 200 300)
(open-on-exit)
(aux-info
(show-image-menu "false")
(follow-active-image "true"))
(dock
(book
(current-page 0)
(dockable "gimp-tool-options"
(tab-style icon)))))
(session-info "dock" "dock"
(position 769 64)
(size 200 265)
(open-on-exit)
(aux-info
(show-image-menu "true")
(follow-active-image "true"))
(dock
(book
(current-page 1)
(dockable "gimp-pattern-grid"
(tab-style preview))
(dockable "gimp-gradient-list"
(tab-style preview)))))
(session-info "dock" "dock"
(position 714 320)
(size 200 384)
(open-on-exit)
(aux-info
(show-image-menu "true")
(follow-active-image "true"))
(dock
(book
(current-page 0)
(dockable "gimp-channel-list"
(tab-style icon)
(preview-size 32)))
(book
(position 169)
(current-page 0)
(dockable "gimp-vectors-list"
(tab-style icon)
(preview-size 32)))))
(session-info "toolbox" "dock"
(position 44 104)
(size 102 526)
(open-on-exit))
(session-info "toplevel" "gimp-file-open-dialog"
(position 392 140)
(size 902 816))
(session-info "display" "gimp-empty-image-window"
(position 178 35)
(size 563 190))
(last-tip-shown 0)
# end of sessionrc

View File

@ -0,0 +1,160 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 2009 Martin Nordholts
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <gegl.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <utime.h>
#include "libgimpbase/gimpbase.h"
#include "dialogs/dialogs-types.h"
#include "dialogs/dialogs.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpsessioninfo.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "tests.h"
typedef struct
{
int dummy;
} GimpTestFixture;
static gboolean gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
GTimeVal *modtime);
static Gimp *gimp = NULL;
int main(int argc, char **argv)
{
gchar *initial_md5 = NULL;
gchar *final_md5 = NULL;
GTimeVal initial_modtime = { 0, };
GTimeVal final_modtime = { 0, };
g_type_init ();
gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
/* Remeber the timestamp and MD5 on sessionrc */
if (!gimp_test_get_sessionrc_timestamp_and_md5 (&initial_md5,
&initial_modtime))
goto fail;
/* Start up GIMP and let the main loop run for a while (quits after
* a short timeout) to let things stabilize. This includes parsing
* sessionrc
*/
gimp = gimp_init_for_gui_testing (FALSE, TRUE);
gimp_test_run_temp_mainloop (4000);
/* Exit. This includes writing sessionrc */
gimp_exit (gimp, TRUE);
/* Now get the new MD5 and modtime */
if (!gimp_test_get_sessionrc_timestamp_and_md5 (&final_md5,
&final_modtime))
goto fail;
/* If things have gone our way, GIMP will have deserialized
* sessionrc, shown the GUI, and then serialized the new sessionrc.
* To make sure we have a new sessionrc we check the modtime, and to
* make sure that the sessionrc remains the same we compare its MD5
*/
if (initial_modtime.tv_sec == final_modtime.tv_sec)
{
g_printerr ("A new sessionrc was not created\n");
goto fail;
}
if (strcmp (initial_md5, final_md5) != 0)
{
g_printerr ("The new sessionrc is not identical to the old one\n");
goto fail;
}
g_free (initial_md5);
g_free (final_md5);
return 0;
fail:
return -1;
}
static gboolean
gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
GTimeVal *modtime)
{
gchar *filename = NULL;
gboolean success = TRUE;
filename = gimp_personal_rc_file ("sessionrc");
/* Get checksum */
if (success)
{
gchar *contents = NULL;
gsize length = 0;
success = g_file_get_contents (filename,
&contents,
&length,
NULL);
if (success)
{
*checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5,
contents,
length);
}
g_free (contents);
}
/* Get modification time */
if (success)
{
GFile *file = g_file_new_for_path (filename);
GFileInfo *info = g_file_query_info (file,
G_FILE_ATTRIBUTE_TIME_MODIFIED, 0,
NULL, NULL);
if (info)
{
g_file_info_get_modification_time (info, modtime);
success = TRUE;
g_object_unref (info);
}
else
{
success = FALSE;
}
g_object_unref (file);
}
g_free (filename);
return success;
}