[Tarantool-patches] [PATCH 2.X v2.1 4/4] module api: external merger tests

Timur Safin tsafin at tarantool.org
Sun Oct 11 17:39:52 MSK 2020


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



More information about the Tarantool-patches mailing list