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
| | require "tempfile"
require "test/unit"
require "mall"
class TestMall < Test::Unit::TestCase
def test_module
assert_kind_of Module, Mall
end
def test_mallinfo
assert Hash === Mall.info
Mall.info.each { |key,value|
assert Symbol === key
assert Fixnum === value
}
end
def test_mallopt
Mall.constants.each { |konst|
rv = Mall.opt(Mall.const_get(konst), 0)
assert(TrueClass === rv || FalseClass === rv)
}
end
def test_trim
if Mall.respond_to?(:trim)
rv = Mall.trim(1024)
assert(TrueClass === rv || FalseClass === rv)
else
warn "Mall.trim not supported"
end
end
def test_xml
if Mall.respond_to?(:xml)
str = Mall.xml
assert_match /<malloc version=/, str
tmp = []
assert_equal tmp, Mall.xml(0, tmp)
assert_match /<malloc version=/, tmp[0]
assert_equal 1, tmp.size
else
warn "Mall.xml not supported"
end
end
def test_dump_stats
if Mall.respond_to?(:dump_stats)
olderr = $stderr.dup
begin
tmp = Tempfile.new('mall_dump_stats')
$stderr.sync = tmp.sync = true
$stderr.reopen(tmp)
assert_nil Mall.dump_stats
assert tmp.stat.size != 0
ensure
$stderr.reopen(olderr)
end
else
warn "Mall.dump_stats not supported"
end
end
end
|