コード例 #1
0
ファイル: test-dbi-stuff.c プロジェクト: nishmu/gnucash
/* Given a synthetic session, use the same logic as
 * QofSession::save_as to save it to a specified sql url, then load it
 * back and compare. */
void
test_dbi_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
{
    QofSession* session_2;
    QofSession* session_3;

    gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
    gchar *log_domain = "gnc.backend.dbi";
    guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
    TestErrorStruct check = { loglevel, log_domain, msg };

    g_test_message ( "Testing %s\n", driver );

    // Save the session data
    session_2 = qof_session_new();
    hdlr = g_log_set_handler (log_domain, loglevel,
			       (GLogFunc)test_checked_handler, &check);
    qof_session_begin( session_2, url, FALSE, TRUE, TRUE );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_2), qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Creation Failed");
        return;
    }
    qof_session_swap_data( session_1, session_2 );
    qof_session_save( session_2, NULL );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Save Failed");
        return;
    }

    // Reload the session data
    session_3 = qof_session_new();
    qof_session_begin( session_3, url, TRUE, FALSE, FALSE );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DB Session Creation Failed");
        return;
    }
    qof_session_load( session_3, NULL );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DBI Session Load Failed");
        return;
    }
    // Compare with the original data
    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
    qof_session_end( session_1 );
    qof_session_destroy( session_1 );
    qof_session_end( session_2 );
    qof_session_destroy( session_2 );
    qof_session_end( session_3 );
    qof_session_destroy( session_3 );
    g_log_remove_handler (log_domain, hdlr);
}
コード例 #2
0
/* Given an already-created url (yeah, bad testing practice: Should
 * start fresh from a synthetic session) load and safe-save it, then
 * load it again into a new session and compare the two. Since
 * safe-save is a more-or-less atomic function call, there's no way to
 * be sure that it's actually doing what it's supposed to without
 * running this test in a debugger and stopping in the middle of the
 * safe-save and inspecting the database. */
void
test_dbi_safe_save( const gchar* driver,  const gchar* url )
{
    QofSession *session_1 = NULL, *session_2 = NULL;

    printf( "Testing safe save %s\n", driver );

    // Load the session data
    session_1 = qof_session_new();
    qof_session_begin( session_1, url, TRUE, FALSE, FALSE );
    if (session_1 && qof_session_get_error(session_1) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_1),
                  qof_session_get_error_message(session_1));
        do_test( FALSE, "DB Session Creation Failed");
        goto cleanup;
    }
    qof_session_load( session_1, NULL );
    /* Do a safe save */
    qof_session_safe_save( session_1, NULL );
    if (session_1 && qof_session_get_error(session_1) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_1));
        do_test( FALSE, "DB Session Safe Save Failed");
        goto cleanup;
    }
    /* Destroy the session and reload it */

    session_2 = qof_session_new();
    qof_session_begin( session_2, url, TRUE, FALSE, FALSE );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_2),
                  qof_session_get_error_message(session_2));
        do_test( FALSE, "DB Session re-creation Failed");
        goto cleanup;
    }
    qof_session_load( session_2, NULL );
    compare_books( qof_session_get_book( session_1 ),
                   qof_session_get_book( session_2 ) );

cleanup:
    if (session_2 != NULL)
    {
        qof_session_end( session_2 );
        qof_session_destroy( session_2 );
    }
    if (session_1 != NULL)
    {
        qof_session_end( session_1 );
        qof_session_destroy( session_1 );
    }
    return;
}
コード例 #3
0
/* Given a synthetic session, use the same logic as
 * QofSession::save_as to save it to a specified sql url, then load it
 * back and compare. */
