File: 4.t

package info (click to toggle)
libglib-perl 3%3A1.329-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,320 kB
  • sloc: perl: 4,938; ansic: 901; makefile: 7
file content (142 lines) | stat: -rw-r--r-- 3,809 bytes parent folder | download | duplicates (7)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl
#
# test Glib::Object derivation in Perl.
# derive from a C object in perl, and derive from a Perl object in perl.
# checks order of execution of initializers and finalizers, so the code
# gets a little hairy.
#
use strict;
use warnings;

use Glib qw(:constants);

# From 7.t.  Do we need a test helper class?
sub ok($$;$) {
    my($test, $num, $name) = @_;

    my $out = $test ? "ok" : "not ok";
    $out .= " $num" if $num;
    $out .= " - $name" if defined $name;

    print "$out\n";

    return $test;
}

sub pass($;$) {
    my($num, $name) = @_;
    return ok(1, $num, $name);
}

sub fail(;$) {
    my($name) = @_;
    return ok(0, 0, $name);
}

print "1..17\n";
pass 1;

my $init_self;

sub Foo::INIT_INSTANCE {
   $init_self = $_[0]*1;
   pass 2, 'Foo::INIT_INSTANCE';
}

sub Foo::FINALIZE_INSTANCE {
   pass 9, 'Foo::FINALIZE_INSTANCE'
}

my $setprop_self;

sub Foo::SET_PROPERTY {
   $setprop_self = $_[0]*1;
   pass $_[2], 'Foo::SET_PROPERTY';
}

sub Foo::GET_PROPERTY {
   pass 6, 'Foo::GET_PROPERTY';
   6;
}

Glib::Type->register (
   Glib::Object::, Foo::,
   properties => [
           Glib::ParamSpec->string (
              'some_string',
              'Some String Property',
              'This property is a string that is used as an example',
              'default value',
              [qw/readable writable/]
           ),
   ]);

sub Bar::INIT_INSTANCE {
   pass 3, 'Bar::INIT_INSTANCE';
}

sub Bar::FINALIZE_INSTANCE {
   pass 8, 'Bar::FINALIZE_INSTANCE';
}

Glib::Type->register (Foo::, Bar::,
                      properties => [
                         Glib::ParamSpec->int ('number', 'some number',
                                               'number in bar but not in foo',
                                               0, 10, 0, ['readable']),
                      ]);

{
   # instantiate a child.  we should get messages from both initializers.
   my $bar = new Bar;
   # make sure we can set parent properties on the child
   $bar->set(some_string => 4);
   ok $init_self == $setprop_self, 5;
   ok $bar->get("some_string") == 6, 7;
   # should see messages from both finalizers here.
}

pass 10;

#
# ensure that any properties added to the subclass were only added to
# the subclass, and not the parent.
#
ok  defined Foo->find_property('some_string'), 11;
ok !defined Foo->find_property('number'),      12;
ok  defined Bar->find_property('number'),      13;

my @fooprops = Foo->list_properties;
my @barprops = Bar->list_properties;

ok @fooprops == 1, 14, 'property count for parent';
ok @barprops == 2, 15, 'property count for child';

my @ancestry = Glib::Type->list_ancestors ('Bar');
my $ancestry_ok = $ancestry[0] eq 'Bar' &&
                  $ancestry[1] eq 'Foo' &&
                  $ancestry[2] eq 'Glib::Object';
print "".($ancestry_ok ? "ok 16" : "not ok")." - ancestry for Bar\n";

my $cname_ok = Glib::Type->package_from_cname ('GObject') eq 'Glib::Object';
print "".($cname_ok ? "ok 17" : "not ok")." - package_from_cname\n";


__END__

Copyright (C) 2003-2006 by the gtk2-perl team (see the file AUTHORS for the
full list)

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Library General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library 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 Library General Public License for more
details.

You should have received a copy of the GNU Library General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.