[libical-glib] Fix the issue with array.py. Right now we use GObject * to replace gpointer. The first reason is tha



commit 105feb193b65514c7244fd2dc7d61cdccde88c26
Author: William Yu <williamyu gnome org>
Date:   Sun May 3 11:22:57 2015 -0400

    Fix the issue with array.py. Right now we use GObject * to replace gpointer. The first reason is that in 
PyGObject, gpointer could only represent integer, none and capsule. The second reason is that the types used 
python, except those primitive types, are mostly subtypes of GObject.

 src/api/i-cal-array.xml |    4 +-
 tests/array.py          |   78 ++++++++++++++++++----------------------------
 2 files changed, 33 insertions(+), 49 deletions(-)
---
diff --git a/src/api/i-cal-array.xml b/src/api/i-cal-array.xml
index 2e7bcf8..d84e854 100644
--- a/src/api/i-cal-array.xml
+++ b/src/api/i-cal-array.xml
@@ -43,7 +43,7 @@
     </method>
     <method name="i_cal_array_append" corresponds="icalarray_append" kind="others" since="1.0">
         <parameter type="ICalArray *" name="array" comment="The #ICalArray to be appended."/>
-        <parameter type="gpointer" name="element" comment="The element to be appended to the #ICalArray"/>
+        <parameter type="GObject *" name="element" comment="The element to be appended to the #ICalArray. 
The reason why to use GOjbect * instead of gpointer is that the variable of type gpointer can only be 
assigned with none, integer or capsule type. The support for other types would be added in the future."/>
         <comment xml:space="preserve">Append @element to the end of the array</comment>
     </method>
     <method name="i_cal_array_remove_element_at" corresponds="icalarray_remove_element_at" kind="others" 
since="1.0">
@@ -54,7 +54,7 @@
     <method name="i_cal_array_element_at" corresponds="icalarray_element_at" kind="others" since="1.0">
         <parameter type="ICalArray *" name="array" comment="The #ICalArray to be queried."/>
         <parameter type="gint" name="position" comment="The position the target element is located"/>
-        <returns type="const void *" annotation="transfer none, allow-none" comment="The element located at 
the @position in the @array"/>
+        <returns type="GObject *" annotation="transfer none, allow-none" comment="The element located at the 
@position in the @array"/>
         <comment xml:space="preserve">Get the element located in the @position in the @array. NULL if 
position if out of bound</comment>
     </method>
     <method name="i_cal_array_sort" corresponds="CUSTOM" annotation="skip" kind="others" since="1.0">
diff --git a/tests/array.py b/tests/array.py
index dc3ce9a..9e7350a 100755
--- a/tests/array.py
+++ b/tests/array.py
@@ -32,57 +32,41 @@ element4 = "are";
 element5 = "you";
 
 #TEST APPEND
-array.append (element1);
-array.append (element2);
-array.append (element3);
-array.append (element4);
-array.append (element5);
+attach1 = ICalGLib.Attach.new_from_url (element1);
+attach2 = ICalGLib.Attach.new_from_url (element2);
+attach3 = ICalGLib.Attach.new_from_url (element3);
+attach4 = ICalGLib.Attach.new_from_url (element4);
+attach5 = ICalGLib.Attach.new_from_url (element5);
 
-e1 = array.element_at(0);
-assert (element1 == e1);
-e2 = array.element_at(1);
-assert (element2 == e2);
-e3 = array.element_at(2);
-assert (element3 == e3);
-e4 = array.element_at(3);
-assert (element4 == e4);
-e5 = array.element_at(4);
-assert (element5 == e5);
-
-#TEST COPY
-clone = array.copy();
-e1 = clone.element_at(0);
-assert (element1 == e1);
-e2 = clone.element_at(1);
-assert (element2 == e2);
-e3 = clone.element_at(2);
-assert (element3 == e3);
-e4 = clone.element_at(3);
-assert (element4 == e4);
-e5 = clone.element_at(4);
-assert (element5 == e5);
-
-#TEST REMOVE
-array.remove_element_at (2);
-e3 = array.element_at(2);
-assert (element4 == e3);
-
-attach1 = ICalGLib.Attach.new_from_url ("hello");
-attach2 = ICalGLib.Attach.new_from_url ("world");
-attach3 = ICalGLib.Attach.new_from_url ("how");
-attach4 = ICalGLib.Attach.new_from_url ("are");
-attach5 = ICalGLib.Attach.new_from_url ("you");
-
-def my_cmp(a, b): 
-    return cmp(a.get_url(), b.get_url());
-   
-array = ICalGLib.Array.new(10000, 10000);
 array.append (attach1);
 array.append (attach2);
 array.append (attach3);
+array.append (attach4);
+array.append (attach5);
 
-#TEST SORT
-#ICalGLib.Array.sort (array, my_cmp);
-
+a1 = array.element_at (0);
+assert (a1 == attach1);
+a2 = array.element_at (1);
+assert (a2 == attach2);
+a3 = array.element_at (2);
+assert (a3 == attach3);
+a4 = array.element_at (3);
+assert (a4 == attach4);
+a5 = array.element_at (4);
+assert (a5 == attach5);
 
+array = array.copy();
+a1 = array.element_at (0);
+assert (a1 == attach1);
+a2 = array.element_at (1);
+assert (a2 == attach2);
+a3 = array.element_at (2);
+assert (a3 == attach3);
+a4 = array.element_at (3);
+assert (a4 == attach4);
+a5 = array.element_at (4);
+assert (a5 == attach5);
 
+array.remove_element_at (2);
+a3 = array.element_at (2);
+assert (a3 == attach4);


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