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_menu_quick.h"
33 #include "cms/cms_types.h"
34 #include "fc/rc_modes.h"
35 #include "fc/runtime_config.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
= {
54 .onDisplayUpdate
= NULL
,
59 TEST(CMSUnittest
, TestCmsDisplayPortRegister
)
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
)
74 displayPort_t
*displayPort
= displayPortTestInit();
75 displayGrab(displayPort
);
76 cmsDisplayPortRegister(displayPort
);
81 TEST(CMSUnittest
, TestCmsMenuExit0
)
84 displayPort_t
*displayPort
= displayPortTestInit();
85 cmsDisplayPortRegister(displayPort
);
88 const void *exit
= cmsMenuExit(displayPort
, (void*)0);
89 EXPECT_EQ(NULL
, exit
);
92 TEST(CMSUnittest
, TestCmsMenuExit1
)
95 displayPort_t
*displayPort
= displayPortTestInit();
96 cmsDisplayPortRegister(displayPort
);
99 const void *exit
= cmsMenuExit(displayPort
, (void*)0);
100 EXPECT_EQ(NULL
, exit
);
103 TEST(CMSUnittest
, TestCmsMenuBack
)
106 displayPort_t
*displayPort
= displayPortTestInit();
107 cmsDisplayPortRegister(displayPort
);
110 const void *exit
= cmsMenuBack(displayPort
);
111 EXPECT_EQ(NULL
, exit
);
114 TEST(CMSUnittest
, TestCmsMenuKey
)
122 #define BUTTON_TIME 250 // msec
123 #define BUTTON_PAUSE 500 // msec
125 displayPort_t
*displayPort
= &testDisplayPort
;
126 cmsDisplayPortRegister(displayPort
);
129 uint16_t result
= cmsHandleKey(displayPort
, KEY_ESC
);
130 EXPECT_EQ(BUTTON_PAUSE
, result
);
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
,
149 .entries
= menuMainEntries
,
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; }