static gboolean
test_real_account (const char* tag, gpointer global_data, gpointer data)
{
    char* msg;
    Account* act = (Account*)data;

    if (!gnc_account_get_parent (act))
    {
        gnc_account_append_child (gnc_book_get_root_account (sixbook), act);
    }

    msg = node_and_account_equal ((xmlNodePtr)global_data, act);
    do_test_args (msg == NULL, "test_real_account",
                  __FILE__, __LINE__, msg);

    g_free (msg);
    return TRUE;
}
Example #2
0
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;
}
Example #3
0
static  gpointer
get_parent (gpointer pObject)
{
    const Account* pAccount;
    const Account* pParent;
    const GncGUID* parent_guid;

    g_return_val_if_fail (pObject != NULL, NULL);
    g_return_val_if_fail (GNC_IS_ACCOUNT (pObject), NULL);

    pAccount = GNC_ACCOUNT (pObject);
    pParent = gnc_account_get_parent (pAccount);
    if (pParent == NULL)
    {
        parent_guid = NULL;
    }
    else
    {
        parent_guid = qof_instance_get_guid (QOF_INSTANCE (pParent));
    }

    return (gpointer)parent_guid;
}
Example #4
0
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;
}
static gchar*
node_and_account_equal (xmlNodePtr node, Account* act)
{
    xmlNodePtr mark;

    while (g_strcmp0 ((char*)node->name, "text") == 0)
    {
        node = node->next;
    }

    if (!check_dom_tree_version (node, "2.0.0"))
    {
        return g_strdup ("version wrong.  Not 2.0.0 or not there");
    }

    if (!node->name || g_strcmp0 ((char*)node->name, "gnc:account"))
    {
        return g_strdup ("Name of toplevel node is bad");
    }

    for (mark = node->xmlChildrenNode; mark; mark = mark->next)
    {
        if (g_strcmp0 ((char*)mark->name, "text") == 0)
        {
        }
        else if (g_strcmp0 ((char*)mark->name, "act:name") == 0)
        {
            if (!equals_node_val_vs_string (mark, xaccAccountGetName (act)))
            {
                return g_strdup ("names differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:id") == 0)
        {
            if (!equals_node_val_vs_guid (mark, xaccAccountGetGUID (act)))
            {
                return g_strdup ("ids differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:type") == 0)
        {
            gchar* txt;
            GNCAccountType type;

            txt = dom_tree_to_text (mark);

            if (!txt)
            {
                return g_strdup ("couldn't get type string");
            }
            else if (!xaccAccountStringToType (txt, &type))
            {
                g_free (txt);
                return g_strdup ("couldn't convert type string to int");
            }
            else if (type != xaccAccountGetType (act))
            {
                g_free (txt);
                return g_strdup ("types differ");
            }
            else
            {
                g_free (txt);
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:commodity") == 0)
        {
            /* This is somewhat BS, because if the commodity isn't a
               currency (and therefore built in) there isn't a
               corresponding currency in the XML, skip the test. jralls
               2010-11-02 */
            if (xaccAccountGetCommodity (act) == NULL) continue;
            if (!equals_node_val_vs_commodity (
                    mark, xaccAccountGetCommodity (act),
                    gnc_account_get_book (act)))
            {
                return g_strdup ("commodities differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:code") == 0)
        {
            if (!equals_node_val_vs_string (mark, xaccAccountGetCode (act)))
            {
                return g_strdup ("codes differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:description") == 0)
        {
            if (!equals_node_val_vs_string (
                    mark, xaccAccountGetDescription (act)))
            {
                return g_strdup ("descriptions differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:slots") == 0)
        {
            /* xaccAccountDeleteOldData (act); */

            if (!equals_node_val_vs_kvp_frame (mark,
                                               qof_instance_get_slots (QOF_INSTANCE (act))))
            {
                return g_strdup ("slots differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:parent") == 0)
        {
            if (!equals_node_val_vs_guid (
                    mark, xaccAccountGetGUID (gnc_account_get_parent (act))))
            {
                return g_strdup ("parent ids differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:commodity-scu") == 0)
        {
            if (!equals_node_val_vs_int (mark, xaccAccountGetCommoditySCU (act)))
            {
                return g_strdup ("commodity scus differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:hidden") == 0)
        {
            if (!equals_node_val_vs_boolean (mark, xaccAccountGetHidden (act)))
            {
                return g_strdup ("Hidden flags differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:placeholder") == 0)
        {
            if (!equals_node_val_vs_boolean (mark, xaccAccountGetPlaceholder (act)))
            {
                return g_strdup ("Placeholder flags differ");
            }
        }
        else if (g_strcmp0 ((char*)mark->name, "act:security") == 0)
        {
            return NULL; // This tag is ignored.
        }
        else
        {
            return g_strdup_printf ("unknown node in dom tree: %s", mark->name);
        }
    }

    return NULL;
}