[folks] Add AbstractFieldDetails.value_type.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add AbstractFieldDetails.value_type.
- Date: Thu, 10 Nov 2011 22:06:37 +0000 (UTC)
commit 0719b657cacd96edfc2a7159c3228b5fc3e7969f
Author: Travis Reitter <travis reitter collabora co uk>
Date: Thu Nov 3 14:05:45 2011 -0700
Add AbstractFieldDetails.value_type.
This allows generic handling of collections of derived objects of
mixed concrete classes.
Helps: bgo#663798 - Add AbstractFieldDetails.value_type
NEWS | 2 +
folks/abstract-field-details.vala | 14 ++++++++++
tests/folks/abstract-field-details.vala | 44 +++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1c51c3a..b14fe55 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Bugs fixed:
store.
* Bug 662314 â Gnome-shell restarts if I change my user status to
disconnected/unavailable
+* Bug 663798 â Add AbstractFieldDetails.value_type
API changes:
* Add AbstractFieldDetails.id to identify instances of details
@@ -19,6 +20,7 @@ API changes:
* Deprecate Role.uid in favor of AbstractFieldDetails.id
* Add AbstractFieldDetails.values_equal() to compare values (but not parameters)
* Implement FavouriteDetails on Edsf.Persona
+* Add AbstractFieldDetails.value_type
Behavior changes:
* PostalAddress.equal() now ignores PostalAddress.uid
diff --git a/folks/abstract-field-details.vala b/folks/abstract-field-details.vala
index 3f5b657..5520706 100644
--- a/folks/abstract-field-details.vala
+++ b/folks/abstract-field-details.vala
@@ -101,6 +101,20 @@ public abstract class Folks.AbstractFieldDetails<T> : Object
set { this._value = value; }
}
+ /**
+ * The { link GLib.Type of the { link AbstractFieldDetails.value}.
+ *
+ * This is particularly useful for treating collections of different types of
+ * { link AbstractFieldDetails} in a uniform way without needing to name them
+ * explicitly.
+ *
+ * @since UNRELEASED
+ */
+ public Type value_type
+ {
+ get { return typeof (T); }
+ }
+
private string _id;
/**
* A unique ID (if any) for this specific detail.
diff --git a/tests/folks/abstract-field-details.vala b/tests/folks/abstract-field-details.vala
index 6d4ef72..63e6a6a 100644
--- a/tests/folks/abstract-field-details.vala
+++ b/tests/folks/abstract-field-details.vala
@@ -32,6 +32,8 @@ public class EmailFieldDetailsTests : Folks.TestCase
this.test_im_field_details_equality);
this.add_test ("RoleFieldDetails equality",
this.test_role_field_details_equality);
+ this.add_test ("Generic AFD handling",
+ this.test_generic_afd_handling);
}
public override void set_up ()
@@ -181,6 +183,48 @@ public class EmailFieldDetailsTests : Folks.TestCase
assert (details_a_1.equal (details_a_2));
assert (!details_a_1.equal (details_b_1));
}
+
+ public void test_generic_afd_handling ()
+ {
+ AbstractFieldDetails afd;
+
+ afd = new EmailFieldDetails ("foo example org");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+
+ afd = new ImFieldDetails ("bar example org");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+
+ afd = new NoteFieldDetails ("Are you writing this down?");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+
+ afd = new PhoneFieldDetails ("+19255551234");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+
+ afd = new PostalAddressFieldDetails (
+ new PostalAddress (null, null, "123 Streetly Way", "Cityville",
+ "Cascadia", null, "USA", null, null));
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (PostalAddress));
+ assert (afd.value_type != typeof (string));
+
+ afd = new RoleFieldDetails (
+ new Role ("Captain", "Obvious Corp.", null));
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (Role));
+ assert (afd.value_type != typeof (string));
+
+ afd = new UrlFieldDetails ("http://other.side.of.nowhere");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+
+ afd = new WebServiceFieldDetails ("bluebomber");
+ assert (afd.get_type ().is_a (typeof (AbstractFieldDetails)));
+ assert (afd.value_type == typeof (string));
+ }
}
public int main (string[] args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]