1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 21:35:27 +03:00

Re #2084: gests for Lua Inputs manipulation

This commit is contained in:
Damjan Adamic 2015-02-18 20:27:45 +01:00
parent b0277ed057
commit bc2dd3dc8b
2 changed files with 69 additions and 6 deletions

View file

@ -36,6 +36,7 @@
#include <math.h>
#include <gtest/gtest.h>
#include "gtests.h"
#if defined(LUA)
@ -50,16 +51,19 @@ extern const char * zchar2string(const char * zstring, int size);
#define EXPECT_ZSTREQ(c_string, z_string) EXPECT_STREQ(c_string, zchar2string(z_string, sizeof(z_string)))
extern void luaInit();
void luaExecStr(const char * str)
::testing::AssertionResult __luaExecStr(const char * str)
{
extern lua_State * L;
if (!L) luaInit();
if (!L) FAIL() << "No Lua state!";
if (!L) return ::testing::AssertionFailure() << "No Lua state!";
if (luaL_dostring(L, str)) {
FAIL() << "lua error: " << lua_tostring(L, -1);
return ::testing::AssertionFailure() << "lua error: " << lua_tostring(L, -1);
}
return ::testing::AssertionSuccess();
}
#define luaExecStr(test) EXPECT_TRUE(__luaExecStr(test))
TEST(Lua, testSetModelInfo)
{
luaExecStr("info = model.getInfo()");
@ -124,4 +128,65 @@ TEST(Lua, testPanicProtection)
EXPECT_EQ(passed, true);
}
#endif
TEST(Lua, testModelInputs)
{
MODEL_RESET();
luaExecStr("noInputs = model.getInputsCount(0)");
luaExecStr("if noInputs > 0 then error('getInputsCount()') end");
// add one line on Input4
luaExecStr("model.insertInput(3, 0, {name='test1', source=MIXSRC_Thr, weight=56, offset=3, switch=2})");
EXPECT_EQ(3, g_model.expoData[0].chn);
EXPECT_ZSTREQ("test1", g_model.expoData[0].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[0].srcRaw);
EXPECT_EQ(56, g_model.expoData[0].weight);
EXPECT_EQ(3, g_model.expoData[0].offset);
EXPECT_EQ(2, g_model.expoData[0].swtch);
// add another one before existing line on Input4
luaExecStr("model.insertInput(3, 0, {name='test2', source=MIXSRC_Rud, weight=-56})");
EXPECT_EQ(3, g_model.expoData[0].chn);
EXPECT_ZSTREQ("test2", g_model.expoData[0].name);
EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw);
EXPECT_EQ(-56, g_model.expoData[0].weight);
EXPECT_EQ(0, g_model.expoData[0].offset);
EXPECT_EQ(0, g_model.expoData[0].swtch);
EXPECT_EQ(3, g_model.expoData[1].chn);
EXPECT_ZSTREQ("test1", g_model.expoData[1].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw);
EXPECT_EQ(56, g_model.expoData[1].weight);
EXPECT_EQ(3, g_model.expoData[1].offset);
EXPECT_EQ(2, g_model.expoData[1].swtch);
// add another line after existing lines on Input4
luaExecStr("model.insertInput(3, model.getInputsCount(3), {name='test3', source=MIXSRC_Ail, weight=100})");
EXPECT_EQ(3, g_model.expoData[0].chn);
EXPECT_ZSTREQ("test2", g_model.expoData[0].name);
EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw);
EXPECT_EQ(-56, g_model.expoData[0].weight);
EXPECT_EQ(0, g_model.expoData[0].offset);
EXPECT_EQ(0, g_model.expoData[0].swtch);
EXPECT_EQ(3, g_model.expoData[1].chn);
EXPECT_ZSTREQ("test1", g_model.expoData[1].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw);
EXPECT_EQ(56, g_model.expoData[1].weight);
EXPECT_EQ(3, g_model.expoData[1].offset);
EXPECT_EQ(2, g_model.expoData[1].swtch);
EXPECT_EQ(3, g_model.expoData[2].chn);
EXPECT_ZSTREQ("test3", g_model.expoData[2].name);
EXPECT_EQ(MIXSRC_Ail, g_model.expoData[2].srcRaw);
EXPECT_EQ(100, g_model.expoData[2].weight);
EXPECT_EQ(0, g_model.expoData[2].offset);
EXPECT_EQ(0, g_model.expoData[2].swtch);
// verify number of lines for Input4
luaExecStr("noInputs = model.getInputsCount(3)");
luaExecStr("if noInputs ~= 3 then error('getInputsCount()') end");
}
#endif // #if defined(LUA)