[libgdata] [gd] Ensure comparisons of two NULL values return 0



commit 1f1c5566c27b697c4f6e623e875f6feb919dae36
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Mar 22 16:59:44 2010 +0000

    [gd] Ensure comparisons of two NULL values return 0
    
    Add test cases too.

 gdata/gd/gdata-gd-email-address.c  |    2 +-
 gdata/gd/gdata-gd-im-address.c     |    2 +-
 gdata/gd/gdata-gd-name.c           |    2 +-
 gdata/gd/gdata-gd-organization.c   |    2 +-
 gdata/gd/gdata-gd-phone-number.c   |    2 +-
 gdata/gd/gdata-gd-postal-address.c |    2 +-
 gdata/gd/gdata-gd-reminder.c       |    2 +-
 gdata/gd/gdata-gd-when.c           |    2 +-
 gdata/gd/gdata-gd-where.c          |    2 +-
 gdata/gd/gdata-gd-who.c            |    2 +-
 gdata/tests/general.c              |   60 ++++++++++++++++++++++++++++++++++++
 11 files changed, 70 insertions(+), 10 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-email-address.c b/gdata/gd/gdata-gd-email-address.c
index 8a9da95..7ac500a 100644
--- a/gdata/gd/gdata-gd-email-address.c
+++ b/gdata/gd/gdata-gd-email-address.c
@@ -343,7 +343,7 @@ gdata_gd_email_address_compare (const GDataGDEmailAddress *a, const GDataGDEmail
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-im-address.c b/gdata/gd/gdata-gd-im-address.c
index a074cfc..27c74dc 100644
--- a/gdata/gd/gdata-gd-im-address.c
+++ b/gdata/gd/gdata-gd-im-address.c
@@ -348,7 +348,7 @@ gdata_gd_im_address_compare (const GDataGDIMAddress *a, const GDataGDIMAddress *
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-name.c b/gdata/gd/gdata-gd-name.c
index 8ba43d8..6880043 100644
--- a/gdata/gd/gdata-gd-name.c
+++ b/gdata/gd/gdata-gd-name.c
@@ -364,7 +364,7 @@ gdata_gd_name_compare (const GDataGDName *a, const GDataGDName *b)
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-organization.c b/gdata/gd/gdata-gd-organization.c
index 3db6fd6..648f62e 100644
--- a/gdata/gd/gdata-gd-organization.c
+++ b/gdata/gd/gdata-gd-organization.c
@@ -522,7 +522,7 @@ gdata_gd_organization_compare (const GDataGDOrganization *a, const GDataGDOrgani
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-phone-number.c b/gdata/gd/gdata-gd-phone-number.c
index acc0305..cc27c96 100644
--- a/gdata/gd/gdata-gd-phone-number.c
+++ b/gdata/gd/gdata-gd-phone-number.c
@@ -374,7 +374,7 @@ gdata_gd_phone_number_compare (const GDataGDPhoneNumber *a, const GDataGDPhoneNu
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-postal-address.c b/gdata/gd/gdata-gd-postal-address.c
index 6a774c0..7163cf0 100644
--- a/gdata/gd/gdata-gd-postal-address.c
+++ b/gdata/gd/gdata-gd-postal-address.c
@@ -694,7 +694,7 @@ gdata_gd_postal_address_compare (const GDataGDPostalAddress *a, const GDataGDPos
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-reminder.c b/gdata/gd/gdata-gd-reminder.c
index 2f0e5a5..3cc4ecc 100644
--- a/gdata/gd/gdata-gd-reminder.c
+++ b/gdata/gd/gdata-gd-reminder.c
@@ -320,7 +320,7 @@ gdata_gd_reminder_compare (const GDataGDReminder *a, const GDataGDReminder *b)
 
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-when.c b/gdata/gd/gdata-gd-when.c
index f5fd997..a3ae146 100644
--- a/gdata/gd/gdata-gd-when.c
+++ b/gdata/gd/gdata-gd-when.c
@@ -404,7 +404,7 @@ gdata_gd_when_compare (const GDataGDWhen *a, const GDataGDWhen *b)
 
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-where.c b/gdata/gd/gdata-gd-where.c
index c23f85e..c8be288 100644
--- a/gdata/gd/gdata-gd-where.c
+++ b/gdata/gd/gdata-gd-where.c
@@ -287,7 +287,7 @@ gdata_gd_where_compare (const GDataGDWhere *a, const GDataGDWhere *b)
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/gd/gdata-gd-who.c b/gdata/gd/gdata-gd-who.c
index 6dd4a63..3423664 100644
--- a/gdata/gd/gdata-gd-who.c
+++ b/gdata/gd/gdata-gd-who.c
@@ -293,7 +293,7 @@ gdata_gd_who_compare (const GDataGDWho *a, const GDataGDWho *b)
 {
 	if (a == NULL && b != NULL)
 		return -1;
-	else if (b == NULL)
+	else if (a != NULL && b == NULL)
 		return 1;
 
 	if (a == b)
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index 3ba42e5..73e01e7 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -1266,6 +1266,12 @@ test_gd_email_address (void)
 	g_assert_cmpint (gdata_gd_email_address_compare (email, email2), !=, 0);
 	g_object_unref (email2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_email_address_compare (email, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_email_address_compare (NULL, email), ==, -1);
+	g_assert_cmpint (gdata_gd_email_address_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_email_address_compare (email, email), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (email));
 	g_assert_cmpstr (xml, ==,
@@ -1328,6 +1334,12 @@ test_gd_im_address (void)
 	g_assert_cmpint (gdata_gd_im_address_compare (im, im2), !=, 0);
 	g_object_unref (im2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_im_address_compare (im, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_im_address_compare (NULL, im), ==, -1);
+	g_assert_cmpint (gdata_gd_im_address_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_im_address_compare (im, im), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (im));
 	g_assert_cmpstr (xml, ==,
@@ -1400,6 +1412,12 @@ test_gd_name (void)
 	g_assert_cmpint (gdata_gd_name_compare (name, name2), !=, 0);
 	g_object_unref (name2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_name_compare (name, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_name_compare (NULL, name), ==, -1);
+	g_assert_cmpint (gdata_gd_name_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_name_compare (name, name), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (name));
 	g_assert_cmpstr (xml, ==,
@@ -1484,6 +1502,12 @@ test_gd_organization (void)
 	g_assert_cmpint (gdata_gd_organization_compare (org, org2), !=, 0);
 	g_object_unref (org2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_organization_compare (org, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_organization_compare (NULL, org), ==, -1);
+	g_assert_cmpint (gdata_gd_organization_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_organization_compare (org, org), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (org));
 	g_assert_cmpstr (xml, ==,
@@ -1556,6 +1580,12 @@ test_gd_phone_number (void)
 	g_assert_cmpint (gdata_gd_phone_number_compare (phone, phone2), !=, 0);
 	g_object_unref (phone2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_phone_number_compare (phone, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_phone_number_compare (NULL, phone), ==, -1);
+	g_assert_cmpint (gdata_gd_phone_number_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_phone_number_compare (phone, phone), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (phone));
 	g_assert_cmpstr (xml, ==,
@@ -1630,6 +1660,12 @@ test_gd_postal_address (void)
 	g_assert_cmpint (gdata_gd_postal_address_compare (postal, postal2), !=, 0);
 	g_object_unref (postal2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_postal_address_compare (postal, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_postal_address_compare (NULL, postal), ==, -1);
+	g_assert_cmpint (gdata_gd_postal_address_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_postal_address_compare (postal, postal), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (postal));
 	g_assert_cmpstr (xml, ==,
@@ -1720,6 +1756,12 @@ test_gd_reminder (void)
 	g_assert (GDATA_IS_GD_REMINDER (reminder));
 	g_clear_error (&error);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_reminder_compare (reminder, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_reminder_compare (NULL, reminder), ==, -1);
+	g_assert_cmpint (gdata_gd_reminder_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_reminder_compare (reminder, reminder), ==, 0);
+
 	/* Check the properties */
 	g_assert (gdata_gd_reminder_get_method (reminder) == NULL);
 	g_assert (gdata_gd_reminder_is_absolute_time (reminder) == FALSE);
@@ -1791,6 +1833,12 @@ test_gd_when (void)
 	g_assert_cmpint (gdata_gd_when_compare (when, when2), !=, 0);
 	g_object_unref (when2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_when_compare (when, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_when_compare (NULL, when), ==, -1);
+	g_assert_cmpint (gdata_gd_when_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_when_compare (when, when), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (when));
 	g_assert_cmpstr (xml, ==,
@@ -1866,6 +1914,12 @@ test_gd_where (void)
 	g_assert_cmpint (gdata_gd_where_compare (where, where2), !=, 0);
 	g_object_unref (where2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_where_compare (where, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_where_compare (NULL, where), ==, -1);
+	g_assert_cmpint (gdata_gd_where_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_where_compare (where, where), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (where));
 	g_assert_cmpstr (xml, ==,
@@ -1924,6 +1978,12 @@ test_gd_who (void)
 	g_assert_cmpint (gdata_gd_who_compare (who, who2), !=, 0);
 	g_object_unref (who2);
 
+	/* More comparisons */
+	g_assert_cmpint (gdata_gd_who_compare (who, NULL), ==, 1);
+	g_assert_cmpint (gdata_gd_who_compare (NULL, who), ==, -1);
+	g_assert_cmpint (gdata_gd_who_compare (NULL, NULL), ==, 0);
+	g_assert_cmpint (gdata_gd_who_compare (who, who), ==, 0);
+
 	/* Check the outputted XML is the same */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (who));
 	g_assert_cmpstr (xml, ==,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]