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