mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add deep comparison routines for test purposes
1) Add routine gncCustomerEqual() which will do a deep comparison between two customers 2) Add routine gncAddressEqual() which will do a deep comparison between two addresses 3) Add more GncAddress gobject parameters for the remaining data items git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18965 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -71,7 +71,14 @@ void mark_address (GncAddress *address)
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_NAME
|
||||
PROP_NAME,
|
||||
PROP_ADDR1,
|
||||
PROP_ADDR2,
|
||||
PROP_ADDR3,
|
||||
PROP_ADDR4,
|
||||
PROP_PHONE,
|
||||
PROP_FAX,
|
||||
PROP_EMAIL
|
||||
};
|
||||
|
||||
/* GObject Initialization */
|
||||
@@ -110,6 +117,27 @@ gnc_address_get_property (GObject *object,
|
||||
case PROP_NAME:
|
||||
g_value_set_string(value, address->name);
|
||||
break;
|
||||
case PROP_ADDR1:
|
||||
g_value_set_string(value, address->addr1);
|
||||
break;
|
||||
case PROP_ADDR2:
|
||||
g_value_set_string(value, address->addr2);
|
||||
break;
|
||||
case PROP_ADDR3:
|
||||
g_value_set_string(value, address->addr3);
|
||||
break;
|
||||
case PROP_ADDR4:
|
||||
g_value_set_string(value, address->addr4);
|
||||
break;
|
||||
case PROP_PHONE:
|
||||
g_value_set_string(value, address->phone);
|
||||
break;
|
||||
case PROP_FAX:
|
||||
g_value_set_string(value, address->fax);
|
||||
break;
|
||||
case PROP_EMAIL:
|
||||
g_value_set_string(value, address->email);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
@@ -132,6 +160,27 @@ gnc_address_set_property (GObject *object,
|
||||
case PROP_NAME:
|
||||
gncAddressSetName(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_ADDR1:
|
||||
gncAddressSetAddr1(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_ADDR2:
|
||||
gncAddressSetAddr2(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_ADDR3:
|
||||
gncAddressSetAddr3(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_ADDR4:
|
||||
gncAddressSetAddr4(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_PHONE:
|
||||
gncAddressSetPhone(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_FAX:
|
||||
gncAddressSetFax(address, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_EMAIL:
|
||||
gncAddressSetEmail(address, g_value_get_string(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
@@ -177,6 +226,77 @@ gnc_address_class_init (GncAddressClass *klass)
|
||||
"a short string to identify the address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_ADDR1,
|
||||
g_param_spec_string ("addr1",
|
||||
"Address Line 1",
|
||||
"The address line 1 is an arbitrary string "
|
||||
"assigned by the user. It is the first "
|
||||
"line of the address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_ADDR2,
|
||||
g_param_spec_string ("addr2",
|
||||
"Address Line 2",
|
||||
"The address line 2 is an arbitrary string "
|
||||
"assigned by the user. It is the second "
|
||||
"line of the address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_ADDR3,
|
||||
g_param_spec_string ("addr3",
|
||||
"Address Line 3",
|
||||
"The address line 3 is an arbitrary string "
|
||||
"assigned by the user. It is the third "
|
||||
"line of the address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_ADDR4,
|
||||
g_param_spec_string ("addr4",
|
||||
"Address Line 4",
|
||||
"The address line 4 is an arbitrary string "
|
||||
"assigned by the user. It is the fourth "
|
||||
"line of the address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_PHONE,
|
||||
g_param_spec_string ("phone",
|
||||
"Phone",
|
||||
"The phone number is the number at this address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_FAX,
|
||||
g_param_spec_string ("fax",
|
||||
"Fax",
|
||||
"The fax number at this address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(gobject_class,
|
||||
PROP_EMAIL,
|
||||
g_param_spec_string ("email",
|
||||
"E-mail address",
|
||||
"The e-mail address at this address.",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
/* Create/Destroy functions */
|
||||
@@ -474,6 +594,58 @@ int gncAddressCompare (const GncAddress *a, const GncAddress *b)
|
||||
return safe_strcmp (a->name, b->name);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gncAddressEqual(const GncAddress* a, const GncAddress* b)
|
||||
{
|
||||
if (a == NULL || b == NULL) return FALSE;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ADDRESS(a), FALSE);
|
||||
g_return_val_if_fail(GNC_IS_ADDRESS(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->addr1, b->addr1) != 0)
|
||||
{
|
||||
PWARN("address lines 1 differ: %s vs %s", a->addr1, b->addr1);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->addr2, b->addr2) != 0)
|
||||
{
|
||||
PWARN("address lines 2 differ: %s vs %s", a->addr2, b->addr1);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->addr3, b->addr3) != 0)
|
||||
{
|
||||
PWARN("address lines 3 differ: %s vs %s", a->addr3, b->addr3);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->addr4, b->addr4) != 0)
|
||||
{
|
||||
PWARN("address lines 4 differ: %s vs %s", a->addr4, b->addr4);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->phone, b->phone) != 0)
|
||||
{
|
||||
PWARN("phone numbers differ: %s vs %s", a->phone, b->phone);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->fax, b->fax) != 0)
|
||||
{
|
||||
PWARN("fax numbers differ: %s vs %s", a->fax, b->fax);
|
||||
return FALSE;
|
||||
}
|
||||
if (safe_strcmp(a->email, b->email) != 0)
|
||||
{
|
||||
PWARN("email addresses differ: %s vs %s", a->email, b->email);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static QofObject GncAddressDesc =
|
||||
{
|
||||
DI(.interface_version =) QOF_OBJECT_VERSION,
|
||||
|
||||
@@ -138,6 +138,12 @@ and +1 if a is more than b or if b is empty.
|
||||
*/
|
||||
int gncAddressCompare (const GncAddress *a, const GncAddress *b);
|
||||
|
||||
/** \brief Deeply compare two addresses
|
||||
|
||||
\return TRUE if all fields match, FALSE otherwise
|
||||
*/
|
||||
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b);
|
||||
|
||||
#define ADDRESS_NAME "name"
|
||||
#define ADDRESS_ONE "number"
|
||||
#define ADDRESS_TWO "street"
|
||||
|
||||
@@ -731,6 +731,28 @@ int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b)
|
||||
return(strcmp(a->name, b->name));
|
||||
}
|
||||
|
||||
gboolean
|
||||
gncCustomerEqual(const GncCustomer *a, const GncCustomer *b)
|
||||
{
|
||||
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 (!gncAddressEqual(a->addr, b->addr))
|
||||
{
|
||||
PWARN("addresses differ");
|
||||
return FALSE;
|
||||
}
|
||||
if (!gncAddressEqual(a->shipaddr, b->shipaddr))
|
||||
{
|
||||
PWARN("addresses differ");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for MODIFY events from addresses. If the address belongs to a customer,
|
||||
* mark the customer as dirty.
|
||||
|
||||
@@ -140,6 +140,7 @@ GList * gncCustomerGetJoblist (const GncCustomer *customer, gboolean show_all);
|
||||
|
||||
gboolean gncCustomerIsDirty (GncCustomer *customer);
|
||||
int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b);
|
||||
gboolean gncCustomerEqual(const GncCustomer *a, const GncCustomer *b);
|
||||
|
||||
#define CUSTOMER_ID "id"
|
||||
#define CUSTOMER_NAME "name"
|
||||
|
||||
Reference in New Issue
Block a user