]> git.saurik.com Git - wxWidgets.git/blob - tests/controls/checklistboxtest.cpp
using button impl
[wxWidgets.git] / tests / controls / checklistboxtest.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/checklistlistbox.cpp
3 // Purpose: wxCheckListBox unit test
4 // Author: Steven Lamerton
5 // Created: 2010-06-30
6 // RCS-ID: $Id$
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "testprec.h"
11
12 #if wxUSE_CHECKLISTBOX
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/checklst.h"
21 #endif // WX_PRECOMP
22
23 #include "itemcontainertest.h"
24 #include "testableframe.h"
25
26 class CheckListBoxTestCase : public ItemContainerTestCase, public CppUnit::TestCase
27 {
28 public:
29 CheckListBoxTestCase() { }
30
31 virtual void setUp();
32 virtual void tearDown();
33
34 private:
35 virtual wxItemContainer *GetContainer() const { return m_check; }
36 virtual wxWindow *GetContainerWindow() const { return m_check; }
37
38 CPPUNIT_TEST_SUITE( CheckListBoxTestCase );
39 wxITEM_CONTAINER_TESTS();
40 CPPUNIT_TEST( Check );
41 CPPUNIT_TEST_SUITE_END();
42
43 void Check();
44
45 wxCheckListBox* m_check;
46
47 DECLARE_NO_COPY_CLASS(CheckListBoxTestCase)
48 };
49
50 // register in the unnamed registry so that these tests are run by default
51 CPPUNIT_TEST_SUITE_REGISTRATION( CheckListBoxTestCase );
52
53 // also include in its own registry so that these tests can be run alone
54 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckListBoxTestCase, "CheckListBoxTestCase" );
55
56 void CheckListBoxTestCase::setUp()
57 {
58 m_check = new wxCheckListBox(wxTheApp->GetTopWindow(), wxID_ANY);
59 }
60
61 void CheckListBoxTestCase::tearDown()
62 {
63 wxDELETE(m_check);
64 }
65
66 void CheckListBoxTestCase::Check()
67 {
68 EventCounter toggled(m_check, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED);
69
70 wxArrayString testitems;
71 testitems.Add("item 0");
72 testitems.Add("item 1");
73 testitems.Add("item 2");
74 testitems.Add("item 3");
75
76 m_check->Append(testitems);
77
78 m_check->Check(0);
79 m_check->Check(1);
80 m_check->Check(1, false);
81
82 //We should not get any events when changing this from code
83 CPPUNIT_ASSERT_EQUAL(0, toggled.GetCount());
84 CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
85 CPPUNIT_ASSERT_EQUAL(false, m_check->IsChecked(1));
86
87 //Make sure a double check of an items doesn't deselect it
88 m_check->Check(0);
89
90 CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
91 }
92
93 #endif // wxUSE_CHECKLISTBOX