2014-08-23 21:57:52 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2014 Uli Schlachter
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local object = require("gears.object")
|
|
|
|
|
|
|
|
describe("gears.object", function()
|
|
|
|
local obj
|
|
|
|
before_each(function()
|
|
|
|
obj = object()
|
|
|
|
obj:add_signal("signal")
|
|
|
|
end)
|
|
|
|
|
2015-06-14 14:21:23 +02:00
|
|
|
it("strong connect non-existent signal", function()
|
2014-08-23 21:57:52 +02:00
|
|
|
assert.has.errors(function()
|
|
|
|
obj:connect_signal("foo", function() end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2015-06-14 14:21:23 +02:00
|
|
|
it("weak connect non-existent signal", function()
|
|
|
|
assert.has.errors(function()
|
|
|
|
obj:weak_connect_signal("foo", function() end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("strong disconnect non-existent signal", function()
|
2014-08-23 21:57:52 +02:00
|
|
|
assert.has.errors(function()
|
|
|
|
obj:disconnect_signal("foo", function() end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("emitting non-existent signal", function()
|
|
|
|
assert.has.errors(function()
|
|
|
|
obj:emit_signal("foo")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2015-06-14 14:21:23 +02:00
|
|
|
it("strong connecting and emitting signal", function()
|
2014-08-23 21:57:52 +02:00
|
|
|
local called = false
|
2015-06-14 14:21:23 +02:00
|
|
|
local function cb()
|
2014-08-23 21:57:52 +02:00
|
|
|
called = true
|
2015-06-14 14:21:23 +02:00
|
|
|
end
|
|
|
|
obj:connect_signal("signal", cb)
|
2014-08-23 21:57:52 +02:00
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_true(called)
|
|
|
|
end)
|
|
|
|
|
2015-06-14 14:21:23 +02:00
|
|
|
it("weak connecting and emitting signal", function()
|
|
|
|
local called = false
|
|
|
|
local function cb()
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
obj:weak_connect_signal("signal", cb)
|
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_true(called)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("strong connecting, disconnecting and emitting signal", function()
|
2014-08-23 21:57:52 +02:00
|
|
|
local called = false
|
|
|
|
local function cb()
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
obj:connect_signal("signal", cb)
|
|
|
|
obj:disconnect_signal("signal", cb)
|
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_false(called)
|
|
|
|
end)
|
|
|
|
|
2015-06-14 14:21:23 +02:00
|
|
|
it("weak connecting, disconnecting and emitting signal", function()
|
|
|
|
local called = false
|
|
|
|
local function cb()
|
|
|
|
called = true
|
|
|
|
end
|
|
|
|
obj:weak_connect_signal("signal", cb)
|
|
|
|
obj:disconnect_signal("signal", cb)
|
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_false(called)
|
|
|
|
end)
|
|
|
|
|
2014-08-23 21:57:52 +02:00
|
|
|
it("arguments to signal", function()
|
|
|
|
obj:connect_signal("signal", function(arg1, arg2)
|
|
|
|
assert.is.equal(obj, arg1)
|
|
|
|
assert.is.same(42, arg2)
|
|
|
|
end)
|
2015-06-14 14:21:23 +02:00
|
|
|
obj:weak_connect_signal("signal", function(arg1, arg2)
|
|
|
|
assert.is.equal(obj, arg1)
|
|
|
|
assert.is.same(42, arg2)
|
|
|
|
end)
|
2014-08-23 21:57:52 +02:00
|
|
|
obj:emit_signal("signal", 42)
|
|
|
|
end)
|
2015-06-14 14:21:23 +02:00
|
|
|
|
|
|
|
it("strong non-auto disconnect", function()
|
|
|
|
local called = false
|
|
|
|
obj:connect_signal("signal", function()
|
|
|
|
called = true
|
|
|
|
end)
|
|
|
|
collectgarbage("collect")
|
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_true(called)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("weak auto disconnect", function()
|
|
|
|
local called = false
|
|
|
|
obj:weak_connect_signal("signal", function()
|
|
|
|
called = true
|
|
|
|
end)
|
|
|
|
collectgarbage("collect")
|
|
|
|
obj:emit_signal("signal")
|
|
|
|
assert.is_false(called)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("strong connect after weak connect", function()
|
|
|
|
local function cb() end
|
|
|
|
obj:weak_connect_signal("signal", cb)
|
|
|
|
assert.has.errors(function()
|
|
|
|
obj:connect_signal("signal", cb)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("weak connect after strong connect", function()
|
|
|
|
local function cb() end
|
|
|
|
obj:connect_signal("signal", cb)
|
|
|
|
assert.has.errors(function()
|
|
|
|
obj:weak_connect_signal("signal", cb)
|
|
|
|
end)
|
|
|
|
end)
|
2014-08-23 21:57:52 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|