static void test_dom_tree_to_commodity_ref(void) { int i; for (i = 0; i < 20; i++) { gnc_commodity *test_com1; gchar *test_str1; gchar *test_str2; gnc_commodity *test_com2; xmlNodePtr test_node; QofBook *book; book = qof_book_new (); test_str1 = get_random_string(); test_str2 = get_random_string(); test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0); test_node = commodity_ref_to_dom_tree("test-com", test_com1); test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book); do_test(gnc_commodity_equiv(test_com1, test_com2), "dom_tree_to_commodity_ref_no_engine"); xmlFreeNode(test_node); gnc_commodity_destroy(test_com1); gnc_commodity_destroy(test_com2); g_free(test_str1); g_free(test_str2); qof_book_destroy (book); } }
static void teardown( Fixture *fixture, gconstpointer pData ) { xaccAccountBeginEdit(fixture->account); xaccAccountDestroy(fixture->account); gnc_commodity_destroy(fixture->commodity); qof_book_destroy( fixture->book ); }
static gboolean test_real_commodity (const char* tag, gpointer globaldata, gpointer data) { const char* msg = node_and_commodity_equal ((xmlNodePtr)globaldata, (gnc_commodity*)data); do_test_args (msg == NULL, "test_real_commodity", __FILE__, __LINE__, msg); gnc_commodity_destroy ((gnc_commodity*)data); return TRUE; }
static gboolean gnc_commodity_end_handler(gpointer data_for_children, GSList* data_from_children, GSList* sibling_data, gpointer parent_data, gpointer global_data, gpointer *result, const gchar *tag) { gnc_commodity *com, *old_com; xmlNodePtr achild; xmlNodePtr tree = (xmlNodePtr)data_for_children; gxpf_data *gdata = (gxpf_data*)global_data; QofBook *book = static_cast<decltype(book)>(gdata->bookdata); if (parent_data) { return TRUE; } /* OK. For some messed up reason this is getting called again with a NULL tag. So we ignore those cases */ if (!tag) { return TRUE; } g_return_val_if_fail(tree, FALSE); com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0); old_com = gnc_commodity_find_currency(book, tree); if (old_com) gnc_commodity_copy(com, old_com); for (achild = tree->xmlChildrenNode; achild; achild = achild->next) { set_commodity_value(achild, com); } if (!valid_commodity(com)) { PWARN("Invalid commodity parsed"); xmlElemDump(stdout, NULL, tree); printf("\n"); fflush(stdout); gnc_commodity_destroy(com); return FALSE; } gdata->cb(tag, gdata->parsedata, com); xmlFreeNode(tree); return TRUE; }
static gboolean test_add_commodity (const char* tag, gpointer globaldata, gpointer data) { com_data* gdata = (com_data*)globaldata; do_test_args (gnc_commodity_equiv ((gnc_commodity*)data, gdata->com), "gnc_commodity_sixtp_parser_create", __FILE__, __LINE__, "%d", gdata->value); gnc_commodity_destroy ((gnc_commodity*)data); return TRUE; }
gboolean equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, QofBook *book) { gnc_commodity *cmpcom; g_return_val_if_fail(node, FALSE); g_return_val_if_fail(com, FALSE); cmpcom = dom_tree_to_commodity_ref_no_engine(node, book); g_return_val_if_fail(cmpcom, FALSE); if (gnc_commodity_equiv(com, cmpcom)) { gnc_commodity_destroy(cmpcom); return TRUE; } else { gnc_commodity_destroy(cmpcom); return FALSE; } }
static void remove_clicked (CommoditiesDialog *cd) { GNCPriceDB *pdb; GList *prices; gboolean can_delete; gnc_commodity *commodity; GtkWidget *dialog; const gchar *message, *warning; gint response; commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree); if (commodity == NULL) return; AccountList_t accounts = gnc_account_get_descendants (gnc_book_get_root_account(cd->book)); can_delete = TRUE; for (AccountList_t::const_iterator node = accounts.begin(); node != accounts.end(); node++) { Account *account = *node; if (commodity == xaccAccountGetCommodity (account)) { can_delete = FALSE; break; } } /* FIXME check for transaction references */ if (!can_delete) { const char *message = _("That commodity is currently used by " "at least one of your accounts. You may " "not delete it."); gnc_warning_dialog (cd->dialog, "%s", message); return; } pdb = gnc_pricedb_get_db (cd->book); prices = gnc_pricedb_get_prices(pdb, commodity, NULL); if (prices) { message = _("This commodity has price quotes. Are " "you sure you want to delete the selected " "commodity and its price quotes?"); warning = "delete_commodity2"; } else { message = _("Are you sure you want to delete the " "selected commodity?"); warning = "delete_commodity"; } dialog = gtk_message_dialog_new(GTK_WINDOW(cd->dialog), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", _("Delete commodity?")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", message); gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_DELETE, GTK_RESPONSE_OK, (gchar *)NULL); response = gnc_dialog_run(GTK_DIALOG(dialog), warning); gtk_widget_destroy(dialog); if (response == GTK_RESPONSE_OK) { gnc_commodity_table *ct; ct = gnc_commodity_table_get_table (cd->book); for (GList *node = prices; node; node = node->next) gnc_pricedb_remove_price(pdb, node->data); gnc_commodity_table_remove (ct, commodity); gnc_commodity_destroy (commodity); commodity = NULL; } gnc_price_list_destroy(prices); gnc_gui_refresh_all (); }
static void test_generation (void) { int i; for (i = 0; i < 20; i++) { gnc_commodity* ran_com; xmlNodePtr test_node; gchar* filename1; int fd; ran_com = get_random_commodity (book); test_node = gnc_commodity_dom_tree_create (ran_com); if (!test_node) { failure_args ("commodity_xml", __FILE__, __LINE__, "gnc_commodity_dom_tree_create returned NULL"); gnc_commodity_destroy (ran_com); continue; } auto compare_msg = node_and_commodity_equal (test_node, ran_com); if (compare_msg != nullptr) { failure_args ("commodity_xml", __FILE__, __LINE__, "node and commodity were not equal: %s", compare_msg); xmlElemDump (stdout, NULL, test_node); xmlFreeNode (test_node); gnc_commodity_destroy (ran_com); continue; } else { success_args ("commodity_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); { sixtp* parser; com_data data; data.com = ran_com; data.value = i; parser = gnc_commodity_sixtp_parser_create (); if (!gnc_xml_parse_file (parser, filename1, test_add_commodity, (gpointer)&data, book)) { failure_args ("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", i); } /* no handling of circular data structures. We'll do that later */ /* sixtp_destroy(parser); */ } g_unlink (filename1); g_free (filename1); gnc_commodity_destroy (ran_com); xmlFreeNode (test_node); } }