// Split line start static gchar* begin_split_string (Transaction *trans, Split *split, gboolean t_void, CsvExportInfo *info) { const gchar *str_rec_date; const gchar *start; gchar *conv; gchar *result; Timespec ts = {0,0}; if (xaccSplitGetReconcile (split) == YREC) { xaccSplitGetDateReconciledTS (split, &ts); str_rec_date = gnc_print_date (ts); } else str_rec_date = ""; if (t_void) { start = xaccTransGetVoidReason (trans) ? xaccTransGetVoidReason (trans) : "" ; conv = csv_txn_test_field_string (info, start); result = g_strconcat (info->end_sep, info->mid_sep, info->mid_sep, str_rec_date, info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, conv, info->mid_sep, NULL); g_free (conv); } else result = g_strconcat (info->end_sep, info->mid_sep, info->mid_sep, str_rec_date, info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, NULL); return result; }
static const char * get_date_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; GncEntry *entry; Timespec ts; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); ts = gncEntryGetDate (entry); return gnc_print_date (ts); }
// Second Date static gchar* add_second_date (gchar *so_far, Transaction *trans, CsvExportInfo *info) { gchar *result; const gchar *second_date; char type; Timespec ts = {0,0}; type = xaccTransGetTxnType (trans); if (type == TXN_TYPE_INVOICE) { xaccTransGetDateDueTS (trans, &ts); second_date = gnc_print_date (ts); result = g_strconcat (so_far, second_date, info->mid_sep, NULL); } else result = g_strconcat (so_far, info->mid_sep, NULL); g_free (so_far); return result; }
void test_qofsession_aqb_kvp( void ) { /* load the accounts from the users datafile */ /* but first, check to make sure we've got a session going. */ QofBackendError io_err; char *file1 = get_filepath("file-book.gnucash"); char *file2 = get_filepath("file-book-hbcislot.gnucash"); if (1) { // A file with no content at all, but a valid XML file QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file1); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); g_free(newfile); g_free(file1); gnc_hook_run(HOOK_BOOK_CLOSED, new_session); //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place } if (1) { // A file with no content except for the book_template_list kvp // slot QofSession *new_session = qof_session_new (); char *newfile = g_strdup_printf("file://%s", file2); qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE); io_err = qof_session_get_error (new_session); //printf("io_err1 = %d\n", io_err); g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist g_assert(io_err != ERR_BACKEND_LOCKED); g_assert(io_err == 0); qof_session_load (new_session, NULL); io_err = qof_session_get_error (new_session); //printf("io_err2 = %d\n", io_err); g_assert(io_err == 0); { GList *templ_list; GncABTransTempl *templ; QofBook *book = qof_session_get_book(new_session); const char* ORIGINAL_NAME = "Some Name"; const char* CHANGED_NAME = "Some Changed Name"; templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; //Raise the edit level so that we can check that it's marked dirty. qof_instance_increase_editlevel(QOF_INSTANCE(book)); g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here // Now we change the name into something else and verify it can be saved gnc_ab_trans_templ_set_name(templ, CHANGED_NAME); { g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty // Here we save the changed kvp gnc_ab_set_book_template_list(book, templ_list); g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty gnc_ab_trans_templ_list_free(templ_list); } { templ_list = gnc_ab_trans_templ_list_new_from_book (book); g_assert_cmpint(g_list_length(templ_list), ==, 1); templ = templ_list->data; g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved! gnc_ab_trans_templ_list_free(templ_list); } } { // Check the kvp slots of a aqbanking-enabled account QofBook *book = qof_session_get_book(new_session); Account* account = gnc_book_get_root_account(book); GDate retrieved_date, original_date; gchar buff[MAX_DATE_LENGTH]; g_assert(account); // The interesting test case here: Can we read the correct date // from the xml file? if (1) { Timespec retrieved_ts = gnc_ab_get_account_trans_retrieval(account); g_test_message("retrieved_ts=%s\n", gnc_print_date(retrieved_ts)); //printf("Time=%s\n", gnc_print_date(retrieved_ts)); retrieved_date = timespec_to_gdate(retrieved_ts); g_date_set_dmy(&original_date, 29, 8, 2014); g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); } // A lower-level test here: Can we write and read again the // trans_retrieval date? This wouldn't need this particular // Account, just a general Account object. if (0) { Timespec original_ts = timespec_now(), retrieved_ts; // Check whether the "ab-trans-retrieval" property of Account // is written and read again correctly. gnc_ab_set_account_trans_retrieval(account, original_ts); retrieved_ts = gnc_ab_get_account_trans_retrieval(account); // printf("original_ts=%s = %d retrieved_ts=%s = %d\n", // gnc_print_date(original_ts), original_ts.tv_sec, // gnc_print_date(retrieved_ts), retrieved_ts.tv_sec); original_date = timespec_to_gdate(original_ts); retrieved_date = timespec_to_gdate(retrieved_ts); qof_print_gdate (buff, sizeof (buff), &original_date); //printf("original_date=%s\n", buff); qof_print_gdate (buff, sizeof (buff), &retrieved_date); //printf("retrieved_date=%s\n", buff); // Is the retrieved date identical to the one written g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0); }