Gtk2-Ex-TiedListColumn
view release on metacpan or search on metacpan
t/TiedTreePath.t view on Meta::CPAN
#!/usr/bin/perl -w
# Copyright 2008, 2009, 2010 Kevin Ryde
# This file is part of Gtk2-Ex-TiedListColumn.
#
# Gtk2-Ex-TiedListColumn 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-TiedListColumn 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-TiedListColumn. If not, see <http://www.gnu.org/licenses/>.
use 5.008;
use strict;
use warnings;
use Test::More tests => 2543;
use lib 't';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings() }
require Gtk2::Ex::TiedTreePath;
my $want_version = 5;
is ($Gtk2::Ex::TiedTreePath::VERSION, $want_version, 'VERSION variable');
is (Gtk2::Ex::TiedTreePath->VERSION, $want_version, 'VERSION class method');
{ ok (eval { Gtk2::Ex::TiedTreePath->VERSION($want_version); 1 },
"VERSION class check $want_version");
my $check_version = $want_version + 1000;
ok (! eval { Gtk2::Ex::TiedTreePath->VERSION($check_version); 1 },
"VERSION class check $check_version");
}
require Gtk2;
MyTestHelpers::glib_gtk_versions();
#------------------------------------------------------------------------------
# new
{
my $path = Gtk2::TreePath->new;
my $aref = Gtk2::Ex::TiedTreePath->new ($path);
require Scalar::Util;
Scalar::Util::weaken ($aref);
is ($aref, undef, 'aref garbage collected when weakened');
}
{
my $path = Gtk2::TreePath->new;
my $aref = Gtk2::Ex::TiedTreePath->new ($path);
require Scalar::Util;
Scalar::Util::weaken ($path);
ok ($path, 'store held alive by aref');
$aref = undef;
is ($path, undef, 'then garbage collected when aref gone');
}
#------------------------------------------------------------------------------
# accessors
{
my $path = Gtk2::TreePath->new;
my @array;
tie @array, 'Gtk2::Ex::TiedTreePath', $path, 0;
my $tobj = tied(@array);
is ($tobj->VERSION, $want_version, 'VERSION object method');
$tobj->VERSION ($want_version);
is ($tobj->path, $path, 'path() accessor');
}
{
my $path = Gtk2::TreePath->new;
my $aref = Gtk2::Ex::TiedTreePath->new ($path);
my $tobj = tied(@$aref);
is ($tobj->VERSION, $want_version, 'VERSION object method');
$tobj->VERSION ($want_version);
is (tied(@$aref)->path, $path, 'path() accessor');
}
#------------------------------------------------------------------------------
my $path = Gtk2::TreePath->new;
tie (my @ttp, 'Gtk2::Ex::TiedTreePath', $path);
sub path_contents {
return [$path->get_indices];
}
sub set_path {
while ($path->up) {}
while (@_) { $path->append_index (shift @_) }
}
#------------------------------------------------------------------------------
# fetch
{
my @array;
tie @array, 'Gtk2::Ex::TiedTreePath', $path;
set_path ();
is ($array[0], undef);
is ($array[1], undef);
set_path (123);
is ($array[0], '123');
is ($array[1], undef);
( run in 1.363 second using v1.01-cache-2.11-cpan-39bf76dae61 )