diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index c31a338e93..b5177d07b4 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -608,3 +608,168 @@ void MenuTestCase::Events() src ); #endif // wxUSE_UIACTIONSIMULATOR } + +namespace +{ + void verifyAccelAssigned( wxString labelText, int keycode ) + { + wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( labelText ); + + REQUIRE( entry ); + REQUIRE( entry->GetKeyCode() == keycode ); + } + + struct key + { + int keycode; + wxString name; + bool skip; + }; + std::vector modKeys = + { + { wxACCEL_NORMAL, "Normal", false }, + { wxACCEL_CTRL, "Ctrl", false }, + { wxACCEL_SHIFT, "Shift", false }, + { wxACCEL_ALT, "Alt", false } + }; + std::vector specialKeys = + { + { WXK_F1, "WXK_F1", false }, + { WXK_F2, "WXK_F2", false }, + { WXK_F3, "WXK_F3", false }, + { WXK_F4, "WXK_F4", false }, + { WXK_F5, "WXK_F5", false }, + { WXK_F6, "WXK_F6", false }, + { WXK_F7, "WXK_F7", false }, + { WXK_F8, "WXK_F8", false }, + { WXK_F9, "WXK_F9", false }, + { WXK_F10, "WXK_F10", false }, + { WXK_F11, "WXK_F11", false }, + { WXK_F12, "WXK_F12", false }, + { WXK_F13, "WXK_F13", false }, + { WXK_F14, "WXK_F14", false }, + { WXK_F15, "WXK_F15", false }, + { WXK_F16, "WXK_F16", false }, + { WXK_F17, "WXK_F17", false }, + { WXK_F18, "WXK_F18", false }, + { WXK_F19, "WXK_F19", false }, + { WXK_F20, "WXK_F20", false }, + { WXK_F21, "WXK_F21", false }, + { WXK_F22, "WXK_F22", false }, + { WXK_F23, "WXK_F23", false }, + { WXK_F24, "WXK_F24", false }, + { WXK_INSERT, "WXK_INSERT", false }, + { WXK_DELETE, "WXK_DELETE", false }, + { WXK_UP, "WXK_UP", false }, + { WXK_DOWN, "WXK_DOWN", false }, + { WXK_PAGEUP, "WXK_PAGEUP", false }, + { WXK_PAGEDOWN, "WXK_PAGEDOWN", false }, + { WXK_LEFT, "WXK_LEFT", false }, + { WXK_RIGHT, "WXK_RIGHT", false }, + { WXK_HOME, "WXK_HOME", false }, + { WXK_END, "WXK_END", false }, + { WXK_RETURN, "WXK_RETURN", false }, + { WXK_BACK, "WXK_BACK", false }, + { WXK_TAB, "WXK_TAB", false }, + { WXK_ESCAPE, "WXK_ESCAPE", false }, + { WXK_SPACE, "WXK_SPACE", false }, + { WXK_MULTIPLY, "WXK_MULTIPLY", false }, + { WXK_ADD, "WXK_ADD", true }, + { WXK_SEPARATOR, "WXK_SEPARATOR", true }, + { WXK_SUBTRACT, "WXK_SUBTRACT", true }, + { WXK_DECIMAL, "WXK_DECIMAL", true }, + { WXK_DIVIDE, "WXK_DIVIDE", true }, + { WXK_CANCEL, "WXK_CANCEL", false }, + { WXK_CLEAR, "WXK_CLEAR", false }, + { WXK_MENU, "WXK_MENU", false }, + { WXK_PAUSE, "WXK_PAUSE", false }, + { WXK_CAPITAL, "WXK_CAPITAL", true }, + { WXK_SELECT, "WXK_SELECT", false }, + { WXK_PRINT, "WXK_PRINT", false }, + { WXK_EXECUTE, "WXK_EXECUTE", false }, + { WXK_SNAPSHOT, "WXK_SNAPSHOT", true }, + { WXK_HELP, "WXK_HELP", false }, + { WXK_NUMLOCK, "WXK_NUMLOCK", false }, + { WXK_SCROLL, "WXK_SCROLL", false }, + { WXK_NUMPAD_INSERT, "WXK_NUMPAD_INSERT", false }, + { WXK_NUMPAD_DELETE, "WXK_NUMPAD_DELETE", false }, + { WXK_NUMPAD_SPACE, "WXK_NUMPAD_SPACE", false }, + { WXK_NUMPAD_TAB, "WXK_NUMPAD_TAB", false }, + { WXK_NUMPAD_ENTER, "WXK_NUMPAD_ENTER", false }, + { WXK_NUMPAD_F1, "WXK_NUMPAD_F1", false }, + { WXK_NUMPAD_F2, "WXK_NUMPAD_F2", false }, + { WXK_NUMPAD_F3, "WXK_NUMPAD_F3", false }, + { WXK_NUMPAD_F4, "WXK_NUMPAD_F4", false }, + { WXK_NUMPAD_HOME, "WXK_NUMPAD_HOME", false }, + { WXK_NUMPAD_LEFT, "WXK_NUMPAD_LEFT", false }, + { WXK_NUMPAD_UP, "WXK_NUMPAD_UP", false }, + { WXK_NUMPAD_RIGHT, "WXK_NUMPAD_RIGHT", false }, + { WXK_NUMPAD_DOWN, "WXK_NUMPAD_DOWN", false }, + { WXK_NUMPAD_PAGEUP, "WXK_NUMPAD_PAGEUP", false }, + { WXK_NUMPAD_PAGEDOWN, "WXK_NUMPAD_PAGEDOWN", false }, + { WXK_NUMPAD_END, "WXK_NUMPAD_END", false }, + { WXK_NUMPAD_BEGIN, "WXK_NUMPAD_BEGIN", false }, + { WXK_NUMPAD_EQUAL, "WXK_NUMPAD_EQUAL", false }, + { WXK_NUMPAD_MULTIPLY, "WXK_NUMPAD_MULTIPLY", false }, + { WXK_NUMPAD_ADD, "WXK_NUMPAD_ADD", false }, + { WXK_NUMPAD_SEPARATOR, "WXK_NUMPAD_SEPARATOR", false }, + { WXK_NUMPAD_SUBTRACT, "WXK_NUMPAD_SUBTRACT", false }, + { WXK_NUMPAD_DECIMAL, "WXK_NUMPAD_DECIMAL", false }, + { WXK_NUMPAD_DIVIDE, "WXK_NUMPAD_DIVIDE", false }, + { WXK_NUMPAD0, "WXK_NUMPAD0", false }, + { WXK_NUMPAD1, "WXK_NUMPAD1", false }, + { WXK_NUMPAD2, "WXK_NUMPAD2", false }, + { WXK_NUMPAD3, "WXK_NUMPAD3", false }, + { WXK_NUMPAD4, "WXK_NUMPAD4", false }, + { WXK_NUMPAD5, "WXK_NUMPAD5", false }, + { WXK_NUMPAD6, "WXK_NUMPAD6", false }, + { WXK_NUMPAD7, "WXK_NUMPAD7", false }, + { WXK_NUMPAD8, "WXK_NUMPAD8", false }, + { WXK_NUMPAD9, "WXK_NUMPAD9", false }, + { WXK_WINDOWS_LEFT, "WXK_WINDOWS_LEFT", false }, + { WXK_WINDOWS_RIGHT, "WXK_WINDOWS_RIGHT", false }, + { WXK_WINDOWS_MENU, "WXK_WINDOWS_MENU", false }, + { WXK_COMMAND, "WXK_COMMAND", true } + }; +} + +TEST_CASE( "wxMenuItemAccelEntry", "[menu][accelentry]" ) +{ + wxMenu* menu = new wxMenu; + + menu->Append( wxID_ANY, "Test" ); + wxMenuItem* item = menu->FindItemByPosition( 0 ); + + SECTION( "Modifier keys" ) + { + for( auto key : modKeys ) + { + INFO( wxString::Format( "Modifier: %s", key.name ) ); + wxAcceleratorEntry accelEntry( key.keycode, 'A' , wxID_ANY, item ); + item->SetAccel( &accelEntry ); + + wxString labelText = item->GetItemLabel(); + INFO( wxString::Format( "Label text: %s", labelText ) ); + + verifyAccelAssigned( labelText, 'A' ); + } + } + + SECTION( "Special keys" ) + { + for( auto key : specialKeys ) + { + if( key.skip ) + continue; + + INFO( wxString::Format( "Keycode: %s", key.name ) ); + wxAcceleratorEntry accelEntry( wxACCEL_NORMAL, key.keycode, wxID_ANY, item ); + item->SetAccel( &accelEntry ); + + wxString labelText = item->GetItemLabel(); + INFO( wxString::Format( "Label text: %s", labelText ) ); + + verifyAccelAssigned( labelText, key.keycode ); + } + } +}