9 #include "test-stuff.h"
16 GDate yesterday, today, tomorrow, before_yesterday, after_tomorrow;
19 g_date_clear(&today, 1);
23 g_date_subtract_days(&yesterday, 1);
24 before_yesterday = yesterday;
25 g_date_subtract_days(&before_yesterday, 1);
27 g_date_add_days(&tomorrow, 1);
28 after_tomorrow = tomorrow;
29 g_date_add_days(&after_tomorrow, 1);
31 one_sx = add_daily_sx(
"foo", &yesterday, NULL, NULL);
39 do_test(g_list_length(model->sx_instance_list) == 1,
"1 GncSxInstances");
41 do_test(g_list_length(insts->
instance_list) == 3,
"yesterday, today and tomorrow");
42 for (iter = insts->
instance_list; iter != NULL; iter = iter->next)
45 do_test(inst->
state == SX_INSTANCE_STATE_TO_CREATE,
"to-create");
58 g_object_unref(G_OBJECT(model));
66 int way_in_the_future_year = 2038;
70 end = g_date_new_dmy(31, 12, way_in_the_future_year);
72 do_test(g_list_length(model->sx_instance_list) == 0,
"no instances");
73 g_object_unref(G_OBJECT(model));
83 int random_offset_within_one_year = 0;
89 g_date_clear(when, 1);
91 while (random_offset_within_one_year == 0)
92 random_offset_within_one_year = get_random_int_in_range(-365, 365);
93 g_date_add_days(when, random_offset_within_one_year);
98 g_date_add_years(end, 1);
100 lonely = add_once_sx(
"once", when);
104 do_test(g_list_length(model->sx_instance_list) == 1,
"1 instances");
106 do_test(g_list_length(instances->
instance_list) == 1,
"1 instance");
108 do_test(g_date_compare(when, &instances->next_instance_date) == 0,
"next instance is expected");
109 do_test(g_date_compare(when, &instance->
date) == 0,
"instance date is expected");
111 g_object_unref(model);
112 success(
"model unref");
131 start = g_date_new();
136 g_date_add_days(end, 3);
138 foo = add_daily_sx(
"foo", start, NULL, NULL);
141 do_test(g_list_length(model->sx_instance_list) == 1,
"one sx");
142 insts = (
GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);
143 do_test(g_list_length(insts->
instance_list) == 4,
"4 instances");
145 inst = _nth_instance(insts, 2);
149 for (i = 0; i < 4; i++)
151 inst = _nth_instance(insts, i);
152 do_test(inst->
state == SX_INSTANCE_STATE_TO_CREATE,
"0 didn't change");
154 success(
"nothing else changed");
157 inst = _nth_instance(insts, 1);
161 inst = _nth_instance(insts, 1);
162 do_test(inst->
state == SX_INSTANCE_STATE_POSTPONED,
"as we said");
163 for (i = 0; i < 4; i++)
167 inst = _nth_instance(insts, i);
168 do_test(inst->
state == SX_INSTANCE_STATE_TO_CREATE,
"still to create");
171 success(
"postponed changed what it needed to");
173 inst = _nth_instance(insts, 1);
175 success(
"changed to reminder");
178 inst = _nth_instance(insts, 0);
179 do_test(inst->
state == SX_INSTANCE_STATE_TO_CREATE,
"left alone");
180 inst = _nth_instance(insts, 1);
181 do_test(inst->
state == SX_INSTANCE_STATE_REMINDER,
"as we asked for");
182 for (i = 2; i < 4; i++)
184 inst = _nth_instance(insts, i);
185 do_test(inst->
state == SX_INSTANCE_STATE_REMINDER,
"changed as well");
189 g_object_unref(model);
194 main(
int argc,
char **argv)
196 g_setenv (
"GNC_UNINSTALLED",
"1", TRUE);
203 for (i = 0; i < 10; i++)
207 test_state_changes();
209 print_test_results();
void gnc_gdate_set_today(GDate *gd)
void gnc_sx_instance_model_change_instance_state(GncSxInstanceModel *model, GncSxInstance *instance, GncSxInstanceState new_state)
utility functions for the GnuCash UI
Anchor Scheduled Transaction info in a book. See src/doc/books.txt for design overview.
void gnc_engine_init(int argc, char **argv)
gint gnc_sx_get_num_occur_daterange(const SchedXaction *sx, const GDate *start_date, const GDate *end_date)
GncSxInstanceModel * gnc_sx_get_instances(const GDate *range_end, gboolean include_disabled)
void qof_init(void)
Initialise the Query Object Framework.
void xaccSchedXactionSetEndDate(SchedXaction *sx, const GDate *newEnd)