[perl-Gtk3] Refactor a test



commit 7215d6d8fbc329f2156da5c3e3895b0e32b5754b
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Fri Feb 8 01:24:25 2013 +0100

    Refactor a test

 t/zz-GtkCellRendererIface.t |  150 ++++++++++++++++---------------------------
 1 files changed, 55 insertions(+), 95 deletions(-)
---
diff --git a/t/zz-GtkCellRendererIface.t b/t/zz-GtkCellRendererIface.t
index 0df2b9a..d9ac499 100644
--- a/t/zz-GtkCellRendererIface.t
+++ b/t/zz-GtkCellRendererIface.t
@@ -6,16 +6,66 @@ use strict;
 use warnings;
 use Glib ':constants';
 
-if (check_gi_version(1, 29, 17)) {
-  plan tests => 15;
-} else {
-  plan skip_all => 'tree model ctors not properly supported';
+plan skip_all => 'tree model ctors not properly supported'
+  unless check_gi_version(1, 29, 17);
+plan tests => 15;
+
+foreach my $package (qw/StandAlone InheritorC InheritorPerl/) {
+  my ($cell, $view) = prepare_cell ($package);
+
+  my ($min, $nat) = $cell->get_preferred_width ($view);
+  ok (defined $min);
+  ok (defined $nat);
+
+  my $rect = { x => 5, y => 5, width => 10, height => 10 };
+  my $aligned_rect = $cell->get_aligned_area ($view, 'selected', $rect);
+  ok (exists $aligned_rect->{x});
+
+  $cell->set (mode => 'editable');
+  $cell->set (editable => TRUE);
+  my $event = Gtk3::Gdk::Event->new ("button-press");
+  my $editable = $cell->start_editing ($event, $view, "0", $rect, $rect, qw(selected));
+  isa_ok ($editable, "Gtk3::Entry");
+  TODO: {
+    local $TODO = 'ref-counting not quite right yet';
+    my $destroyed = FALSE;
+    $editable->signal_connect (destroy => sub { $destroyed = TRUE });
+    undef $editable;
+    ok ($destroyed, 'editable was destroyed');
+  }
+}
+
+sub prepare_cell {
+  my ($package) = @_;
+
+  my $model = Gtk3::ListStore->new ('Glib::String');
+  foreach (qw/foo fluffy flurble frob frobnitz ftang fire truck/) {
+    my $iter = $model->append;
+    $model->set ($iter, 0, $_);
+  }
+  my $view = Gtk3::TreeView->new ($model);
+
+  my $cell = $package->new;
+  my $column = Gtk3::TreeViewColumn->new_with_attributes (
+                 'stand-alone', $cell);
+  $view->append_column ($column);
+
+  return ($cell, $view);
 }
 
 {
   package StandAlone;
   use Glib::Object::Subclass
-    Gtk3::CellRenderer::
+    Gtk3::CellRenderer::,
+    properties => [
+      Glib::ParamSpec->boolean (
+        'editable',
+        'editable',
+        'editable',
+        Glib::FALSE,
+        [qw/readable writable/],
+      ),
+    ],
     ;
   use Test::More;
   sub GET_PREFERRED_WIDTH {
@@ -33,30 +83,6 @@ if (check_gi_version(1, 29, 17)) {
 }
 
 {
-  my ($cell, $view) = prepare_cell ('StandAlone');
-
-  my ($min, $nat) = $cell->get_preferred_width ($view);
-  is ($min, 23);
-  is ($nat, 42);
-
-  my $rect = { x => 5, y => 5, width => 10, height => 10 };
-  my $aligned_rect = $cell->get_aligned_area ($view, 'selected', $rect);
-  is_deeply ($rect, $aligned_rect);
-
-  $cell->set (mode => 'editable');
-  my $event = Gtk3::Gdk::Event->new ("button-press");
-  my $editable = $cell->start_editing ($event, $view, "0", $rect, $rect, qw(selected));
-  isa_ok ($editable, "Gtk3::Entry");
-  TODO: {
-    local $TODO = 'ref-counting not quite right yet';
-    my $destroyed = FALSE;
-    $editable->signal_connect (destroy => sub { $destroyed = TRUE });
-    undef $editable;
-    ok ($destroyed, 'editable was destroyed');
-  }
-}
-
-{
   package InheritorC;
   use Glib::Object::Subclass
     Gtk3::CellRendererText::
@@ -73,30 +99,6 @@ if (check_gi_version(1, 29, 17)) {
 }
 
 {
-  my ($cell, $view) = prepare_cell ('InheritorC');
-
-  my ($min, $nat) = $cell->get_preferred_width ($view);
-  ok (defined $min);
-  ok (defined $nat);
-
-  my $rect = { x => 5, y => 5, width => 10, height => 10 };
-  my $aligned_rect = $cell->get_aligned_area ($view, 'selected', $rect);
-  ok (exists $aligned_rect->{x});
-
-  $cell->set (editable => TRUE);
-  my $event = Gtk3::Gdk::Event->new ("button-press");
-  my $editable = $cell->start_editing ($event, $view, "0", $rect, $rect, qw(selected));
-  isa_ok ($editable, "Gtk3::Entry");
-  TODO: {
-    local $TODO = 'ref-counting not quite right yet';
-    my $destroyed = FALSE;
-    $editable->signal_connect (destroy => sub { $destroyed = TRUE });
-    undef $editable;
-    ok ($destroyed, 'editable was destroyed');
-  }
-}
-
-{
   package InheritorPerl;
   use Glib::Object::Subclass
     StandAlone::
@@ -111,45 +113,3 @@ if (check_gi_version(1, 29, 17)) {
     return shift->SUPER::START_EDITING (@_);
   }
 }
-
-{
-  my ($cell, $view) = prepare_cell ('InheritorPerl');
-
-  my ($min, $nat) = $cell->get_preferred_width ($view);
-  ok (defined $min);
-  ok (defined $nat);
-
-  my $rect = { x => 5, y => 5, width => 10, height => 10 };
-  my $aligned_rect = $cell->get_aligned_area ($view, 'selected', $rect);
-  ok (exists $aligned_rect->{x});
-
-  $cell->set (mode => 'editable');
-  my $event = Gtk3::Gdk::Event->new ("button-press");
-  my $editable = $cell->start_editing ($event, $view, "0", $rect, $rect, qw(selected));
-  isa_ok ($editable, "Gtk3::Entry");
-  TODO: {
-    local $TODO = 'ref-counting not quite right yet';
-    my $destroyed = FALSE;
-    $editable->signal_connect (destroy => sub { $destroyed = TRUE });
-    undef $editable;
-    ok ($destroyed, 'editable was destroyed');
-  }
-}
-
-sub prepare_cell {
-  my ($package) = @_;
-
-  my $model = Gtk3::ListStore->new ('Glib::String');
-  foreach (qw/foo fluffy flurble frob frobnitz ftang fire truck/) {
-    my $iter = $model->append;
-    $model->set ($iter, 0, $_);
-  }
-  my $view = Gtk3::TreeView->new ($model);
-
-  my $cell = $package->new;
-  my $column = Gtk3::TreeViewColumn->new_with_attributes (
-                 'stand-alone', $cell);
-  $view->append_column ($column);
-
-  return ($cell, $view);
-}


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