r15374 - gnucash/branches/sx-cleanup/src - Unit test for state-consistency model, move docs into header. Other misc.

Josh Sled jsled at cvs.gnucash.org
Sun Jan 14 11:41:37 EST 2007


Author: jsled
Date: 2007-01-14 11:41:36 -0500 (Sun, 14 Jan 2007)
New Revision: 15374
Trac: http://svn.gnucash.org/trac/changeset/15374

Modified:
   gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
   gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
   gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c
   gnucash/branches/sx-cleanup/src/doc/sx.rst
Log:
Unit test for state-consistency model, move docs into header.  Other misc.


Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c	2007-01-14 04:34:25 UTC (rev 15373)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c	2007-01-14 16:41:36 UTC (rev 15374)
@@ -702,6 +702,8 @@
 
                for (new_iter_iter = new_iter; new_iter_iter != NULL; new_iter_iter = new_iter_iter->next)
                {
+                    GncSxInstance *inst = (GncSxInstance*)new_iter_iter->data;
+                    inst->parent = existing;
                     existing->list = g_list_append(existing->list, new_iter_iter->data);
                }
                g_list_free(new_iter);
@@ -1259,7 +1261,6 @@
      summary->need_dialog
           = (summary->num_instances != 0
              && summary->num_auto_create_no_notify_instances != summary->num_instances);
-     
 }
 
 void

Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h	2007-01-14 04:34:25 UTC (rev 15373)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h	2007-01-14 16:41:36 UTC (rev 15374)
@@ -138,6 +138,32 @@
 GncSxVariable* gnc_sx_variable_new_full(gchar *name, gnc_numeric value, gboolean editable);
 void gnc_sx_variable_free(GncSxVariable *var);
 
+/**
+ * There is a constraint around a sequence of upcoming instance states.  In
+ * short: the last-created state and a list of postponed instances are modeled,
+ * but upcoming reminders are not.  As such, a reminder can never be before any
+ * other (modeled) instance type.  For instance, the following sequences are
+ * disallowed:
+ * 
+ * [...]
+ * remind    <- will be lost/skipped over; must be converted to `postponed`.
+ * to-create <- this will be the last-recorded state.
+ * [...]
+ * 
+ * [...]
+ * remind    <- same as previous; will be lost/skipped; must be `postponed`.
+ * postponed
+ * [...]
+ * 
+ * remind    <- same...
+ * ignore
+ * [...]
+ * 
+ * 
+ * As such, the SinceLastRun model will enforce that there are no previous
+ * `remind` instances at every state change.  They will be silently converted to
+ * `postponed`-state transactions.
+ **/
 void gnc_sx_instance_model_change_instance_state(GncSxInstanceModel *model,
                                                  GncSxInstance *instance,
                                                  GncSxInstanceState new_state);

Modified: gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c	2007-01-14 04:34:25 UTC (rev 15373)
+++ gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c	2007-01-14 16:41:36 UTC (rev 15374)
@@ -99,6 +99,12 @@
      remove_sx(lonely);
 }
 
+static GncSxInstance*
+_nth_instance(GncSxInstances *instances, int i)
+{
+     return (GncSxInstance*)g_list_nth_data(instances->list, i);
+}
+
 static void
 test_state_changes()
 {
@@ -109,26 +115,62 @@
      GncSxInstance *inst;
 
      start = g_date_new();
-     g_date_clear(start, 1);
      g_date_set_time_t(start, time(NULL));
      
      end = g_date_new();
-     g_date_clear(end, 1);
      g_date_set_time_t(end, time(NULL));
-     g_date_add_days(end, 1);
+     g_date_add_days(end, 3);
 
      foo = add_daily_sx("foo", start, NULL, NULL);
-
      model = gnc_sx_get_instances(end);
 
-     insts = (GncSxInstances*)model->sx_instance_list->data;
-     inst = (GncSxInstance*)insts->list->data;
+     do_test(g_list_length(model->sx_instance_list) == 1, "one sx");
+     insts = (GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);
+     do_test(g_list_length(insts->list) == 4, "4 instances");
+
+     inst = _nth_instance(insts, 2);
+     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_TO_CREATE);
+     {
+          int i;
+          for (i = 0; i < 4; i++)
+          {
+               inst = _nth_instance(insts, i);
+               do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "0 didn't change");
+          }
+          success("nothing else changed");
+     }
+
+     inst = _nth_instance(insts, 1);
+     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_POSTPONED);
+     {
+          int i;
+          inst = _nth_instance(insts, 1);
+          do_test(inst->state == SX_INSTANCE_STATE_POSTPONED, "as we said");
+          for (i = 0; i < 4; i++)
+          {
+               if (i == 1)
+                    continue; // skip
+               inst = _nth_instance(insts, i);
+               do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "still to create");
+          }
+     }
+     success("postponed changed what it needed to");
+
+     inst = _nth_instance(insts, 1);
      gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_REMINDER);
      success("changed to reminder");
