mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add functions to compare 2 business objects for equality, and use them in 'make check' tests.
Adds functions to compare 2 business objects for equality. The 'make check' tests can then use these functions to store and reload objects and compare them for equality. This allows the sql backend to be tested. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19028 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a9d83d7126
commit
3284ec4703
@ -597,6 +597,7 @@ int gncAddressCompare (const GncAddress *a, const GncAddress *b)
|
||||
gboolean
|
||||
gncAddressEqual(const GncAddress* a, const GncAddress* b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
|
||||
|
@ -693,6 +693,70 @@ int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b)
|
||||
return safe_strcmp (a->desc, b->desc);
|
||||
}
|
||||
|
||||
gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_BILLTERM(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_BILLTERM(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->name, b->name) != 0)
|
||||
{
|
||||
PWARN("Names differ: %s vs %s", a->name, b->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->desc, b->desc) != 0)
|
||||
{
|
||||
PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->type != b->type)
|
||||
{
|
||||
PWARN("Types differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->due_days != b->due_days)
|
||||
{
|
||||
PWARN("Due days differ: %d vs %d", a->due_days, b->due_days);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->disc_days != b->disc_days)
|
||||
{
|
||||
PWARN("Discount days differ: %d vs %d", a->disc_days, b->disc_days);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->discount, b->discount))
|
||||
{
|
||||
PWARN("Discounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->cutoff != b->cutoff)
|
||||
{
|
||||
PWARN("Cutoffs differ: %d vs %d", a->cutoff, b->cutoff);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->invisible != b->invisible)
|
||||
{
|
||||
PWARN("Invisible flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// gint64 refcount;
|
||||
// GncBillTerm * parent; /* if non-null, we are an immutable child */
|
||||
// GncBillTerm * child; /* if non-null, we have not changed */
|
||||
// GList * children; /* list of children for disconnection */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean gncBillTermIsDirty (const GncBillTerm *term)
|
||||
{
|
||||
if (!term) return FALSE;
|
||||
|
@ -144,6 +144,7 @@ gint64 gncBillTermGetRefcount (const GncBillTerm *term);
|
||||
/** @} */
|
||||
|
||||
int gncBillTermCompare (const GncBillTerm *a, const GncBillTerm *b);
|
||||
gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b);
|
||||
|
||||
/********************************************************/
|
||||
/* functions to compute dates from Bill Terms */
|
||||
|
@ -734,11 +734,66 @@ int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b)
|
||||
gboolean
|
||||
gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_CUSTOMER(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_CUSTOMER(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->name, b->name) != 0)
|
||||
{
|
||||
PWARN("Names differ: %s vs %s", a->name, b->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->notes, b->notes) != 0)
|
||||
{
|
||||
PWARN("Notes differ: %s vs %s", a->notes, b->notes);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncBillTermEqual(a->terms, b->terms))
|
||||
{
|
||||
PWARN("Bill terms differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_equal(a->currency, b->currency))
|
||||
{
|
||||
PWARN("currencies differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncTaxTableEqual(a->taxtable, b->taxtable))
|
||||
{
|
||||
PWARN("tax tables differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->taxtable_override != b->taxtable_override)
|
||||
{
|
||||
PWARN("Tax table override flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->taxincluded != b->taxincluded)
|
||||
{
|
||||
PWARN("Tax included flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncAddressEqual(a->addr, b->addr))
|
||||
{
|
||||
PWARN("addresses differ");
|
||||
@ -750,6 +805,22 @@ gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->credit, b->credit))
|
||||
{
|
||||
PWARN("Credit amounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->discount, b->discount))
|
||||
{
|
||||
PWARN("Discount amounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* FIXME: Need to check jobs list
|
||||
GList * jobs;
|
||||
*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -558,6 +558,77 @@ int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
|
||||
return(strcmp(a->username, b->username));
|
||||
}
|
||||
|
||||
gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL ) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->username, b->username) != 0)
|
||||
{
|
||||
PWARN("Usernames differ: %s vs %s", a->username, b->username);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncAddressEqual(a->addr, b->addr))
|
||||
{
|
||||
PWARN("Addresses differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_equal(a->currency, b->currency))
|
||||
{
|
||||
PWARN("Currencies differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->language, b->language) != 0)
|
||||
{
|
||||
PWARN("Languages differ: %s vs %s", a->language, b->language);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->acl, b->acl) != 0)
|
||||
{
|
||||
PWARN("ACLs differ: %s vs %s", a->acl, b->acl);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!xaccAccountEqual(a->ccard_acc, b->ccard_acc, TRUE))
|
||||
{
|
||||
PWARN("Accounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->workday, b->workday))
|
||||
{
|
||||
PWARN("Workdays differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->rate, b->rate))
|
||||
{
|
||||
PWARN("Rates differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Package-Private functions */
|
||||
|
||||
static const char * _gncEmployeePrintable (gpointer item)
|
||||
|
@ -105,6 +105,7 @@ static inline GncEmployee * gncEmployeeLookup (const QofBook *book, const GncGUI
|
||||
}
|
||||
|
||||
gboolean gncEmployeeIsDirty (const GncEmployee *employee);
|
||||
gboolean gncEmployeeEqual(const GncEmployee* e1, const GncEmployee* e2);
|
||||
|
||||
#define EMPLOYEE_ID "id"
|
||||
#define EMPLOYEE_USERNAME "username"
|
||||
|
@ -1420,6 +1420,116 @@ int gncEntryCompare (const GncEntry *a, const GncEntry *b)
|
||||
return qof_instance_guid_compare(a, b);
|
||||
}
|
||||
|
||||
#define CHECK_STRING(X, Y, FIELD) \
|
||||
if (safe_strcmp((X)->FIELD, (Y)->FIELD) != 0) \
|
||||
{ \
|
||||
PWARN("%s differ: %s vs %s", #FIELD, (X)->FIELD, (Y)->FIELD); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
#define CHECK_ACCOUNT(X, Y, FIELD) \
|
||||
if (!xaccAccountEqual((X)->FIELD, (Y)->FIELD, TRUE)) \
|
||||
{ \
|
||||
PWARN("%s differ", #FIELD); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
#define CHECK_NUMERIC(X, Y, FIELD) \
|
||||
if (!gnc_numeric_equal((X)->FIELD, (Y)->FIELD)) \
|
||||
{ \
|
||||
PWARN("%s differ", #FIELD); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
#define CHECK_VALUE(X, Y, FIELD) \
|
||||
if ((X)->FIELD != (Y)->FIELD) \
|
||||
{ \
|
||||
PWARN("%s differ", #FIELD); \
|
||||
return FALSE; \
|
||||
}
|
||||
|
||||
gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ENTRY(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_ENTRY(b), FALSE);
|
||||
|
||||
CHECK_STRING(a, b, desc);
|
||||
CHECK_STRING(a, b, action);
|
||||
CHECK_STRING(a, b, notes);
|
||||
CHECK_NUMERIC(a, b, quantity);
|
||||
|
||||
if (a->invoice != NULL)
|
||||
{
|
||||
CHECK_ACCOUNT(a, b, i_account);
|
||||
CHECK_NUMERIC(a, b, i_price);
|
||||
CHECK_VALUE(a, b, i_taxable);
|
||||
CHECK_VALUE(a, b, i_taxincluded);
|
||||
if (!gncTaxTableEqual(a->i_tax_table, b->i_tax_table))
|
||||
{
|
||||
PWARN("i_tax_table differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CHECK_NUMERIC(a, b, i_discount);
|
||||
CHECK_VALUE(a, b, i_disc_type);
|
||||
CHECK_VALUE(a, b, i_disc_how);
|
||||
CHECK_NUMERIC(a, b, i_value);
|
||||
CHECK_NUMERIC(a, b, i_value_rounded);
|
||||
CHECK_NUMERIC(a, b, i_tax_value);
|
||||
CHECK_NUMERIC(a, b, i_tax_value_rounded);
|
||||
CHECK_NUMERIC(a, b, i_disc_value);
|
||||
CHECK_NUMERIC(a, b, i_disc_value_rounded);
|
||||
|
||||
#if 0
|
||||
Timespec date;
|
||||
Timespec date_entered;
|
||||
|
||||
/* employee bill data */
|
||||
GncEntryPaymentType b_payment;
|
||||
|
||||
/* customer invoice */
|
||||
GList * i_tax_values;
|
||||
Timespec i_taxtable_modtime;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
if (a->bill != NULL)
|
||||
{
|
||||
CHECK_ACCOUNT(a, b, b_account);
|
||||
CHECK_NUMERIC(a, b, b_price);
|
||||
|
||||
CHECK_NUMERIC(a, b, b_value);
|
||||
CHECK_NUMERIC(a, b, b_value_rounded);
|
||||
CHECK_NUMERIC(a, b, b_tax_value);
|
||||
CHECK_NUMERIC(a, b, b_tax_value_rounded);
|
||||
#if 0
|
||||
Timespec date;
|
||||
Timespec date_entered;
|
||||
|
||||
/* vendor bill data */
|
||||
gboolean b_taxable;
|
||||
gboolean b_taxincluded;
|
||||
GncTaxTable * b_tax_table;
|
||||
gboolean billable;
|
||||
GncOwner billto;
|
||||
|
||||
/* employee bill data */
|
||||
GncEntryPaymentType b_payment;
|
||||
|
||||
/* vendor bill */
|
||||
GList * b_tax_values;
|
||||
Timespec b_taxtable_modtime;
|
||||
#endif
|
||||
}
|
||||
/* FIXME: Need real tests */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* Object declaration */
|
||||
|
||||
|
@ -231,6 +231,7 @@ gboolean gncEntryIsOpen (const GncEntry *entry);
|
||||
void gncEntryBeginEdit (GncEntry *entry);
|
||||
void gncEntryCommitEdit (GncEntry *entry);
|
||||
int gncEntryCompare (const GncEntry *a, const GncEntry *b);
|
||||
gboolean gncEntryEqual(const GncEntry *a, const GncEntry *b);
|
||||
|
||||
#define ENTRY_DATE "date"
|
||||
#define ENTRY_DATE_ENTERED "date-entered"
|
||||
|
@ -1897,6 +1897,97 @@ int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
|
||||
return qof_instance_guid_compare(a, b);
|
||||
}
|
||||
|
||||
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_INVOICE(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_INVOICE(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->notes, b->notes) != 0)
|
||||
{
|
||||
PWARN("Notes differ: %s vs %s", a->notes, b->notes);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->billing_id, b->billing_id) != 0)
|
||||
{
|
||||
PWARN("Billing IDs differ: %s vs %s", a->billing_id, b->billing_id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->printname, b->printname) != 0)
|
||||
{
|
||||
PWARN("Printnames differ: %s vs %s", a->printname, b->printname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncBillTermEqual(a->terms, b->terms))
|
||||
{
|
||||
PWARN("Billterms differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncJobEqual(a->job, b->job))
|
||||
{
|
||||
PWARN("Jobs differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_equal(a->currency, b->currency))
|
||||
{
|
||||
PWARN("Currencies differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!xaccAccountEqual(a->posted_acc, b->posted_acc, TRUE))
|
||||
{
|
||||
PWARN("Posted accounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!xaccTransEqual(a->posted_txn, b->posted_txn, TRUE, TRUE, TRUE, FALSE))
|
||||
{
|
||||
PWARN("Posted tx differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!gncLotEqual(a->posted_lot, b->posted_lot))
|
||||
{
|
||||
PWARN("Posted lots differ");
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* FIXME: Need real checks */
|
||||
#if 0
|
||||
GList *entries;
|
||||
GList *prices;
|
||||
GncOwner owner;
|
||||
GncOwner billto;
|
||||
Timespec date_opened;
|
||||
Timespec date_posted;
|
||||
|
||||
gnc_numeric to_charge_amount;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* Package-Private functions */
|
||||
|
||||
|
@ -193,6 +193,7 @@ static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID
|
||||
void gncInvoiceBeginEdit (GncInvoice *invoice);
|
||||
void gncInvoiceCommitEdit (GncInvoice *invoice);
|
||||
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
|
||||
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b);
|
||||
gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
|
||||
gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
|
||||
|
||||
|
@ -460,6 +460,46 @@ int gncJobCompare (const GncJob * a, const GncJob *b)
|
||||
return (safe_strcmp(a->id, b->id));
|
||||
}
|
||||
|
||||
gboolean gncJobEqual(const GncJob * a, const GncJob *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->name, b->name) != 0)
|
||||
{
|
||||
PWARN("Names differ: %s vs %s", a->name, b->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->desc, b->desc) != 0)
|
||||
{
|
||||
PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* FIXME: Need real tests */
|
||||
#if 0
|
||||
GncOwner owner;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Package-Private functions */
|
||||
|
||||
|
@ -98,6 +98,7 @@ static inline GncJob * gncJobLookup (const QofBook *book, const GncGUID *guid)
|
||||
/* Other functions */
|
||||
|
||||
int gncJobCompare (const GncJob *a, const GncJob *b);
|
||||
gboolean gncJobEqual(const GncJob *a, const GncJob *b);
|
||||
|
||||
#define JOB_ID "id"
|
||||
#define JOB_NAME "name"
|
||||
|
@ -496,6 +496,55 @@ int gncOrderCompare (const GncOrder *a, const GncOrder *b)
|
||||
return qof_instance_guid_compare(a, b);
|
||||
}
|
||||
|
||||
gboolean gncOrderEqual(const GncOrder * a, const GncOrder *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ORDER(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_ORDER(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->notes, b->notes) != 0)
|
||||
{
|
||||
PWARN("Notes differ: %s vs %s", a->notes, b->notes);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->reference, b->reference) != 0)
|
||||
{
|
||||
PWARN("References differ: %s vs %s", a->reference, b->reference);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->printname, b->printname) != 0)
|
||||
{
|
||||
PWARN("printnames differ: %s vs %s", a->printname, b->printname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* FIXME: Need real tests */
|
||||
#if 0
|
||||
GncOwner owner;
|
||||
GList * entries;
|
||||
Timespec opened;
|
||||
Timespec closed;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* =========================================================== */
|
||||
/* Package-Private functions */
|
||||
|
||||
|
@ -92,6 +92,7 @@ GList * gncOrderGetEntries (GncOrder *order);
|
||||
void gncOrderBeginEdit (GncOrder *order);
|
||||
void gncOrderCommitEdit (GncOrder *order);
|
||||
int gncOrderCompare (const GncOrder *a, const GncOrder *b);
|
||||
gboolean gncOrderEqual(const GncOrder *a, const GncOrder *b);
|
||||
|
||||
gboolean gncOrderIsClosed (const GncOrder *order);
|
||||
|
||||
|
@ -859,6 +859,93 @@ int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b)
|
||||
return safe_strcmp (a->name, b->name);
|
||||
}
|
||||
|
||||
gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
if (!xaccAccountEqual(a->account, b->account, TRUE))
|
||||
{
|
||||
PWARN("accounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->type != b->type)
|
||||
{
|
||||
PWARN("types differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_numeric_equal(a->amount, b->amount))
|
||||
{
|
||||
PWARN("amounts differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->name, b->name) != 0)
|
||||
{
|
||||
PWARN("Names differ: %s vs %s", a->name, b->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->invisible != b->invisible)
|
||||
{
|
||||
PWARN("invisible flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((a->entries != NULL) != (b->entries != NULL))
|
||||
{
|
||||
PWARN("only one has entries");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->entries != NULL && b->entries != NULL)
|
||||
{
|
||||
GncTaxTableEntryList* a_node;
|
||||
GncTaxTableEntryList* b_node;
|
||||
|
||||
for (a_node = a->entries, b_node = b->entries;
|
||||
a_node != NULL && b_node != NULL;
|
||||
a_node = a_node->next, b_node = b_node->next)
|
||||
{
|
||||
if (!gncTaxTableEntryEqual((GncTaxTableEntry*)a_node->data,
|
||||
(GncTaxTableEntry*)b_node->data))
|
||||
{
|
||||
PWARN("entries differ");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (a_node != NULL || b_node != NULL)
|
||||
{
|
||||
PWARN("Unequal number of entries");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* See src/doc/business.txt for an explanation of the following */
|
||||
/* Code that handles this is *identical* to that in gncBillTerm */
|
||||
gint64 refcount;
|
||||
GncTaxTable * parent; /* if non-null, we are an immutable child */
|
||||
GncTaxTable * child; /* if non-null, we have not changed */
|
||||
GList * children; /* list of children for disconnection */
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* This will add value to the account-value for acc, creating a new
|
||||
|
@ -134,6 +134,7 @@ void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry);
|
||||
void gncTaxTableChanged (GncTaxTable *table);
|
||||
void gncTaxTableBeginEdit (GncTaxTable *table);
|
||||
void gncTaxTableCommitEdit (GncTaxTable *table);
|
||||
gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b);
|
||||
|
||||
/** @name Get Functions
|
||||
@{ */
|
||||
@ -169,6 +170,7 @@ gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
|
||||
|
||||
int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
|
||||
int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
|
||||
gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
|
||||
|
||||
/************************************************/
|
||||
|
||||
|
@ -639,6 +639,78 @@ int gncVendorCompare (const GncVendor *a, const GncVendor *b)
|
||||
return(strcmp(a->name, b->name));
|
||||
}
|
||||
|
||||
gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
|
||||
{
|
||||
if (a == NULL && b == NULL) return TRUE;
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_VENDOR(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_VENDOR(b), FALSE);
|
||||
|
||||
if (safe_strcmp(a->id, b->id) != 0)
|
||||
{
|
||||
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->name, b->name) != 0)
|
||||
{
|
||||
PWARN("Names differ: %s vs %s", a->name, b->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (safe_strcmp(a->notes, b->notes) != 0)
|
||||
{
|
||||
PWARN("Notes differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncBillTermEqual(a->terms, b->terms))
|
||||
{
|
||||
PWARN("BillTerms differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncAddressEqual(a->addr, b->addr))
|
||||
{
|
||||
PWARN("Addresses differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gnc_commodity_equal(a->currency, b->currency))
|
||||
{
|
||||
PWARN("Currencies differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gncTaxTableEqual(a->taxtable, b->taxtable))
|
||||
{
|
||||
PWARN("Tax tables differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->taxtable_override != b->taxtable_override)
|
||||
{
|
||||
PWARN("Tax table override flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->taxincluded != b->taxincluded)
|
||||
{
|
||||
PWARN("Tax included flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (a->active != b->active)
|
||||
{
|
||||
PWARN("Active flags differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// GList * jobs;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
|
||||
{
|
||||
if (!vendor) return NULL;
|
||||
|
@ -105,6 +105,7 @@ GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor);
|
||||
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all);
|
||||
gboolean gncVendorIsDirty (const GncVendor *vendor);
|
||||
int gncVendorCompare (const GncVendor *a, const GncVendor *b);
|
||||
gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b);
|
||||
|
||||
/** Return a pointer to the instance gncVendor that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
|
@ -36,6 +36,9 @@
|
||||
#include "Transaction.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gncCustomer.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gncEmployee.h"
|
||||
#include "gncVendor.h"
|
||||
|
||||
static QofLogModule log_module = "test-dbi";
|
||||
|
||||
@ -58,15 +61,131 @@ compare_customers( QofBook* book_1, QofBook* book_2 )
|
||||
do_compare( book_1, book_2, GNC_ID_CUSTOMER, compare_single_customer, "Customer lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_employee( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncEmployee* emp_1 = GNC_EMPLOYEE(inst);
|
||||
GncEmployee* emp_2 = gncEmployeeLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncEmployeeEqual( emp_1, emp_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_employees( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_EMPLOYEE, compare_single_employee, "Employee lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_invoice( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncInvoice* inv_1 = GNC_INVOICE(inst);
|
||||
GncInvoice* inv_2 = gncInvoiceLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncInvoiceEqual( inv_1, inv_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_invoices( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_INVOICE, compare_single_invoice, "Invoice lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_job( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncJob* job_1 = GNC_JOB(inst);
|
||||
GncJob* job_2 = gncJobLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncJobEqual( job_1, job_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_jobs( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_JOB, compare_single_job, "Job lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_vendor( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncVendor* vendor_1 = GNC_VENDOR(inst);
|
||||
GncVendor* vendor_2 = gncVendorLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncVendorEqual( vendor_1, vendor_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_vendors( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_VENDOR, compare_single_vendor, "Vendor lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_billterm( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncBillTerm* bt_1 = GNC_BILLTERM(inst);
|
||||
GncBillTerm* bt_2 = gncBillTermLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncBillTermEqual( bt_1, bt_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_billterms( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_BILLTERM, compare_single_billterm, "Billterms lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_single_taxtable( QofInstance* inst, gpointer user_data )
|
||||
{
|
||||
CompareInfoStruct* info = (CompareInfoStruct*)user_data;
|
||||
GncTaxTable* tt_1 = GNC_TAXTABLE(inst);
|
||||
GncTaxTable* tt_2 = gncTaxTableLookup( info->book_2, qof_instance_get_guid(inst) );
|
||||
|
||||
if (!gncTaxTableEqual( tt_1, tt_2 ))
|
||||
{
|
||||
info->result = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_taxtables( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
do_compare( book_1, book_2, GNC_ID_TAXTABLE, compare_single_taxtable, "TaxTable lists match" );
|
||||
}
|
||||
|
||||
static void
|
||||
compare_books( QofBook* book_1, QofBook* book_2 )
|
||||
{
|
||||
compare_billterms( book_1, book_2 );
|
||||
compare_taxtables( book_1, book_2 );
|
||||
|
||||
compare_customers( book_1, book_2 );
|
||||
// compare_invoices( book_1, book_2 );
|
||||
// compare_jobs( book_1, book_2 );
|
||||
// compare_vendors( book_1, book_2 );
|
||||
// compare_billterms( book_1, book_2 );
|
||||
// compare_employees( book_1, book_2 );
|
||||
compare_employees( book_1, book_2 );
|
||||
compare_invoices( book_1, book_2 );
|
||||
compare_jobs( book_1, book_2 );
|
||||
compare_vendors( book_1, book_2 );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "gnc-commodity.h"
|
||||
#include "gncAddress.h"
|
||||
#include "gncCustomer.h"
|
||||
#include "gncInvoice.h"
|
||||
|
||||
#include "gnc-backend-sql.h"
|
||||
|
||||
@ -66,6 +67,12 @@ create_session(void)
|
||||
gnc_commodity* currency;
|
||||
GncAddress* addr;
|
||||
GncCustomer* cust;
|
||||
GncEmployee* emp;
|
||||
GncVendor* v;
|
||||
GncInvoice* inv;
|
||||
GncJob* job;
|
||||
GncTaxTable* tt;
|
||||
GncTaxTableEntry* tte;
|
||||
|
||||
table = gnc_commodity_table_get_table( book );
|
||||
currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" );
|
||||
@ -74,12 +81,30 @@ create_session(void)
|
||||
xaccAccountSetType( acct1, ACCT_TYPE_BANK );
|
||||
xaccAccountSetName( acct1, "Bank 1" );
|
||||
xaccAccountSetCommodity( acct1, currency );
|
||||
|
||||
xaccAccountSetHidden( acct1, FALSE );
|
||||
xaccAccountSetPlaceholder( acct1, FALSE );
|
||||
gnc_account_append_child( root, acct1 );
|
||||
|
||||
acct2 = xaccMallocAccount( book );
|
||||
xaccAccountSetType( acct2, ACCT_TYPE_BANK );
|
||||
xaccAccountSetName( acct2, "Bank 1" );
|
||||
xaccAccountSetName( acct2, "Bank 2" );
|
||||
xaccAccountSetCommodity( acct2, currency );
|
||||
xaccAccountSetHidden( acct2, FALSE );
|
||||
xaccAccountSetPlaceholder( acct2, FALSE );
|
||||
gnc_account_append_child( root, acct2 );
|
||||
|
||||
tt = gncTaxTableCreate( book );
|
||||
gncTaxTableSetName( tt, "tt" );
|
||||
tte = gncTaxTableEntryCreate();
|
||||
gncTaxTableEntrySetAccount( tte, acct1 );
|
||||
gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_VALUE );
|
||||
gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
|
||||
gncTaxTableAddEntry( tt, tte );
|
||||
tte = gncTaxTableEntryCreate();
|
||||
gncTaxTableEntrySetAccount( tte, acct2 );
|
||||
gncTaxTableEntrySetType( tte, GNC_AMT_TYPE_PERCENT );
|
||||
gncTaxTableEntrySetAmount( tte, gnc_numeric_zero() );
|
||||
gncTaxTableAddEntry( tt, tte );
|
||||
|
||||
cust = gncCustomerCreate( book );
|
||||
gncCustomerSetID( cust, "0001" );
|
||||
@ -96,6 +121,12 @@ create_session(void)
|
||||
gncAddressSetPhone( addr, "(123) 555-2121" );
|
||||
gncAddressSetEmail( addr, "cust@mycustomer.com" );
|
||||
|
||||
emp = gncEmployeeCreate( book );
|
||||
gncEmployeeSetID( emp, "0001" );
|
||||
gncEmployeeSetUsername( emp, "gnucash" );
|
||||
gncEmployeeSetLanguage( emp, "english" );
|
||||
gncEmployeeSetCurrency( emp, currency );
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user