<commit_before>  /******************************************************************
 *
 * Round for C
 *
 * Copyright (C) <NAME> 2015
 *
 * This is licensed under BSD-style license, see file COPYING.
 *
 ******************************************************************/

#include <boost/test/unit_test.hpp>
#include <string>
#include <round/script/lua.h>

#include "ScriptTestController.h"

#if defined(ROUND_SUPPORT_LUA)

BOOST_AUTO_TEST_SUITE(script)
BOOST_AUTO_TEST_SUITE(lua)

static const char *LUA_ECHO_CODE = "function " RPC_HELLO_METHOD_NAME "(params)\n"
  "return params\n"
  "end";

static const char* LUA_SETKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_SET_KEY_METHOD_NAME "(jsonParams)" \
  "  params = json.decode(jsonParams)\n" \
  "  return " ROUND_SYSTEM_METHOD_SET_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"], params[\"" ROUND_SYSTEM_METHOD_PARAM_VALUE "\"])\n" \
  "end\n";
static const char* LUA_GETKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_GET_KEY_METHOD_NAME "(jsonParams)" \
  "  params = json.decode(jsonParams)\n" \
  "  return " ROUND_SYSTEM_METHOD_REMOVE_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"])\n" \
  "end\n";
static const char* LUA_REMOVEKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_REMOVE_KEY_METHOD_NAME "(jsonParams):\n" \
  "  params = json.decode(jsonParams)\n" \
  "  return " ROUND_SYSTEM_METHOD_REMOVE_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"])\n" \
  "end\n";

BOOST_AUTO_TEST_CASE(LuaEngineTest)
{
#define SCRIPT_ECHO_LOOP 10
#define LUA_ECHO_PARAM "hello"

  RoundLuaEngine* luaEngine = round_lua_engine_new();

  RoundMethod* method = round_method_new();
  round_method_setname(method, RPC_HELLO_METHOD_NAME);
  round_method_setstringcode(method, LUA_ECHO_CODE);

  RoundJSONObject* resObj;<commit_msg>* Updated LUA functions.<commit_after>  /******************************************************************
 *
 * Round for C
 *
 * Copyright (C) <NAME> 2015
 *
 * This is licensed under BSD-style license, see file COPYING.
 *
 ******************************************************************/

#include <boost/test/unit_test.hpp>
#include <string>
#include <round/script/lua.h>

#include "ScriptTestController.h"

#if defined(ROUND_SUPPORT_LUA)

BOOST_AUTO_TEST_SUITE(script)
BOOST_AUTO_TEST_SUITE(lua)

static const char *LUA_ECHO_CODE = "function " RPC_HELLO_METHOD_NAME "(params)\n"
  "return params\n"
  "end";

static const char* LUA_SETKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_SET_KEY_METHOD_NAME "(jsonParams)" \
  "  params = json.decode(jsonParams)\n" \
  "  return " ROUND_SYSTEM_METHOD_SET_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"], params[\"" ROUND_SYSTEM_METHOD_PARAM_VALUE "\"])\n" \
  "end\n";
static const char* LUA_GETKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_GET_KEY_METHOD_NAME "(jsonParams)" \
  "  params = json.decode(jsonParams)\n" \
  "  success, value = " ROUND_SYSTEM_METHOD_GET_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"])\n" \
  "  return value\n" \
  "end\n";
static const char* LUA_REMOVEKEY_CODE = \
  "json = require(\"json\") -- JSON4Lua\n" \
  "function " RPC_REMOVE_KEY_METHOD_NAME "(jsonParams)\n" \
  "  params = json.decode(jsonParams)\n" \
  "  return " ROUND_SYSTEM_METHOD_REMOVE_REGISTRY "(params[\"" ROUND_SYSTEM_METHOD_PARAM_KEY "\"])\n" \
  "end\n";

BOOST_AUTO_TEST_CASE(LuaEngineTest)
{
#define SCRIPT_ECHO_LOOP 10
#define LUA_ECHO_PARAM "hello"

  RoundLuaEngine* luaEngine = round_lua_engine_new();

  RoundMethod* method = round_method_new();
  round_method_setname(method, RPC_HELLO_METHOD_NAME);
  round_method_setstringcode(method, LUA_ECHO_CODE);

  RoundJSONObject* resObj;
{'fraction_non_alphanumeric': 0.202674357629785, 'fraction_numerical': 0.0047194546407970635, 'mean_word_length': 5.193181818181818, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3197935', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1372, 'n_words': 233}