]>
git.saurik.com Git - wxWidgets.git/blob - tests/menu/accelentry.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/menu/accelentry.cpp
3 // Purpose: wxAcceleratorEntry unit test
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2010 Vadim Zeitlin
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
23 #include "wx/scopedptr.h"
25 class AccelEntryTestCase
: public CppUnit::TestCase
28 AccelEntryTestCase() {}
31 CPPUNIT_TEST_SUITE( AccelEntryTestCase
);
32 CPPUNIT_TEST( Create
);
33 CPPUNIT_TEST( ToFromString
);
34 CPPUNIT_TEST_SUITE_END();
39 wxDECLARE_NO_COPY_CLASS(AccelEntryTestCase
);
42 // register in the unnamed registry so that these tests are run by default
43 CPPUNIT_TEST_SUITE_REGISTRATION( AccelEntryTestCase
);
45 // also include in its own registry so that these tests can be run alone
46 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AccelEntryTestCase
, "AccelEntryTestCase" );
51 void CheckAccelEntry(const wxAcceleratorEntry
& accel
, int keycode
, int flags
)
53 CPPUNIT_ASSERT_EQUAL( keycode
, accel
.GetKeyCode() );
54 CPPUNIT_ASSERT_EQUAL( flags
, accel
.GetFlags() );
57 } // anonymous namespace
59 void AccelEntryTestCase::Create()
61 wxScopedPtr
<wxAcceleratorEntry
>
62 pa(wxAcceleratorEntry::Create("Foo\tCtrl+Z"));
64 CPPUNIT_ASSERT( pa
->IsOk() );
66 CheckAccelEntry(*pa
, 'Z', wxACCEL_CTRL
);
69 // There must be a TAB in the string passed to Create()
70 pa
.reset(wxAcceleratorEntry::Create("Shift-Q"));
71 CPPUNIT_ASSERT( !pa
);
73 pa
.reset(wxAcceleratorEntry::Create("Bar\tShift-Q"));
75 CPPUNIT_ASSERT( pa
->IsOk() );
76 CheckAccelEntry(*pa
, 'Q', wxACCEL_SHIFT
);
79 pa
.reset(wxAcceleratorEntry::Create("bloordyblop"));
80 CPPUNIT_ASSERT( !pa
);
83 void AccelEntryTestCase::ToFromString()
85 wxAcceleratorEntry
a(wxACCEL_ALT
, 'X');
86 CPPUNIT_ASSERT_EQUAL( "Alt+X", a
.ToString() );
88 CPPUNIT_ASSERT( a
.FromString("Alt+Shift+F1") );
89 CheckAccelEntry(a
, WXK_F1
, wxACCEL_ALT
| wxACCEL_SHIFT
);
91 CPPUNIT_ASSERT( !a
.FromString("bloordyblop") );