Gtk2-Ex-TiedListColumn

 view release on metacpan or  search on metacpan

t/TiedMenuChildren.t  view on Meta::CPAN

#
# 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;

use lib 't';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings() }

require Gtk2::Ex::TiedMenuChildren;

require Gtk2;
MyTestHelpers::glib_gtk_versions();

Gtk2->init_check
  or plan skip_all => 'due to no DISPLAY available';
plan tests => 2546;

my $want_version = 5;
is ($Gtk2::Ex::TiedMenuChildren::VERSION, $want_version,
    'VERSION variable');
is (Gtk2::Ex::TiedMenuChildren->VERSION,  $want_version,
    'VERSION class method');
{ ok (eval { Gtk2::Ex::TiedMenuChildren->VERSION($want_version); 1 },
      "VERSION class check $want_version");
  my $check_version = $want_version + 1000;
  ok (! eval { Gtk2::Ex::TiedMenuChildren->VERSION($check_version); 1 },
      "VERSION class check $check_version");
}

#------------------------------------------------------------------------------
# new

{
  my $menu = Gtk2::Menu->new;
  my $aref = Gtk2::Ex::TiedMenuChildren->new ($menu);
  require Scalar::Util;
  Scalar::Util::weaken ($aref);
  is ($aref, undef, 'aref garbage collected when weakened');
}

{
  my $menu = Gtk2::Menu->new;
  my $aref = Gtk2::Ex::TiedMenuChildren->new ($menu);
  require Scalar::Util;
  Scalar::Util::weaken ($menu);
  ok ($menu, 'store held alive by aref');
  $aref = undef;
  is ($menu, undef, 'then garbage collected when aref gone');
}


#------------------------------------------------------------------------------
# accessors

{
  my $menu = Gtk2::Menu->new;
  my @array;
  tie @array, 'Gtk2::Ex::TiedMenuChildren', $menu;
  my $tobj = tied(@array);

  is ($tobj->VERSION, $want_version, 'VERSION object method');
  $tobj->VERSION ($want_version);

  is ($tobj->menu, $menu, 'menu() accessor');
}


#------------------------------------------------------------------------------

my $menu = Gtk2::Menu->new;
tie (my @ttp, 'Gtk2::Ex::TiedMenuChildren', $menu);

sub menu_contents {
  return [$menu->get_children];
}

sub set_menu {
  foreach my $item ($menu->get_children) {
    $menu->remove ($item);
  }
  foreach my $item (@_) {
    $menu->append ($item);
  }
}

my $one   = Gtk2::MenuItem->new_with_label('one');   $one->set_name('One');
my $two   = Gtk2::MenuItem->new_with_label('two');   $two->set_name('Two');
my $three = Gtk2::MenuItem->new_with_label('three'); $three->set_name('Three');
my $four  = Gtk2::MenuItem->new_with_label('four');  $four->set_name('Four');
my $five  = Gtk2::MenuItem->new_with_label('five');  $five->set_name('Five');
my $six   = Gtk2::MenuItem->new_with_label('six');   $six->set_name('Six');
my $seven = Gtk2::MenuItem->new_with_label('seven'); $seven->set_name('Seven');
my $eight = Gtk2::MenuItem->new_with_label('eight'); $eight->set_name('Eight');
my $nine  = Gtk2::MenuItem->new_with_label('nine');  $nine->set_name('Nine');


#------------------------------------------------------------------------------
# fetch

{
  my @array;
  tie @array, 'Gtk2::Ex::TiedMenuChildren', $menu;

  is ($array[0], undef);
  is ($array[1], undef);



( run in 3.671 seconds using v1.01-cache-2.11-cpan-d8267643d1d )