2010-12-03 07:39:57 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/menu/accelentry.cpp
|
|
|
|
// Purpose: wxAcceleratorEntry unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2010-12-03
|
|
|
|
// Copyright: (c) 2010 Vadim Zeitlin
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/accel.h"
|
2020-10-12 23:41:57 -04:00
|
|
|
#include "wx/scopedptr.h"
|
2010-12-03 07:39:57 -05:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void CheckAccelEntry(const wxAcceleratorEntry& accel, int keycode, int flags)
|
|
|
|
{
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( keycode == accel.GetKeyCode() );
|
|
|
|
CHECK( flags == accel.GetFlags() );
|
2010-12-03 07:39:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the creation of accelerator keys using the Create function
|
|
|
|
*/
|
|
|
|
TEST_CASE( "wxAcceleratorEntry::Create", "[accelentry]" )
|
2010-12-03 07:39:57 -05:00
|
|
|
{
|
2020-10-12 23:41:57 -04:00
|
|
|
wxScopedPtr<wxAcceleratorEntry> pa;
|
2019-08-04 06:54:13 -04:00
|
|
|
|
|
|
|
SECTION( "Correct behavior" )
|
|
|
|
{
|
2020-10-12 23:41:57 -04:00
|
|
|
pa.reset( wxAcceleratorEntry::Create("Foo\tCtrl+Z") );
|
2010-12-03 07:39:57 -05:00
|
|
|
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( pa );
|
|
|
|
CHECK( pa->IsOk() );
|
2019-08-04 06:54:13 -04:00
|
|
|
CheckAccelEntry(*pa, 'Z', wxACCEL_CTRL);
|
|
|
|
}
|
2010-12-03 07:39:57 -05:00
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
SECTION( "Tab missing" )
|
|
|
|
{
|
2020-10-12 23:41:57 -04:00
|
|
|
pa.reset( wxAcceleratorEntry::Create("Shift-Q") );
|
2010-12-03 07:39:57 -05:00
|
|
|
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( !pa );
|
2019-08-04 06:54:13 -04:00
|
|
|
}
|
2010-12-15 07:03:54 -05:00
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
SECTION( "No accelerator key specified" )
|
|
|
|
{
|
2020-10-12 23:41:57 -04:00
|
|
|
pa.reset( wxAcceleratorEntry::Create("bloordyblop") );
|
2010-12-03 07:39:57 -05:00
|
|
|
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( !pa );
|
2019-08-04 06:54:13 -04:00
|
|
|
}
|
2010-12-03 07:39:57 -05:00
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
SECTION( "Display name parsing" )
|
|
|
|
{
|
2020-10-12 23:41:57 -04:00
|
|
|
pa.reset( wxAcceleratorEntry::Create("Test\tBackSpace") );
|
2019-08-04 06:54:13 -04:00
|
|
|
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( pa );
|
|
|
|
CHECK( pa->IsOk() );
|
2019-08-04 06:54:13 -04:00
|
|
|
CheckAccelEntry(*pa, WXK_BACK, wxACCEL_NORMAL);
|
|
|
|
}
|
2010-12-03 07:39:57 -05:00
|
|
|
}
|
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the creation of accelerator keys from strings and also the
|
|
|
|
* creation of strings from an accelerator key
|
|
|
|
*/
|
|
|
|
TEST_CASE( "wxAcceleratorEntry::StringTests", "[accelentry]" )
|
2010-12-03 07:39:57 -05:00
|
|
|
{
|
|
|
|
wxAcceleratorEntry a(wxACCEL_ALT, 'X');
|
|
|
|
|
2019-08-04 06:54:13 -04:00
|
|
|
SECTION( "Create string from key" )
|
|
|
|
{
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( "Alt+X" == a.ToString() );
|
2019-08-04 06:54:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "Create from valid string" )
|
|
|
|
{
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( a.FromString("Alt+Shift+F1") );
|
2019-08-04 06:54:13 -04:00
|
|
|
CheckAccelEntry(a, WXK_F1, wxACCEL_ALT | wxACCEL_SHIFT);
|
2022-06-08 10:40:23 -04:00
|
|
|
|
|
|
|
// Note that this is just "+" and not WXK_ADD.
|
|
|
|
CHECK( a.FromString("Ctrl-+") );
|
|
|
|
CheckAccelEntry(a, '+', wxACCEL_CTRL);
|
|
|
|
|
|
|
|
// But this is WXK_NUMPAD_ADD, to distinguish it from the main "+" key.
|
|
|
|
CHECK( a.FromString("Ctrl-Num +") );
|
|
|
|
CheckAccelEntry(a, WXK_NUMPAD_ADD, wxACCEL_CTRL);
|
2019-08-04 06:54:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION( "Create from invalid string" )
|
|
|
|
{
|
2019-08-05 14:51:46 -04:00
|
|
|
CHECK( !a.FromString("bloordyblop") );
|
2019-08-04 06:54:13 -04:00
|
|
|
}
|
2010-12-03 07:39:57 -05:00
|
|
|
}
|