File: zz-GtkActionGroup.t

package info (click to toggle)
libgtk3-perl 0.038-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: perl: 4,228; makefile: 11
file content (124 lines) | stat: -rw-r--r-- 3,489 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl

# Copied from Gtk2/t/GtkActionGroup.t

BEGIN { require './t/inc/setup.pl' }

use strict;
use warnings;

plan tests => 28;

use Glib 'TRUE', 'FALSE';

my $action_group = Gtk3::ActionGroup->new ('Fred');

isa_ok ($action_group, 'Gtk3::ActionGroup');
is ($action_group->get_name, 'Fred');

$action_group->set_sensitive (1);
is ($action_group->get_sensitive, 1);

$action_group->set_visible (1);
is ($action_group->get_visible, 1);

my $action = Gtk3::Action->new ('Barney');

$action_group->add_action ($action);

my @list = $action_group->list_actions;
is (@list, 1);
is ($list[0], $action);
is ($action_group->get_action ('Barney'), $action);
$action_group->remove_action ($action);
@list = $action_group->list_actions;
is (@list, 0);

$action_group->add_action_with_accel ($action, undef);
$action_group->remove_action ($action);

$action_group->add_action_with_accel ($action, "<shift>a");
$action_group->remove_action ($action);

my @action_entries = (
  {
    name        => 'open',
    stock_id    => 'gtk-open',
    label       => 'Open',
    accelerator => '<control>o',
    tooltip     => 'Open something',
    callback    => sub { ok (TRUE) },
  },
  {
    name        => 'new',
    stock_id    => 'gtk-new',
  },
  {
    name        => 'old',
    label       => 'Old',
  },
  [ 'close', 'gtk-close', 'Close', '<control>w', 'Close something', sub { ok (TRUE) } ],
  [ 'quit', 'gtk-quit', undef, '<control>q', ],
  [ 'sep',  undef, 'blank', ],
);

my @toggle_entries = (
  [ "Bold", 'gtk-bold', "_Bold",               # name, stock id, label
     "<control>B", "Bold",                     # accelerator, tooltip
    \&activate_action, TRUE ],                 # is_active
);

use constant COLOR_RED   => 0;
use constant COLOR_GREEN => 1;
use constant COLOR_BLUE  => 2;

my @color_entries = (
  # name,    stock id, label,    accelerator,  tooltip, value
  [ "Red",   undef,    "_Red",   "<control>R", "Blood", COLOR_RED   ],
  [ "Green", undef,    "_Green", "<control>G", "Grass", COLOR_GREEN ],
  [ "Blue",  undef,    "_Blue",  "<control>B", "Sky",   COLOR_BLUE  ],
);

#$action_group->add_actions (\@action_entries, 42)
$action_group->add_actions (\@action_entries);
@list = $action_group->list_actions;
is (@list, 6);

$action_group->add_toggle_actions (\@toggle_entries, 42);
#$action_group->add_toggle_actions (\@toggle_entries);
@list = $action_group->list_actions;
is (@list, 7);


#$action_group->add_radio_actions (\@color_entries, COLOR_BLUE, \&on_change, 42);
$action_group->add_radio_actions (\@color_entries, COLOR_GREEN, \&on_change);
@list = $action_group->list_actions;
is (@list, 10);

$action_group->set_translation_domain("de_DE");

$action_group = Gtk3::ActionGroup->new ("Fred");

$action_group->set_translate_func(sub {
  my ($string, $data) = @_;

  is($string, "Urgs");
  is($data, "bla");

  return "Sgru";
}, "bla");

is($action_group->translate_string("Urgs"), "Sgru");

# as of 2.6.0 we have the ability to call the translation function
# from add_*_actions like we're supposed to, so let's test that.
# the following should result in 14 oks.
$action_group->set_translate_func (sub { ok(TRUE, 'xlate'); reverse $_[0]; });
$action_group->add_actions (\@action_entries);
$action_group->add_toggle_actions (\@toggle_entries, 42);
$action_group->add_radio_actions (\@color_entries, COLOR_GREEN, \&on_change);

__END__

Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the
full list).  See LICENSE for more information.