-     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_POSTPONED);
-     success("changed to postponed");
-     gnc_sx_instance_model_change_instance_state(model, inst, SX_INSTANCE_STATE_TO_CREATE);
-     success("changed to to-create");
+     {
+          int i;
+          inst = _nth_instance(insts, 0);
+          do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "left alone");
+          inst = _nth_instance(insts, 1);
+          do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "as we asked for");
+          for (i = 2; i < 4; i++)
+          {
+               inst = _nth_instance(insts, i);
+               do_test(inst->state == SX_INSTANCE_STATE_REMINDER, "changed as well");
+          }
+     }
 
      g_object_unref(model);
      remove_sx(foo);

Modified: gnucash/branches/sx-cleanup/src/doc/sx.rst
===================================================================
--- gnucash/branches/sx-cleanup/src/doc/sx.rst	2007-01-14 04:34:25 UTC (rev 15373)
+++ gnucash/branches/sx-cleanup/src/doc/sx.rst	2007-01-14 16:41:36 UTC (rev 15374)
@@ -41,13 +41,15 @@
       - [ ] add instances
       - [ ] remove instances
       - [ ] make "weird"
-  - [ ] ensure variable consistency model is upheld.
+  - [x] ensure state consistency model is upheld
   - [ ] check variables-unbound logic
   - [ ] verify summary counts
   - [ ] check "since last run" states
     - [ ] -autocreate[, ±notify]
     - [ ] +autocreate, -notify
     - [ ] +autocreate, +notify
+    - [ ] +autocreate, -notify, w/postponed
+    - [ ] +autocreate, +notify, w/postponed
   - [ ] bugs
     - [ ] Scheduled Transactions on 31st/last put in following month - <http://bugzilla.gnome.org/show_bug.cgi?id=104844>
     - [ ] Expired scheduled transactions never run - <http://bugzilla.gnome.org/show_bug.cgi?id=375892>
@@ -55,6 +57,7 @@
 
 - sx list page
   - [/] make into split panel
+    - [ ] fix slider position
   - [ ] {0, 1, 2, 4, 8, 12} month selection for dense calendar
 
 - sx editor
@@ -193,35 +196,6 @@
         instantiation of.
     created: the instance has been created in this interaction cycle.
 
-The SX need to store?
-- last state of *created* instance
-- postponed instance list
-
-There is a constraint around a sequence of upcoming instance states.  In
-short: the last-created state and a list of postponed instances are modeled,
-but upcoming reminders are not.  As such, a reminder can never be before any
-other (modeled) instance type.  For instance, the following sequences are
-disallowed:
-
-[...]
-remind    <- will be lost/skipped over; must be converted to `postponed`.
-to-create <- this will be the last-recorded state.
-[...]
-
-[...]
-remind    <- same as previous; will be lost/skipped; must be `postponed`.
-postponed
-[...]
-
-remind    <- same...
-ignore
-[...]
-
-
-As such, the SinceLastRun model will enforce that there are no previous
-`remind` instances at every state change.  They will be silently converted to
-`postponed`-state transactions.
-
 Formula Parsing
 ------------------------
 
@@ -232,7 +206,6 @@
 - the date of the transaction
 - a variable-binding table.
 
-
 Testing Notes
 ---------------------
 



More information about the gnucash-changes mailing list