update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / test / unit / cms_unittest.cc
blob7d439ee7dc939065753715a55be35bf54e035af0
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_menu_quick.h"
33 #include "cms/cms_types.h"
34 #include "fc/rc_modes.h"
35 #include "fc/runtime_config.h"
36 #include "osd/osd.h"
37 #include "pg/pg_ids.h"
39 PG_REGISTER(osdConfig_t, osdConfig, PG_OSD_CONFIG, 0);
41 void cmsMenuOpen(void);
42 const void *cmsMenuBack(displayPort_t *pDisplay);
43 uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key);
44 extern CMS_Menu *currentMenu; // Points to top entry of the current page
47 #include "unittest_macros.h"
48 #include "unittest_displayport.h"
49 #include "gtest/gtest.h"
51 CMS_Menu cmsx_menuQuick = {
52 .onEnter = NULL,
53 .onExit = NULL,
54 .onDisplayUpdate = NULL,
55 .entries = NULL,
59 TEST(CMSUnittest, TestCmsDisplayPortRegister)
61 cmsInit();
62 displayPort_t *displayPort = displayPortTestInit();
63 for (int ii = 0; ii < CMS_MAX_DEVICE; ++ii) {
64 const bool registered = cmsDisplayPortRegister(displayPort);
65 EXPECT_TRUE(registered);
67 const bool registered = cmsDisplayPortRegister(displayPort);
68 EXPECT_FALSE(registered);
71 TEST(CMSUnittest, TestCmsMenuOpen)
73 cmsInit();
74 displayPort_t *displayPort = displayPortTestInit();
75 displayGrab(displayPort);
76 cmsDisplayPortRegister(displayPort);
78 cmsMenuOpen();
81 TEST(CMSUnittest, TestCmsMenuExit0)
83 cmsInit();
84 displayPort_t *displayPort = displayPortTestInit();
85 cmsDisplayPortRegister(displayPort);
87 cmsMenuOpen();
88 const void *exit = cmsMenuExit(displayPort, (void*)0);
89 EXPECT_EQ(NULL, exit);
92 TEST(CMSUnittest, TestCmsMenuExit1)
94 cmsInit();
95 displayPort_t *displayPort = displayPortTestInit();
96 cmsDisplayPortRegister(displayPort);
98 cmsMenuOpen();
99 const void *exit = cmsMenuExit(displayPort, (void*)0);
100 EXPECT_EQ(NULL, exit);
103 TEST(CMSUnittest, TestCmsMenuBack)
105 cmsInit();
106 displayPort_t *displayPort = displayPortTestInit();
107 cmsDisplayPortRegister(displayPort);
109 cmsMenuOpen();
110 const void *exit = cmsMenuBack(displayPort);
111 EXPECT_EQ(NULL, exit);
114 TEST(CMSUnittest, TestCmsMenuKey)
116 #define KEY_ENTER 0
117 #define KEY_UP 1
118 #define KEY_DOWN 2
119 #define KEY_LEFT 3
120 #define KEY_RIGHT 4
121 #define KEY_ESC 5
122 #define BUTTON_TIME 250 // msec
123 #define BUTTON_PAUSE 500 // msec
124 cmsInit();
125 displayPort_t *displayPort = &testDisplayPort;
126 cmsDisplayPortRegister(displayPort);
128 cmsMenuOpen();
129 uint16_t result = cmsHandleKey(displayPort, KEY_ESC);
130 EXPECT_EQ(BUTTON_PAUSE, result);
132 // STUBS
134 extern "C" {
135 static const OSD_Entry menuMainEntries[] =
137 {"-- MAIN MENU --", OME_Label, NULL, NULL},
138 {"SAVE&REBOOT", OME_OSD_Exit, cmsMenuExit, (void*)1},
139 {"EXIT", OME_OSD_Exit, cmsMenuExit, (void*)0},
140 {NULL, OME_END, NULL, NULL}
142 CMS_Menu cmsx_menuMain = {
143 #ifdef CMS_MENU_DEBUG
144 .GUARD_text = "MENUMAIN",
145 .GUARD_type = OME_MENU,
146 #endif
147 .onEnter = NULL,
148 .onExit = NULL,
149 .entries = menuMainEntries,
151 uint8_t armingFlags;
152 int16_t debug[4];
153 float rcData[18];
154 void delay(uint32_t) {}
155 uint32_t micros(void) { return 0; }
156 uint32_t millis(void) { return 0; }
157 void saveConfigAndNotify(void) {}
158 void stopMotors(void) {}
159 void motorShutdown(void) {}
160 void systemReset(void) {}
161 void setArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
162 void unsetArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
163 bool IS_RC_MODE_ACTIVE(boxId_e) { return false; }
164 void setRebootRequired(void) {}
165 bool getRebootRequired(void) { return false; }