[glib] GVariant: support comparing booleans
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GVariant: support comparing booleans
- Date: Fri, 6 Jul 2012 21:29:44 +0000 (UTC)
commit f66052fc87caada2552f651e9a21f1daac86b2a1
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jul 6 17:27:54 2012 -0400
GVariant: support comparing booleans
g_variant_compare() is documented as working on booleans but somehow
this case was missed. Add it and test it.
Problem discovered by Charles Kerr.
glib/gvariant.c | 4 ++++
glib/tests/gvariant.c | 5 +++++
2 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/glib/gvariant.c b/glib/gvariant.c
index 6ff7714..5f2337c 100644
--- a/glib/gvariant.c
+++ b/glib/gvariant.c
@@ -2748,6 +2748,10 @@ g_variant_compare (gconstpointer one,
switch (g_variant_classify (a))
{
+ case G_VARIANT_CLASS_BOOLEAN:
+ return g_variant_get_boolean (a) -
+ g_variant_get_boolean (b);
+
case G_VARIANT_CLASS_BYTE:
return ((gint) g_variant_get_byte (a)) -
((gint) g_variant_get_byte (b));
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index 7f7d56c..d3d8aa2 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -4079,6 +4079,11 @@ test_compare (void)
g_assert (g_variant_compare (a, b) < 0);
g_variant_unref (a);
g_variant_unref (b);
+ a = g_variant_new_boolean (FALSE);
+ b = g_variant_new_boolean (TRUE);
+ g_assert (g_variant_compare (a, b) < 0);
+ g_variant_unref (a);
+ g_variant_unref (b);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]