static QofSession* create_session(void) { QofSession* session = qof_session_new(); QofBook* book = qof_session_get_book( session ); Account* root = gnc_book_get_root_account( book ); Account* acct1; Account* acct2; KvpFrame* frame; Transaction* tx; Split* spl1; Split* spl2; Timespec ts; struct timeval tv; gnc_commodity_table* table; gnc_commodity* currency; table = gnc_commodity_table_get_table( book ); currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" ); acct1 = xaccMallocAccount( book ); xaccAccountSetType( acct1, ACCT_TYPE_BANK ); xaccAccountSetName( acct1, "Bank 1" ); xaccAccountSetCommodity( acct1, currency ); frame = qof_instance_get_slots( QOF_INSTANCE(acct1) ); kvp_frame_set_gint64( frame, "int64-val", 100 ); kvp_frame_set_double( frame, "double-val", 3.14159 ); kvp_frame_set_numeric( frame, "numeric-val", gnc_numeric_zero() ); time( &(tv.tv_sec) ); tv.tv_usec = 0; ts.tv_sec = tv.tv_sec; ts.tv_nsec = 1000 * tv.tv_usec; kvp_frame_set_timespec( frame, "timespec-val", ts ); kvp_frame_set_string( frame, "string-val", "abcdefghijklmnop" ); kvp_frame_set_guid( frame, "guid-val", qof_instance_get_guid( QOF_INSTANCE(acct1) ) ); gnc_account_append_child( root, acct1 ); acct2 = xaccMallocAccount( book ); xaccAccountSetType( acct2, ACCT_TYPE_BANK ); xaccAccountSetName( acct2, "Bank 1" ); tx = xaccMallocTransaction( book ); xaccTransBeginEdit( tx ); xaccTransSetCurrency( tx, currency ); spl1 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl1 ); spl2 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl2 ); xaccTransCommitEdit( tx ); return session; }
static gboolean spl_account_handler(xmlNodePtr node, gpointer data) { struct split_pdata *pdata = data; GncGUID *id = dom_tree_to_guid(node); Account *account; g_return_val_if_fail(id, FALSE); account = xaccAccountLookup (id, pdata->book); if (!account && gnc_transaction_xml_v2_testing && !guid_equal (id, guid_null ())) { account = xaccMallocAccount (pdata->book); xaccAccountSetGUID (account, id); xaccAccountSetCommoditySCU (account, xaccSplitGetAmount (pdata->split).denom); } xaccAccountInsertSplit (account, pdata->split); g_free(id); return TRUE; }
void SetUp() { QofBook *book = qof_book_new(); Account *root = gnc_account_create_root(book); t_asset_account1 = xaccMallocAccount(book); xaccAccountSetName(t_asset_account1, "Asset"); gnc_account_append_child(root, t_asset_account1); t_bank_account = xaccMallocAccount(book); xaccAccountSetName(t_bank_account, "Bank"); gnc_account_append_child(t_asset_account1, t_bank_account); t_asset_account2 = xaccMallocAccount(book); xaccAccountSetName(t_asset_account2, "Asset-Bank"); gnc_account_append_child(root, t_asset_account2); t_sav_account = xaccMallocAccount(book); xaccAccountSetName(t_sav_account, "Bank"); gnc_account_append_child(t_asset_account2, t_sav_account); t_expense_account = xaccMallocAccount(book); xaccAccountSetName(t_expense_account, "Expense"); gnc_account_append_child(root, t_expense_account); t_expense_account1 = xaccMallocAccount(book); xaccAccountSetName(t_expense_account1, "Food"); gnc_account_append_child(t_expense_account, t_expense_account1); t_expense_account2 = xaccMallocAccount(book); xaccAccountSetName(t_expense_account2, "Drink"); gnc_account_append_child(t_expense_account, t_expense_account2); }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); fixture->customer = gncCustomerCreate(fixture->book); gncOwnerInitCustomer(&fixture->owner, fixture->customer); }
static void sxtg_book_begin (QofBook *book) { Account *root; root = xaccMallocAccount(book); xaccAccountBeginEdit(root); xaccAccountSetType(root, ACCT_TYPE_ROOT); xaccAccountSetName(root, "Template Root"); xaccAccountCommitEdit(root); gnc_book_set_template_root (book, root); }
static Account * hierarchy_merge_accounts (GSList *dalist, gnc_commodity *com) { GSList *mark; Account *ret = xaccMallocAccount (gnc_get_current_book ()); for (mark = dalist; mark; mark = mark->next) { GncExampleAccount *xea = mark->data; add_new_accounts_with_random_guids (ret, xea->root, com); } return ret; }
static Account* load_single_account (GncSqlBackend* be, GncSqlRow* row, GList** l_accounts_needing_parents) { const GncGUID* guid; Account* pAccount = NULL; g_return_val_if_fail (be != NULL, NULL); g_return_val_if_fail (row != NULL, NULL); g_return_val_if_fail (l_accounts_needing_parents != NULL, NULL); guid = gnc_sql_load_guid (be, row); if (guid != NULL) { pAccount = xaccAccountLookup (guid, be->book); } if (pAccount == NULL) { pAccount = xaccMallocAccount (be->book); } xaccAccountBeginEdit (pAccount); gnc_sql_load_object (be, row, GNC_ID_ACCOUNT, pAccount, col_table); xaccAccountCommitEdit (pAccount); /* If we don't have a parent and this isn't the root account, it might be because the parent account hasn't been loaded yet. Remember the account and its parent guid for later. */ if (gnc_account_get_parent (pAccount) == NULL && pAccount != gnc_book_get_root_account (be->book)) { account_parent_guid_struct* s = static_cast<decltype (s)> ( g_malloc (sizeof (account_parent_guid_struct))); g_assert (s != NULL); s->pAccount = pAccount; gnc_sql_load_object (be, row, GNC_ID_ACCOUNT, s, parent_col_table); *l_accounts_needing_parents = g_list_prepend (*l_accounts_needing_parents, s); } return pAccount; }
static void set_root_template_guid( gpointer pObject, /*@ null @*/ gpointer pValue ) { QofBook* book = QOF_BOOK(pObject); GncGUID* guid = (GncGUID*)pValue; Account* root; g_return_if_fail( pObject != NULL ); g_return_if_fail( QOF_IS_BOOK(pObject) ); g_return_if_fail( pValue != NULL ); root = gnc_book_get_template_root( book ); if ( root == NULL ) { root = xaccMallocAccount( book ); xaccAccountBeginEdit( root ); xaccAccountSetType( root, ACCT_TYPE_ROOT ); xaccAccountCommitEdit( root ); gnc_book_set_template_root( book, root ); } qof_instance_set_guid( QOF_INSTANCE(root), guid ); }
static Account* load_single_account (GncSqlBackend* sql_be, GncSqlRow& row, ParentGuidVec& l_accounts_needing_parents) { const GncGUID* guid; Account* pAccount = NULL; g_return_val_if_fail (sql_be != NULL, NULL); guid = gnc_sql_load_guid (sql_be, row); if (guid != NULL) { pAccount = xaccAccountLookup (guid, sql_be->book()); } if (pAccount == NULL) { pAccount = xaccMallocAccount (sql_be->book()); } xaccAccountBeginEdit (pAccount); gnc_sql_load_object (sql_be, row, GNC_ID_ACCOUNT, pAccount, col_table); xaccAccountCommitEdit (pAccount); /* If we don't have a parent and this isn't the root account, it might be because the parent account hasn't been loaded yet. Remember the account and its parent guid for later. */ if (gnc_account_get_parent (pAccount) == NULL && pAccount != gnc_book_get_root_account (sql_be->book())) { auto s = new ParentGuid; s->pAccount = pAccount; gnc_sql_load_object (sql_be, row, GNC_ID_ACCOUNT, s, parent_col_table); l_accounts_needing_parents.push_back(s); } return pAccount; }
Account * xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency, const char *accname, GNCAccountType acctype, gboolean placeholder) { Account * acc; g_return_val_if_fail (root, NULL); /* build the account name */ if (!currency) { PERR ("No currency specified!"); return NULL; } /* See if we've got one of these going already ... */ acc = gnc_account_lookup_by_name(root, accname); if (acc == NULL) { /* Guess not. We'll have to build one. */ acc = xaccMallocAccount(gnc_account_get_book (root)); xaccAccountBeginEdit (acc); xaccAccountSetName (acc, accname); xaccAccountSetCommodity (acc, currency); xaccAccountSetType (acc, acctype); xaccAccountSetPlaceholder (acc, placeholder); /* Hang the account off the root. */ gnc_account_append_child (root, acc); xaccAccountCommitEdit (acc); } return acc; }
static void xaccSchedXactionInit(SchedXaction *sx, QofBook *book) { Account *ra; const GncGUID *guid; gchar guidstr[GUID_ENCODING_LENGTH+1]; qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book); /* create a new template account for our splits */ sx->template_acct = xaccMallocAccount(book); guid = qof_instance_get_guid( sx ); xaccAccountBeginEdit( sx->template_acct ); guid_to_string_buff( guid, guidstr ); xaccAccountSetName( sx->template_acct, guidstr); xaccAccountSetCommodity (sx->template_acct, gnc_commodity_table_lookup( gnc_commodity_table_get_table(book), "template", "template") ); xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK ); xaccAccountCommitEdit( sx->template_acct ); ra = gnc_book_get_template_root( book ); gnc_account_append_child( ra, sx->template_acct ); }
static void test_transaction (void) { int i; for (i = 0; i < 50; i++) { Transaction* ran_trn; xmlNodePtr test_node; gnc_commodity* com, *new_com; gchar* filename1; int fd; /* The next line exists for its side effect of creating the * account tree. */ get_random_account_tree (book); ran_trn = get_random_transaction (book); new_com = get_random_commodity (book); if (!ran_trn) { failure_args ("transaction_xml", __FILE__, __LINE__, "get_random_transaction returned NULL"); return; } { /* xaccAccountInsertSplit can reorder the splits. */ GList* list = g_list_copy (xaccTransGetSplitList (ran_trn)); GList* node = list; for (; node; node = node->next) { Split* s = static_cast<decltype (s)> (node->data); Account* a = xaccMallocAccount (book); xaccAccountBeginEdit (a); xaccAccountSetCommodity (a, new_com); xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom); xaccAccountInsertSplit (a, s); xaccAccountCommitEdit (a); } g_list_free (list); } com = xaccTransGetCurrency (ran_trn); test_node = gnc_transaction_dom_tree_create (ran_trn); if (!test_node) { failure_args ("transaction_xml", __FILE__, __LINE__, "gnc_transaction_dom_tree_create returned NULL"); really_get_rid_of_transaction (ran_trn); continue; } auto compare_msg = node_and_transaction_equal (test_node, ran_trn); if (compare_msg != nullptr) { failure_args ("transaction_xml", __FILE__, __LINE__, "node and transaction were not equal: %s", compare_msg); xmlElemDump (stdout, NULL, test_node); printf ("\n"); fflush (stdout); xmlFreeNode (test_node); really_get_rid_of_transaction (ran_trn); continue; } else { success_args ("transaction_xml", __FILE__, __LINE__, "%d", i); } filename1 = g_strdup_printf ("test_file_XXXXXX"); fd = g_mkstemp (filename1); write_dom_node_to_file (test_node, fd); close (fd); { GList* node = xaccTransGetSplitList (ran_trn); for (; node; node = node->next) { Split* s = static_cast<decltype (s)> (node->data); Account* a1 = xaccSplitGetAccount (s); Account* a2 = xaccMallocAccount (book); xaccAccountBeginEdit (a2); xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1)); xaccAccountSetGUID (a2, xaccAccountGetGUID (a1)); xaccAccountCommitEdit (a2); } } { sixtp* parser; tran_data data; const char* msg = "[xaccAccountScrubCommodity()] Account \"\" does not have a commodity!"; const char* logdomain = "gnc.engine.scrub"; GLogLevelFlags loglevel = static_cast<decltype (loglevel)> (G_LOG_LEVEL_CRITICAL); TestErrorStruct check = { loglevel, const_cast<char*> (logdomain), const_cast<char*> (msg) }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); data.trn = ran_trn; data.com = com; data.value = i; parser = gnc_transaction_sixtp_parser_create (); if (!gnc_xml_parse_file (parser, filename1, test_add_transaction, (gpointer)&data, book)) { failure_args ("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", i); } else really_get_rid_of_transaction (data.new_trn); } /* no handling of circular data structures. We'll do that later */ /* sixtp_destroy(parser); */ g_unlink (filename1); g_free (filename1); really_get_rid_of_transaction (ran_trn); xmlFreeNode (test_node); } }
static void gnc_plugin_business_cmd_test_init_data (GtkAction *action, GncMainWindowActionData *data) { QofBook *book = gnc_get_current_book(); GncCustomer *customer = gncCustomerCreate(book); GncAddress *address = gncCustomerGetAddr(customer); GncInvoice *invoice = gncInvoiceCreate(book); GncOwner *owner = gncOwnerNew(); GncJob *job = gncJobCreate(book); Account *root = gnc_book_get_root_account(book); Account *inc_acct = xaccMallocAccount(book); Account *bank_acct = xaccMallocAccount(book); Account *tax_acct = xaccMallocAccount(book); Account *ar_acct = xaccMallocAccount(book); Timespec now; // Create Customer gncCustomerSetID(customer, "000001"); gncCustomerSetName(customer, "Test Customer"); gncCustomerSetCurrency(customer, gnc_default_currency()); gncAddressSetName(address, "Contact Person"); gncAddressSetAddr1(address, "20 Customer Lane"); gncAddressSetAddr2(address, "Customer M/S"); gncAddressSetAddr3(address, "Addr3, XXX 12345"); // Create the Owner gncOwnerInitCustomer(owner, customer); // Create the Invoice timespecFromTime64(&now, time(NULL)); gncInvoiceSetID(invoice, "000012"); gncInvoiceSetOwner(invoice, owner); gncInvoiceSetDateOpened(invoice, now); gncInvoiceSetCurrency(invoice, gnc_default_currency()); // Create the Job gncJobSetID(job, "000025"); gncJobSetName(job, "Test Job"); gncJobSetReference(job, "Customer's ref#"); gncJobSetOwner(job, owner); // MODIFY THE OWNER gncOwnerInitJob(owner, job); // Create the A/R account xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE); xaccAccountSetName(ar_acct, "A/R"); xaccAccountSetCommodity(ar_acct, gnc_default_currency()); gnc_account_append_child(root, ar_acct); // Create the Income account xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME); xaccAccountSetName(inc_acct, "Income"); xaccAccountSetCommodity(inc_acct, gnc_default_currency()); gnc_account_append_child(root, inc_acct); // Create the Bank account xaccAccountSetType(bank_acct, ACCT_TYPE_BANK); xaccAccountSetName(bank_acct, "Bank"); xaccAccountSetCommodity(bank_acct, gnc_default_currency()); gnc_account_append_child(root, bank_acct); // Create the Tax account xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY); xaccAccountSetName(tax_acct, "Tax-Holding"); xaccAccountSetCommodity(tax_acct, gnc_default_currency()); gnc_account_append_child(root, tax_acct); // Launch the invoice editor gnc_ui_invoice_edit (GTK_WINDOW (data->window), invoice); }
static void test_transaction(void) { int i; for (i = 0; i < 50; i++) { Transaction *ran_trn; Account *root; xmlNodePtr test_node; gnc_commodity *com, *new_com; gchar *compare_msg; gchar *filename1; int fd; /* The next line exists for its side effect of creating the * account tree. */ root = get_random_account_tree(book); ran_trn = get_random_transaction(book); new_com = get_random_commodity( book ); if (!ran_trn) { failure_args("transaction_xml", __FILE__, __LINE__, "get_random_transaction returned NULL"); return; } { /* xaccAccountInsertSplit can reorder the splits. */ GList * list = g_list_copy(xaccTransGetSplitList (ran_trn)); GList * node = list; for ( ; node; node = node->next) { Split * s = node->data; Account * a = xaccMallocAccount(book); xaccAccountBeginEdit (a); xaccAccountSetCommodity( a, new_com ); xaccAccountSetCommoditySCU (a, xaccSplitGetAmount (s).denom); xaccAccountInsertSplit (a, s); xaccAccountCommitEdit (a); } g_list_free(list); } com = xaccTransGetCurrency (ran_trn); test_node = gnc_transaction_dom_tree_create(ran_trn); if (!test_node) { failure_args("transaction_xml", __FILE__, __LINE__, "gnc_transaction_dom_tree_create returned NULL"); really_get_rid_of_transaction(ran_trn); continue; } if ((compare_msg = node_and_transaction_equal(test_node, ran_trn)) != NULL) { failure_args("transaction_xml", __FILE__, __LINE__, "node and transaction were not equal: %s", compare_msg); xmlElemDump(stdout, NULL, test_node); printf("\n"); fflush(stdout); xmlFreeNode(test_node); really_get_rid_of_transaction(ran_trn); continue; } else { success_args("transaction_xml", __FILE__, __LINE__, "%d", i ); } filename1 = g_strdup_printf("test_file_XXXXXX"); fd = g_mkstemp(filename1); write_dom_node_to_file(test_node, fd); close(fd); { GList * node = xaccTransGetSplitList (ran_trn); for ( ; node; node = node->next) { Split * s = node->data; Account * a1 = xaccSplitGetAccount(s); Account * a2 = xaccMallocAccount(book); xaccAccountBeginEdit (a2); xaccAccountSetCommoditySCU (a2, xaccAccountGetCommoditySCU (a1)); xaccAccountSetGUID (a2, xaccAccountGetGUID (a1)); xaccAccountCommitEdit (a2); } } { sixtp *parser; tran_data data; data.trn = ran_trn; data.com = com; data.value = i; g_print(" There will follow a bunch of CRIT scrub errors about the account not having a commodity. There isn't an account in the XML, so of course not. Ignore the errors\n"); parser = gnc_transaction_sixtp_parser_create(); if (!gnc_xml_parse_file(parser, filename1, test_add_transaction, (gpointer)&data, book)) { failure_args("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", i); } else really_get_rid_of_transaction (data.new_trn); /* no handling of circular data structures. We'll do that later */ /* sixtp_destroy(parser); */ } g_unlink(filename1); g_free(filename1); really_get_rid_of_transaction(ran_trn); xmlFreeNode(test_node); } }