void
test_dbi_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
{
    QofSession* session_2;
    QofSession* session_3;

    printf( "Testing %s\n", driver );

    // Save the session data
    session_2 = qof_session_new();
    qof_session_begin( session_2, url, FALSE, TRUE, TRUE );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(session_2), qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Creation Failed");
        return;
    }
    qof_session_swap_data( session_1, session_2 );
    qof_session_save( session_2, NULL );
    if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_2));
        do_test( FALSE, "First DB Session Save Failed");
        return;
    }

    // Reload the session data
    session_3 = qof_session_new();
    qof_session_begin( session_3, url, TRUE, FALSE, FALSE );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DB Session Creation Failed");
        return;
    }
    qof_session_load( session_3, NULL );
    if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %s", qof_session_get_error_message(session_3));
        do_test( FALSE, "Second DBI Session Load Failed");
        return;
    }
    // Compare with the original data
    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
    qof_session_end( session_1 );
    qof_session_destroy( session_1 );
    qof_session_end( session_2 );
    qof_session_destroy( session_2 );
    g_print(" You may ignore the warning about the lock file having no entries: We had to ignore locking to run two sessions on the same database\n");
    qof_session_end( session_3 );
    qof_session_destroy( session_3 );
}
コード例 #4
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
static void
qof_instance_coll_copy(QofInstance *original, gpointer user_data)
{
    QofInstanceCopyData *qecd;
    QofBook *book;
    QofInstance *inst;
    const GncGUID *g;

    g_return_if_fail(original != NULL);
    g_return_if_fail(user_data != NULL);
    qecd = (QofInstanceCopyData*)user_data;
    book = qof_session_get_book(qecd->new_session);
    if (!qof_object_compliance(original->e_type, TRUE))
    {
        return;
    }
    inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
    qecd->to = inst;
    qecd->from = original;
    g = qof_instance_get_guid(original);
    qof_instance_set_guid(qecd->to, g);
    qof_begin_edit(inst);
    g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
    qof_commit_edit(inst);
}
コード例 #5
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
gboolean
qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
{
    QofInstanceCopyData qecd;

    g_return_val_if_fail(new_session, FALSE);
    if (!entity_coll)
    {
        return FALSE;
    }
    qof_event_suspend();
    qecd.param_list = NULL;
    qecd.new_session = new_session;
    qof_book_set_partial(qof_session_get_book(qecd.new_session));
    qof_collection_foreach(entity_coll, qof_instance_coll_foreach, &qecd);
    qof_class_param_foreach(qof_collection_get_type(entity_coll),
                            qof_instance_param_cb, &qecd);
    qof_collection_foreach(entity_coll, qof_instance_coll_copy, &qecd);
    if (qecd.param_list != NULL)
    {
        g_slist_free(qecd.param_list);
    }
    qof_event_resume();
    return TRUE;
}
コード例 #6
0
static void
gnc_plugin_business_cmd_export_employee (GtkAction *action, GncMainWindowActionData *mw)
{
    QofSession *current_session, *chart_session;
    QofBook *book;
    QofCollection *coll;
    gchar *filename;
    gboolean success;

    current_session = gnc_get_current_session();
    book = qof_session_get_book(current_session);
    chart_session = qof_session_new();
    success = FALSE;
    filename = gnc_file_dialog(_("Export Employees to XML"), NULL,
                               NULL, GNC_FILE_DIALOG_EXPORT);
    if (filename)
    {
        gchar* url = g_strdup_printf( "qsf:%s", filename );
        qof_session_begin(chart_session, url, TRUE, TRUE);
        coll = qof_book_get_collection(book, GNC_ID_EMPLOYEE);
        success = qof_instance_copy_coll_r(chart_session, coll);
        if (success)
        {
            qof_session_save(chart_session, NULL);
        }
        g_free(url);
    }
    show_session_error(qof_session_get_error(chart_session), filename,
                       GNC_FILE_DIALOG_EXPORT);
    qof_session_end(chart_session);
    g_free(filename);
    gnc_set_current_session(current_session);
}
コード例 #7
0
ファイル: test-guid.cpp プロジェクト: Bob-IT/gnucash
static void
run_test (void)
{
    int i;
    QofSession *sess;
    QofBook *book;
    QofInstance *ent;
    QofCollection *col;
    QofIdType type;
    GncGUID guid;

    sess = get_random_session ();
    book = qof_session_get_book (sess);
    do_test ((NULL != book), "book not created");

    col = qof_book_get_collection (book, "asdf");
    type = qof_collection_get_type (col);

    for (i = 0; i < NENT; i++)
    {
        ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, NULL));
        guid_replace(&guid);
        ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE,
                                                     "guid", &guid, NULL));
        do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
                 "duplicate guid");
        ent->e_type = type;
        qof_collection_insert_entity (col, ent);
        do_test ((NULL != qof_collection_lookup_entity (col, &guid)),
                 "guid not found");
    }

    /* Make valgrind happy -- destroy the session. */
    qof_session_destroy(sess);
}
コード例 #8
0
ファイル: test-load-xml2.c プロジェクト: nishmu/gnucash
static void
test_load_file(const char *filename)
{
    QofSession *session;
    QofBook *book;
    Account *root;
    gboolean ignore_lock;
    gchar *logdomain = "GConf";
    guint loglevel = G_LOG_LEVEL_WARNING;
    TestErrorStruct check = { loglevel, logdomain, NULL };
    g_log_set_handler (logdomain, loglevel,
		       (GLogFunc)test_checked_handler, &check);

    session = qof_session_new();

    remove_locks(filename);

    ignore_lock = (safe_strcmp(g_getenv("SRCDIR"), ".") != 0);
    qof_session_begin(session, filename, ignore_lock, FALSE, TRUE);

    qof_session_load(session, NULL);
    book = qof_session_get_book (session);

    root = gnc_book_get_root_account(book);
    do_test (gnc_account_get_book (root) == book,
             "book and root account don't match");

    do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
                 "session load xml2", __FILE__, __LINE__,
                 "qof error=%d for file [%s]",
                 qof_session_get_error(session), filename);
    /* Uncomment the line below to generate corrected files */
    qof_session_save( session, NULL );
    qof_session_end(session);
}
コード例 #9
0
ファイル: test-lots.cpp プロジェクト: CAARNICL/gnucash
static void
run_test (void)
{
    QofSession *sess;
    QofBook *book;
    Account *root;

    /* --------------------------------------------------------- */
    /* In the first test, we will merely try to see if we can run
     * without crashing.  We don't check to see if data is good. */
    sess = get_random_session ();
    book = qof_session_get_book (sess);
    do_test ((NULL != book), "create random data");

    add_random_transactions_to_book (book, transaction_num);

    root = gnc_book_get_root_account (book);
    xaccAccountTreeScrubLots (root);

    /* --------------------------------------------------------- */
    /* In the second test, we create an account with unrealized gains,
     * and see if that gets fixed correctly, with the correct balances,
     * and etc.
     * XXX not implemented
     */
    success ("automatic lot scrubbing lightly tested and seem to work");
    qof_session_end (sess);

}
コード例 #10
0
int
main (int argc, char** argv)
{
    QofSession* session;

    qof_init ();
    cashobjects_register ();
    session = qof_session_new ();
    sixbook = qof_session_get_book (session);
    if (argc > 1)
    {
        test_files_in_dir (argc, argv, test_real_account,
                           gnc_account_sixtp_parser_create (),
                           "gnc:account", sixbook);
    }
    else
    {
        test_generation ();
    }

    qof_session_destroy (session);
    print_test_results ();
    qof_close ();
    exit (get_rv ());
}
コード例 #11
0
static void
run_test (void)
{
    Account *act1;
    Account *act2;
    //Split *spl;
    QofSession *session;
    QofBook *book;

    session = qof_session_new ();
    book = qof_session_get_book (session);

    act1 = get_random_account(book);
    do_test(act1 != NULL, "random account created");

    act2 = get_random_account(book);
    do_test(act2 != NULL, "random account created");
#if 0
    spl = get_random_split(book, act1, NULL);
    do_test(spl != NULL, "random split created");

    do_test(act1 == xaccSplitGetAccount(spl), "xaccAccountInsertSplit()");
#endif
    //FIXME
    //xaccSplitSetAccount (spl, NULL);
    //do_test(xaccSplitGetAccount(spl) == NULL, "xaccAccountRemoveSplit()");
}
コード例 #12
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
gboolean qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent)
{
    struct recurse_s store;
    QofCollection *coll;
    gboolean success;

    if ((!new_session) || (!ent))
    {
        return FALSE;
    }
    store.session = new_session;
    success = TRUE;
    store.success = success;
    store.ref_list = qof_class_get_referenceList(ent->e_type);
    success = qof_instance_copy_to_session(new_session, ent);
    if (success == TRUE)
    {
        coll = qof_book_get_collection(qof_session_get_book(new_session), ent->e_type);
        if (coll)
        {
            qof_collection_foreach(coll, recurse_ent_cb, &store);
        }
    }
    return success;
}
コード例 #13
0
ファイル: test-recursive.c プロジェクト: nizarklai/gnucash-1
static void
test_recursion (QofSession *original, guint counter)
{
    QofSession *copy;
    QofCollection *grand_coll;
    struct tally c;
    QofBook *book;
    guint d, e, f;

    c.nulls = 0;
    c.total = 0;
    c.collect = 0;
    c.book = NULL;
    book = qof_session_get_book(original);
    grand_coll = qof_book_get_collection(book, GRAND_MODULE_NAME);
    copy = qof_session_new();
    if (debug)
    {
        /*         FIXME XML backend can't handle STDOUT
         *         qof_session_begin(copy, QOF_STDOUT, TRUE, FALSE); */
    }
    /* TODO: implement QOF_TYPE_CHOICE testing. */
    qof_instance_copy_coll_r(copy, grand_coll);
    /* test the original */
    qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c);
    book = qof_session_get_book(copy);
    /* test the copy */
    d = c.nulls;
    e = c.total;
    f = c.collect;
    c.nulls = 0;
    c.total = 0;
    c.collect = 0;
    c.book = book;
    qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c);
    do_test((d == c.nulls), "Null parents do not match");
    do_test((e == c.total), "Total parents do not match");
    do_test((f == c.collect), "Number of children in descendents does not match");
    if (counter == 4 && debug == TRUE)
    {
        /*      FIXME XML backend can't handle STDOUT
         *      qof_session_save(copy, NULL);
                qof_session_save(original, NULL); */
    }
    qof_session_end(copy);
    copy = NULL;
}
コード例 #14
0
static void
gnc_commodities_dialog_create (GtkWidget * parent, CommoditiesDialog *cd)
{
    GtkWidget *button;
    GtkWidget *scrolled_window;
    GtkBuilder *builder;
    GtkTreeView *view;
    GtkTreeSelection *selection;

    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-commodities.glade", "securities_dialog");

    cd->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "securities_dialog"));
    cd->session = gnc_get_current_session();
    cd->book = qof_session_get_book(cd->session);
    cd->show_currencies = gnc_prefs_get_bool(GNC_PREFS_GROUP, GNC_PREF_INCL_ISO);

    // Set the style context for this dialog so it can be easily manipulated with css
    gnc_widget_set_style_context (GTK_WIDGET(cd->dialog), "GncCommoditiesDialog");

    gtk_builder_connect_signals(builder, cd);

    /* parent */
    if (parent != NULL)
        gtk_window_set_transient_for (GTK_WINDOW (cd->dialog), GTK_WINDOW (parent));

    /* buttons */
    cd->remove_button = GTK_WIDGET(gtk_builder_get_object (builder, "remove_button"));
    cd->edit_button = GTK_WIDGET(gtk_builder_get_object (builder, "edit_button"));

    /* commodity tree */

    scrolled_window = GTK_WIDGET(gtk_builder_get_object (builder, "commodity_list_window"));
    view = gnc_tree_view_commodity_new(cd->book,
                                       "state-section", STATE_SECTION,
                                       "show-column-menu", TRUE,
                                       NULL);
    cd->commodity_tree = GNC_TREE_VIEW_COMMODITY(view);
    gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(cd->commodity_tree), TRUE);
    gnc_tree_view_commodity_set_filter (cd->commodity_tree,
                                        gnc_commodities_dialog_filter_ns_func,
                                        gnc_commodities_dialog_filter_cm_func,
                                        cd, NULL);
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
    g_signal_connect (G_OBJECT (selection), "changed",
                      G_CALLBACK (gnc_commodities_dialog_selection_changed), cd);

    g_signal_connect (G_OBJECT (cd->commodity_tree), "row-activated",
                      G_CALLBACK (row_activated_cb), cd);

    /* Show currency button */
    button = GTK_WIDGET(gtk_builder_get_object (builder, "show_currencies_button"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), cd->show_currencies);

    g_object_unref(G_OBJECT(builder));
    gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(cd->dialog), GTK_WINDOW(parent));
}
コード例 #15
0
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;
}
コード例 #16
0
static void
test_db (GNCPriceDB* db)
{
    xmlNodePtr test_node;
    gchar* filename1;
    int fd;
    QofBook* book = qof_instance_get_book (QOF_INSTANCE (db));

    test_node = gnc_pricedb_dom_tree_create (db);

    if (!test_node && db)
    {
        failure_args ("pricedb_xml", __FILE__, __LINE__,
                      "gnc_pricedb_dom_tree_create returned NULL");
        return;
    }

    if (!db)
        return;

    filename1 = g_strdup_printf ("test_file_XXXXXX");

    fd = g_mkstemp (filename1);

    write_dom_node_to_file (test_node, fd);

    close (fd);

    {
        sixtp *parser;
	load_counter lc = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        sixtp_gdv2 data = {book, lc, NULL, NULL, FALSE};

        parser = sixtp_new ();

        if (!sixtp_add_some_sub_parsers
            (parser, TRUE,
             "gnc:pricedb", gnc_pricedb_sixtp_parser_create (),
             NULL, NULL))
        {
            failure_args ("sixtp_add_some_sub_parsers failed",
                          __FILE__, __LINE__, "%d", iter);
        }
        else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb,
                                      (gpointer)&data,
                                      qof_session_get_book (session)))
        {
            failure_args ("gnc_xml_parse_file returned FALSE",
                          __FILE__, __LINE__, "%d", iter);
        }
    }

    g_unlink (filename1);
    g_free (filename1);
    xmlFreeNode (test_node);
}
コード例 #17
0
ファイル: gnucash-bin.c プロジェクト: cstim/gnucash-svn
static void
inner_main_add_price_quotes(void *closure, int argc, char **argv)
{
    SCM mod, add_quotes, scm_book, scm_result = SCM_BOOL_F;
    QofSession *session = NULL;

    scm_c_eval_string("(debug-set! stack 200000)");

    mod = scm_c_resolve_module("gnucash price-quotes");
    scm_set_current_module(mod);

    load_gnucash_modules();

    qof_event_suspend();
    scm_c_eval_string("(gnc:price-quotes-install-sources)");

    if (!gnc_quote_source_fq_installed())
    {
        g_print("%s", _("No quotes retrieved. Finance::Quote isn't "
                        "installed properly.\n"));
        goto fail;
    }

    add_quotes = scm_c_eval_string("gnc:book-add-quotes");
    session = gnc_get_current_session();
    if (!session) goto fail;

    qof_session_begin(session, add_quotes_file, FALSE, FALSE);
    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;

    qof_session_load(session, NULL);
    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;

    scm_book = gnc_book_to_scm(qof_session_get_book(session));
    scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book);

    qof_session_save(session, NULL);
    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;

    qof_session_destroy(session);
    if (!scm_is_true(scm_result))
    {
        g_warning("Failed to add quotes to %s.", add_quotes_file);
        goto fail;
    }

    qof_event_resume();
    gnc_shutdown(0);
    return;
