r15349 - gnucash/branches/sx-cleanup/src/app-utils/test - Add basic unit test for sx-instance generation code.
Josh Sled
jsled at cvs.gnucash.org
Fri Jan 12 19:01:54 EST 2007
Author: jsled
Date: 2007-01-12 19:01:53 -0500 (Fri, 12 Jan 2007)
New Revision: 15349
Trac: http://svn.gnucash.org/trac/changeset/15349
Added:
gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c
Modified:
gnucash/branches/sx-cleanup/src/app-utils/test/Makefile.am
Log:
Add basic unit test for sx-instance generation code.
Modified: gnucash/branches/sx-cleanup/src/app-utils/test/Makefile.am
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/test/Makefile.am 2007-01-12 23:55:59 UTC (rev 15348)
+++ gnucash/branches/sx-cleanup/src/app-utils/test/Makefile.am 2007-01-13 00:01:53 UTC (rev 15349)
@@ -4,7 +4,8 @@
test-component-manager \
test-exp-parser \
test-scm-query-string \
- test-print-parse-amount
+ test-print-parse-amount \
+ test-sx
test_exp_parser_SOURCES = \
${top_builddir}/src/core-utils/gnc-gconf-utils.c \
@@ -51,7 +52,8 @@
test-exp-parser \
test-print-parse-amount \
test-scm-query-string \
- test-print-queries
+ test-print-queries \
+ test-sx
EXTRA_DIST = \
test-load-module \
Added: gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c 2007-01-12 23:55:59 UTC (rev 15348)
+++ gnucash/branches/sx-cleanup/src/app-utils/test/test-sx.c 2007-01-13 00:01:53 UTC (rev 15349)
@@ -0,0 +1,107 @@
+#include "config.h"
+#include <stdlib.h>
+#include <glib.h>
+#include "SX-book.h"
+#include "gnc-sx-instance-model.h"
+#include "gnc-ui-util.h"
+
+#include "test-stuff.h"
+#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;
+ GDate *yesterday, *range_end_tomorrow;
+
+ 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);
+
+ range_end_tomorrow = g_date_new();
+ g_date_clear(range_end_tomorrow, 1);
+ g_date_set_time_t(range_end_tomorrow, time(NULL));
+ g_date_add_days(range_end_tomorrow, 1);
+ model = gnc_sx_get_instances(range_end_tomorrow);
+
+ {
+ GncSxInstances *insts;
+ GList *iter;
+
+ do_test(g_list_length(model->sx_instance_list) == 1, "1 GncSxInstances");
+ insts = (GncSxInstances*)model->sx_instance_list->data;
+ do_test(g_list_length(insts->list) == 3, "yesterday, today and tomorrow");
+ for (iter = insts->list; iter != NULL; iter = iter->next)
+ {
+ GncSxInstance *inst = (GncSxInstance*)iter->data;
+ do_test(inst->state == SX_INSTANCE_STATE_TO_CREATE, "to-create");
+ }
+ }
+}
+
+static void
+test_once()
+{
+ ;
+}
+
+int
+main(int argc, char **argv)
+{
+ g_type_init();
+ qof_init();
+ gnc_engine_init(0, NULL);
+
+ test_empty();
+ test_basic();
+ test_once();
+
+ print_test_results();
+ exit(get_rv());
+}
More information about the gnucash-changes
mailing list