From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id CADD044643C for ; Sun, 11 Oct 2020 17:40:10 +0300 (MSK) From: Timur Safin Date: Sun, 11 Oct 2020 17:39:52 +0300 Message-Id: <95573e40e3253be184ce9d92bbd856c17a2842de.1602425022.git.tsafin@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2.X v2.1 4/4] module api: external merger tests List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org Cc: tarantool-patches@dev.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