fail:
    if (session && qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
        g_warning("Session Error: %s", qof_session_get_error_message(session));
    qof_event_resume();
    gnc_shutdown(1);
}
コード例 #18
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
/** \brief Adds a new reference to the partial book data hash.

Retrieves any existing reference list and appends the new reference.

If the book is not already marked as partial, it will be marked as
partial.
*/
static void
qof_session_update_reference_list(QofSession *session, QofInstanceReference *reference)
{
    QofBook  *book;
    GList    *book_ref_list;

    book = qof_session_get_book(session);
    book_ref_list = (GList*)qof_book_get_data(book, ENTITYREFERENCE);
    book_ref_list = g_list_append(book_ref_list, reference);
    qof_book_set_data(book, ENTITYREFERENCE, book_ref_list);
    qof_book_set_partial(book);
}
コード例 #19
0
ファイル: qofsession.cpp プロジェクト: Isendir/gnucash
/* XXX This exports the list of accounts to a file.  It does not
 * export any transactions.  It's a place-holder until full
 * book-closing is implemented.
 */
gboolean
qof_session_export (QofSession *tmp_session,
                    QofSession *real_session,
                    QofPercentageFunc percentage_func)
{
    QofBook *book, *book2;
    QofBackend *be;

    if ((!tmp_session) || (!real_session)) return FALSE;

    book = qof_session_get_book (real_session);
    ENTER ("tmp_session=%p real_session=%p book=%p book_id=%s",
           tmp_session, real_session, book,
           qof_session_get_url(tmp_session)
           ? qof_session_get_url(tmp_session) : "(null)");

    /* There must be a backend or else.  (It should always be the file
     * backend too.)
     */
    book2 = qof_session_get_book(tmp_session);
    be = qof_book_get_backend(book2);
    if (!be)
        return FALSE;

    be->percentage = percentage_func;
    if (be->export_fn)
    {
        int err;

        (be->export_fn)(be, book);
        err = qof_backend_get_error(be);

        if (ERR_BACKEND_NO_ERR != err)
        {
            return FALSE;
        }
    }

    return TRUE;
}
コード例 #20
0
ファイル: qofsession.cpp プロジェクト: Isendir/gnucash
void
qof_session_ensure_all_data_loaded (QofSession *session)
{
    QofBackend* backend;

    if (session == NULL) return;
    backend = qof_session_get_backend(session);
    if (backend == NULL) return;

    if (backend->load == NULL) return;
    backend->load(backend, qof_session_get_book(session), LOAD_TYPE_LOAD_ALL);
    qof_session_push_error (session, qof_backend_get_error(backend), NULL);
}
コード例 #21
0
ファイル: gnc-tree-view-owner.c プロジェクト: nishmu/gnucash
/** Select the row in the tree that was selected when the user last
 *  quit gnucash.  Its job is to map from owner name to tree row and
 *  select the row.
 *
 *  @param tree A pointer to the GncTreeViewOwner embedded.
 *
 *  @param owner_name A pointer to the full owner name. */
