From: Timur Safin <tsafin@tarantool.org>
To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2.X v2.1 4/4] module api: external merger tests
Date: Sun, 11 Oct 2020 17:39:52 +0300 [thread overview]
Message-ID: <95573e40e3253be184ce9d92bbd856c17a2842de.1602425022.git.tsafin@tarantool.org> (raw)
In-Reply-To: <cover.1602425022.git.tsafin@tarantool.org>
Added few simple tests for newly introduced
module api functions:
- luaL_checkibuf
- box_tuple_validate
Part of #5384
---
test/app-tap/module_api.c | 26 ++++++++++++++++++
test/app-tap/module_api.test.lua | 45 +++++++++++++++++++++++++++++++-
2 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/test/app-tap/module_api.c b/test/app-tap/module_api.c
index a79fbed0d..fdf1c2d62 100644
--- a/test/app-tap/module_api.c
+++ b/test/app-tap/module_api.c
@@ -150,6 +150,15 @@ test_checkint64(lua_State *L)
return 1;
}
+static int
+test_checkibuf(lua_State *L)
+{
+ struct ibuf *buf;
+ buf = luaL_checkibuf(L, -1);
+ lua_pushboolean(L, buf != NULL);
+ return 1;
+}
+
static int
test_touint64(lua_State *L)
{
@@ -451,6 +460,21 @@ test_iscallable(lua_State *L)
return 1;
}
+static int
+test_tuple_validate(lua_State *L)
+{
+ int valid = 0;
+ box_tuple_t *tuple = luaT_istuple(L, -1);
+
+ if (tuple != NULL) {
+ box_tuple_format_t *format = box_tuple_format_default();
+ valid = box_tuple_validate(format, tuple) == 0;
+ }
+ lua_pushboolean(L, valid);
+
+ return 1;
+}
+
LUA_API int
luaopen_module_api(lua_State *L)
{
@@ -464,6 +488,7 @@ luaopen_module_api(lua_State *L)
{"test_pushint64", test_pushint64 },
{"test_checkuint64", test_checkuint64 },
{"test_checkint64", test_checkint64 },
+ {"checkibuf", test_checkibuf},
{"test_touint64", test_touint64 },
{"test_toint64", test_toint64 },
{"test_fiber", test_fiber },
@@ -479,6 +504,7 @@ luaopen_module_api(lua_State *L)
{"test_state", test_state},
{"test_tostring", test_tostring},
{"iscallable", test_iscallable},
+ {"tuple_validate", test_tuple_validate},
{NULL, NULL}
};
luaL_register(L, "module_api", lib);
diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua
index a6658cc61..12a3ab5ca 100755
--- a/test/app-tap/module_api.test.lua
+++ b/test/app-tap/module_api.test.lua
@@ -38,6 +38,47 @@ local function test_pushcdata(test, module)
test:is(gc_counter, 1, 'pushcdata gc')
end
+local function test_buffers(test, module)
+ test:plan(8)
+ local ffi = require('ffi')
+ local buffer = require('buffer')
+
+ local bufalloc = buffer.static_alloc("char", 128)
+ local ibuf = buffer.ibuf()
+ local pbuf = ibuf:alloc(128)
+
+ test:ok(not module.checkibuf(nil), 'checkibuf of nil')
+ test:ok(not module.checkibuf({}), 'checkibuf of {}')
+ test:ok(not module.checkibuf(1LL), 'checkibuf of 1LL')
+ test:ok(not module.checkibuf(box.NULL), 'checkibuf of box.NULL')
+ test:ok(not module.checkibuf(buffer.reg1), 'checkibuf of reg1')
+ test:ok(not module.checkibuf(bufalloc), 'checkibuf of allocated buffer')
+ test:ok(module.checkibuf(ibuf), 'checkibuf of ibuf')
+ test:ok(not module.checkibuf(pbuf), 'checkibuf of pointer to ibuf data')
+end
+
+local function test_tuples(test, module)
+ test:plan(8)
+
+ local nottuple1 = {}
+ local nottuple2 = {1, 2}
+ local nottuple3 = {1, nil, 2}
+ local nottuple4 = {1, box.NULL, 2, 3}
+ local tuple1 = box.tuple.new(nottuple1)
+ local tuple2 = box.tuple.new(nottuple2)
+ local tuple3 = box.tuple.new(nottuple3)
+ local tuple4 = box.tuple.new(nottuple4)
+
+ test:ok(not module.tuple_validate(nottuple1), "not tuple 1")
+ test:ok(not module.tuple_validate(nottuple2), "not tuple 2")
+ test:ok(not module.tuple_validate(nottuple3), "not tuple 3")
+ test:ok(not module.tuple_validate(nottuple4), "not tuple 4")
+ test:ok(module.tuple_validate(tuple1), "tuple 1")
+ test:ok(module.tuple_validate(tuple2), "tuple 2")
+ test:ok(module.tuple_validate(tuple3), "tuple 3")
+ test:ok(module.tuple_validate(tuple4), "tuple 4")
+end
+
local function test_iscallable(test, module)
local ffi = require('ffi')
@@ -117,7 +158,7 @@ local function test_iscallable(test, module)
end
local test = require('tap').test("module_api", function(test)
- test:plan(24)
+ test:plan(26)
local status, module = pcall(require, 'module_api')
test:is(status, true, "module")
test:ok(status, "module is loaded")
@@ -143,6 +184,8 @@ local test = require('tap').test("module_api", function(test)
test:test("pushcdata", test_pushcdata, module)
test:test("iscallable", test_iscallable, module)
+ test:test("buffers", test_buffers, module)
+ test:test("validate", test_tuples, module)
space:drop()
end)
--
2.20.1
prev parent reply other threads:[~2020-10-11 14:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-11 14:39 [Tarantool-patches] [PATCH 2.X v2.1 0/4] module api: extend for external merger Lua module Timur Safin
2020-10-11 14:39 ` [Tarantool-patches] [PATCH 2.X v2.1 1/4] module api: export box_tuple_validate Timur Safin
2020-10-11 15:42 ` Vladislav Shpilevoy
2020-10-11 15:51 ` Timur Safin
2020-10-11 14:39 ` [Tarantool-patches] [PATCH 2.X v2.1 2/4] module api: export box_key_def_dup Timur Safin
2020-10-11 14:39 ` [Tarantool-patches] [PATCH 2.X v2.1 3/4] module api: luaL_checkibuf Timur Safin
2020-10-11 14:39 ` Timur Safin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95573e40e3253be184ce9d92bbd856c17a2842de.1602425022.git.tsafin@tarantool.org \
--to=tsafin@tarantool.org \
--cc=alexander.turenko@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 2.X v2.1 4/4] module api: external merger tests' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox