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/>.
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
)
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
)
60 displayPort_t
*displayPort
= displayPortTestInit();
61 displayGrab(displayPort
);
62 cmsDisplayPortRegister(displayPort
);
67 TEST(CMSUnittest
, TestCmsMenuExit0
)
70 displayPort_t
*displayPort
= displayPortTestInit();
71 cmsDisplayPortRegister(displayPort
);
74 long exit
= cmsMenuExit(displayPort
, (void*)0);
78 TEST(CMSUnittest
, TestCmsMenuExit1
)
81 displayPort_t
*displayPort
= displayPortTestInit();
82 cmsDisplayPortRegister(displayPort
);
85 long exit
= cmsMenuExit(displayPort
, (void*)0);
89 TEST(CMSUnittest
, TestCmsMenuBack
)
92 displayPort_t
*displayPort
= displayPortTestInit();
93 cmsDisplayPortRegister(displayPort
);
96 long exit
= cmsMenuBack(displayPort
);
100 TEST(CMSUnittest
, TestCmsMenuKey
)
108 #define BUTTON_TIME 250 // msec
109 #define BUTTON_PAUSE 500 // msec
111 displayPort_t
*displayPort
= &testDisplayPort
;
112 cmsDisplayPortRegister(displayPort
);
115 uint16_t result
= cmsHandleKey(displayPort
, KEY_ESC
);
116 EXPECT_EQ(BUTTON_PAUSE
, result
);
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
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; }