Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / src / test / unit / cms_unittest.cc
blobba7a00dceb118aa14ab3b302ab7ac1a29472af13
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 #include "osd/osd.h"
36 #include "pg/pg_ids.h"
38 PG_REGISTER(osdConfig_t, osdConfig, PG_OSD_CONFIG, 0);
40 void cmsMenuOpen(void);
41 const void *cmsMenuBack(displayPort_t *pDisplay);
42 uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key);
43 extern CMS_Menu *currentMenu; // Points to top entry of the current page
46 #include "unittest_macros.h"
47 #include "unittest_displayport.h"
48 #include "gtest/gtest.h"
50 TEST(CMSUnittest, TestCmsDisplayPortRegister)
52 cmsInit();
53 displayPort_t *displayPort = displayPortTestInit();
54 for (int ii = 0; ii < CMS_MAX_DEVICE; ++ii) {
55 const bool registered = cmsDisplayPortRegister(displayPort);
56 EXPECT_TRUE(registered);
58 const bool registered = cmsDisplayPortRegister(displayPort);
59 EXPECT_FALSE(registered);
62 TEST(CMSUnittest, TestCmsMenuOpen)
64 cmsInit();
65 displayPort_t *displayPort = displayPortTestInit();
66 displayGrab(displayPort);
67 cmsDisplayPortRegister(displayPort);
69 cmsMenuOpen();
72 TEST(CMSUnittest, TestCmsMenuExit0)
74 cmsInit();
75 displayPort_t *displayPort = displayPortTestInit();
76 cmsDisplayPortRegister(displayPort);
78 cmsMenuOpen();
79 const void *exit = cmsMenuExit(displayPort, (void*)0);
80 EXPECT_EQ(NULL, exit);
83 TEST(CMSUnittest, TestCmsMenuExit1)
85 cmsInit();
86 displayPort_t *displayPort = displayPortTestInit();
87 cmsDisplayPortRegister(displayPort);
89 cmsMenuOpen();
90 const void *exit = cmsMenuExit(displayPort, (void*)0);
91 EXPECT_EQ(NULL, exit);
94 TEST(CMSUnittest, TestCmsMenuBack)
96 cmsInit();
97 displayPort_t *displayPort = displayPortTestInit();
98 cmsDisplayPortRegister(displayPort);
100 cmsMenuOpen();
101 const void *exit = cmsMenuBack(displayPort);
102 EXPECT_EQ(NULL, exit);
105 TEST(CMSUnittest, TestCmsMenuKey)
107 #define KEY_ENTER 0
108 #define KEY_UP 1
109 #define KEY_DOWN 2
110 #define KEY_LEFT 3
111 #define KEY_RIGHT 4
112 #define KEY_ESC 5
113 #define BUTTON_TIME 250 // msec
114 #define BUTTON_PAUSE 500 // msec
115 cmsInit();
116 displayPort_t *displayPort = &testDisplayPort;
117 cmsDisplayPortRegister(displayPort);
119 cmsMenuOpen();
120 uint16_t result = cmsHandleKey(displayPort, KEY_ESC);
121 EXPECT_EQ(BUTTON_PAUSE, result);
123 // STUBS
125 extern "C" {
126 static const OSD_Entry menuMainEntries[] =
128 {"-- MAIN MENU --", OME_Label, NULL, NULL},
129 {"SAVE&REBOOT", OME_OSD_Exit, cmsMenuExit, (void*)1},
130 {"EXIT", OME_OSD_Exit, cmsMenuExit, (void*)0},
131 {NULL, OME_END, NULL, NULL}
133 CMS_Menu cmsx_menuMain = {
134 #ifdef CMS_MENU_DEBUG
135 .GUARD_text = "MENUMAIN",
136 .GUARD_type = OME_MENU,
137 #endif
138 .onEnter = NULL,
139 .onExit = NULL,
140 .entries = menuMainEntries,
142 uint8_t armingFlags;
143 int16_t debug[4];
144 int16_t rcData[18];
145 void delay(uint32_t) {}
146 uint32_t micros(void) { return 0; }
147 uint32_t millis(void) { return 0; }
148 void saveConfigAndNotify(void) {}
149 void stopMotors(void) {}
150 void motorShutdown(void) {}
151 void systemReset(void) {}
152 void setArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
153 void unsetArmingDisabled(armingDisableFlags_e flag) { UNUSED(flag); }
154 bool IS_RC_MODE_ACTIVE(boxId_e) { return false; }
155 void setRebootRequired(void) {}
156 bool getRebootRequired(void) { return false; }