r18965 - gnucash/trunk/src/business/business-core - Add deep comparison routines for test purposes

Phil Longstaff plongstaff at code.gnucash.org
Fri Mar 26 15:13:34 EDT 2010


Author: plongstaff
Date: 2010-03-26 15:13:34 -0400 (Fri, 26 Mar 2010)
New Revision: 18965
Trac: http://svn.gnucash.org/trac/changeset/18965

Modified:
   gnucash/trunk/src/business/business-core/gncAddress.c
   gnucash/trunk/src/business/business-core/gncAddress.h
   gnucash/trunk/src/business/business-core/gncCustomer.c
   gnucash/trunk/src/business/business-core/gncCustomer.h
Log:
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


Modified: gnucash/trunk/src/business/business-core/gncAddress.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.c	2010-03-25 22:08:34 UTC (rev 18964)
+++ gnucash/trunk/src/business/business-core/gncAddress.c	2010-03-26 19:13:34 UTC (rev 18965)
@@ -71,7 +71,14 @@
 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 @@
     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 @@
     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 @@
                           "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 @@
     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,

Modified: gnucash/trunk/src/business/business-core/gncAddress.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncAddress.h	2010-03-25 22:08:34 UTC (rev 18964)
+++ gnucash/trunk/src/business/business-core/gncAddress.h	2010-03-26 19:13:34 UTC (rev 18965)
@@ -138,6 +138,12 @@
 */
 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"

Modified: gnucash/trunk/src/business/business-core/gncCustomer.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.c	2010-03-25 22:08:34 UTC (rev 18964)
+++ gnucash/trunk/src/business/business-core/gncCustomer.c	2010-03-26 19:13:34 UTC (rev 18965)
@@ -731,6 +731,28 @@
     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.

Modified: gnucash/trunk/src/business/business-core/gncCustomer.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncCustomer.h	2010-03-25 22:08:34 UTC (rev 18964)
+++ gnucash/trunk/src/business/business-core/gncCustomer.h	2010-03-26 19:13:34 UTC (rev 18965)
@@ -140,6 +140,7 @@
 
 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"



More information about the gnucash-changes mailing list