static void
tree_restore_selected_row (GncTreeViewOwner *view,
                           GncOwnerType owner_type,
                           const gchar *owner_guid_str)
{
    GncOwner *owner = gncOwnerNew();
    QofBook *book;
    GncGUID owner_guid;

    book = qof_session_get_book (gnc_get_current_session());
    if (string_to_guid (owner_guid_str, &owner_guid))
        if (gncOwnerGetOwnerFromTypeGuid (book, owner, gncOwnerTypeToQofIdType(owner_type), &owner_guid))
            gnc_tree_view_owner_set_selected_owner(view, owner);
}
コード例 #22
0
void
test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url )
{
    QofSession* session_2;
    QofSession* session_3;

    gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table";
    gchar *log_domain = "gnc.backend.dbi";
    guint loglevel = G_LOG_LEVEL_WARNING, hdlr;
    TestErrorStruct check = { loglevel, log_domain, msg };

    g_test_message ( "Testing %s\n", driver );

    // Save the session data
    session_2 = qof_session_new();
    qof_session_begin( session_2, url, FALSE, TRUE, TRUE );
    qof_session_swap_data( session_1, session_2 );
    qof_session_save( session_2, NULL );

    // Reload the session data
    session_3 = qof_session_new();
    qof_session_begin( session_3, url, TRUE, FALSE, FALSE );
    qof_session_load( session_3, NULL );

    // Compare with the original data
    compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) );
    qof_session_end( session_1 );
    qof_session_destroy( session_1 );
    qof_session_end( session_2 );
    qof_session_destroy( session_2 );

    hdlr = g_log_set_handler (log_domain, loglevel,
			      (GLogFunc)test_checked_handler, &check);
    qof_session_end( session_3 );
    g_log_remove_handler (log_domain, hdlr);
    qof_session_destroy( session_3 );
}
コード例 #23
0
ファイル: top-level.c プロジェクト: Gnucash/gnucash
/** Save all persistent program state to disk.  This function finds the
 *  name of the "new" state file associated with a specific book guid.
 *  It saves some top level data, then iterates through the list of
 *  open windows calling a helper function to save each window.
 *
 *  @note The name of the state file is based on the name of the data
 *  file, not the path name of the data file.  If there are multiple
 *  data files with the same name, the state files will be suffixed
 *  with a number.  E.G. test_account, test_account_2, test_account_3,
 *  etc.
 *
 *  @param session The QofSession whose state should be saved.
 *
 *  @param unused */
