app/tests: Add dockrc to session regression testing

Add dockrc to session regression testing and do some general cleanups
and generalizations in the test.
This commit is contained in:
Martin Nordholts 2009-09-19 12:52:09 +02:00
parent d9f89832c7
commit fca590925b
3 changed files with 121 additions and 45 deletions

View File

@ -1,6 +1,5 @@
/colorrc /colorrc
/controllerrc /controllerrc
/dockrc
/menurc /menurc
/parasiterc /parasiterc
/pluginrc /pluginrc

42
app/tests/gimpdir/dockrc Normal file
View File

@ -0,0 +1,42 @@
# recently closed docks
(GimpSessionInfo "Palettes - FG/BG - Images"
(position 586 116)
(size 200 573)
(open-on-exit)
(aux-info
(show-image-menu "false")
(follow-active-image "true"))
(dock
(book
(current-page 0)
(dockable "gimp-palette-list"
(tab-style preview)))
(book
(position 141)
(current-page 0)
(dockable "gimp-color-editor"
(tab-style preview)
(aux-info
(current-page "GimpColorSelect"))))
(book
(position 414)
(current-page 0)
(dockable "gimp-image-list"
(tab-style preview)))))
(GimpSessionInfo "Selection, Fonts"
(position 200 179)
(size 200 300)
(open-on-exit)
(aux-info
(show-image-menu "false")
(follow-active-image "true"))
(dock
(book
(current-page 1)
(dockable "gimp-selection-editor"
(tab-style icon))
(dockable "gimp-font-list"
(tab-style preview)))))
# end of recently closed docks

View File

@ -41,63 +41,79 @@ typedef struct
int dummy; int dummy;
} GimpTestFixture; } GimpTestFixture;
typedef struct
{
gchar *md5;
GTimeVal modtime;
} GimpTestFileState;
static gboolean gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
GTimeVal *modtime); static gboolean gimp_test_get_file_state_verbose (gchar *filename,
GimpTestFileState *filestate);
static gboolean gimp_test_file_state_changes (gchar *filename,
GimpTestFileState *state1,
GimpTestFileState *state2);
static Gimp *gimp = NULL; static Gimp *gimp = NULL;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gchar *initial_md5 = NULL; GimpTestFileState initial_sessionrc_state = { NULL, { 0, 0 } };
gchar *final_md5 = NULL; GimpTestFileState initial_dockrc_state = { NULL, { 0, 0 } };
GTimeVal initial_modtime = { 0, }; GimpTestFileState final_sessionrc_state = { NULL, { 0, 0 } };
GTimeVal final_modtime = { 0, }; GimpTestFileState final_dockrc_state = { NULL, { 0, 0 } };
gchar *sessionrc_filename = gimp_personal_rc_file ("sessionrc");
gchar *dockrc_filename = gimp_personal_rc_file ("dockrc");
g_type_init (); g_type_init ();
gtk_init (&argc, &argv); gtk_init (&argc, &argv);
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
/* Remeber the timestamp and MD5 on sessionrc */ /* Remeber the modtimes and MD5s */
if (!gimp_test_get_sessionrc_timestamp_and_md5 (&initial_md5, if (!gimp_test_get_file_state_verbose (sessionrc_filename,
&initial_modtime)) &initial_sessionrc_state))
goto fail;
if (!gimp_test_get_file_state_verbose (dockrc_filename,
&initial_dockrc_state))
goto fail; goto fail;
/* Start up GIMP and let the main loop run for a while (quits after /* Start up GIMP */
* a short timeout) to let things stabilize. This includes parsing
* sessionrc
*/
gimp = gimp_init_for_gui_testing (FALSE, TRUE); gimp = gimp_init_for_gui_testing (FALSE, TRUE);
/* Let the main loop run for a while (quits after a short timeout)
* to let things stabilize. This includes parsing sessionrc and
* dockrc
*/
gimp_test_run_temp_mainloop (4000); gimp_test_run_temp_mainloop (4000);
/* Exit. This includes writing sessionrc */ /* Exit. This includes writing sessionrc and dockrc*/
gimp_exit (gimp, TRUE); gimp_exit (gimp, TRUE);
/* Now get the new MD5 and modtime */ /* Now get the new modtimes and MD5s */
if (!gimp_test_get_sessionrc_timestamp_and_md5 (&final_md5, if (!gimp_test_get_file_state_verbose (sessionrc_filename,
&final_modtime)) &final_sessionrc_state))
goto fail;
if (!gimp_test_get_file_state_verbose (dockrc_filename,
&final_dockrc_state))
goto fail; goto fail;
/* If things have gone our way, GIMP will have deserialized /* If things have gone our way, GIMP will have deserialized
* sessionrc, shown the GUI, and then serialized the new sessionrc. * sessionrc and dockrc, shown the GUI, and then serialized the new
* To make sure we have a new sessionrc we check the modtime, and to * files. To make sure we have new files we check the modtime, and
* make sure that the sessionrc remains the same we compare its MD5 * to make sure that their content remains the same we compare their
* MD5
*/ */
if (initial_modtime.tv_sec == final_modtime.tv_sec) if (!gimp_test_file_state_changes ("sessionrc",
{ &initial_sessionrc_state,
g_printerr ("A new sessionrc was not created\n"); &final_sessionrc_state))
goto fail; goto fail;
} if (!gimp_test_file_state_changes ("dockrc",
if (strcmp (initial_md5, final_md5) != 0) &initial_dockrc_state,
{ &final_dockrc_state))
g_printerr ("The new sessionrc is not identical to the old one\n"); goto fail;
goto fail;
}
g_free (initial_md5);
g_free (final_md5);
/* Don't bother freeing stuff, the process is short-lived */
return 0; return 0;
fail: fail:
@ -105,13 +121,10 @@ int main(int argc, char **argv)
} }
static gboolean static gboolean
gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum, gimp_test_get_file_state_verbose (gchar *filename,
GTimeVal *modtime) GimpTestFileState *filestate)
{ {
gchar *filename = NULL; gboolean success = TRUE;
gboolean success = TRUE;
filename = gimp_personal_rc_file ("sessionrc");
/* Get checksum */ /* Get checksum */
if (success) if (success)
@ -125,9 +138,9 @@ gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
NULL); NULL);
if (success) if (success)
{ {
*checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, filestate->md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
contents, contents,
length); length);
} }
g_free (contents); g_free (contents);
@ -142,7 +155,7 @@ gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
NULL, NULL); NULL, NULL);
if (info) if (info)
{ {
g_file_info_get_modification_time (info, modtime); g_file_info_get_modification_time (info, &filestate->modtime);
success = TRUE; success = TRUE;
g_object_unref (info); g_object_unref (info);
} }
@ -154,7 +167,29 @@ gimp_test_get_sessionrc_timestamp_and_md5 (gchar **checksum,
g_object_unref (file); g_object_unref (file);
} }
g_free (filename); if (! success)
g_printerr ("Failed to get initial file info for '%s'\n", filename);
return success; return success;
} }
static gboolean
gimp_test_file_state_changes (gchar *filename,
GimpTestFileState *state1,
GimpTestFileState *state2)
{
if (state1->modtime.tv_sec == state2->modtime.tv_sec &&
state1->modtime.tv_usec == state2->modtime.tv_usec)
{
g_printerr ("A new '%s' was not created\n", filename);
return FALSE;
}
if (strcmp (state1->md5, state2->md5) != 0)
{
g_printerr ("'%s' was changed but should not have been\n", filename);
return FALSE;
}
return TRUE;
}