com gtk/php-gtk: Fixed some NTRVNRP methods and added unit tests for them: TODO2 ext/gtk+/gtktextview.overrides ext/gtk+/gtktreeview.overrides test/unittests/GtkTextBufferTest.php test/unittests/GtkTextViewTest.php test/unittests/GtkTreeViewTest.php

[email protected] (David Soria Parra) Tue, 07 Mar 2006 12:39:26 +0000
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    541abe9e92d155794c6dfb4070b01d2feab0145d
Author:    Christian Weiske <[email protected]>         Tue, 7 Mar 2006 12:39:26 +0000
Parents:   9db097a5a29aee9ca6db3c1885de94a82db2fe1c
Branches:  master

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

Log:
Fixed some NTRVNRP methods and added unit tests for them

Changed paths:
  M  TODO2
  M  ext/gtk+/gtktextview.overrides
  M  ext/gtk+/gtktreeview.overrides
  M  test/unittests/GtkTextBufferTest.php
  M  test/unittests/GtkTextViewTest.php
  M  test/unittests/GtkTreeViewTest.php
diff_541abe9e92d155794c6dfb4070b01d2feab0145d.txt (text/plain, 12.4 KB)
541abe9e92d155794c6dfb4070b01d2feab0145d
diff --git a/TODO2 b/TODO2
index 2d4db50..9d4dc7b 100644
--- a/TODO2
+++ b/TODO2
@@ -76,13 +76,7 @@ Classes and Functions
    with their _menu counterparts (so that append_page accepts a third
    parameter from append_page_menu)
 * GtkTextBuffer
-    get_bounds NTRVNRP
     get_iter_at_child_anchor NTRVNRP
-    get_selection_bounds NTRVNRP
-* GtkTextView
-    get_iter_at_location NTRVNRP
-    get_iter_location NTRVNRP
-    get_visible_rect NTRVNRP
 * GtkTreeModel
 	method      GtkTreeModel::get: varargs methods not supported
 	method      GtkTreeModel::get_valist: unknown type 'va_list'
@@ -109,7 +103,6 @@ Classes and Functions
 	method      GtkTreeView::set_search_equal_func: unknown type 'GtkTreeViewSearchEqualFunc'
 	method      GtkTreeView::tree_to_widget_coords: unknown type 'gint*'
 	method      GtkTreeView::widget_to_tree_coords: unknown type 'gint*'
-    get_visible_rect NTRVNRP
 * GtkTextBuffer
 	method      GtkTextBuffer::create_tag: varargs methods not supported
 	method      GtkTextBuffer::insert_with_tags: varargs methods not supported
diff --git a/ext/gtk+/gtktextview.overrides b/ext/gtk+/gtktextview.overrides
index 3ce5218..df6cb3f 100644
--- a/ext/gtk+/gtktextview.overrides
+++ b/ext/gtk+/gtktextview.overrides
@@ -9,6 +9,48 @@ ignore
 %% {{{ GtkTextBuffer
 
 %%
+override gtk_text_buffer_get_bounds
+PHP_METHOD
+{
+    GtkTextIter start, end;
+    zval *php_start = NULL;
+    zval *php_end = NULL;
+
+    NOT_STATIC_METHOD();
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), ""))
+        return;
+
+    gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(PHPG_GOBJECT(this_ptr)), &start, &end);
+
+    phpg_gboxed_new(&php_start, GTK_TYPE_TEXT_ITER, &start, TRUE, TRUE TSRMLS_CC);
+    phpg_gboxed_new(&php_end, GTK_TYPE_TEXT_ITER, &end, TRUE, TRUE TSRMLS_CC);
+
+    php_gtk_build_value(&return_value, "(NN)", php_start, php_end);
+}
+
+%%
+override gtk_text_buffer_get_selection_bounds
+PHP_METHOD
+{
+    GtkTextIter start, end;
+    zval *php_start = NULL;
+    zval *php_end = NULL;
+
+    NOT_STATIC_METHOD();
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), ""))
+        return;
+
+    if (gtk_text_buffer_get_selection_bounds(GTK_TEXT_BUFFER(PHPG_GOBJECT(this_ptr)), &start, &end)) {
+        phpg_gboxed_new(&php_start, GTK_TYPE_TEXT_ITER, &start, TRUE, TRUE TSRMLS_CC);
+        phpg_gboxed_new(&php_end, GTK_TYPE_TEXT_ITER, &end, TRUE, TRUE TSRMLS_CC);
+
+        php_gtk_build_value(&return_value, "(NN)", php_start, php_end);
+    } else {
+        RETURN_FALSE;
+    }
+}
+
+%%
 override gtk_text_buffer_get_start_iter
 PHP_METHOD
 {
@@ -203,6 +245,32 @@ PHP_METHOD
 
 
 %%
+add-arginfo GtkTextView get_iter_at_location
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_INFO(0, x)
+    ZEND_ARG_INFO(0, y)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_text_view_get_iter_at_location
+PHP_METHOD
+{
+    gint x, y;
+    GtkTextIter iter;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "ii", &x, &y))
+        return;
+
+    gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(PHPG_GOBJECT(this_ptr)), &iter, x, y);
+
+    phpg_gboxed_new(&return_value, GTK_TYPE_TEXT_ITER, &iter, TRUE, TRUE TSRMLS_CC);
+}
+
+
+%%
 add-arginfo GtkTextView get_iter_at_position
 static
 ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
