示例#1
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;

    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
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);
}
示例#5
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);
}
示例#6
0
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);
}
示例#7
0
int main (int argc, char ** argv)
{
    gchar* filename;
    QofSession* session_1;

    qof_init();
    cashobjects_register();
    xaccLogDisable();
    qof_load_backend_library ("../.libs/", GNC_LIB_NAME);

    // Create a session with data
    session_1 = qof_session_new();
    qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE );
    qof_session_load( session_1, NULL );

    filename = tempnam( "/tmp", "test-sqlite3-" );
    printf( "Using filename: %s\n", filename );
    test_dbi_store_and_reload( "sqlite3", session_1, filename );

    printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL );
    if ( strlen( TEST_MYSQL_URL ) > 0 )
    {
        session_1 = qof_session_new();
        qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE );
        qof_session_load( session_1, NULL );
        test_dbi_store_and_reload( "mysql", session_1, TEST_MYSQL_URL );
    }

    printf( "TEST_PGSQL_URL='%s'\n", TEST_PGSQL_URL );
    if ( strlen( TEST_PGSQL_URL ) > 0 )
    {
        session_1 = qof_session_new();
        qof_session_begin( session_1, DBI_TEST_XML_FILENAME, FALSE, FALSE );
        qof_session_load( session_1, NULL );
        test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL );
    }
    print_test_results();
    qof_close();
    exit(get_rv());
}
示例#8
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 );
}
示例#9
0
文件: sqlite3test.c 项目: 573/gnucash
int main()
{
    qof_log_init();
    qof_init();
    gnc_module_system_init();
    char * no_args[1] = { NULL };
    gnc_engine_init(0, no_args);

    QofSession * s = qof_session_new();
    qof_session_begin(s, "sqlite3:///tmp/blah.gnucash", 0, 1, 0);
    qof_session_load(s, NULL);
    qof_session_save(s, NULL);
    qof_session_end(s);
    return 0;
}
示例#10
0
int main()
{
    const char* testurl = "sqlite3://" TESTFILE;
    qof_log_init();
    qof_init();
    gnc_module_system_init();
    char * no_args[1] = { NULL };
    gnc_engine_init(0, no_args);

    QofSession * s = qof_session_new();
    qof_session_begin(s, testurl, 0, 1, 0);
    qof_session_load(s, NULL);
    qof_session_save(s, NULL);
    qof_session_end(s);
    unlink(TESTFILE);
    return 0;
}
示例#11
0
/* Test the gnc_dbi_load logic that forces a newer database to be
 * opened read-only and an older one to be safe-saved. Again, it would
 * be better to do this starting from a fresh file, but instead we're
 * being lazy and using an existing one. */
