Extend the scope of BOXPARALYZE to cover stick commands, adjustments, and CMS.
[betaflight.git] / src / test / unit / cms_unittest.cc
blob2a4130899312c0399eabe5fc064b33bb62d51f8a
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <stdio.h>
22 #include <limits.h>
24 #include <math.h>
26 #define USE_BARO
28 extern "C" {
29 #include "platform.h"
30 #include "target.h"
31 #include "cms/cms.h"
32 #include "cms/cms_types.h"
33 #include "fc/rc_modes.h"
34 #include "fc/runtime_config.h"
35 void cmsMenuOpen(void);
36 long cmsMenuBack(displayPort_t *pDisplay);
37 uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key);
38 extern CMS_Menu *currentMenu; // Points to top entry of the current page
41 #include "unittest_macros.h"
42 #include "unittest_displayport.h"
43 #include "gtest/gtest.h"
45 TEST(CMSUnittest, TestCmsDisplayPortRegister)
47 cmsInit();
48 displayPort_t *displayPort = displayPortTestInit();
49 for (int ii = 0; ii < CMS_MAX_DEVICE; ++ii) {
50 const bool registered = cmsDisplayPortRegister(displayPort);
51 EXPECT_EQ(true, registered);
53 const bool registered = cmsDisplayPortRegister(displayPort);
54 EXPECT_EQ(false, registered);
57 TEST(CMSUnittest, TestCmsMenuOpen)
59 cmsInit();
60 displayPort_t *displayPort = displayPortTestInit();
61 displayGrab(displayPort);
62 cmsDisplayPortRegister(displayPort);
64 cmsMenuOpen();
67 TEST(CMSUnittest, TestCmsMenuExit0)
69 cmsInit();
70 displayPort_t *displayPort = displayPortTestInit();
71 cmsDisplayPortRegister(displayPort);
73 cmsMenuOpen();
74 long exit = cmsMenuExit(displayPort, (void*)0);
75 EXPECT_EQ(0, exit);
78 TEST(CMSUnittest, TestCmsMenuExit1)
80 cmsInit();
81 displayPort_t *displayPort = displayPortTestInit();
82 cmsDisplayPortRegister(displayPort);
84 cmsMenuOpen();
85 long exit = cmsMenuExit(displayPort, (void*)0);
86 EXPECT_EQ(0, exit);
89 TEST(CMSUnittest, TestCmsMenuBack)
91 cmsInit();
92 displayPort_t *displayPort = displayPortTestInit();
93 cmsDisplayPortRegister(displayPort);
95 cmsMenuOpen();
96 long exit = cmsMenuBack(displayPort);
97 EXPECT_EQ(0, exit);
100 TEST(CMSUnittest, TestCmsMenuKey)
102 #define KEY_ENTER 0
103 #define KEY_UP 1
104 #define KEY_DOWN 2
105 #define KEY_LEFT 3
106 #define KEY_RIGHT 4
107 #define KEY_ESC 5
108 #define BUTTON_TIME 250 // msec
109 #define BUTTON_PAUSE 500 // msec
110 cmsInit();
111 displayPort_t *displayPort = &testDisplayPort;
112 cmsDisplayPortRegister(displayPort);
114 cmsMenuOpen();
115 uint16_t result = cmsHandleKey(displayPort, KEY_ESC);
116 EXPECT_EQ(BUTTON_PAUSE, result);
118 // STUBS
120 extern "C" {
121 static OSD_Entry menuMainEntries[] =
123 {"-- MAIN MENU --", OME_Label, NULL, NULL, 0},
124 {"SAVE&REBOOT", OME_OSD_Exit, cmsMenuExit, (void*)1, 0},
125 {"EXIT", OME_OSD_Exit, cmsMenuExit, (void*)0, 0},
126 {NULL, OME_END, NULL, NULL, 0}
128 CMS_Menu menuMain = {
129 #ifdef CMS_MENU_DEBUG
130 "MENUMAIN",
131 OME_MENU,
132 #endif
133 NULL,
134 NULL,
135 menuMainEntries,
137 uint8_t armingFlags;
138 int16_t debug[4];
139 int16_t rcData[18];
140 void delay(uint32_t) {}
141 uint32_t micros(void) { return 0; }
142 uint32_t millis(void) { return 0; }
143 void saveConfigAndNotify(void) {}
144 void stopMotors(void) {}
145 void stopPwmAllMotors(void) {}
146 void systemReset(void) {}
147 void setArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
148 void unsetArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
149 bool IS_RC_MODE_ACTIVE(boxId_e) { return false; }