planner r926 - in trunk: . docs/user-guide/eu eds-backend eds-backend/planner-source eds-backend/utils libegg/recent-files libplanner python src tests
- From: mvdpot svn gnome org
- To: svn-commits-list gnome org
- Subject: planner r926 - in trunk: . docs/user-guide/eu eds-backend eds-backend/planner-source eds-backend/utils libegg/recent-files libplanner python src tests
- Date: Tue, 22 Jul 2008 14:11:07 +0000 (UTC)
Author: mvdpot
Date: Tue Jul 22 14:11:07 2008
New Revision: 926
URL: http://svn.gnome.org/viewvc/planner?rev=926&view=rev
Log:
2008-07-22 Maurice van der Pot <griffon26 kfk4ever com>
* src/Makefile.am:
Now building everything in src/ except planner_main.c into a convenience
library that can be used for testing.
* src/planner-cmd-manager.c (transaction_cmd_do): Abort redo-ing as soon as
the end of the transaction is encountered. Fixes bug #420443 reported by
Lincoln Phipps <lincoln phipps openmutual net>.
* tests/Makefile.am:
* tests/cmd-manager-test.c (test_cmd_do), (test_cmd_undo),
(test_cmd_free), (test_cmd), (main):
Added test for PlannerCmdManager, including regression test for bug #420443.
Added:
trunk/tests/cmd-manager-test.c
Modified:
trunk/ (props changed)
trunk/ChangeLog
trunk/docs/user-guide/eu/ (props changed)
trunk/eds-backend/ (props changed)
trunk/eds-backend/planner-source/ (props changed)
trunk/eds-backend/utils/ (props changed)
trunk/libegg/recent-files/ (props changed)
trunk/libplanner/ (props changed)
trunk/python/ (props changed)
trunk/src/ (props changed)
trunk/src/Makefile.am
trunk/src/planner-cmd-manager.c
trunk/tests/Makefile.am
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Tue Jul 22 14:11:07 2008
@@ -15,8 +15,20 @@
endif
bin_PROGRAMS = planner
+planner_SOURCES = \
+ planner-main.c
+planner_LDFLAGS = -export-dynamic
+planner_LDADD = \
+ libplannerapp.la \
+ $(top_builddir)/libplanner/libplanner-1.la \
+ $(top_builddir)/libegg/recent-files/libeggrecent.la \
+ $(PLANNER_LIBS)
+
+
+# Create a convenience library to link our tests against
+noinst_LTLIBRARIES = libplannerapp.la
-planner_SOURCES = \
+libplannerapp_la_SOURCES = \
$(built_sources) \
eel-canvas-rect.c \
eel-canvas-rect.h \
@@ -56,7 +68,6 @@
planner-group-model.h \
planner-list-model.c \
planner-list-model.h \
- planner-main.c \
planner-phase-dialog.c \
planner-phase-dialog.h \
planner-plugin.c \
@@ -152,12 +163,6 @@
planner-usage-tree.c \
planner-usage-tree.h
-planner_LDADD = \
- $(top_builddir)/libplanner/libplanner-1.la \
- $(top_builddir)/libegg/recent-files/libeggrecent.la \
- $(PLANNER_LIBS)
-
-planner_LDFLAGS = -export-dynamic
#
# Plugins
@@ -220,7 +225,7 @@
# i *think* these should actually be stamp-* files
built_sources = planner-marshal.h planner-marshal.c
-$(planner_OBJECTS): $(built_sources)
+$(libplannerapp_la_OBJECTS): $(built_sources)
EXTRA_DIST = planner-marshal.list
Modified: trunk/src/planner-cmd-manager.c
==============================================================================
--- trunk/src/planner-cmd-manager.c (original)
+++ trunk/src/planner-cmd-manager.c Tue Jul 22 14:11:07 2008
@@ -398,6 +398,11 @@
return TRUE;
}
+/* This function redoes a single command by calling its do_func function. In
+ * case of a transaction the command will be of type BEGIN_TRANSACTION and its
+ * do_func will point to transaction_cmd_do, which will take care of all other
+ * commands upto END_TRANSACTION.
+ */
gboolean
planner_cmd_manager_redo (PlannerCmdManager *manager)
{
@@ -439,6 +444,10 @@
* Transaction commands
*/
+/* This function is used for the do_func of a BEGIN_TRANSACTION command. It
+ * loops through all subcommands of a transaction and executes their functions
+ * until it encounters an END_TRANSACTION command.
+ */
static gboolean
transaction_cmd_do (PlannerCmd *cmd)
{
@@ -451,14 +460,14 @@
break;
}
- if (cmd_sub->do_func) {
- cmd_sub->do_func (cmd_sub);
- }
-
if (cmd_sub->type == PLANNER_CMD_TYPE_END_TRANSACTION) {
break;
}
+ if (cmd_sub->do_func) {
+ cmd_sub->do_func (cmd_sub);
+ }
+
g_assert (cmd_sub->type == PLANNER_CMD_TYPE_NORMAL);
}
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Tue Jul 22 14:11:07 2008
@@ -8,7 +8,9 @@
-DEXAMPLESDIR=\"$(top_srcdir)/tests/files\"
LDADD = \
- $(top_builddir)/libplanner/libplanner-1.la \
+ $(top_builddir)/src/libplannerapp.la \
+ $(top_builddir)/libplanner/libplanner-1.la \
+ $(top_builddir)/libegg/recent-files/libeggrecent.la \
$(PLANNER_LIBS)
check_LTLIBRARIES = libselfcheck.la
@@ -17,7 +19,7 @@
self-check.c \
self-check.h
-check_PROGRAMS = scheduler-test time-test calendar-test task-test
+check_PROGRAMS = $(TESTS)
scheduler_test_SOURCES = scheduler-test.c
scheduler_test_LDADD = $(LDADD) libselfcheck.la
@@ -31,10 +33,19 @@
task_test_SOURCES = task-test.c
task_test_LDADD = $(LDADD) libselfcheck.la
+cmd_manager_test_SOURCES = cmd-manager-test.c
+cmd_manager_test_LDADD = $(LDADD) libselfcheck.la
+
TESTS_ENVIRONMENT = \
PLANNER_STORAGEMODULEDIR=$(top_builddir)/libplanner/.libs \
PLANNER_FILEMODULESDIR=$(top_builddir)/libplanner/.libs \
PLANNER_PLUGINDIR=$(top_builddir)/src/.libs \
PLANNER_DATADIR=$(top_srcdir)/data
-TESTS = scheduler-test time-test calendar-test task-test
+TESTS = \
+ calendar-test \
+ cmd-manager-test \
+ scheduler-test \
+ task-test \
+ time-test
+
Added: trunk/tests/cmd-manager-test.c
==============================================================================
--- (empty file)
+++ trunk/tests/cmd-manager-test.c Tue Jul 22 14:11:07 2008
@@ -0,0 +1,222 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Maurice van der Pot <griffon26 kfk4ever com>
+ *
+ * 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>
+#include <string.h>
+#include <stdlib.h>
+#include "src/planner-cmd-manager.h"
+#include "self-check.h"
+
+typedef struct {
+ gchar actions[100];
+ gint next;
+} ActionHistory;
+
+typedef struct {
+ PlannerCmd base;
+
+ ActionHistory *action_history;
+ gboolean allocated;
+ gchar id;
+} TestCmd;
+
+static gboolean
+test_cmd_do (PlannerCmd *cmd_base)
+{
+ TestCmd *cmd;
+ ActionHistory *history;
+
+ cmd = (TestCmd*) cmd_base;
+
+ history = cmd->action_history;
+
+ CHECK_BOOLEAN_RESULT (cmd->allocated, TRUE);
+ CHECK_INTEGER_RESULT (history->actions[history->next], 0);
+ history->actions[history->next] = cmd->id;
+ history->next++;
+
+ return TRUE;
+}
+
+static void
+test_cmd_undo (PlannerCmd *cmd_base)
+{
+ TestCmd *cmd;
+ ActionHistory *history;
+
+ cmd = (TestCmd*) cmd_base;
+
+ history = cmd->action_history;
+
+ CHECK_BOOLEAN_RESULT (cmd->allocated, TRUE);
+ CHECK_BOOLEAN_RESULT (history->next > 0, TRUE);
+ CHECK_BOOLEAN_RESULT (history->actions[history->next - 1] == cmd->id, TRUE);
+
+ history->actions[--history->next] = 0;
+}
+
+static void
+test_cmd_free (PlannerCmd *cmd_base)
+{
+ TestCmd *cmd;
+
+ cmd = (TestCmd*) cmd_base;
+
+ CHECK_BOOLEAN_RESULT (cmd->allocated, TRUE);
+ cmd->allocated = FALSE;
+}
+
+
+static PlannerCmd *
+test_cmd (PlannerCmdManager *cmd_manager,
+ ActionHistory *action_history,
+ gchar cmd_id)
+{
+ PlannerCmd *cmd_base;
+ TestCmd *cmd;
+ gchar cmd_name[10];
+
+ CHECK_BOOLEAN_RESULT (cmd_id != 0, TRUE);
+
+ g_snprintf (cmd_name, sizeof(cmd_name), "cmd %c", cmd_id);
+
+ cmd_base = planner_cmd_new (TestCmd,
+ cmd_name,
+ test_cmd_do,
+ test_cmd_undo,
+ test_cmd_free);
+
+ cmd = (TestCmd *) cmd_base;
+
+ cmd->action_history = action_history;
+ cmd->allocated = TRUE;
+ cmd->id = cmd_id;
+
+ planner_cmd_manager_insert_and_do (cmd_manager,
+ cmd_base);
+
+ return cmd_base;
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ ActionHistory action_history;
+
+ g_type_init ();
+
+ PlannerCmdManager *cmd_manager = planner_cmd_manager_new ();
+
+ /* Initialise the action history */
+ memset(action_history.actions, 0, sizeof(action_history.actions));
+ action_history.next = 0;
+
+ /* Test adding a bunch of normal commands */
+ test_cmd(cmd_manager, &action_history, '1');
+ test_cmd(cmd_manager, &action_history, '2');
+ test_cmd(cmd_manager, &action_history, '3');
+ test_cmd(cmd_manager, &action_history, '4');
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "1234");
+
+ /* Test undo and redo with normal commands */
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123");
+
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "1234");
+
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "1");
+
+ planner_cmd_manager_redo (cmd_manager);
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123");
+
+ /* Test if undo and redo stop at the end of the queue */
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "1234");
+ planner_cmd_manager_redo (cmd_manager);
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "1234");
+
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "");
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "");
+
+ /* Test if performing a new action after some undos prevents redoes
+ * from happening */
+ planner_cmd_manager_redo (cmd_manager);
+ planner_cmd_manager_redo (cmd_manager);
+ test_cmd(cmd_manager, &action_history, '3');
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123");
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123");
+
+ /* Test adding some transactions as well as normal commands */
+ planner_cmd_manager_begin_transaction (cmd_manager, "trans 1");
+ test_cmd(cmd_manager, &action_history, 'a');
+ test_cmd(cmd_manager, &action_history, 'b');
+ test_cmd(cmd_manager, &action_history, 'c');
+ test_cmd(cmd_manager, &action_history, 'd');
+ planner_cmd_manager_end_transaction (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcd");
+
+ planner_cmd_manager_begin_transaction (cmd_manager, "trans 2");
+ test_cmd(cmd_manager, &action_history, 'i');
+ planner_cmd_manager_end_transaction (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi");
+
+ test_cmd(cmd_manager, &action_history, '5');
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi5");
+
+ planner_cmd_manager_begin_transaction (cmd_manager, "trans 3");
+ test_cmd(cmd_manager, &action_history, 'x');
+ test_cmd(cmd_manager, &action_history, 'y');
+ planner_cmd_manager_end_transaction (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi5xy");
+
+ /* Test undo & redo with a mix of transactions and normal commands */
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi5");
+
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi5xy");
+
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ planner_cmd_manager_undo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123");
+
+ planner_cmd_manager_redo (cmd_manager);
+ planner_cmd_manager_redo (cmd_manager);
+ CHECK_STRING_RESULT (g_strdup(action_history.actions), "123abcdi");
+
+ g_object_unref (cmd_manager);
+
+ return EXIT_SUCCESS;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]