static void
gnc_save_all_state (gpointer session, gpointer unused)
{
    QofBook *book;
    gchar guid_string[GUID_ENCODING_LENGTH+1];
    const GncGUID *guid;
    GKeyFile *keyfile = NULL;

    keyfile = gnc_state_get_current ();
    if (keyfile)
    {
        /* Remove existing Window and Page groups from the keyfile
         * They will be regenerated.
         */
        gsize num_groups, curr;
        gchar **groups = g_key_file_get_groups (keyfile, &num_groups);
        for (curr=0; curr < num_groups; curr++)
        {
            if (g_str_has_prefix (groups[curr], "Window ") ||
                    g_str_has_prefix (groups[curr], "Page "))
            {
                DEBUG ("Removing state group %s", groups[curr]);
                g_key_file_remove_group (keyfile, groups[curr], NULL);
            }
        }
        g_strfreev (groups);
    }

    /* Store the book's GncGUID in the top level group */
    book = qof_session_get_book(session);
    guid = qof_entity_get_guid(QOF_INSTANCE(book));
    guid_to_string_buff(guid, guid_string);
    g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
                          guid_string);

    gnc_main_window_save_all_windows(keyfile);

#ifdef DEBUG
    /*  Debugging: dump a copy to the trace log */
    {
        gchar *file_data;
        gsize file_length;
        file_data = g_key_file_to_data(keyfile, &file_length, NULL);
        DEBUG("=== File Data Written===\n%s\n=== File End ===\n", file_data);
        g_free(file_data);
    }
