Gtk2-Ex-TiedListColumn
view release on metacpan or search on metacpan
t/TiedListColumn.t view on Meta::CPAN
# 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 Gtk2::Ex::TiedListColumn;
use Test::More tests => 2525;
use lib 't';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings() }
my $want_version = 5;
is ($Gtk2::Ex::TiedListColumn::VERSION, $want_version, 'VERSION variable');
is (Gtk2::Ex::TiedListColumn->VERSION, $want_version, 'VERSION class method');
{ ok (eval { Gtk2::Ex::TiedListColumn->VERSION($want_version); 1 },
"VERSION class check $want_version");
my $check_version = $want_version + 1000;
ok (! eval { Gtk2::Ex::TiedListColumn->VERSION($check_version); 1 },
"VERSION class check $check_version");
}
require Gtk2;
MyTestHelpers::glib_gtk_versions();
diag "ListStore can('insert_with_values'): ",
Gtk2::ListStore->can('insert_with_values')||'no',"\n";
#------------------------------------------------------------------------------
# new
{
my $store = Gtk2::ListStore->new ('Glib::String');
my $aref = Gtk2::Ex::TiedListColumn->new ($store);
require Scalar::Util;
Scalar::Util::weaken ($aref);
is ($aref, undef, 'aref garbage collected when weakened');
}
{
my $store = Gtk2::ListStore->new ('Glib::String');
my $aref = Gtk2::Ex::TiedListColumn->new ($store);
require Scalar::Util;
Scalar::Util::weaken ($store);
ok ($store, 'store held alive by aref');
$aref = undef;
is ($store, undef, 'then garbage collected when aref gone');
}
#------------------------------------------------------------------------------
# accessors
{
my $store = Gtk2::ListStore->new ('Glib::String');
my @array;
tie @array, 'Gtk2::Ex::TiedListColumn', $store, 0;
my $tobj = tied(@array);
is ($tobj->VERSION, $want_version, 'VERSION object method');
$tobj->VERSION ($want_version);
is ($tobj->model, $store,
'model() accessor');
is ($tobj->column, 0,
'column() accessor');
}
{
my $store = Gtk2::ListStore->new ('Glib::String');
my $aref = Gtk2::Ex::TiedListColumn->new ($store);
my $tobj = tied(@$aref);
is ($tobj->VERSION, $want_version, 'VERSION object method');
$tobj->VERSION ($want_version);
is (tied(@$aref)->model, $store,
'model() accessor');
is (tied(@$aref)->column, 0,
'column() accessor');
}
#------------------------------------------------------------------------------
my $store = Gtk2::ListStore->new (('Glib::Int') x 6, 'Glib::String');
tie my @tarr, 'Gtk2::Ex::TiedListColumn', $store, 6;
my @plain;
sub store_contents {
my @ret;
for (my $iter = $store->get_iter_first;
$iter;
$iter = $store->iter_next($iter)) {
push @ret, $store->get_value($iter,6);
}
return \@ret;
}
sub set_store {
@plain = @_;
$store->clear;
foreach (@_) {
my $iter = $store->insert (999);
$store->set_value ($iter, 6 => $_);
( run in 1.735 second using v1.01-cache-2.11-cpan-99c4e6809bf )