File: test-leaks.lua

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (86 lines) | stat: -rw-r--r-- 2,679 bytes parent folder | download | duplicates (4)
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
-- Some memory leak checks as integration tests.

local runner = require("_runner")
local awful = require("awful")
local cairo = require("lgi").cairo
local create_wibox = require("_wibox_helper").create_wibox
local wibox = require("wibox")

local prepare_for_collect = nil
local function emit_refresh()
    awesome.emit_signal("refresh")
end

-- Make the layoutbox in the default config GC'able
for s in screen do
    s.mywibox:set_widget(wibox.widget.textbox())
    s.mywibox.visible = false
    s.mywibox = nil
    s.mylayoutbox = nil
end
emit_refresh()

-- Test if some objects can be garbage collected
local function collectable(a, b, c, d, e, f, g, h, last)
    assert(last == nil, "got more arguments than supported")
    local objs = setmetatable({ a, b, c, d, e, f, g, h }, { __mode = "v" })
    a, b, c, d, e, f, g, h = nil, nil, nil, nil, nil, nil, nil, nil -- luacheck: ignore
    if prepare_for_collect then
        prepare_for_collect()
        prepare_for_collect = nil
    end
    collectgarbage("collect")
    collectgarbage("collect")
    collectgarbage("collect")
    -- Check if the table is now empty
    for _, v in pairs(objs) do
        print("Some object was not garbage collected!")
        error(v)
    end
end

-- Use the layoutbox for testing delayed tooltips
local function tooltip_delayed()
    local l = awful.widget.layoutbox(1)
    local t = l._layoutbox_tooltip
    assert(t)
    return l, t
end

local function tooltip_now()
    local w = wibox.widget.textbox("some textbox")
    local t = awful.tooltip({ objects = {w} })
    return w, t
end

-- First test some basic widgets
collectable(wibox.widget.base.make_widget())
collectable(wibox.widget.textbox("foo"))
collectable(wibox.layout.fixed.horizontal())
collectable(wibox.layout.align.horizontal())

-- Then some random widgets from awful
collectable(awful.widget.launcher({ image = cairo.ImageSurface(cairo.Format.ARGB32, 20, 20), command = "bash" }))
collectable(awful.widget.prompt())
collectable(wibox.widget.textclock())
collectable(awful.widget.layoutbox(1))

-- Some widgets do things via timer.delayed_call
prepare_for_collect = emit_refresh
collectable(tooltip_delayed())

prepare_for_collect = emit_refresh
collectable(tooltip_now())

prepare_for_collect = emit_refresh
collectable(awful.widget.taglist{screen=1, filter=awful.widget.taglist.filter.all})

prepare_for_collect = emit_refresh
collectable(awful.widget.tasklist{screen=1, filter=awful.widget.tasklist.filter.currenttags})

prepare_for_collect = emit_refresh
collectable(create_wibox())

runner.run_steps({ function() return true end })

-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80