Fix doc path
[opentx.git] / radio / src / tests / functions.cpp
blobfc8c48159d847466b67290241da37822ce28774b
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "gtests.h"
23 class SpecialFunctionsTest : public OpenTxTest {};
25 #if defined(CPUARM)
26 TEST_F(SpecialFunctionsTest, SwitchFiledSize)
28 // test the size of swtch member
29 g_model.customFn[0].swtch = SWSRC_LAST;
30 EXPECT_EQ(g_model.customFn[0].swtch, SWSRC_LAST) << "CustomFunctionData.swtch member is too small to hold all possible values";
31 g_model.customFn[0].swtch = -SWSRC_LAST;
32 EXPECT_EQ(g_model.customFn[0].swtch, -SWSRC_LAST) << "CustomFunctionData.swtch member is too small to hold all possible values";
35 #if defined(PCBTARANIS) || defined(PCBHORUS)
36 TEST_F(SpecialFunctionsTest, FlightReset)
38 g_model.customFn[0].swtch = SWSRC_SA0;
39 g_model.customFn[0].func = FUNC_RESET;
40 g_model.customFn[0].all.val = FUNC_RESET_FLIGHT;
41 g_model.customFn[0].active = true;
43 mainRequestFlags = 0;
44 simuSetSwitch(0, 0);
45 evalFunctions(g_model.customFn, modelFunctionsContext);
46 EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), false);
48 // now trigger SA0
49 simuSetSwitch(0, -1);
51 // flightReset() should be called
52 evalFunctions(g_model.customFn, modelFunctionsContext);
53 EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), true);
55 // now reset mainRequestFlags, and it should stay reset (flightReset() should not be called again)
56 mainRequestFlags = 0;
57 evalFunctions(g_model.customFn, modelFunctionsContext);
58 EXPECT_EQ((bool)(mainRequestFlags & (1 << REQUEST_FLIGHT_RESET)), false);
61 #if defined(GVARS)
62 TEST_F(SpecialFunctionsTest, GvarsInc)
64 simuSetSwitch(0, 0); // SA-
66 g_model.customFn[0].swtch = SWSRC_SA0;
67 g_model.customFn[0].func = FUNC_ADJUST_GVAR;
68 g_model.customFn[0].all.mode = FUNC_ADJUST_GVAR_INCDEC;
69 g_model.customFn[0].all.param = 0; // GV1
70 g_model.customFn[0].all.val = -1; // inc/dec value
71 g_model.customFn[0].active = true;
73 g_model.flightModeData[0].gvars[0] = 10; // GV1 = 10;
74 evalFunctions(g_model.customFn, modelFunctionsContext);
75 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 10);
77 // now trigger SA0
78 simuSetSwitch(0, -1); // SAdown
79 evalFunctions(g_model.customFn, modelFunctionsContext);
80 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
81 evalFunctions(g_model.customFn, modelFunctionsContext);
82 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
84 simuSetSwitch(0, 0); // SA-
85 evalFunctions(g_model.customFn, modelFunctionsContext);
86 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 9);
88 simuSetSwitch(0, -1); // SAdown
89 evalFunctions(g_model.customFn, modelFunctionsContext);
90 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
91 evalFunctions(g_model.customFn, modelFunctionsContext);
92 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
94 simuSetSwitch(0, 0); // SA-
95 evalFunctions(g_model.customFn, modelFunctionsContext);
96 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 8);
98 g_model.customFn[0].all.val = 10; // inc/dec value
100 simuSetSwitch(0, -1); // SAdown
101 evalFunctions(g_model.customFn, modelFunctionsContext);
102 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
103 evalFunctions(g_model.customFn, modelFunctionsContext);
104 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
106 simuSetSwitch(0, 0); // SA-
107 evalFunctions(g_model.customFn, modelFunctionsContext);
108 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 18);
110 simuSetSwitch(0, -1); // SAdown
111 evalFunctions(g_model.customFn, modelFunctionsContext);
112 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 28);
113 evalFunctions(g_model.customFn, modelFunctionsContext);
114 EXPECT_EQ(g_model.flightModeData[0].gvars[0], 28);
116 #endif // #if defined(GVARS)
118 #endif // #if defined(PCBTARANIS) || defined(PCBHORUS)
120 #endif // #if defined(CPUARM)