File: leak.t

package info (click to toggle)
perl-tk 1%3A800.025-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,444 kB
  • ctags: 19,081
  • sloc: ansic: 206,740; perl: 40,187; makefile: 4,371; sh: 2,373; yacc: 762
file content (139 lines) | stat: -rw-r--r-- 2,912 bytes parent folder | download
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
#!/usr/bin/perl -w
# -*- perl -*-

#
# $Id: leak.t,v 1.3 2002/03/07 23:04:54 eserte Exp $
# Author: Slaven Rezic
#

# Some leak tests. You need Devel::Leak installed and a debugging perl.
# I usually use this arguments to perl's Configure:
#
#     -Doptimize='-g -DPERL_DEBUGGING_MSTATS' -Dusemymalloc='y'
#
# With the patches for tkGlue.c and pTkCallback.c (see the patches
# subdirectory), the problems here should get away.
#

use strict;
use Config;
use Tk;
use Tk::Button;
use Tk::Canvas;

BEGIN {
    if (!eval q{
	use Test;
	use Devel::Leak;
	die if $Config{optimize} !~ /-DPERL_DEBUGGING_MSTATS/;
	1;
    }) {
	print "# tests only work with installed Test and Devel::Leak modules\n";
	print "# also -DPERL_DEBUGGING_MSTATS have to be set\n";
	print "1..1\n";
	print "ok 1\n";
	exit;
    }
}

{
    # gather all todos marked with "TODO: number"
    my @todos;
    open(DATA, $0) or die $!;
    while(<DATA>) {
	push @todos, $1 if (/^\#\s+TODO:\s+(\d+)/);
    }
    close DATA;
    plan tests => 8, todo => [@todos];
}

my $mw = new MainWindow;
my $handle;
my($c1,$c2);

# Tests for leaking subroutine set

# first binding always creates some SVs
$mw->bind("<Motion>" => [sub { warn }]);

$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    $mw->bind("<Motion>" => [sub { warn }]);
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# TODO: 2
$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    $mw->bind("<Motion>" => sub { warn });
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# TODO: 3
$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    $mw->bind("<Motion>" => \&test);
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

my $btn = $mw->Button(-command => sub { warn });
# TODO: 4
$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    $btn->configure(-command => sub { warn });
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# Tests for leaking Tk_GetUid (e.g. canvas items)

my $c = $mw->Canvas->pack;
$c->createLine(10,10,100,100, -tags => "a");

$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    $c->createLine(10,10,100,100,-tags => "a");
    $c->delete("a");
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# TODO: 6
$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    my $id = $c->createLine(10,10,100,100);
    $c->delete($id);
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# Tests for leaking widget destroys
my $btn2 = $mw->Button;
$btn2->destroy;

# TODO: 7
$c1 = Devel::Leak::NoteSV($handle);
for(1..100) {
    my $btn2 = $mw->Button;
    $btn2->destroy;
}
$c2 = Devel::Leak::NoteSV($handle);
ok($c1, $c2);

# Tests for leaking fileevent callbacks
$mw->fileevent(\*STDOUT, 'readable', sub { });
$mw->fileevent(\*STDOUT, 'readable','');

# TODO: 8
$c1 = Devel::Leak::NoteSV($handle);
$mw->fileevent(\*STDOUT, 'readable', sub { });
$mw->fileevent(\*STDOUT, 'readable','');
$c2 = Devel::Leak::CheckSV($handle);
ok($c1, $c2);

sub test { warn }

__END__