]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: tests/menu/accelentry.cpp | |
3 | // Purpose: wxAcceleratorEntry unit test | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2010-12-03 | |
6 | // Copyright: (c) 2010 Vadim Zeitlin | |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | // ---------------------------------------------------------------------------- | |
10 | // headers | |
11 | // ---------------------------------------------------------------------------- | |
12 | ||
13 | #include "testprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #endif // WX_PRECOMP | |
21 | ||
22 | #include "wx/accel.h" | |
23 | #include "wx/scopedptr.h" | |
24 | ||
25 | class AccelEntryTestCase : public CppUnit::TestCase | |
26 | { | |
27 | public: | |
28 | AccelEntryTestCase() {} | |
29 | ||
30 | private: | |
31 | CPPUNIT_TEST_SUITE( AccelEntryTestCase ); | |
32 | CPPUNIT_TEST( Create ); | |
33 | CPPUNIT_TEST( ToFromString ); | |
34 | CPPUNIT_TEST_SUITE_END(); | |
35 | ||
36 | void Create(); | |
37 | void ToFromString(); | |
38 | ||
39 | wxDECLARE_NO_COPY_CLASS(AccelEntryTestCase); | |
40 | }; | |
41 | ||
42 | // register in the unnamed registry so that these tests are run by default | |
43 | CPPUNIT_TEST_SUITE_REGISTRATION( AccelEntryTestCase ); | |
44 | ||
45 | // also include in its own registry so that these tests can be run alone | |
46 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AccelEntryTestCase, "AccelEntryTestCase" ); | |
47 | ||
48 | namespace | |
49 | { | |
50 | ||
51 | void CheckAccelEntry(const wxAcceleratorEntry& accel, int keycode, int flags) | |
52 | { | |
53 | CPPUNIT_ASSERT_EQUAL( keycode, accel.GetKeyCode() ); | |
54 | CPPUNIT_ASSERT_EQUAL( flags, accel.GetFlags() ); | |
55 | } | |
56 | ||
57 | } // anonymous namespace | |
58 | ||
59 | void AccelEntryTestCase::Create() | |
60 | { | |
61 | wxScopedPtr<wxAcceleratorEntry> | |
62 | pa(wxAcceleratorEntry::Create("Foo\tCtrl+Z")); | |
63 | CPPUNIT_ASSERT( pa ); | |
64 | CPPUNIT_ASSERT( pa->IsOk() ); | |
65 | ||
66 | CheckAccelEntry(*pa, 'Z', wxACCEL_CTRL); | |
67 | ||
68 | ||
69 | // There must be a TAB in the string passed to Create() | |
70 | pa.reset(wxAcceleratorEntry::Create("Shift-Q")); | |
71 | CPPUNIT_ASSERT( !pa ); | |
72 | ||
73 | pa.reset(wxAcceleratorEntry::Create("Bar\tShift-Q")); | |
74 | CPPUNIT_ASSERT( pa ); | |
75 | CPPUNIT_ASSERT( pa->IsOk() ); | |
76 | CheckAccelEntry(*pa, 'Q', wxACCEL_SHIFT); | |
77 | ||
78 | ||
79 | pa.reset(wxAcceleratorEntry::Create("bloordyblop")); | |
80 | CPPUNIT_ASSERT( !pa ); | |
81 | } | |
82 | ||
83 | void AccelEntryTestCase::ToFromString() | |
84 | { | |
85 | wxAcceleratorEntry a(wxACCEL_ALT, 'X'); | |
86 | CPPUNIT_ASSERT_EQUAL( "Alt+X", a.ToString() ); | |
87 | ||
88 | CPPUNIT_ASSERT( a.FromString("Alt+Shift+F1") ); | |
89 | CheckAccelEntry(a, WXK_F1, wxACCEL_ALT | wxACCEL_SHIFT); | |
90 | ||
91 | CPPUNIT_ASSERT( !a.FromString("bloordyblop") ); | |
92 | } |