From bc2dd3dc8bf3bb5d5c84cbf7471f7f37cdd20d78 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Wed, 18 Feb 2015 20:27:45 +0100 Subject: [PATCH] Re #2084: gests for Lua Inputs manipulation --- radio/src/tests/gtests.h | 2 -- radio/src/tests/lua.cpp | 73 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/radio/src/tests/gtests.h b/radio/src/tests/gtests.h index eff8915d7..464e69b4e 100644 --- a/radio/src/tests/gtests.h +++ b/radio/src/tests/gtests.h @@ -48,8 +48,6 @@ inline void TELEMETRY_RESET() #endif } -void MIXER_RESET(); - bool checkScreenshot(QString test); #endif diff --git a/radio/src/tests/lua.cpp b/radio/src/tests/lua.cpp index 625a51960..bdb502133 100644 --- a/radio/src/tests/lua.cpp +++ b/radio/src/tests/lua.cpp @@ -36,6 +36,7 @@ #include #include +#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)