[libgdata] gd: Fix comparison of GDataGDReminders with non-equal relative times
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] gd: Fix comparison of GDataGDReminders with non-equal relative times
- Date: Sun, 1 Sep 2013 04:49:40 +0000 (UTC)
commit 089fff676d2a22a8506b16e341805fccca599d6b
Author: Philip Withnall <philip tecnocode co uk>
Date: Sat Aug 31 22:44:02 2013 -0600
gd: Fix comparison of GDataGDReminders with non-equal relative times
Two GDataGDReminders would previously compare as equal if their methods were
equal but their relative times were not. Now they only compare equal if both
their methods and their relative (or absolute) times are equal.
This includes a test case.
Spotted by Miao Yu <will yu yahoo com>.
gdata/gd/gdata-gd-reminder.c | 13 +++++++------
gdata/tests/general.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-reminder.c b/gdata/gd/gdata-gd-reminder.c
index 8ed7344..fab5f23 100644
--- a/gdata/gd/gdata-gd-reminder.c
+++ b/gdata/gd/gdata-gd-reminder.c
@@ -148,7 +148,7 @@ gdata_gd_reminder_class_init (GDataGDReminderClass *klass)
static gint
compare_with (GDataComparable *self, GDataComparable *other)
{
- gint method_cmp;
+ gint method_cmp, time_cmp;
GDataGDReminder *a = (GDataGDReminder*) self, *b = (GDataGDReminder*) other;
if (gdata_gd_reminder_is_absolute_time (a) != gdata_gd_reminder_is_absolute_time (b))
@@ -156,14 +156,15 @@ compare_with (GDataComparable *self, GDataComparable *other)
method_cmp = g_strcmp0 (a->priv->method, b->priv->method);
if (gdata_gd_reminder_is_absolute_time (a) == TRUE) {
- if (method_cmp == 0 && a->priv->absolute_time == b->priv->absolute_time)
- return 0;
+ time_cmp = a->priv->absolute_time - b->priv->absolute_time;
} else {
- if (method_cmp == 0 && a->priv->relative_time == b->priv->relative_time)
- return 0;
+ time_cmp = a->priv->relative_time - b->priv->relative_time;
}
- return method_cmp;
+ if (method_cmp == 0)
+ return time_cmp;
+ else
+ return method_cmp;
}
static void
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index a9c1123..6a8d417 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -2896,6 +2896,40 @@ test_gd_reminder_escaping (void)
}
static void
+test_gd_reminder_comparison (void)
+{
+ GDataGDReminder *reminder1, *reminder2;
+
+#define ASSERT_COMPARISON(op) \
+ g_assert_cmpint (gdata_comparable_compare (GDATA_COMPARABLE (reminder1), GDATA_COMPARABLE
(reminder2)), op, 0)
+
+ /* Check for equality. */
+ reminder1 = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, -1, 15);
+ reminder2 = gdata_gd_reminder_new (GDATA_GD_REMINDER_ALERT, -1, 15);
+ ASSERT_COMPARISON(==);
+
+ /* Different methods, same time type, same time. */
+ gdata_gd_reminder_set_method (reminder1, GDATA_GD_REMINDER_SMS);
+ ASSERT_COMPARISON(>);
+
+ /* Same method, different time type, same time. */
+ gdata_gd_reminder_set_method (reminder1, GDATA_GD_REMINDER_ALERT);
+ gdata_gd_reminder_set_relative_time (reminder1, -1);
+ gdata_gd_reminder_set_absolute_time (reminder1, 5);
+ ASSERT_COMPARISON(>);
+
+ /* Same method, same time type, different time. */
+ gdata_gd_reminder_set_absolute_time (reminder1, -1);
+ gdata_gd_reminder_set_relative_time (reminder1, 20);
+ ASSERT_COMPARISON(>);
+
+ g_object_unref (reminder2);
+ g_object_unref (reminder1);
+
+#undef ASSERT_COMPARISON
+}
+
+static void
test_gd_when (void)
{
GDataGDWhen *when, *when2;
@@ -4259,6 +4293,7 @@ main (int argc, char *argv[])
g_test_add_func ("/gd/postal_address/escaping", test_gd_postal_address_escaping);
g_test_add_func ("/gd/reminder", test_gd_reminder);
g_test_add_func ("/gd/reminder/escaping", test_gd_reminder_escaping);
+ g_test_add_func ("/gd/reminder/comparison", test_gd_reminder_comparison);
g_test_add_func ("/gd/when", test_gd_when);
g_test_add_func ("/gd/when/escaping", test_gd_when_escaping);
g_test_add_func ("/gd/where", test_gd_where);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]