void
test_dbi_version_control( const gchar* driver,  const gchar* url )
{

    QofSession *sess;
    QofBook *book;
    QofBackend *qbe;
    QofBackendError err;
    gint ourversion = gnc_get_long_version();

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

    // Load the session data
    sess = qof_session_new();
    qof_session_begin( sess, url, TRUE, FALSE, FALSE );
    if (sess && qof_session_get_error(sess) != ERR_BACKEND_NO_ERR)
    {
        g_warning("Session Error: %d, %s", qof_session_get_error(sess),
                  qof_session_get_error_message(sess));
        do_test( FALSE, "DB Session Creation Failed");
        goto cleanup;
    }
    qof_session_load( sess, NULL );
    qbe = qof_session_get_backend( sess );
    book = qof_session_get_book( sess );
    qof_book_begin_edit( book );
    gnc_sql_set_table_version( (GncSqlBackend*)qbe,
                               "Gnucash", GNUCASH_RESAVE_VERSION - 1 );
    qof_book_commit_edit( book );
    qof_session_end( sess );
    qof_session_destroy( sess );
    sess = qof_session_new();
    qof_session_begin( sess, url, TRUE, FALSE, FALSE );
    qof_session_load( sess, NULL );
    err = qof_session_pop_error( sess );
    do_test( err == ERR_SQL_DB_TOO_OLD, "DB Failed to flag too old" );
    qbe = qof_session_get_backend( sess );
    book = qof_session_get_book( sess );
    qof_book_begin_edit( book );
    gnc_sql_set_table_version( (GncSqlBackend*)qbe,
                               "Gnucash", ourversion );
    gnc_sql_set_table_version( (GncSqlBackend*)qbe,
                               "Gnucash-Resave", ourversion + 1 );
    qof_book_commit_edit( book );
    qof_session_end( sess );
    qof_session_destroy( sess );
    sess = qof_session_new();
    qof_session_begin( sess, url, TRUE, FALSE, FALSE );
    qof_session_load( sess, NULL );
    qof_session_ensure_all_data_loaded( sess );
    err = qof_session_pop_error( sess );
    do_test( err == ERR_SQL_DB_TOO_NEW, "DB Failed to flag too new" );
cleanup:
    qbe = qof_session_get_backend( sess );
    book = qof_session_get_book( sess );
    qof_book_begin_edit( book );
    gnc_sql_set_table_version( (GncSqlBackend*)qbe,
                               "Gnucash-Resave", GNUCASH_RESAVE_VERSION );
    qof_book_commit_edit( book );
    qof_session_end( sess );
    qof_session_destroy( sess );
}
示例#12
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;

    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 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:
    hdlr = g_log_set_handler (log_domain, loglevel,
			       (GLogFunc)test_checked_handler, &check);
    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 );
    }
    g_log_remove_handler (log_domain, hdlr);
    return;
}
示例#13
0
void
test_qofsession_aqb_kvp( void )
{
    /* load the accounts from the users datafile */
    /* but first, check to make sure we've got a session going. */
    QofBackendError io_err;
    char *file1 = get_filepath("file-book.gnucash");
    char *file2 = get_filepath("file-book-hbcislot.gnucash");

    if (1)
    {
        // A file with no content at all, but a valid XML file
        QofSession *new_session = qof_session_new ();
        char *newfile = g_strdup_printf("file://%s", file1);

        qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE);
        io_err = qof_session_get_error (new_session);
        //printf("io_err1 = %d\n", io_err);
        g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler

        g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist
        g_assert(io_err != ERR_BACKEND_LOCKED);
        g_assert(io_err == 0);

        qof_session_load (new_session, NULL);
        io_err = qof_session_get_error (new_session);
        //printf("io_err2 = %d\n", io_err);
        g_assert(io_err == 0);

        g_free(newfile);
        g_free(file1);

        gnc_hook_run(HOOK_BOOK_CLOSED, new_session);
        //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place
    }

    if (1)
    {
        // A file with no content except for the book_template_list kvp
        // slot
        QofSession *new_session = qof_session_new ();
        char *newfile = g_strdup_printf("file://%s", file2);

        qof_session_begin (new_session, newfile, TRUE, FALSE, FALSE);
        io_err = qof_session_get_error (new_session);
        //printf("io_err1 = %d\n", io_err);
        g_assert(io_err != ERR_BACKEND_NO_HANDLER); // Do not have no handler

        g_assert(io_err != ERR_BACKEND_NO_SUCH_DB); // DB must exist
        g_assert(io_err != ERR_BACKEND_LOCKED);
        g_assert(io_err == 0);

        qof_session_load (new_session, NULL);
        io_err = qof_session_get_error (new_session);
        //printf("io_err2 = %d\n", io_err);
        g_assert(io_err == 0);

        {
            GList *templ_list;
            GncABTransTempl *templ;
            QofBook *book = qof_session_get_book(new_session);
            const char* ORIGINAL_NAME = "Some Name";
            const char* CHANGED_NAME = "Some Changed Name";

            templ_list = gnc_ab_trans_templ_list_new_from_book (book);
            g_assert_cmpint(g_list_length(templ_list), ==, 1);

            templ = templ_list->data;
	    //Raise the edit level so that we can check that it's marked dirty.
	    qof_instance_increase_editlevel(QOF_INSTANCE(book));
	    g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here

            // Now we change the name into something else and verify it can be saved
            gnc_ab_trans_templ_set_name(templ, CHANGED_NAME);
            {
                g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty

                // Here we save the changed kvp
                gnc_ab_set_book_template_list(book, templ_list);
                g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty
                gnc_ab_trans_templ_list_free(templ_list);
            }

            {
                templ_list = gnc_ab_trans_templ_list_new_from_book (book);
                g_assert_cmpint(g_list_length(templ_list), ==, 1);

                templ = templ_list->data;
                g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved!
                gnc_ab_trans_templ_list_free(templ_list);
            }
        }

        {
            // Check the kvp slots of a aqbanking-enabled account
            QofBook *book = qof_session_get_book(new_session);
            Account* account = gnc_book_get_root_account(book);
            GDate retrieved_date, original_date;
            gchar buff[MAX_DATE_LENGTH];

            g_assert(account);

            // The interesting test case here: Can we read the correct date
            // from the xml file?
            if (1)
            {
                Timespec retrieved_ts = gnc_ab_get_account_trans_retrieval(account);
                g_test_message("retrieved_ts=%s\n", gnc_print_date(retrieved_ts));
                //printf("Time=%s\n", gnc_print_date(retrieved_ts));

                retrieved_date = timespec_to_gdate(retrieved_ts);
                g_date_set_dmy(&original_date, 29, 8, 2014);

                g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0);
            }

            // A lower-level test here: Can we write and read again the
            // trans_retrieval date? This wouldn't need this particular
            // Account, just a general Account object.
            if (0)
            {
                Timespec original_ts = timespec_now(), retrieved_ts;

                // Check whether the "ab-trans-retrieval" property of Account
                // is written and read again correctly.
                gnc_ab_set_account_trans_retrieval(account, original_ts);
                retrieved_ts = gnc_ab_get_account_trans_retrieval(account);

//                printf("original_ts=%s = %d  retrieved_ts=%s = %d\n",
//                       gnc_print_date(original_ts), original_ts.tv_sec,
//                       gnc_print_date(retrieved_ts), retrieved_ts.tv_sec);

                original_date = timespec_to_gdate(original_ts);
                retrieved_date = timespec_to_gdate(retrieved_ts);

                qof_print_gdate (buff, sizeof (buff), &original_date);
                //printf("original_date=%s\n", buff);
                qof_print_gdate (buff, sizeof (buff), &retrieved_date);
                //printf("retrieved_date=%s\n", buff);

                // Is the retrieved date identical to the one written
                g_assert_cmpint(g_date_compare(&retrieved_date, &original_date), ==, 0);
            }
示例#14
0
static void
test_employee (void)
{
    QofBackend *be;
    QofBook *book;
    QofSession *session;
    GncEmployee *employee;

    session = qof_session_new();
    qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
    book = qof_session_get_book(session);
    /* The book *must* have a backend to pass the test of the 'dirty' flag */
    /* See the README file for details */

    be = qof_book_get_backend (book);

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_new (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
#if 0
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
#endif
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (safe_strcmp (str, res) == 0, "Printable equals");
    }
}
示例#15
0
static gboolean
gxi_parse_file (GncXmlImportData *data)
{
    QofSession *session = NULL;
    QofBook *book;
    QofBackend *backend;
    QofBackendError io_err = ERR_BACKEND_NO_ERR;
    gchar *message = NULL;
    gboolean success = FALSE;

    if (data->n_unassigned || data->n_impossible)
        goto cleanup_parse_file;

    /* fill subst hash table with byte sequence substitutions */
    data->subst = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
    g_hash_table_foreach (data->ambiguous_ht, (GHFunc) subst_insert_amb, data);
    g_hash_table_foreach (data->unique, (GHFunc) subst_insert_unique, data);

    if (!data->subst)
        goto cleanup_parse_file;

    /* create a temporary QofSession */
    gxi_session_destroy (data);
    session = qof_session_new ();
    data->session = session;
    qof_session_begin (session, data->filename, TRUE, FALSE, FALSE);
    io_err = qof_session_get_error (session);
    if (io_err != ERR_BACKEND_NO_ERR)
    {
        message = _("The file could not be reopened.");
        goto cleanup_parse_file;
    }

    xaccLogDisable ();
    gxi_update_progress_bar (_("Reading file..."), 0.0);
    qof_session_load (session, gxi_update_progress_bar);
    gxi_update_progress_bar (NULL, -1.0);
    xaccLogEnable ();

    io_err = qof_session_get_error (session);
    if (io_err == ERR_BACKEND_NO_ERR)
    {
        /* loaded sucessfully now. strange, but ok */
        success = TRUE;
        goto cleanup_parse_file;
    }
    else if (io_err != ERR_FILEIO_NO_ENCODING)
    {
        /* another error, cannot handle this here */
        message = _("The file could not be reopened.");
        goto cleanup_parse_file;
    }

    qof_session_pop_error (session);
    book = qof_session_get_book (session);
    backend = qof_book_get_backend (book);

    gxi_update_progress_bar (_("Parsing file..."), 0.0);
    success = gnc_xml2_parse_with_subst (backend, book, data->subst);
    gxi_update_progress_bar (NULL, -1.0);

    if (success)
        data->session = session;
    else
        message = _("There was an error parsing the file.");

cleanup_parse_file:

    if (data->subst)
    {
        g_hash_table_destroy (data->subst);
        data->subst = NULL;
    }
    if (message)
    {
        gnc_error_dialog (data->assistant, "%s", message);
    }
    if (!success)
        gxi_session_destroy (data);

    return success;
}
示例#16
0
文件: Session.hpp 项目: 573/gnucash
 void begin(const QString& book_id, bool ignore_lock, bool create_if_nonexistent, bool force)
 {
     qof_session_begin(gobj(), book_id.toUtf8(), ignore_lock, create_if_nonexistent, force);
 }