r15360 - gnucash/branches/sx-cleanup/src - Add frequency=once SX test + support.

Josh Sled jsled at cvs.gnucash.org
Sat Jan 13 14:58:39 EST 2007


Author: jsled
Date: 2007-01-13 14:58:39 -0500 (Sat, 13 Jan 2007)
New Revision: 15360
Trac: http://svn.gnucash.org/trac/changeset/15360

Modified:
   gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c
   gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.c
   gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.h
Log:
Add frequency=once SX test + support.

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-13 19:39:28 UTC (rev 15359)
+++ gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c	2007-01-13 19:58:39 UTC (rev 15360)
@@ -13,13 +13,14 @@
 {
      GncSxInstanceModel *model;
      GDate *yesterday, *range_end_tomorrow;
+     SchedXaction *foo;
 
      yesterday = g_date_new();
      g_date_clear(yesterday, 1);
      g_date_set_time_t(yesterday, time(NULL));
      g_date_subtract_days(yesterday, 1);
 
-     add_daily_sx("foo", yesterday, NULL, NULL);
+     foo = add_daily_sx("foo", yesterday, NULL, NULL);
 
      range_end_tomorrow = g_date_new();
      g_date_clear(range_end_tomorrow, 1);
@@ -42,6 +43,7 @@
      }
 
      g_object_unref(G_OBJECT(model));
+     remove_sx(foo);
 }
 
 static void
@@ -59,6 +61,44 @@
      success("empty");
 }
 
+static void
+test_once()
+{
+     SchedXaction *lonely;
+     GDate *when, *end;
+     int random_offset_within_one_year = 0;
+     GncSxInstanceModel *model;
+     GncSxInstances *instances;
+     GncSxInstance *instance;
+
+     when = g_date_new();
+     g_date_clear(when, 1);
+     g_date_set_time_t(when, time(NULL));
+     while (random_offset_within_one_year == 0)
+          random_offset_within_one_year = get_random_int_in_range(-365, 365);
+     g_date_add_days(when, random_offset_within_one_year);
+
+     end = g_date_new();
+     g_date_clear(end, 1);
+     g_date_set_time_t(end, time(NULL));
+     g_date_add_years(end, 1);
+
+     lonely = add_once_sx("once", when);
+
+     model = gnc_sx_get_instances(end);
+
+     do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");
+     instances = (GncSxInstances*)model->sx_instance_list->data;
+     do_test(g_list_length(instances->list) == 1, "1 instance");
+     instance = (GncSxInstance*)instances->list->data;
+     do_test(g_date_compare(when, &instances->next_instance_date) == 0, "next instance is expected");
+     do_test(g_date_compare(when, &instance->date) == 0, "instance date is expected");
+
+     g_object_unref(model);
+     success("model unref");
+     remove_sx(lonely);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -67,6 +107,11 @@
      gnc_engine_init(0, NULL);
 
      test_empty();
+     {
+          int i;
+          for (i = 0; i < 10; i++)
+               test_once();
+     }
      test_basic();
 
      print_test_results();

Modified: gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.c	2007-01-13 19:39:28 UTC (rev 15359)
+++ gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.c	2007-01-13 19:58:39 UTC (rev 15360)
@@ -2169,6 +2169,16 @@
      return freq;
 }
 
+static FreqSpec*
+once_freq(GDate *when)
+{
+     QofBook *book = qof_session_get_book(gnc_get_current_session());
+     FreqSpec *freq = xaccFreqSpecMalloc(book);
+     xaccFreqSpecSetOnceDate(freq, when);
+     xaccFreqSpecSetUIType(freq, UIFREQ_ONCE);
+     return freq;
+}
+
 static SchedXaction*
 add_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur, FreqSpec *fs)
 {
@@ -2193,6 +2203,12 @@
      return add_sx(name, start, end, last_occur, daily_freq(start, 1));
 }
 
+SchedXaction*
+add_once_sx(gchar *name, GDate *when)
+{
+     return add_sx(name, when, NULL, NULL, once_freq(when));
+}
+
 void
 remove_sx(SchedXaction *sx)
 {

Modified: gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.h
===================================================================
--- gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.h	2007-01-13 19:39:28 UTC (rev 15359)
+++ gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.h	2007-01-13 19:58:39 UTC (rev 15360)
@@ -90,6 +90,7 @@
 void make_random_changes_to_session (QofSession *session);
 
 SchedXaction* add_daily_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur);
+SchedXaction* add_once_sx(gchar *name, GDate *when);
 void remove_sx(SchedXaction *sx);
 
 #endif



More information about the gnucash-changes mailing list