@@ -232,6 +300,35 @@ PHP_METHOD
 
 
 %%
+add-arginfo GtkTextView get_iter_location
+static
+ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
+    ZEND_ARG_OBJ_INFO(0, iter, GtkTextIter, 0)
+ZEND_END_ARG_INFO();
+
+%%
+override gtk_text_view_get_iter_location
+PHP_METHOD
+{
+    zval *php_iter = NULL;
+    GtkTextIter *iter = NULL;
+    GdkRectangle rect;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "O", &php_iter, gtktextiter_ce))
+        return;
+
+    if (php_iter && IS_OBJECT == Z_TYPE_P(php_iter)) {
+        iter = (GtkTextIter *) PHPG_GBOXED(php_iter);
+    }
+
+    gtk_text_view_get_iter_location(GTK_TEXT_VIEW(PHPG_GOBJECT(this_ptr)), iter, &rect);
+    phpg_gboxed_new(&return_value, GDK_TYPE_RECTANGLE, &rect, TRUE, TRUE TSRMLS_CC);
+}
+
+
+%%
 add-arginfo GtkTextView get_line_at_y
 static
 ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
@@ -287,6 +384,20 @@ PHP_METHOD
     php_gtk_build_value(&return_value, "(ii)", y, height);
 }
 
+%%
+override gtk_text_view_get_visible_rect
+PHP_METHOD
+{
+    GdkRectangle rect;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), ""))
+        return;
+
+    gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(PHPG_GOBJECT(this_ptr)), &rect);
+    phpg_gboxed_new(&return_value, GDK_TYPE_RECTANGLE, &rect, TRUE, TRUE TSRMLS_CC);
+}
 
 %%
 add-arginfo GtkTextView window_to_buffer_coords
diff --git a/ext/gtk+/gtktreeview.overrides b/ext/gtk+/gtktreeview.overrides
index 448405e..cac8c96 100644
--- a/ext/gtk+/gtktreeview.overrides
+++ b/ext/gtk+/gtktreeview.overrides
@@ -1323,6 +1323,22 @@ PHP_METHOD
 
 
 %%
+override gtk_tree_view_get_visible_rect
+PHP_METHOD
+{
+    GdkRectangle rect;
+
+    NOT_STATIC_METHOD();
+
+    if (!php_gtk_parse_args(ZEND_NUM_ARGS(), ""))
+        return;
+
+    gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(PHPG_GOBJECT(this_ptr)), &rect);
+    phpg_gboxed_new(&return_value, GDK_TYPE_RECTANGLE, &rect, TRUE, TRUE TSRMLS_CC);
+}
+
+
+%%
 add-arginfo GtkTreeView tree_to_widget_coords
 static
 ZEND_BEGIN_ARG_INFO(ARGINFO_NAME, 0)
diff --git a/test/unittests/GtkTextBufferTest.php b/test/unittests/GtkTextBufferTest.php
index 890729d..d1af8a0 100644
--- a/test/unittests/GtkTextBufferTest.php
+++ b/test/unittests/GtkTextBufferTest.php
@@ -10,11 +10,11 @@ require_once "PHPUnit2/Framework/TestSuite.php";
 // You may remove the following line when all tests have been implemented.
 require_once "PHPUnit2/Framework/IncompleteTestError.php";
 
-require_once "";
+//require_once "";
 
 /**
  * Test class for GtkTextBuffer.
- * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 13:26:41.
+ * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 11:37:05.
  */
 class GtkTextBufferTest extends PHPUnit2_Framework_TestCase {
     /**
@@ -37,6 +37,7 @@ class GtkTextBufferTest extends PHPUnit2_Framework_TestCase {
      * @access protected
      */
     protected function setUp() {
+        $this->tb = new GtkTextBuffer();
     }
 
     /**
@@ -169,11 +170,16 @@ class GtkTextBufferTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testGet_bounds().
+     *  get_bounds should return an array with start and end iterator
      */
     public function testGet_bounds() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $this->tb->set_text('Hello world');
+        $ar = $this->tb->get_bounds();
+        $this->assertTrue(is_array($ar));
+        $this->assertEquals(2, count($ar));
+        $this->assertEquals('GtkTextIter', get_class($ar[0]));
+        $this->assertEquals('GtkTextIter', get_class($ar[1]));
+        $this->assertEquals('Hello world', $this->tb->get_text($ar[0], $ar[1]));
     }
 
     /**
@@ -281,11 +287,28 @@ class GtkTextBufferTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testGet_selection_bounds().
+     * selection bounds with selection
      */
     public function testGet_selection_bounds() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        //Something selected -> should return array
