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
|
--
-- test for load_extension
--
-- before running this script, you must compile extension-functions.c
-- e.g., in directory extras:
-- gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib
--
-- then run this script from the top level directory: lua test/test-dyld.lua
local sqlite3 = require "lsqlite3"
local os = os
local lunit = require "lunitx"
local tests_sqlite3
if _VERSION >= 'Lua 5.2' then
tests_sqlite3 = lunit.module('tests-sqlite3','seeall')
_ENV = tests_sqlite3
else
module('tests_sqlite3', lunit.testcase, package.seeall)
tests_sqlite3 = _M
end
-- compat
function lunit_wrap (name, fcn)
tests_sqlite3['test_o_'..name] = fcn
end
function lunit_TestCase (name)
return lunit.module(name,'seeall')
end
local db_dyld = lunit_TestCase("Load Extension")
function db_dyld.setup()
db_dyld.db = assert( sqlite3.open_memory() )
assert_equal( sqlite3.OK, db_dyld.db:exec("CREATE TABLE test (id, name)") )
assert_equal( sqlite3.OK, db_dyld.db:exec("INSERT INTO test VALUES (1, 'Hello World')") )
assert_equal( sqlite3.OK, db_dyld.db:exec("INSERT INTO test VALUES (2, 'Hello Lua')") )
assert_equal( sqlite3.OK, db_dyld.db:exec("INSERT INTO test VALUES (3, 'Hello sqlite3')") )
end
function db_dyld.teardown()
assert( db_dyld.db:close() )
end
function db_dyld.test()
local db = db_dyld.db
assert_function( db.load_extension )
assert_true( db:load_extension "extras/libsqlitefunctions" )
for row in db:nrows("SELECT log10(id) as val FROM test WHERE name='Hello World'") do
assert_equal (row.val, 0.0)
end
for row in db:nrows("SELECT reverse(name) as val FROM test WHERE id = 2") do
assert_equal (row.val, 'auL olleH')
end
for row in db:nrows("SELECT padl(name, 16) as val FROM test WHERE id = 3") do
assert_equal (row.val, ' Hello sqlite3')
end
end
|