]>
git.saurik.com Git - wxWidgets.git/blob - tests/menu/accelentry.cpp
da871f79d06659f7b56859df6932291ec9df863f
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/menu/accelentry.cpp
3 // Purpose: wxAcceleratorEntry unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2010 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/scopedptr.h"
26 class AccelEntryTestCase
: public CppUnit::TestCase
29 AccelEntryTestCase() {}
32 CPPUNIT_TEST_SUITE( AccelEntryTestCase
);
33 CPPUNIT_TEST( Create
);
34 CPPUNIT_TEST( ToFromString
);
35 CPPUNIT_TEST_SUITE_END();
40 wxDECLARE_NO_COPY_CLASS(AccelEntryTestCase
);
43 // register in the unnamed registry so that these tests are run by default
44 CPPUNIT_TEST_SUITE_REGISTRATION( AccelEntryTestCase
);
46 // also include in its own registry so that these tests can be run alone
47 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AccelEntryTestCase
, "AccelEntryTestCase" );
52 void CheckAccelEntry(const wxAcceleratorEntry
& accel
, int keycode
, int flags
)
54 CPPUNIT_ASSERT_EQUAL( keycode
, accel
.GetKeyCode() );
55 CPPUNIT_ASSERT_EQUAL( flags
, accel
.GetFlags() );
58 } // anonymous namespace
60 void AccelEntryTestCase::Create()
62 wxScopedPtr
<wxAcceleratorEntry
>
63 pa(wxAcceleratorEntry::Create("Foo\tCtrl+Z"));
65 CPPUNIT_ASSERT( pa
->IsOk() );
67 CheckAccelEntry(*pa
, 'Z', wxACCEL_CTRL
);
70 // There must be a TAB in the string passed to Create()
71 pa
.reset(wxAcceleratorEntry::Create("Shift-Q"));
72 CPPUNIT_ASSERT( !pa
);
74 pa
.reset(wxAcceleratorEntry::Create("Bar\tShift-Q"));
76 CPPUNIT_ASSERT( pa
->IsOk() );
77 CheckAccelEntry(*pa
, 'Q', wxACCEL_SHIFT
);
80 pa
.reset(wxAcceleratorEntry::Create("bloordyblop"));
81 CPPUNIT_ASSERT( !pa
);
84 void AccelEntryTestCase::ToFromString()
86 wxAcceleratorEntry
a(wxACCEL_ALT
, 'X');
87 CPPUNIT_ASSERT_EQUAL( "Alt+X", a
.ToString() );
89 CPPUNIT_ASSERT( a
.FromString("Alt+Shift+F1") );
90 CheckAccelEntry(a
, WXK_F1
, wxACCEL_ALT
| wxACCEL_SHIFT
);
92 CPPUNIT_ASSERT( !a
.FromString("bloordyblop") );