Ejemplo n.º 1
0
xmlNodePtr
gnc_book_dom_tree_create(QofBook *book)
{
    xmlNodePtr ret;
    G_GNUC_UNUSED gboolean allow_incompat = TRUE;

    ret = xmlNewNode(NULL, BAD_CAST gnc_book_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST gnc_v2_book_version_string);

    xmlAddChild(ret, guid_to_dom_tree(book_id_string,
                                      qof_book_get_guid(book)));

    if (qof_instance_get_slots (QOF_INSTANCE (book)))
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
                             qof_instance_get_slots (QOF_INSTANCE (book)));
        if (kvpnode)
            xmlAddChild(ret, kvpnode);
    }

#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
    /* theoretically, we should be adding all the below to the book
     * but in fact, there's enough brain damage in the code already
     * that we are only going to hand-edit the file at a higher layer.
     * And that's OK, since its probably a performance boost anyway.
     */
    xmlAddChild(ret, gnc_commodity_dom_tree_create(
                    gnc_commodity_table_get_table(book)));
    xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_pricedb_get_db(book)));
    if (allow_incompat)
    {
        accnode = gnc_account_dom_tree_create(account, FALSE);
        xmlAddChild (ret, rootAccNode);
    }
    append_account_tree (ret, gnc_book_get_root(book));

    xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
                                       traverse_txns, ret);

    /* xxx FIXME hack alert how are we going to handle
     *  gnc_book_get_template_group handled ???   */
    xmlAddChild(ret, gnc_schedXaction_dom_tree_create(
                    gnc_book_get_schedxactions(book)));

#endif

    return ret;
}
Ejemplo n.º 2
0
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);
    }
}