// Purpose: Test keyboard events
// Author: Vadim Zeitlin
// Created: 2010-09-05
-// RCS-ID: $Id$
// Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
///////////////////////////////////////////////////////////////////////////////
#pragma hdrstop
#endif
-#if wxUSE_UIACTIONSIMULATOR
+// FIXME: As all the other tests involving wxUIActionSimulator, this one is
+// broken under OS X, the test window siply never gets any events.
+#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
#ifndef WX_PRECOMP
#include "wx/app.h"
{
public:
KeyboardTestWindow(wxWindow *parent)
- : wxWindow(parent, wxID_ANY)
+ : wxWindow(parent, wxID_ANY, wxPoint(0, 0), parent->GetClientSize())
{
Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(KeyboardTestWindow::OnKeyDown));
Connect(wxEVT_CHAR, wxKeyEventHandler(KeyboardTestWindow::OnChar));
int m_mods;
};
-// These functions are only needed because of wx bug: currently, modifiers key
-// events are inconsistent between platforms and wxMSW generates key down event
-// for e.g. WXK_CONTROL with wxMOD_CONTROL set and key up event with it unset
-// while wxGTK does exactly vice versa. So we provide these helpers to make it
-// possible to make the tests pass under all platforms for now but ideally they
-// should all be made to behave the same and this should become unnecessary.
-
+// Helper for ModKeyDown().
int GetModForKey(int keycode)
{
switch ( keycode )
return wxMOD_NONE;
}
-#ifdef __WXGTK__
-
-KeyDesc ModKeyDown(int keycode)
-{
- // Second level bug: currently wxUIActionSimulator produces different
- // modifiers than actually pressing the key. So while the above comment is
- // true for keys pressed by user, when simulating them we do get the
- // corresponding bit set for the modifier press events.
- //
- // Again, this is a bug and wxUIActionSimulator should be fixed to behave
- // as the real events do but until this happens just work around this here.
- return KeyDesc(keycode, GetModForKey(keycode));
-}
-
-KeyDesc ModKeyUp(int keycode)
-{
- return KeyDesc(keycode, GetModForKey(keycode));
-}
-
-#else // Assume MSW-like behaviour for all the other platforms.
-
+// Helper function to allow writing just ModKeyDown(WXK_CONTROL) instead of
+// more verbose KeyDesc(WXK_CONTROL, wxMOD_CONTROL).
KeyDesc ModKeyDown(int keycode)
{
return KeyDesc(keycode, GetModForKey(keycode));
}
+// Another helper provided for symmetry with ModKeyDown() only.
KeyDesc ModKeyUp(int keycode)
{
return KeyDesc(keycode);
}
-#endif // Platforms.
-
// Verify that the event object corresponds to our idea of what it should be.
void TestEvent(int line, const wxKeyEvent& ev, const KeyDesc& desc)
{
ev.GetKeyCode() );
#if wxUSE_UNICODE
- if ( desc.m_keycode < 0x80 )
+ if ( desc.m_keycode < WXK_START )
{
- // FIXME: Currently wxMSW generates 'A' key code for key down/up events
- // for the 'a' physical key while wxGTK and wxOSX/Cocoa generate them
- // with 'a' and it's not clear which behaviour is more correct so don't
- // test this for those events, only test it for EVT_CHAR where the
- // correct behaviour is clear.
-
- if ( t == wxEVT_CHAR )
- {
- // For 7-bit ASCII Unicode keys are the same as normal key codes.
- CPPUNIT_ASSERT_EQUAL_MESSAGE( "wrong Unicode key in " + msg,
- (char)desc.m_keycode,
- (char)ev.GetUnicodeKey() );
- }
+ // For Latin-1 our key code is the same as Unicode character value.
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "wrong Unicode key in " + msg,
+ (char)desc.m_keycode,
+ (char)ev.GetUnicodeKey() );
}
- else
+ else // Special key
{
- // In this test we don't use any really Unicode characters so far so
- // anything above 0x80 must be special keys (e.g. WXK_CONTROL &c) which
- // don't have any Unicode equivalent.
+ // Key codes above WXK_START don't correspond to printable characters.
CPPUNIT_ASSERT_EQUAL_MESSAGE( "wrong non-zero Unicode key in " + msg,
0,
(int)ev.GetUnicodeKey() );
void KeyboardEventTestCase::ShiftSpecial()
{
wxUIActionSimulator sim;
- sim.Char(WXK_TAB, wxMOD_SHIFT);
+ sim.Char(WXK_F3, wxMOD_SHIFT);
wxYield();
CPPUNIT_ASSERT_EQUAL( 2, m_win->GetKeyDownCount() );
ASSERT_KEY_EVENT_IS( m_win->GetKeyDownEvent(0),
ModKeyDown(WXK_SHIFT) );
ASSERT_KEY_EVENT_IS( m_win->GetKeyDownEvent(1),
- KeyDesc(WXK_TAB, wxMOD_SHIFT) );
+ KeyDesc(WXK_F3, wxMOD_SHIFT) );
CPPUNIT_ASSERT_EQUAL( 1, m_win->GetCharCount() );
ASSERT_KEY_EVENT_IS( m_win->GetCharEvent(),
- KeyDesc(WXK_TAB, wxMOD_SHIFT) );
+ KeyDesc(WXK_F3, wxMOD_SHIFT) );
CPPUNIT_ASSERT_EQUAL( 2, m_win->GetKeyUpCount() );
ASSERT_KEY_EVENT_IS( m_win->GetKeyUpEvent(0),
- KeyDesc(WXK_TAB, wxMOD_SHIFT) );
+ KeyDesc(WXK_F3, wxMOD_SHIFT) );
ASSERT_KEY_EVENT_IS( m_win->GetKeyUpEvent(1),
ModKeyUp(WXK_SHIFT) );
}