NAME
Test::Weaken::Gtk2 -- Gtk2 helpers for Test::Weaken
SYNOPSIS
use Test::Weaken::Gtk2;
DESCRIPTION
This is a few functions to help Test::Weaken leak checking on Gtk2 widgets etc. The functions can be used individually, or combined into larger application-specific contents etc handlers.
This module doesn't load Gtk2. If Gtk2 is not loaded then the functions simply return empty, false, or do nothing, as appropriate. This module also doesn't load Test::Weaken, that's left to a test script.
FUNCTIONS
Contents Functions
@widgets = Test::Weaken::Gtk2::contents_container ($ref)-
If
$refis aGtk2::Containeror subclass then return its widget children per$container->get_children(). If$refis not a container, orGtk2is not loaded, then return an empty list.Container children are held in C structures (unless the container is implemented in Perl) and so generally not reached by the traversal
Test::Weakendoes. -
If
$refis aGtk2::MenuItemthen return its submenu per$item->get_submenu(), or if it's aGtk2::MenuToolButtonthen per$item->get_menu(). If there's no menu, or$refis not such a widget, then return an empty list.The submenu in both cases is held in the item's C structure and is not otherwise reached by the traversal
Test::Weakendoes.Only the MenuItem and MenuToolButton classes are acted on currently, just in case a
get_submenu()/get_menu()on some other Gtk class isn't a simple property fetch but perhaps some kind of constructor. Other classes which are a simple fetch could be added here in the future. @widgets = Test::Weaken::Gtk2::contents_cell_renderers ($ref)-
If
$refis a widget with theGtk2::CellLayoutinterface then return itsGtk2::CellRendererobjects fromget_cells(). Or if$refis aGtk2::TreeViewColumnorGtk2::CellViewthenget_cell_renderers(). For anything else the return is an empty list.get_cellsis new in Gtk 2.12.get_cell_renderers()is the previous style. The renderers in a C code viewer widget are held in C structures and are not otherwise reached by the traversalTest::Weakendoes.Gtk2::CellViewas of Gtk 2.20.1 has a bug or severe misfeature where it gives ag_assert()failure on attempting get cells when there's no display row set, including when no model. The returned cells are correct, there's just an assert logged.contents_cell_renderers()suppresses that warning so as to help leak checking of CellViews not yet displaying anything.
When a C-code widget has sub-widgets or renderers as part of its implementation, those children will end up extracted and leak checked by the functions above. This is usually desirable in as much as it notices leaks, even though they may not relate to Perl level code.
Destructor Functions
Test::Weaken::Gtk2::destructor_destroy ($top)-
Call
$top->destroy(), or if$topis an arrayref then calldestroy()on its first element. This can be used when a constructed widget or object requires an explicitdestroy(). For example,my $leaks = leaks({ constructor => sub { Gtk2::Window->new('toplevel') }, destructor => \&Test::Weaken::Gtk2::destructor_destroy, });The arrayref case is designed for multiple widgets etc returned from a constructor, the first of which is a toplevel window or similar needing a
destroy(),my $leaks = leaks({ constructor => sub { my $toplevel = Gtk2::Window->new('toplevel'); my $label = Gtk2::Label->new('Hello World'); $toplevel->add($label); return [ $toplevel, $label ]; }, destructor => \&Test::Weaken::Gtk2::destructor_destroy, });All
Gtk2::Objects supportdestroy()but most don't need it for garbage collection.Gtk2::Windowis the most common which does. Another is a MenuItem which has an AccelLabel and is not in a menu (see notes in Gtk2::MenuItem). Test::Weaken::Gtk2::destructor_destroy_and_iterate ($top)-
The same as
destructor_destroy()above, but in addition runGtk2->main_iteration_do()for queued main loop actions. There's a limit on the number of iterations done, so as to protect against a runaway main loop.This is good if some finalizations are only done in an idle handler, or perhaps under a timer which has now expired. Currently queued events from the X server are run, but there's no read or wait for further events.
Ignore Functions
$bool = Test::Weaken::Gtk2::ignore_default_display ($ref)$bool = Test::Weaken::Gtk2::ignore_default_screen ($ref)$bool = Test::Weaken::Gtk2::ignore_default_root_window ($ref)-
Return true if
$refis respectively the default display, screen or root window, as perGtk2::Gdk::Display->get_default Gtk2::Gdk::Screen->get_default Gtk2::Gdk->get_default_root_windowIf there's no respective default then return false. This happens if
Gtk2is not loaded yet, orGtk2->init()not called yet, and under Gtk 2.0.x there's noGtk2::Gdk::Displayclass andGtk2::Gdk::Screenclasses at all (only a default root window).my $leaks = leaks({ constructor => sub { make_something }, ignore => \&Test::Weaken::Gtk2::ignore_default_display, });These default objects are generally permanent, existing across a test, and on that basis will not normally be tracked for leaking. Usually they're not seen by
leaks()anyway, since they're only in the C structures of widgets, windows, etc. These ignores can be used if operating on the root window, or holding a display or screen in Perl code.
EXPORTS
Nothing is exported by default, but the functions can be requested in usual Exporter style.
use Test::Weaken::Gtk2 'contents_container';
There's no :all tag since new functions are likely to be added in the future and an import of all would risk name clashes with application functions etc.
SEE ALSO
Test::Weaken, Gtk2::Container, Gtk2::MenuItem, Gtk2::Object, Gtk2::Window, Gtk2::Gdk::Display
HOME PAGE
http://user42.tuxfamily.org/gtk2-ex-widgetbits/index.html
LICENSE
Copyright 2008, 2009, 2010, 2011, 2012 Kevin Ryde
Gtk2-Ex-WidgetBits is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Gtk2-Ex-WidgetBits is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Gtk2-Ex-WidgetBits. If not, see http://www.gnu.org/licenses/.