mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[Engine Unit Testing] Unit tests for Account.c
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21525 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -39,13 +39,11 @@
|
||||
#include "gnc-lot.h"
|
||||
#include "gnc-pricedb.h"
|
||||
|
||||
#define GNC_ID_ROOT_ACCOUNT "RootAccount"
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_ACCOUNT;
|
||||
|
||||
/* The Canonical Account Separator. Pre-Initialized. */
|
||||
static gchar account_separator[8] = ".";
|
||||
gunichar account_uc_separator = ':';
|
||||
static gunichar account_uc_separator = ':';
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -88,76 +86,6 @@ enum
|
||||
PROP_SORT_ORDER,
|
||||
};
|
||||
|
||||
typedef struct AccountPrivate
|
||||
{
|
||||
/* The accountName is an arbitrary string assigned by the user.
|
||||
* It is intended to a short, 5 to 30 character long string that
|
||||
* is displayed by the GUI as the account mnemonic.
|
||||
*/
|
||||
char *accountName;
|
||||
|
||||
/* The accountCode is an arbitrary string assigned by the user.
|
||||
* It is intended to be reporting code that is a synonym for the
|
||||
* accountName. Typically, it will be a numeric value that follows
|
||||
* the numbering assignments commonly used by accountants, such
|
||||
* as 100, 200 or 600 for top-level accounts, and 101, 102.. etc.
|
||||
* for detail accounts.
|
||||
*/
|
||||
char *accountCode;
|
||||
|
||||
/* The description is an arbitrary string assigned by the user.
|
||||
* It is intended to be a longer, 1-5 sentence description of what
|
||||
* this account is all about.
|
||||
*/
|
||||
char *description;
|
||||
|
||||
/* The type field is the account type, picked from the enumerated
|
||||
* list that includes ACCT_TYPE_BANK, ACCT_TYPE_STOCK,
|
||||
* ACCT_TYPE_CREDIT, ACCT_TYPE_INCOME, etc. Its intended use is to
|
||||
* be a hint to the GUI as to how to display and format the
|
||||
* transaction data.
|
||||
*/
|
||||
GNCAccountType type;
|
||||
|
||||
/*
|
||||
* The commodity field denotes the kind of 'stuff' stored
|
||||
* in this account. The 'amount' field of a split indicates
|
||||
* how much of the 'stuff' there is.
|
||||
*/
|
||||
gnc_commodity * commodity;
|
||||
int commodity_scu;
|
||||
gboolean non_standard_scu;
|
||||
|
||||
/* The parent and children pointers are used to implement an account
|
||||
* hierarchy, of accounts that have sub-accounts ("detail accounts").
|
||||
*/
|
||||
Account *parent; /* back-pointer to parent */
|
||||
GList *children; /* list of sub-accounts */
|
||||
|
||||
/* protected data - should only be set by backends */
|
||||
gnc_numeric starting_balance;
|
||||
gnc_numeric starting_cleared_balance;
|
||||
gnc_numeric starting_reconciled_balance;
|
||||
|
||||
/* cached parameters */
|
||||
gnc_numeric balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
|
||||
gboolean balance_dirty; /* balances in splits incorrect */
|
||||
|
||||
GList *splits; /* list of split pointers */
|
||||
gboolean sort_dirty; /* sort order of splits is bad */
|
||||
|
||||
LotList *lots; /* list of lot pointers */
|
||||
GNCPolicy *policy; /* Cached pointer to policy method */
|
||||
|
||||
/* The "mark" flag can be used by the user to mark this account
|
||||
* in any way desired. Handy for specialty traversals of the
|
||||
* account tree. */
|
||||
short mark;
|
||||
} AccountPrivate;
|
||||
|
||||
#define GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_ACCOUNT, AccountPrivate))
|
||||
|
||||
@@ -921,7 +849,7 @@ gnc_account_get_book(const Account *account)
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
static Account *
|
||||
Account *
|
||||
gnc_coll_get_root_account (QofCollection *col)
|
||||
{
|
||||
if (!col) return NULL;
|
||||
@@ -1153,7 +1081,9 @@ xaccFreeAccount (Account *acc)
|
||||
xaccSplitDestroy (s);
|
||||
}
|
||||
g_list_free(slist);
|
||||
/* Nothing here (or in xaccAccountCommitEdit) NULLs priv->splits, so this asserts every time.
|
||||
g_assert(priv->splits == NULL);
|
||||
*/
|
||||
}
|
||||
|
||||
CACHE_REPLACE(priv->accountName, NULL);
|
||||
@@ -4980,4 +4910,28 @@ gboolean xaccAccountRegister (void)
|
||||
return qof_object_register (&account_object_def);
|
||||
}
|
||||
|
||||
/* ======================= UNIT TESTING ACCESS =======================
|
||||
* The following functions are for unit testing use only.
|
||||
*/
|
||||
static AccountPrivate*
|
||||
utest_account_get_private (Account *acc)
|
||||
{
|
||||
return GET_PRIVATE (acc);
|
||||
}
|
||||
|
||||
AccountTestFunctions*
|
||||
_utest_account_fill_functions(void)
|
||||
{
|
||||
AccountTestFunctions* func = g_new(AccountTestFunctions, 1);
|
||||
|
||||
func->get_private = utest_account_get_private;
|
||||
func->coll_get_root_account = gnc_coll_get_root_account;
|
||||
func->xaccFreeAccountChildren = xaccFreeAccountChildren;
|
||||
func->xaccFreeAccount = xaccFreeAccount;
|
||||
func->qofAccountSetParent = qofAccountSetParent;
|
||||
func->gnc_account_lookup_by_full_name_helper =
|
||||
gnc_account_lookup_by_full_name_helper;
|
||||
|
||||
return func;
|
||||
}
|
||||
/* ======================= END OF FILE =========================== */
|
||||
|
||||
@@ -164,6 +164,7 @@ typedef enum
|
||||
* for now, see NUM_ACCOUNT_TYPES */
|
||||
ACCT_TYPE_CREDITLINE = 18, /**< line of credit -- don't use this for
|
||||
* now, see NUM_ACCOUNT_TYPES */
|
||||
ACCT_TYPE_LAST
|
||||
} GNCAccountType;
|
||||
|
||||
|
||||
@@ -204,13 +205,14 @@ void xaccAccountDestroy (Account *account);
|
||||
gboolean xaccAccountEqual(const Account *a, const Account* b,
|
||||
gboolean check_guids);
|
||||
|
||||
/** The xaccAccountOrder() subroutine defines a sorting order
|
||||
* on accounts. It takes pointers to two accounts, and
|
||||
* returns -1 if the first account is "less than" the second,
|
||||
* returns +1 if the first is "greater than" the second, and
|
||||
* 0 if they are equal. To determine the sort order, first
|
||||
* the account codes are compared, and if these are equal, then
|
||||
* account types, and, if these are equal, the account names.
|
||||
/** The xaccAccountOrder() subroutine defines a sorting order on
|
||||
* accounts. It takes pointers to two accounts, and returns an int < 0 if
|
||||
* the first account is "less than" the second, returns an int > 0 if the
|
||||
* first is "greater than" the second, and 0 if they are equal. To
|
||||
* determine the sort order, first the account codes are compared,
|
||||
* and if these are equal, then account types, then account
|
||||
* names. If still equal, it compares GUID to ensure that there
|
||||
* aren't any ties.
|
||||
*/
|
||||
int xaccAccountOrder (const Account *account_1, const Account *account_2);
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
|
||||
#include "Account.h"
|
||||
|
||||
#define GNC_ID_ROOT_ACCOUNT "RootAccount"
|
||||
|
||||
/** STRUCTS *********************************************************/
|
||||
|
||||
/** This is the data that describes an account.
|
||||
@@ -50,6 +52,76 @@
|
||||
*/
|
||||
|
||||
/** \struct Account */
|
||||
typedef struct AccountPrivate
|
||||
{
|
||||
/* The accountName is an arbitrary string assigned by the user.
|
||||
* It is intended to a short, 5 to 30 character long string that
|
||||
* is displayed by the GUI as the account mnemonic.
|
||||
*/
|
||||
char *accountName;
|
||||
|
||||
/* The accountCode is an arbitrary string assigned by the user.
|
||||
* It is intended to be reporting code that is a synonym for the
|
||||
* accountName. Typically, it will be a numeric value that follows
|
||||
* the numbering assignments commonly used by accountants, such
|
||||
* as 100, 200 or 600 for top-level accounts, and 101, 102.. etc.
|
||||
* for detail accounts.
|
||||
*/
|
||||
char *accountCode;
|
||||
|
||||
/* The description is an arbitrary string assigned by the user.
|
||||
* It is intended to be a longer, 1-5 sentence description of what
|
||||
* this account is all about.
|
||||
*/
|
||||
char *description;
|
||||
|
||||
/* The type field is the account type, picked from the enumerated
|
||||
* list that includes ACCT_TYPE_BANK, ACCT_TYPE_STOCK,
|
||||
* ACCT_TYPE_CREDIT, ACCT_TYPE_INCOME, etc. Its intended use is to
|
||||
* be a hint to the GUI as to how to display and format the
|
||||
* transaction data.
|
||||
*/
|
||||
GNCAccountType type;
|
||||
|
||||
/*
|
||||
* The commodity field denotes the kind of 'stuff' stored
|
||||
* in this account. The 'amount' field of a split indicates
|
||||
* how much of the 'stuff' there is.
|
||||
*/
|
||||
gnc_commodity * commodity;
|
||||
int commodity_scu;
|
||||
gboolean non_standard_scu;
|
||||
|
||||
/* The parent and children pointers are used to implement an account
|
||||
* hierarchy, of accounts that have sub-accounts ("detail accounts").
|
||||
*/
|
||||
Account *parent; /* back-pointer to parent */
|
||||
GList *children; /* list of sub-accounts */
|
||||
|
||||
/* protected data - should only be set by backends */
|
||||
gnc_numeric starting_balance;
|
||||
gnc_numeric starting_cleared_balance;
|
||||
gnc_numeric starting_reconciled_balance;
|
||||
|
||||
/* cached parameters */
|
||||
gnc_numeric balance;
|
||||
gnc_numeric cleared_balance;
|
||||
gnc_numeric reconciled_balance;
|
||||
|
||||
gboolean balance_dirty; /* balances in splits incorrect */
|
||||
|
||||
GList *splits; /* list of split pointers */
|
||||
gboolean sort_dirty; /* sort order of splits is bad */
|
||||
|
||||
LotList *lots; /* list of lot pointers */
|
||||
GNCPolicy *policy; /* Cached pointer to policy method */
|
||||
|
||||
/* The "mark" flag can be used by the user to mark this account
|
||||
* in any way desired. Handy for specialty traversals of the
|
||||
* account tree. */
|
||||
short mark;
|
||||
} AccountPrivate;
|
||||
|
||||
struct account_s
|
||||
{
|
||||
QofInstance inst;
|
||||
@@ -63,4 +135,19 @@ void xaccAccountSetGUID (Account *account, const GncGUID *guid);
|
||||
/* Register Accounts with the engine */
|
||||
gboolean xaccAccountRegister (void);
|
||||
|
||||
/* Structure for accessing static functions for testing */
|
||||
typedef struct
|
||||
{
|
||||
AccountPrivate *(*get_private) (Account *acc);
|
||||
Account *(*coll_get_root_account) (QofCollection *col);
|
||||
void (*xaccFreeAccountChildren) (Account *acc);
|
||||
void (*xaccFreeAccount) (Account *acc);
|
||||
void (*qofAccountSetParent) (Account *acc, QofInstance *parent);
|
||||
Account *(*gnc_account_lookup_by_full_name_helper) (const Account *acc,
|
||||
gchar **names);
|
||||
} AccountTestFunctions;
|
||||
|
||||
AccountTestFunctions* _utest_account_fill_functions(void);
|
||||
|
||||
|
||||
#endif /* XACC_ACCOUNT_P_H */
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
include $(top_srcdir)/test-templates/Makefile.decl
|
||||
|
||||
MODULEPATH = src/engine
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I${top_srcdir} \
|
||||
@@ -81,12 +84,36 @@ test_link_LDADD = ../libgncmod-engine.la \
|
||||
${top_builddir}/src/libqof/qof/libgnc-qof.la \
|
||||
${top_builddir}/src/core-utils/libgnc-core-utils.la
|
||||
|
||||
EXTRA_DIST = \
|
||||
EXTRA_DIST += \
|
||||
test-create-account \
|
||||
test-create-account.scm \
|
||||
test-scm-query-import \
|
||||
test-scm-query-import.scm
|
||||
|
||||
TEST_PROGS += test-engine
|
||||
|
||||
noinst_PROGRAMS = ${TEST_PROGS}
|
||||
|
||||
test_engine_SOURCES = \
|
||||
test-engine.c \
|
||||
utest-Account.c
|
||||
|
||||
test_engine_HEADERS = \
|
||||
${top_srcdir}/${MODULEPATH}/gnc-engine.h
|
||||
|
||||
test_enginedir = ${top_builddir}/${MODULEPATH}/test
|
||||
|
||||
test_engine_LDADD = \
|
||||
${top_builddir}/${MODULEPATH}/libgncmod-engine.la \
|
||||
${top_builddir}/src/test-core/libtest-core.la
|
||||
|
||||
|
||||
test_engine_CFLAGS = \
|
||||
${DEFAULT_INCLUDES} \
|
||||
-I${top_srcdir}/${MODULEPATH}/ \
|
||||
-DTESTPROG=test_engine \
|
||||
${GLIB_CFLAGS}
|
||||
|
||||
clean-local:
|
||||
rm -f translog.*
|
||||
|
||||
|
||||
46
src/engine/test/test-engine.c
Normal file
46
src/engine/test/test-engine.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/********************************************************************
|
||||
* testmain.c: GLib g_test test execution file. *
|
||||
* Copyright 2011 John Ralls <jralls@ceridwen.us> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
#include "qof.h"
|
||||
|
||||
extern void test_suite_account();
|
||||
//extern void test_suite_transaction();
|
||||
//extern void test_suite_split();
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
g_type_init(); /* Initialize the GObject system */
|
||||
g_test_init ( &argc, &argv, NULL ); /* initialize test program */
|
||||
qof_log_init_filename_special("stderr"); /* Init the log system */
|
||||
g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */
|
||||
|
||||
test_suite_account();
|
||||
// test_suite_transaction();
|
||||
// test_suite_split();
|
||||
|
||||
return g_test_run( );
|
||||
}
|
||||
2430
src/engine/test/utest-Account.c
Normal file
2430
src/engine/test/utest-Account.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ test_qof_SOURCES = \
|
||||
test-qofobject.c \
|
||||
test-qofsession.c
|
||||
|
||||
test_qof_HEADERSS = \
|
||||
test_qof_HEADERS = \
|
||||
$(top_srcdir)/${MODULEPATH}/qofbook.h \
|
||||
$(top_srcdir)/${MODULEPATH}/qofinstance.h \
|
||||
$(top_srcdir)/${MODULEPATH}/kvp_frame.h \
|
||||
@@ -26,6 +26,7 @@ test_qof_HEADERSS = \
|
||||
TEST_PROGS += test-qof
|
||||
|
||||
noinst_PROGRAMS = ${TEST_PROGS}
|
||||
test_qofdir = ${top_builddir}/${MODULEPATH}/test
|
||||
|
||||
#The tests might require more libraries, but try to keep them
|
||||
#as independent as possible.
|
||||
|
||||
Reference in New Issue
Block a user