mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
2001-10-12 Dave Peticolas <dave@krondo.com>
* src/test-core/test-stuff.c (get_random_string_without): new func * src/engine/test-core/test-engine-stuff.c (get_random_kvp_frame_depth): fix bug (get_random_session): new func * src/engine/Account.c (xaccAccountEqual): more warnings, use gnc_commodity_equal * src/engine/Group.c (xaccGroupEqual): more warnings * src/engine/Transaction.c: use gnc_commodity_equal * src/engine/gnc-book.c (gnc_book_equal): compare commodity tables * src/engine/gnc-commodity.c (gnc_commodity_equal): new func (gnc_commodity_table_equal): new func * src/engine/gnc-session.c (gnc_session_begin): destroy old backend * src/backend/postgres/test/.cvsignore: ignore test files * src/backend/postgres/test/Makefile.am: add file backend .la to get symbols for gdb * src/backend/postgres/test/run-tests.sh: remove test files before starting test * src/backend/postgres/test/test-db.c: when books differ, write out xml files * src/backend/file/test/test-xml-account.c (test_add_account): fix for strong commodity equal test git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5581 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
028f272249
commit
1506523cf6
36
ChangeLog
36
ChangeLog
@ -1,3 +1,39 @@
|
||||
2001-10-12 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/test-core/test-stuff.c (get_random_string_without): new func
|
||||
|
||||
* src/engine/test-core/test-engine-stuff.c
|
||||
(get_random_kvp_frame_depth): fix bug
|
||||
(get_random_session): new func
|
||||
|
||||
* src/engine/Account.c (xaccAccountEqual): more warnings, use
|
||||
gnc_commodity_equal
|
||||
|
||||
* src/engine/Group.c (xaccGroupEqual): more warnings
|
||||
|
||||
* src/engine/Transaction.c: use gnc_commodity_equal
|
||||
|
||||
* src/engine/gnc-book.c (gnc_book_equal): compare commodity tables
|
||||
|
||||
* src/engine/gnc-commodity.c (gnc_commodity_equal): new func
|
||||
(gnc_commodity_table_equal): new func
|
||||
|
||||
* src/engine/gnc-session.c (gnc_session_begin): destroy old backend
|
||||
|
||||
* src/backend/postgres/test/.cvsignore: ignore test files
|
||||
|
||||
* src/backend/postgres/test/Makefile.am: add file backend .la
|
||||
to get symbols for gdb
|
||||
|
||||
* src/backend/postgres/test/run-tests.sh: remove test files
|
||||
before starting test
|
||||
|
||||
* src/backend/postgres/test/test-db.c: when books differ, write
|
||||
out xml files
|
||||
|
||||
* src/backend/file/test/test-xml-account.c (test_add_account):
|
||||
fix for strong commodity equal test
|
||||
|
||||
2001-10-11 Rob Browning <rlb@defaultvalue.org>
|
||||
|
||||
* configure.in: require at least g-wrap 1.3.1.
|
||||
|
@ -194,7 +194,22 @@ typedef struct act_data_struct act_data;
|
||||
static gboolean
|
||||
test_add_account(const char *tag, gpointer globaldata, gpointer data)
|
||||
{
|
||||
Account *account = data;
|
||||
act_data *gdata = (act_data*)globaldata;
|
||||
gnc_commodity * com;
|
||||
gnc_commodity * new_com;
|
||||
gnc_commodity_table *t;
|
||||
|
||||
com = xaccAccountGetCommodity (account);
|
||||
|
||||
t = gnc_book_get_commodity_table (gnc_session_get_book (session));
|
||||
|
||||
new_com = gnc_commodity_table_lookup (t,
|
||||
gnc_commodity_get_namespace (com),
|
||||
gnc_commodity_get_mnemonic (com));
|
||||
|
||||
if (new_com)
|
||||
xaccAccountSetCommodity (account, new_com);
|
||||
|
||||
do_test_args(xaccAccountEqual((Account*)data, (Account*)(gdata->act),
|
||||
TRUE),
|
||||
|
@ -4,3 +4,4 @@ Makefile.in
|
||||
gnc_test
|
||||
test-db
|
||||
test-escape
|
||||
test_file_*
|
||||
|
@ -24,6 +24,7 @@ LDADD = -L${top_srcdir}/src/gnc-module -L${top_srcdir}/src/gnc-module/.libs \
|
||||
${top_srcdir}/src/engine/libgw-kvp.la \
|
||||
${top_srcdir}/src/engine/test-core/libgncmod-test-engine.la \
|
||||
${top_srcdir}/src/backend/postgres/libgncmod-backend-postgres.la \
|
||||
${top_srcdir}/src/backend/file/libgncmod-backend-file.la \
|
||||
-lltdl
|
||||
|
||||
CFLAGS = \
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
EXIT_VALUE=0
|
||||
|
||||
rm -f test_file_*
|
||||
./db-control.sh create
|
||||
|
||||
./db-control.sh start
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Backend.h"
|
||||
#include "TransLog.h"
|
||||
@ -12,34 +13,69 @@
|
||||
#include "test-stuff.h"
|
||||
#include "test-engine-stuff.h"
|
||||
|
||||
static void
|
||||
save_xml_file (GNCSession *session, const char *filename_base)
|
||||
{
|
||||
GNCBackendError io_err;
|
||||
char cwd[1024];
|
||||
char *filename;
|
||||
|
||||
g_return_if_fail (session && filename);
|
||||
|
||||
getcwd (cwd, sizeof (cwd));
|
||||
|
||||
filename = g_strdup_printf ("file:/%s/%s", cwd, filename_base);
|
||||
|
||||
gnc_session_begin (session, filename, FALSE, TRUE);
|
||||
|
||||
io_err = gnc_session_get_error (session);
|
||||
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
|
||||
|
||||
gnc_session_save (session);
|
||||
io_err = gnc_session_get_error (session);
|
||||
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
|
||||
|
||||
gnc_session_end (session);
|
||||
io_err = gnc_session_get_error (session);
|
||||
g_return_if_fail (io_err == ERR_BACKEND_NO_ERR);
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
save_xml_files (GNCSession *session_1, GNCSession *session_2)
|
||||
{
|
||||
g_return_if_fail (session_1 && session_2);
|
||||
|
||||
save_xml_file (session_1, "test_file_1");
|
||||
save_xml_file (session_2, "test_file_2");
|
||||
}
|
||||
|
||||
static void
|
||||
run_test (void)
|
||||
{
|
||||
GNCBook *book;
|
||||
GNCBook *book_db;
|
||||
GNCSession *session;
|
||||
GNCSession *session_db;
|
||||
GNCBackendError io_err;
|
||||
char *filename;
|
||||
gboolean ok;
|
||||
|
||||
session = gnc_session_new ();
|
||||
|
||||
book = get_random_book (session);
|
||||
|
||||
gnc_session_set_book (session, book);
|
||||
session = get_random_session ();
|
||||
|
||||
filename = g_strdup ("postgres://localhost:7777/gnc_test?mode=single-file");
|
||||
gnc_session_begin (session, filename, FALSE, TRUE);
|
||||
|
||||
gnc_session_begin (session, filename, FALSE, TRUE);
|
||||
io_err = gnc_session_get_error (session);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning gnc_test"))
|
||||
return;
|
||||
|
||||
gnc_session_save (session);
|
||||
io_err = gnc_session_get_error (session);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Saving gnc_test"))
|
||||
return;
|
||||
|
||||
gnc_session_end (session);
|
||||
io_err = gnc_session_get_error (session);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test"))
|
||||
return;
|
||||
|
||||
@ -49,23 +85,29 @@ run_test (void)
|
||||
session_db = gnc_session_new ();
|
||||
|
||||
gnc_session_begin (session_db, filename, FALSE, FALSE);
|
||||
g_free (filename);
|
||||
|
||||
io_err = gnc_session_get_error (session_db);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Beginning gnc_test load"))
|
||||
return;
|
||||
|
||||
gnc_session_load (session_db);
|
||||
io_err = gnc_session_get_error (session_db);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Loading gnc_test"))
|
||||
return;
|
||||
|
||||
gnc_session_end (session_db);
|
||||
io_err = gnc_session_get_error (session_db);
|
||||
if (!do_test (io_err == ERR_BACKEND_NO_ERR, "Ending gnc_test load"))
|
||||
return;
|
||||
|
||||
book_db = gnc_session_get_book (session_db);
|
||||
ok = gnc_book_equal (gnc_session_get_book (session),
|
||||
gnc_session_get_book (session_db));
|
||||
|
||||
do_test (gnc_book_equal (book, book_db), "Books not equal");
|
||||
do_test (ok, "Books not equal");
|
||||
|
||||
if (!ok)
|
||||
save_xml_files (session, session_db);
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -87,8 +129,6 @@ guile_main (int argc, char **argv)
|
||||
set_max_group_depth (3);
|
||||
set_max_group_accounts (5);
|
||||
|
||||
random_character_include_funky_chars (FALSE);
|
||||
|
||||
xaccLogDisable ();
|
||||
|
||||
run_test ();
|
||||
|
@ -403,7 +403,7 @@ xaccAccountEqual(Account *aa, Account *ab, gboolean check_guids)
|
||||
|
||||
if (aa->type != ab->type)
|
||||
{
|
||||
PWARN ("types differ");
|
||||
PWARN ("types differ: %d vs %d", aa->type, ab->type);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -425,7 +425,7 @@ xaccAccountEqual(Account *aa, Account *ab, gboolean check_guids)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_equiv(aa->commodity, ab->commodity))
|
||||
if (!gnc_commodity_equal(aa->commodity, ab->commodity))
|
||||
{
|
||||
PWARN ("commodities differ");
|
||||
return FALSE;
|
||||
|
@ -125,7 +125,14 @@ xaccGroupEqual(AccountGroup *ga,
|
||||
|
||||
if (!xaccAccountEqual(aa, ab, check_guids))
|
||||
{
|
||||
PWARN ("accounts differ");
|
||||
char sa[GUID_ENCODING_LENGTH + 1];
|
||||
char sb[GUID_ENCODING_LENGTH + 1];
|
||||
|
||||
guid_to_string_buff (xaccAccountGetGUID (aa), sa);
|
||||
guid_to_string_buff (xaccAccountGetGUID (ab), sb);
|
||||
|
||||
PWARN ("accounts %s and %s differ", sa, sb);
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
@ -862,7 +862,7 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb,
|
||||
}
|
||||
}
|
||||
|
||||
if(!gnc_commodity_equiv(ta->common_currency, tb->common_currency))
|
||||
if(!gnc_commodity_equal(ta->common_currency, tb->common_currency))
|
||||
{
|
||||
PWARN ("commodities differ %s vs %s",
|
||||
gnc_commodity_get_unique_name (ta->common_currency),
|
||||
|
@ -326,6 +326,13 @@ gnc_book_equal (GNCBook *book_1, GNCBook *book_2)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_table_equal (gnc_book_get_commodity_table (book_1),
|
||||
gnc_book_get_commodity_table (book_2)))
|
||||
{
|
||||
PWARN ("commodity tables differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* FIXME: do scheduled transactions and template group */
|
||||
|
||||
return TRUE;
|
||||
|
@ -33,7 +33,9 @@
|
||||
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "guid.h"
|
||||
|
||||
static short module = MOD_ENGINE;
|
||||
|
||||
/* parts per unit is nominal, i.e. number of 'partname' units in
|
||||
* a 'unitname' unit. fraction is transactional, i.e. how many
|
||||
@ -317,6 +319,51 @@ gnc_commodity_equiv(const gnc_commodity * a, const gnc_commodity * b) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b)
|
||||
{
|
||||
if (a == b) return TRUE;
|
||||
|
||||
if (!a || !b)
|
||||
{
|
||||
PWARN ("one is NULL");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->namespace, b->namespace) != 0)
|
||||
{
|
||||
PWARN ("namespaces differ: %s vs %s", a->namespace, b->namespace);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->mnemonic, b->mnemonic) != 0)
|
||||
{
|
||||
PWARN ("mnemonics differ: %s vs %s", a->mnemonic, b->mnemonic);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->fullname, b->fullname) != 0)
|
||||
{
|
||||
PWARN ("fullnames differ: %s vs %s", a->fullname, b->fullname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->exchange_code, b->exchange_code) != 0)
|
||||
{
|
||||
PWARN ("exchange codes differ: %s vs %s",
|
||||
a->exchange_code, b->exchange_code);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->fraction != b->fraction)
|
||||
{
|
||||
PWARN ("fractions differ: %d vs %d", a->fraction, b->fraction);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* gnc_commodity_table_new
|
||||
@ -767,4 +814,40 @@ gnc_commodity_table_destroy(gnc_commodity_table * t) {
|
||||
g_free(t);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
table_equal_helper (gnc_commodity *cm_1, gpointer user_data)
|
||||
{
|
||||
gnc_commodity_table *t_2 = user_data;
|
||||
gnc_commodity *cm_2;
|
||||
|
||||
cm_2 = gnc_commodity_table_lookup (t_2,
|
||||
gnc_commodity_get_namespace (cm_1),
|
||||
gnc_commodity_get_mnemonic (cm_1));
|
||||
|
||||
if (!cm_2)
|
||||
{
|
||||
PWARN ("one has commodity %s, the other does not",
|
||||
gnc_commodity_get_unique_name (cm_1));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return gnc_commodity_equal (cm_1, cm_2);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_commodity_table_equal(gnc_commodity_table *t_1,
|
||||
gnc_commodity_table *t_2)
|
||||
{
|
||||
gboolean ok;
|
||||
|
||||
if (t_1 == t_2) return TRUE;
|
||||
if (!t_1 || !t_2) return FALSE;
|
||||
|
||||
ok = gnc_commodity_table_foreach_commodity (t_1, table_equal_helper, t_2);
|
||||
if (!ok)
|
||||
return FALSE;
|
||||
|
||||
return gnc_commodity_table_foreach_commodity (t_2, table_equal_helper, t_1);
|
||||
}
|
||||
|
||||
/* ========================= END OF FILE ============================== */
|
||||
|
@ -65,13 +65,17 @@ void gnc_commodity_set_fraction(gnc_commodity * cm, int smallest_fraction);
|
||||
void gnc_commodity_set_mark(gnc_commodity * cm, gint16 mark);
|
||||
|
||||
gboolean gnc_commodity_equiv(const gnc_commodity * a, const gnc_commodity * b);
|
||||
|
||||
gboolean gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b);
|
||||
|
||||
/* gnc_commodity_table functions : operate on a database of commodity
|
||||
* info */
|
||||
|
||||
gnc_commodity_table * gnc_commodity_table_new(void);
|
||||
void gnc_commodity_table_destroy(gnc_commodity_table * table);
|
||||
|
||||
gboolean gnc_commodity_table_equal(gnc_commodity_table *t_1,
|
||||
gnc_commodity_table *t_2);
|
||||
|
||||
gnc_commodity * gnc_commodity_table_lookup(const gnc_commodity_table * table,
|
||||
const char * namespace,
|
||||
const char * mnemonic);
|
||||
|
@ -238,7 +238,7 @@ gnc_session_load_backend(GNCSession * session, char * backend_name)
|
||||
|
||||
gboolean
|
||||
gnc_session_begin (GNCSession *session, const char * book_id,
|
||||
gboolean ignore_lock, gboolean create_if_nonexistent)
|
||||
gboolean ignore_lock, gboolean create_if_nonexistent)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -279,6 +279,18 @@ gnc_session_begin (GNCSession *session, const char * book_id,
|
||||
session->logpath = xaccResolveFilePath(session->fullpath);
|
||||
PINFO ("logpath=%s", session->logpath ? session->logpath : "(null)");
|
||||
|
||||
/* destroy the old backend */
|
||||
if (session->backend && session->backend->destroy_backend)
|
||||
{
|
||||
session->backend->destroy_backend(session->backend);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free(session->backend);
|
||||
}
|
||||
|
||||
session->backend = NULL;
|
||||
|
||||
/* check to see if this is a type we know how to handle */
|
||||
if (!g_strncasecmp(book_id, "file:", 5) ||
|
||||
*session->fullpath == '/')
|
||||
|
@ -262,8 +262,8 @@ get_random_kvp_frame_depth (gint depth)
|
||||
{
|
||||
gchar *key;
|
||||
kvp_value *val;
|
||||
|
||||
key = get_random_string();
|
||||
|
||||
key = get_random_string_without("/");
|
||||
val = get_random_kvp_value_depth (-1, depth + 1);
|
||||
|
||||
if(!key)
|
||||
@ -837,3 +837,18 @@ get_random_book (GNCSession *session)
|
||||
|
||||
return book;
|
||||
}
|
||||
|
||||
GNCSession *
|
||||
get_random_session (void)
|
||||
{
|
||||
GNCSession *session;
|
||||
GNCBook *book;
|
||||
|
||||
session = gnc_session_new ();
|
||||
|
||||
book = gnc_session_get_book (session);
|
||||
|
||||
gnc_book_set_group (book, get_random_group (session));
|
||||
|
||||
return session;
|
||||
}
|
||||
|
@ -50,5 +50,6 @@ const char *get_random_commodity_namespace(void);
|
||||
Query* get_random_query(void);
|
||||
|
||||
GNCBook * get_random_book (GNCSession *session);
|
||||
GNCSession * get_random_session (void);
|
||||
|
||||
#endif
|
||||
|
@ -234,13 +234,13 @@ gchar
|
||||
get_random_character(void)
|
||||
{
|
||||
if (!rcend)
|
||||
random_character_include_funky_chars (FALSE);
|
||||
random_character_include_funky_chars (TRUE);
|
||||
|
||||
return random_chars[get_random_int_in_range(0, rcend)];
|
||||
}
|
||||
|
||||
gchar*
|
||||
get_random_string(void)
|
||||
gchar *
|
||||
get_random_string_without(const char *exclude_chars)
|
||||
{
|
||||
gchar *ret;
|
||||
int len;
|
||||
@ -264,14 +264,27 @@ get_random_string(void)
|
||||
}
|
||||
ret = g_new0(gchar, len);
|
||||
|
||||
for(i = 0; i < len - 1; i++)
|
||||
for (i = 0; i < len - 1; i++)
|
||||
{
|
||||
ret[i] = get_random_character();
|
||||
char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = get_random_character ();
|
||||
} while (exclude_chars && strchr (exclude_chars, c));
|
||||
|
||||
ret[i] = c;
|
||||
}
|
||||
|
||||
return g_strstrip (ret);
|
||||
}
|
||||
|
||||
gchar *
|
||||
get_random_string(void)
|
||||
{
|
||||
return get_random_string_without (NULL);
|
||||
}
|
||||
|
||||
gint64
|
||||
get_random_gint64(void)
|
||||
{
|
||||
|
@ -123,6 +123,7 @@ gint get_random_int_in_range(int start, int end);
|
||||
void random_character_include_funky_chars (gboolean use_funky_chars);
|
||||
gchar get_random_character(void);
|
||||
gchar* get_random_string(void);
|
||||
gchar* get_random_string_without(const char *exclude_chars);
|
||||
gint64 get_random_gint64(void);
|
||||
double get_random_double(void);
|
||||
const char* get_random_string_in_array(const char* str_list[]);
|
||||
|
Loading…
Reference in New Issue
Block a user