r15356 - gnucash/branches/sx-cleanup/src - Move SX test convenience functions to test-engine-stuff, extend.

Josh Sled jsled at cvs.gnucash.org
Sat Jan 13 14:37:00 EST 2007


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

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:
Move SX test convenience functions to test-engine-stuff, extend.


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:35:00 UTC (rev 15355)
+++ gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c	2007-01-13 19:36:59 UTC (rev 15356)
@@ -9,49 +9,6 @@
 #include "test-engine-stuff.h"
 
 static void
-test_empty()
-{
-     // no sxes should exist at this point.
-     int way_in_the_future_year = 2038;
-     GDate *end;
-     GncSxInstanceModel *model;
-
-     end = g_date_new_dmy(31, 12, way_in_the_future_year);
-     model = gnc_sx_get_instances(end);
-     do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
-     success("empty");
-}
-
-static FreqSpec*
-daily_freq(GDate* start, int multiplier)
-{
-     FreqSpec *freq = xaccFreqSpecMalloc(gnc_get_current_book());
-     xaccFreqSpecSetDaily(freq, start, multiplier);
-     return freq;
-}
-
-static void
-add_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur, FreqSpec *fs)
-{
-     SchedXaction *sx = xaccSchedXactionMalloc(gnc_get_current_book());
-     xaccSchedXactionSetName(sx, name);
-     xaccSchedXactionSetStartDate(sx, start);
-     if (end != NULL)
-          xaccSchedXactionSetEndDate(sx, end);
-     if (last_occur != NULL)
-          xaccSchedXactionSetLastOccurDate(sx, last_occur);
-     xaccSchedXactionSetFreqSpec(sx, fs);
-
-     gnc_sxes_add_sx(gnc_book_get_schedxactions(gnc_get_current_book()), sx);
-}
-
-static void
-add_daily_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur)
-{
-     add_sx(name, start, end, last_occur, daily_freq(start, 1));
-}
-
-static void
 test_basic()
 {
      GncSxInstanceModel *model;
@@ -83,12 +40,23 @@
                do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "to-create");
           }
      }
+
+     g_object_unref(G_OBJECT(model));
 }
 
 static void
-test_once()
+test_empty()
 {
-     ;
+     // no sxes should exist at this point.
+     int way_in_the_future_year = 2038;
+     GDate *end;
+     GncSxInstanceModel *model;
+
+     end = g_date_new_dmy(31, 12, way_in_the_future_year);
+     model = gnc_sx_get_instances(end);
+     do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
+     g_object_unref(G_OBJECT(model));
+     success("empty");
 }
 
 int
@@ -100,7 +68,6 @@
 
      test_empty();
      test_basic();
-     test_once();
 
      print_test_results();
      exit(get_rv());

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:35:00 UTC (rev 15355)
+++ gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.c	2007-01-13 19:36:59 UTC (rev 15356)
@@ -32,8 +32,12 @@
 #include "Group.h"
 #include "GroupP.h"
 #include "gnc-engine.h"
+#include "gnc-session.h"
 #include "Transaction.h"
 #include "TransactionP.h"
+#include "FreqSpec.h"
+#include "SchedXaction.h"
+#include "SX-book.h"
 
 #include "test-engine-stuff.h"
 #include "test-stuff.h"
@@ -2154,3 +2158,45 @@
 
   return q;
 }
+
+static FreqSpec*
+daily_freq(GDate* start, int multiplier)
+{
+     QofBook *book = qof_session_get_book(gnc_get_current_session());
+     FreqSpec *freq = xaccFreqSpecMalloc(book);
+     xaccFreqSpecSetDaily(freq, start, multiplier);
+     xaccFreqSpecSetUIType(freq, UIFREQ_DAILY);
+     return freq;
+}
+
+static SchedXaction*
+add_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur, FreqSpec *fs)
+{
+     QofBook *book = qof_session_get_book(gnc_get_current_session());
+     SchedXaction *sx = xaccSchedXactionMalloc(book);
+     xaccSchedXactionSetName(sx, name);
+     xaccSchedXactionSetStartDate(sx, start);
+     if (end != NULL)
+          xaccSchedXactionSetEndDate(sx, end);
+     if (last_occur != NULL)
+          xaccSchedXactionSetLastOccurDate(sx, last_occur);
+     xaccSchedXactionSetFreqSpec(sx, fs);
+
+     gnc_sxes_add_sx(gnc_book_get_schedxactions(book), sx);
+
+     return sx;
+}
+
+SchedXaction*
+add_daily_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur)
+{
+     return add_sx(name, start, end, last_occur, daily_freq(start, 1));
+}
+
+void
+remove_sx(SchedXaction *sx)
+{
+     QofBook *book = qof_session_get_book(gnc_get_current_session());
+     SchedXactions *sxes = gnc_book_get_schedxactions(book);
+     gnc_sxes_del_sx(sxes, 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:35:00 UTC (rev 15355)
+++ gnucash/branches/sx-cleanup/src/engine/test-core/test-engine-stuff.h	2007-01-13 19:36:59 UTC (rev 15356)
@@ -11,6 +11,7 @@
 #include "qof.h"
 #include "Query.h"
 #include "gnc-pricedb.h"
+#include "SchedXaction.h"
 
 Timespec* get_random_timespec(void);
 void random_timespec_zero_nsec (gboolean zero_nsec);
@@ -88,4 +89,7 @@
 void make_random_changes_to_book (QofBook *book);
 void make_random_changes_to_session (QofSession *session);
 
+SchedXaction* add_daily_sx(gchar *name, GDate *start, GDate *end, GDate *last_occur);
+void remove_sx(SchedXaction *sx);
+
 #endif



More information about the gnucash-changes mailing list