aboutsummaryrefslogtreecommitdiffstats
path: root/spec/abletonlink_spec.lua
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-12-13 12:31:29 +0000
committers-ol <s+removethis@s-ol.nu>2022-12-13 15:38:48 +0000
commit428b68cfd0b767cdfc716ffb68f8746e3ae192e0 (patch)
tree13b8d39a21041bb7bb2f84e77864cbcb89879014 /spec/abletonlink_spec.lua
downloadlua-abletonlink-428b68cfd0b767cdfc716ffb68f8746e3ae192e0.tar.gz
lua-abletonlink-428b68cfd0b767cdfc716ffb68f8746e3ae192e0.zip
implement simple get/setters
Diffstat (limited to 'spec/abletonlink_spec.lua')
-rw-r--r--spec/abletonlink_spec.lua81
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/abletonlink_spec.lua b/spec/abletonlink_spec.lua
new file mode 100644
index 0000000..a2e4398
--- /dev/null
+++ b/spec/abletonlink_spec.lua
@@ -0,0 +1,81 @@
+local assert = require 'luassert'
+local say = require("say")
+local function greater_than(state, arguments)
+ local min, val = arguments[1], arguments[2]
+ return min < val
+end
+assert:register('assertion', 'greater_than', greater_than, 'assertion.greater_than.positive', 'assertion.greater_than.negative')
+say:set_namespace("en")
+say:set("assertion.greater_than.positive", "Expected %s < %s")
+say:set("assertion.greater_than.negative", "Expected %s >= %s")
+
+describe("abletonlink library", function()
+ local link = require 'abletonlink'
+
+ it("exports a _VERSION", function()
+ -- asset.is.equal('1.0.0', link._VERSION)
+ end)
+
+ it("can create and destroy link objects", function()
+ local l = link.create(120)
+ l:destroy()
+
+ assert.has.error(function()
+ l:is_enabled()
+ end)
+ end)
+
+ it("can be enabled and disabled", function()
+ local l = link.create(120)
+ assert.is_false(l:is_enabled())
+ l:enable()
+ assert.is_true(l:is_enabled())
+
+ l:enable(false)
+ assert.is_false(l:is_enabled())
+ l:enable(true)
+ assert.is_true(l:is_enabled())
+ end)
+
+ it("start/stop sync can be enabled and disabled", function()
+ local l = link.create(120)
+ assert.is_false(l:is_start_stop_sync_enabled())
+ l:enable_start_stop_sync()
+ assert.is_true(l:is_start_stop_sync_enabled())
+
+ l:enable_start_stop_sync(false)
+ assert.is_false(l:is_start_stop_sync_enabled())
+ l:enable_start_stop_sync(true)
+ assert.is_true(l:is_start_stop_sync_enabled())
+ end)
+
+ test("num_peers()", function()
+ local a, b = link.create(120), link.create(120)
+ assert.equal(0, a:num_peers())
+ assert.equal(0, b:num_peers())
+
+ a:enable()
+ b:enable()
+
+ -- stall a bit for connections to succeed
+ for i=1,10000 do
+ i = math.random()
+ end
+
+ assert.greater_than(0, a:num_peers())
+ assert.greater_than(0, b:num_peers())
+ end)
+
+ test("clock_micros()", function()
+ local l = link.create(120)
+
+ local last = 0
+
+ for i=1,10 do
+ local next = l:clock_micros()
+ assert.is.number(next)
+ assert.is.greater_than(last, next)
+ last = next
+ end
+ end)
+end)