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"
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
)
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
)
65 displayPort_t
*displayPort
= displayPortTestInit();
66 displayGrab(displayPort
);
67 cmsDisplayPortRegister(displayPort
);
72 TEST(CMSUnittest
, TestCmsMenuExit0
)
75 displayPort_t
*displayPort
= displayPortTestInit();
76 cmsDisplayPortRegister(displayPort
);
79 const void *exit
= cmsMenuExit(displayPort
, (void*)0);
80 EXPECT_EQ(NULL
, exit
);
83 TEST(CMSUnittest
, TestCmsMenuExit1
)
86 displayPort_t
*displayPort
= displayPortTestInit();
87 cmsDisplayPortRegister(displayPort
);
90 const void *exit
= cmsMenuExit(displayPort
, (void*)0);
91 EXPECT_EQ(NULL
, exit
);
94 TEST(CMSUnittest
, TestCmsMenuBack
)
97 displayPort_t
*displayPort
= displayPortTestInit();
98 cmsDisplayPortRegister(displayPort
);
101 const void *exit
= cmsMenuBack(displayPort
);
102 EXPECT_EQ(NULL
, exit
);
105 TEST(CMSUnittest
, TestCmsMenuKey
)
113 #define BUTTON_TIME 250 // msec
114 #define BUTTON_PAUSE 500 // msec
116 displayPort_t
*displayPort
= &testDisplayPort
;
117 cmsDisplayPortRegister(displayPort
);
120 uint16_t result
= cmsHandleKey(displayPort
, KEY_ESC
);
121 EXPECT_EQ(BUTTON_PAUSE
, result
);
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
,
140 .entries
= menuMainEntries
,
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; }