+        $this->tb->set_text('Hello world');
+        $this->tb->select_range($this->tb->get_start_iter(), $this->tb->get_end_iter());
+        $ar = $this->tb->get_selection_bounds();
+        $this->assertTrue(is_array($ar));
+        $this->assertEquals(2, count($ar));
+        $this->assertEquals('GtkTextIter', get_class($ar[0]));
+        $this->assertEquals('GtkTextIter', get_class($ar[1]));
+        $this->assertEquals('Hello world', $this->tb->get_text($ar[0], $ar[1]));
+    }
+
+    /**
+     * selection bounds with no selection
+     */
+    public function testGet_selection_boundsNoSelection() {
+        //Something selected -> should return array
+        $this->tb->set_text('Hello world');
+        $ar = $this->tb->get_selection_bounds();
+        $this->assertFalse($ar);
     }
 
     /**
diff --git a/test/unittests/GtkTextViewTest.php b/test/unittests/GtkTextViewTest.php
index 2d5ca5e..ca2f586 100644
--- a/test/unittests/GtkTextViewTest.php
+++ b/test/unittests/GtkTextViewTest.php
@@ -10,11 +10,9 @@ require_once "PHPUnit2/Framework/TestSuite.php";
 // You may remove the following line when all tests have been implemented.
 require_once "PHPUnit2/Framework/IncompleteTestError.php";
 
-require_once "";
-
 /**
  * Test class for GtkTextView.
- * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 13:26:41.
+ * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 11:37:05.
  */
 class GtkTextViewTest extends PHPUnit2_Framework_TestCase {
     /**
@@ -37,6 +35,7 @@ class GtkTextViewTest extends PHPUnit2_Framework_TestCase {
      * @access protected
      */
     protected function setUp() {
+        $this->tv = new GtkTextView();
     }
 
     /**
@@ -164,8 +163,9 @@ class GtkTextViewTest extends PHPUnit2_Framework_TestCase {
      * @todo Implement testGet_iter_at_location().
      */
     public function testGet_iter_at_location() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $iter = $this->tv->get_iter_at_location(0,0);
+        $this->assertEquals('GtkTextIter', get_class($iter));
+        $this->assertNotNull($iter);
     }
 
     /**
@@ -177,11 +177,18 @@ class GtkTextViewTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testGet_iter_location().
+     * 
      */
     public function testGet_iter_location() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $iter = $this->tv->get_buffer()->get_end_iter();
+        $this->assertNotNull($iter);
+
+        $rect = $this->tv->get_iter_location($iter);
+        $this->assertEquals('GdkRectangle', get_class($rect));
+        $this->assertNotNull($rect);
+        //this values *should* be null as the view isn't visible
+        $this->assertEquals(0, $rect->x);
+        $this->assertEquals(0, $rect->y);
     }
 
     /**
@@ -265,11 +272,17 @@ class GtkTextViewTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testGet_visible_rect().
+     *
      */
     public function testGet_visible_rect() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $rect = $this->tv->get_visible_rect();
+        $this->assertEquals('GdkRectangle', get_class($rect));
+        $this->assertNotNull($rect);
+        //this values *should* be null as the view isn't visible
+        $this->assertEquals(0, $rect->x);
+        $this->assertEquals(0, $rect->y);
+//        $this->assertEquals(0, $rect->width);
+//        $this->assertEquals(0, $rect->height);
     }
 
     /**
diff --git a/test/unittests/GtkTreeViewTest.php b/test/unittests/GtkTreeViewTest.php
index c2199af..c88e293 100644
--- a/test/unittests/GtkTreeViewTest.php
+++ b/test/unittests/GtkTreeViewTest.php
@@ -10,11 +10,9 @@ require_once "PHPUnit2/Framework/TestSuite.php";
 // You may remove the following line when all tests have been implemented.
 require_once "PHPUnit2/Framework/IncompleteTestError.php";
 
-require_once "";
-
 /**
  * Test class for GtkTreeView.
- * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 13:26:41.
+ * Generated by PHPUnit2_Util_Skeleton on 2006-03-07 at 11:37:05.
  */
 class GtkTreeViewTest extends PHPUnit2_Framework_TestCase {
     /**
@@ -37,6 +35,7 @@ class GtkTreeViewTest extends PHPUnit2_Framework_TestCase {
      * @access protected
      */
     protected function setUp() {
+        $this->tv = new GtkTreeView();
     }
 
     /**
@@ -265,11 +264,15 @@ class GtkTreeViewTest extends PHPUnit2_Framework_TestCase {
     }
 
     /**
-     * @todo Implement testGet_visible_rect().
+     *
      */
     public function testGet_visible_rect() {
-        // Remove the following line when you implement this test.
-        throw new PHPUnit2_Framework_IncompleteTestError;
+        $rect = $this->tv->get_visible_rect();
+        $this->assertEquals('GdkRectangle', get_class($rect));
+        $this->assertNotNull($rect);
+        //this values *should* be null as the view isn't visible
+        $this->assertEquals(0, $rect->x);
+        $this->assertEquals(0, $rect->y);
     }
 
     /**