com gtk/php-gtk: While fixing the NTRVNRP methods GtkTreeModelF ilter::convert_iter_to_child_iter GtkTreeModelFil ter::convert_child_iter_to_iter I noted that the gtktreemodelfilter constructor does not really work, since the second parameter seems to be ignored at all. Further, there is a memlea k when trying to get the virtual-root property of a tree model filter. Just check the unit test.: TODO2 ext/gtk+/gtktreeview.overrides te st/unittests/GtkTr

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    12fae4bdc13c525681a7f54ae48207296ee67e13
Author:    Christian Weiske <[email protected]>         Fri, 30 Jun 2006 22:50:35 +0000
Parents:   4b6971b757dcebf48821ee27d869948fa77c89ea
Branches:  master

Link:       http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=12fae4bdc13c525681a7f54ae48207296ee67e13

Log:
While fixing the NTRVNRP methods
GtkTreeModelFilter::convert_iter_to_child_iter
GtkTreeModelFilter::convert_child_iter_to_iter
I noted that the gtktreemodelfilter constructor
does not really work, since the second parameter seems
to be ignored at all.
Further, there is a memleak when trying to get the
virtual-root property of a tree model filter.
Just check the unit test.

Changed paths:
  M  TODO2
  M  ext/gtk+/gtktreeview.overrides
  M  test/unittests/GtkTreeModelFilterTest.php


Diff:
12fae4bdc13c525681a7f54ae48207296ee67e13
diff --git a/TODO2 b/TODO2
index 02b922e..85f383d 100644
--- a/TODO2
+++ b/TODO2
@@ -62,8 +62,8 @@ Classes and Functions
 	method      GtkTreeModel::rows_reordered: unknown type 'gint*'
 	maybe implement some SPL interfaces?
 * GtkTreeModelFilter
-    NTRVNRP: convert_child_iter_to_iter(GtkTreeIter sort_iter, GtkTreeIter child_iter)
-    NTRVNRP: convert_iter_to_child_iter(GtkTreeIter child_iter, GtkTreeIter sorted_iter);
+    memleak when using get_property('virtual-root')
+    second constructor parameter doesn't work (see unit test)
 * GtkTreeModelSort
     NTRVNRP: convert_child_iter_to_iter(GtkTreeIter sort_iter, GtkTreeIter child_iter)
     NTRVNRP: convert_iter_to_child_iter(GtkTreeIter child_iter, GtkTreeIter sorted_iter);
diff --git a/ext/gtk+/gtktreeview.overrides b/ext/gtk+/gtktreeview.overrides
index ca1787b..d3f5854 100644
--- a/ext/gtk+/gtktreeview.overrides
+++ b/ext/gtk+/gtktreeview.overrides
@@ -1421,6 +1421,70 @@ PHP_METHOD
 }
 
 %%
+add-arginfo GtkTreeModelFilter convert_child_iter_to_iter
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_OBJ_INFO(0, child_iter, GtkTreeIter, 1)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_tree_model_filter_convert_child_iter_to_iter
+PHP_METHOD
+{
+    GtkTreeIter *filter_iter = NULL, *child_iter = NULL;
+    zval *php_child_iter;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "O", &php_child_iter, gboxed_ce))
+        return;
+
+    if (phpg_gboxed_check(php_child_iter, GTK_TYPE_TREE_ITER, FALSE TSRMLS_CC)) {
+        child_iter = (GtkTreeIter *) PHPG_GBOXED(php_child_iter);
+    } else {
+        php_error(E_WARNING, "%s::%s() expects child_iter argument to be a valid GtkTreeIter object",
+                  get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C));
+        return;
+    }
+
+    gtk_tree_model_filter_convert_child_iter_to_iter(GTK_TREE_MODEL_FILTER(PHPG_GOBJECT(this_ptr)), filter_iter, child_iter);
+
+    phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &filter_iter, TRUE, TRUE TSRMLS_CC);
+}
+
+%%
+add-arginfo GtkTreeModelFilter convert_iter_to_child_iter
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_OBJ_INFO(0, filter_iter, GtkTreeIter, 1)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_tree_model_filter_convert_iter_to_child_iter
+PHP_METHOD
+{
+    GtkTreeIter *child_iter = NULL, *filter_iter = NULL;
+    zval *php_filter_iter;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "O", &php_filter_iter, gboxed_ce))
+        return;
+
+    if (phpg_gboxed_check(php_filter_iter, GTK_TYPE_TREE_ITER, FALSE TSRMLS_CC)) {
+        filter_iter = (GtkTreeIter *) PHPG_GBOXED(php_filter_iter);
+    } else {
+        php_error(E_WARNING, "%s::%s() expects filter_iter argument to be a valid GtkTreeIter object",
+                  get_active_class_name(NULL TSRMLS_CC), get_active_function_name(TSRMLS_C));
+        return;
+    }
+
+    gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(PHPG_GOBJECT(this_ptr)), child_iter, filter_iter);
+
+    phpg_gboxed_new(&return_value, GTK_TYPE_TREE_ITER, &child_iter, TRUE, TRUE TSRMLS_CC);
+}
+
+%%
 add-arginfo GtkTreeModelFilter set_visible_func
 static
 ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
diff --git a/test/unittests/GtkTreeModelFilterTest.php b/test/unittests/GtkTreeModelFilterTest.php
index 574d2e6..76a2ac4 100644
--- a/test/unittests/GtkTreeModelFilterTest.php
+++ b/test/unittests/GtkTreeModelFilterTest.php
@@ -37,6 +37,24 @@ class GtkTreeModelFilterTest extends PHPUnit2_Framework_TestCase {
      * @access protected
      */
     protected function setUp() {
+        $this->mod = new GtkTreeStore(Gtk::TYPE_STRING);
+        $this->a = $this->mod->append(null, array('a'));
+            $this->aa = $this->mod->append($this->a, array('aa'));
+            $this->ab = $this->mod->append($this->a, array('ab'));
+            $this->ac = $this->mod->append($this->a, array('ac'));
+            $this->ad = $this->mod->append($this->a, array('ad'));
+        $this->b = $this->mod->append(null, array('b'));
+        $this->c = $this->mod->append(null, array('c'));
+
+
+        $path_a = $this->mod->get_string_from_iter($this->a);
+        $this->tmf = new GtkTreeModelFilter($this->mod, $path_a);
+
+        $this->assertEquals(3, $this->mod->iter_n_children(null));
+        $this->assertEquals(4, $this->mod->iter_n_children($this->a));
+
+        $this->assertNotNull($this->tmf->get_property('virtual-root'));
+        $this->assertEquals(4, $this->tmf->iter_n_children(null));
     }
 
     /**
@@ -73,11 +91,21 @@ class GtkTreeModelFilterTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testConvert_iter_to_child_iter().
+     *
      */
     public function testConvert_iter_to_child_iter() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $a = $this->tmf->get_iter_first();
+        $this->assertType('GtkTreeIter', $a);
+//        var_dump($this->tmf->get_value($a, 0));
+        $this->assertEquals('aa', $this->tmf->get_value($a, 0));
+
+        $child_a = $this->tmf->convert_iter_to_child_iter($a);
+        $this->assertNotNull($child_a);
+        $this->assertType('GtkTreeIter', $child_a);
+        $this->assertEquals(
+            'aa',
+            $this->mod->get_value($child_a, 0)
+        );
     }
 
     /**
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.