26 #include <unittest-support.h>
28 #include "../gnc-backend-sql.h"
30 static const gchar *suitename =
"/backend/sql/gnc-backend-sql";
31 void test_suite_gnc_backend_sql (
void);
176 test_dirty_cb (
QofBook* book, gboolean dirty, gpointer data)
178 g_assert (data != NULL);
181 else if (*(guint*)data)
192 test_gnc_sql_commit_edit (
void)
196 guint dirty_called = 0;
198 gchar *msg1 =
"[gnc_sql_commit_edit()] gnc_sql_commit_edit(): Unknown object type 'null'\n";
199 gchar *msg2 =
"[gnc_sql_commit_edit()] gnc_sql_commit_edit(): Unknown object type 'Book'\n";
200 guint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
201 gchar *logdomain =
"gnc.backend.sql";
206 test_add_error (&check1);
207 test_add_error (&check2);
208 hdlr1 = g_log_set_handler (logdomain, loglevel,
209 (GLogFunc)test_list_handler, NULL);
210 g_test_log_set_fatal_handler ((GTestLogFatalFunc)test_list_handler, NULL);
212 qof_object_initialize ();
218 inst = g_object_new (QOF_TYPE_INSTANCE, NULL);
222 qof_instance_set_dirty_flag (inst, TRUE);
227 g_assert_cmpint (dirty_called, == , 1);
231 g_assert_cmpint (dirty_called, == , 0);
232 g_assert_cmpint (check1.hits, ==, 2);
233 g_assert_cmpint (check2.hits, ==, 0);
239 g_assert_cmpint (dirty_called, == , 1);
243 g_assert_cmpint (dirty_called, == , 1);
244 g_assert_cmpint (check1.hits, ==, 2);
245 g_assert_cmpint (check2.hits, ==, 0);
247 qof_instance_set_dirty_flag (QOF_INSTANCE (be.
book), TRUE);
251 g_assert_cmpint (dirty_called, == , 1);
255 g_assert_cmpint (dirty_called, == , 0);
256 g_assert_cmpint (check1.hits, ==, 2);
257 g_assert_cmpint (check2.hits, ==, 2);
259 g_log_remove_handler (logdomain, hdlr1);
260 g_object_unref (inst);
261 g_object_unref (be.
book);
579 gnc_date_string_to_timespec_gmt (gchar *datestr)
582 gint yr, mo, da, hr, min;
584 GDateTime *dt = NULL;
586 sscanf (datestr,
"%04d-%02d-%02d %02d:%02d:%02lf",
587 &yr, &mo, &da, &hr, &min, &sec);
588 g_assert_cmpint (1, <=, yr);
589 g_assert_cmpint (9999, >=, yr);
590 g_assert_cmpint (1, <=, mo);
591 g_assert_cmpint (12, >=, mo);
592 g_assert_cmpint (1, <=, da);
593 if (mo == 1 || mo == 3 || mo == 5 || mo == 7
594 || mo == 8 || mo == 10 || mo == 12)
595 g_assert_cmpint (31, >=, da);
597 g_assert_cmpint (30, >=, da);
598 else if (yr % 4 == 0 && !(yr % 400 == 0 && yr % 2000 != 0))
599 g_assert_cmpint (29, >=, da);
601 g_assert_cmpint (28, >=, da);
602 g_assert_cmpint (0, <=, hr);
603 g_assert_cmpint (60, >=, hr);
604 g_assert_cmpint (0, <=, min);
605 g_assert_cmpint (60, >=, min);
606 g_assert_cmpfloat (0.0, <=, sec);
607 g_assert_cmpfloat (60.0, >=, sec);
608 dt = g_date_time_new_utc (yr, mo, da, hr, min, sec);
609 ts->tv_sec = g_date_time_to_unix (dt);
610 ts->tv_nsec = g_date_time_get_microsecond (dt) * 1000;
611 g_date_time_unref (dt);
617 test_gnc_sql_convert_timespec_to_string ()
620 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
621 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
622 0, NULL, 0,
"", NULL, 0,
"", NULL, NULL
624 NULL, NULL, FALSE, FALSE, FALSE, 0, 0, NULL,
625 "%4d-%02d-%02d %02d:%02d:%02d"
627 gchar *date[numtests] = {
"1995-03-11 19:17:26",
628 "2001-04-20 11:44:07",
629 "1964-02-29 09:15:23",
630 "1959-04-02 00:00:00",
631 "2043-11-22 05:32:45",
632 "2153-12-18 01:15:30"
635 for (i = 0; i < numtests; i++)
638 Timespec *ts = gnc_date_string_to_timespec_gmt (date[i]);
640 g_assert_cmpstr (date[i], ==, datestr);
978 test_suite_gnc_backend_sql (
void)
999 GNC_TEST_ADD_FUNC (suitename,
"gnc sql commit edit", test_gnc_sql_commit_edit);
1038 GNC_TEST_ADD_FUNC (suitename,
"gnc sql convert timespec to string", test_gnc_sql_convert_timespec_to_string);
void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
QofBook * qof_book_new(void)
Use a 64-bit unsigned int timespec.
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
gboolean qof_book_session_not_saved(const QofBook *book)
void qof_book_mark_session_dirty(QofBook *book)
void gnc_sql_commit_edit(GncSqlBackend *be, QofInstance *inst)
gboolean(* rollbackTransaction)(GncSqlConnection *)
gboolean(* beginTransaction)(GncSqlConnection *)
gboolean(* commitTransaction)(GncSqlConnection *)
gchar * gnc_sql_convert_timespec_to_string(const GncSqlBackend *be, Timespec ts)