bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2018 Dovecot authors, see the included COPYING file */
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi#include "test-lib.h"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi#include "dlua-script-private.h"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomistatic void test_lua(void)
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi{
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi static const char *luascript =
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi"function script_init(req)\n"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi" dovecot.i_debug(\"lua script init called\")\n"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi" return 0\n"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi"end\n"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi"function lua_function()\n"
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi"end\n";
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi const char *error = NULL;
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi struct dlua_script *script = NULL;
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_begin("lua script");
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi dlua_dovecot_register(script);
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_assert(dlua_script_init(script, &error) == 0);
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_assert(dlua_script_has_function(script, "lua_function"));
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi dlua_script_unref(&script);
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_end();
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi}
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomiint main(void) {
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi void (*tests[])(void) = {
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi test_lua,
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi NULL
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi };
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi return test_run(tests);
e88e76e782853e826d00524ee1133e64fb69b3d9Aki Tuomi}