#endif
    LEAVE("");
}
コード例 #24
0
ファイル: test-query.c プロジェクト: 573/gnucash
static void
run_test (void)
{
    QofSession *session;
    Account *root;
    QofBook *book;

    session = get_random_session ();
    book = qof_session_get_book (session);
    root = gnc_book_get_root_account (book);

    add_random_transactions_to_book (book, 20);

    xaccAccountTreeForEachTransaction (root, test_trans_query, book);

    qof_session_end (session);
}
コード例 #25
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
static void
qof_instance_list_foreach(gpointer data, gpointer user_data)
{
    QofInstanceCopyData *qecd;
    QofInstance *original;
    QofInstance *inst;
    QofBook *book;
    const GncGUID *g;

    g_return_if_fail(data != NULL);
    original = QOF_INSTANCE(data);
    g_return_if_fail(user_data != NULL);
    qecd = (QofInstanceCopyData*)user_data;
    if (qof_instance_guid_match(qecd->new_session, original))
    {
        return;
    }
    qecd->from = original;
    if (!qof_object_compliance(original->e_type, FALSE))
    {
        qecd->error = TRUE;
        return;
    }
    book = qof_session_get_book(qecd->new_session);
    inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
    if (!inst)
    {
        PERR (" failed to create new entity type=%s.", original->e_type);
        qecd->error = TRUE;
        return;
    }
    qecd->to = inst;
    g = qof_instance_get_guid(original);
    qof_instance_set_guid(qecd->to, g);
    if (qecd->param_list != NULL)
    {
        g_slist_free(qecd->param_list);
        qecd->param_list = NULL;
    }
    qof_class_param_foreach(original->e_type, qof_instance_param_cb, qecd);
    qof_begin_edit(inst);
    g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
    qof_commit_edit(inst);
}
コード例 #26
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
void
qof_session_safe_save(QofSession *session, QofPercentageFunc percentage_func)
{
    QofBackend *be = session->backend;
    gint err;
    char *msg = NULL;
    g_return_if_fail( be != NULL );
    g_return_if_fail( be->safe_sync != NULL );
    be->percentage = percentage_func;
    (be->safe_sync)( be, qof_session_get_book( session ));
    err = qof_backend_get_error(session->backend);
    msg = qof_backend_get_message(session->backend);
    if (err != ERR_BACKEND_NO_ERR)
    {
        g_free(session->book_id);
        session->book_id = NULL;
        qof_session_push_error (session, err, msg);
    }
}
コード例 #27
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
gboolean
qof_instance_copy_to_session(QofSession* new_session, QofInstance* original)
{
    QofInstanceCopyData qecd;
    QofInstance *inst;
    QofBook *book;

    if (!new_session || !original)
    {
        return FALSE;
    }
    if (qof_instance_guid_match(new_session, original))
    {
        return FALSE;
    }
    if (!qof_object_compliance(original->e_type, TRUE))
    {
        return FALSE;
    }
    qof_event_suspend();
    qecd.param_list = NULL;
    book = qof_session_get_book(new_session);
    qecd.new_session = new_session;
    qof_book_set_partial(book);
    inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
    qecd.to = inst;
    qecd.from = original;
    qof_instance_set_guid(qecd.to, qof_instance_get_guid(original));
    qof_begin_edit(inst);
    qof_class_param_foreach(original->e_type, qof_instance_param_cb, &qecd);
    qof_commit_edit(inst);
    if (g_slist_length(qecd.param_list) == 0)
    {
        return FALSE;
    }
    g_slist_foreach(qecd.param_list, qof_instance_foreach_copy, &qecd);
    g_slist_free(qecd.param_list);
    qof_event_resume();
    return TRUE;
}
コード例 #28
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
static void
qof_instance_coll_foreach(QofInstance *original, gpointer user_data)
{
    QofInstanceCopyData *qecd;
    const GncGUID *g;
    QofBook *targetBook;
    QofCollection *coll;
    QofInstance *copy;

    g_return_if_fail(original != NULL);
    g_return_if_fail(user_data != NULL);
    copy = NULL;
    qecd = (QofInstanceCopyData*)user_data;
    targetBook = qof_session_get_book(qecd->new_session);
    g = qof_instance_get_guid(original);
    coll = qof_book_get_collection(targetBook, original->e_type);
    copy = qof_collection_lookup_entity(coll, g);
    if (copy)
    {
        qecd->error = TRUE;
    }
}
コード例 #29
0
static void
test_generation (void)
{
    for (iter = 0; iter < 20; iter++)
    {
        GNCPriceDB* db;
        g_message ("iter=%d", iter);
        session = qof_session_new ();
        db = get_random_pricedb (qof_session_get_book (session));
        if (!db)
        {
            failure_args ("gnc_random_price_db returned NULL",
                          __FILE__, __LINE__, "%d", iter);
            return;
        }
        if (gnc_pricedb_get_num_prices (db))
            test_db (db);

        gnc_pricedb_destroy (db);
        qof_session_end (session);
    }
}
コード例 #30
0
ファイル: qofsession.c プロジェクト: kleopatra999/gnucash-2
static gboolean
qof_instance_guid_match(QofSession *new_session, QofInstance *original)
{
    QofInstance *copy;
    const GncGUID *g;
    QofIdTypeConst type;
    QofBook *targetBook;
    QofCollection *coll;

    copy = NULL;
    g_return_val_if_fail(original != NULL, FALSE);
    targetBook = qof_session_get_book(new_session);
    g_return_val_if_fail(targetBook != NULL, FALSE);
    g = qof_instance_get_guid(original);
    type = g_strdup(original->e_type);
    coll = qof_book_get_collection(targetBook, type);
    copy = qof_collection_lookup_entity(coll, g);
    if (copy)
    {
        return TRUE;
    }
    return FALSE;
}