[perl-Gtk3] Add two interface tests
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add two interface tests
- Date: Sat, 14 Jan 2012 18:47:20 +0000 (UTC)
commit 9d97bdf142400ff7cb1defe1ceb5278ddac62f33
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Sat Jan 14 19:44:49 2012 +0100
Add two interface tests
These exercise some of the vfunc machinery in
Glib::Object::Introspection.
t/zz-GtkCellLayoutIface.t | 109 +++++++++++++++++++++++++++++++
t/zz-GtkCellRendererIface.t | 152 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 261 insertions(+), 0 deletions(-)
---
diff --git a/t/zz-GtkCellLayoutIface.t b/t/zz-GtkCellLayoutIface.t
new file mode 100644
index 0000000..d7abff0
--- /dev/null
+++ b/t/zz-GtkCellLayoutIface.t
@@ -0,0 +1,109 @@
+#!/usr/bin/env perl
+
+BEGIN { require './t/inc/setup.pl' }
+
+use strict;
+use warnings;
+use Glib ':constants';
+
+plan tests => 29;
+
+my $cell = Gtk3::CellRendererText->new ();
+
+my $layout = CustomCellLayout->new ();
+$layout->pack_start ($cell, TRUE);
+$layout->pack_end ($cell, FALSE);
+$layout->clear ();
+$layout->add_attribute ($cell, text => 42);
+$layout->clear_attributes ($cell);
+$layout->reorder ($cell, 42);
+
+my @cells = $layout->get_cells ();
+is (scalar @cells, 2);
+isa_ok ($cells[0], 'Gtk3::CellRendererText');
+isa_ok ($cells[1], 'Gtk3::CellRendererToggle');
+
+my $callback = sub {
+ my ($cb_layout, $cb_cell, $model, $iter, $data) = @_;
+ is ($cb_layout, $layout);
+ is ($cb_cell, $cell);
+ isa_ok ($model, 'Gtk3::ListStore');
+ isa_ok ($iter, 'Gtk3::TreeIter');
+ is ($data, 'bla!');
+};
+$layout->set_cell_data_func ($cell, $callback, 'bla!');
+$layout->set_cell_data_func ($cell, undef);
+
+package CustomCellLayout;
+
+use strict;
+use warnings;
+use Glib ':constants';
+
+use Test::More;
+
+use Glib::Object::Subclass
+ Gtk3::Widget::,
+ interfaces => [ Gtk3::CellLayout:: ],
+ ;
+
+sub PACK_START {
+ my ($self, $cell, $expand) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+ is ($expand, TRUE);
+}
+
+sub PACK_END {
+ my ($self, $cell, $expand) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+ is ($expand, FALSE);
+}
+
+sub CLEAR {
+ my ($self) = @_;
+ isa_ok ($self, __PACKAGE__);
+}
+
+sub ADD_ATTRIBUTE {
+ my ($self, $cell, $attribute, $column) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+ is ($attribute, 'text');
+ is ($column, 42);
+}
+
+sub SET_CELL_DATA_FUNC {
+ my ($self, $cell, $func, $data) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+ if (defined $func) {
+ my $model = Gtk3::ListStore->new (qw/Glib::String/);
+ $func->($self, $cell, $model, $model->append (), $data);
+ }
+}
+
+sub CLEAR_ATTRIBUTES {
+ my ($self, $cell) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+}
+
+sub REORDER {
+ my ($self, $cell, $position) = @_;
+ isa_ok ($self, __PACKAGE__);
+ isa_ok ($cell, 'Gtk3::CellRenderer');
+ is ($position, 42);
+}
+
+sub grow_the_stack { 0 .. 500 };
+
+sub GET_CELLS {
+ my ($self) = @_;
+ isa_ok ($self, __PACKAGE__);
+ $self->{cell_one} = Gtk3::CellRendererText->new;
+ $self->{cell_two} = Gtk3::CellRendererToggle->new;
+ my @list = grow_the_stack();
+ return [$self->{cell_one}, $self->{cell_two}]; # FIXME: list instead of array ref?
+}
diff --git a/t/zz-GtkCellRendererIface.t b/t/zz-GtkCellRendererIface.t
new file mode 100644
index 0000000..1eb7c0d
--- /dev/null
+++ b/t/zz-GtkCellRendererIface.t
@@ -0,0 +1,152 @@
+#!/usr/bin/env perl
+
+BEGIN { require './t/inc/setup.pl' }
+
+use strict;
+use warnings;
+use Glib ':constants';
+use Cairo::GObject;
+
+plan tests => 15;
+
+{
+ package StandAlone;
+ use Glib::Object::Subclass
+ Gtk3::CellRenderer::
+ ;
+ use Test::More;
+ sub GET_PREFERRED_WIDTH {
+ my ($cell, $widget) = @_;
+ return (23, 42);
+ }
+ sub GET_ALIGNED_AREA {
+ my ($cell, $widget, $flags, $cell_area) = @_;
+ return $cell_area;
+ }
+ sub START_EDITING {
+ my ($cell, $event, $widget, $path, $bg_area, $cell_area, $flags) = @_;
+ return Gtk3::Entry->new;
+ }
+}
+
+{
+ 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::
+ ;
+ sub GET_PREFERRED_WIDTH {
+ return shift->SUPER::GET_PREFERRED_WIDTH (@_);
+ }
+ sub GET_ALIGNED_AREA {
+ return shift->SUPER::GET_ALIGNED_AREA (@_);
+ }
+ sub START_EDITING {
+ return shift->SUPER::START_EDITING (@_);
+ }
+}
+
+{
+ 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::
+ ;
+ sub GET_PREFERRED_WIDTH {
+ return shift->SUPER::GET_PREFERRED_WIDTH (@_);
+ }
+ sub GET_ALIGNED_AREA {
+ return shift->SUPER::GET_ALIGNED_AREA (@_);
+ }
+ sub START_EDITING {
+ 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]