wxMessageBox off the main thread lost result code.
[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 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "testprec.h"
10
11 #if wxUSE_CHECKLISTBOX
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/checklst.h"
20 #endif // WX_PRECOMP
21
22 #include "itemcontainertest.h"
23 #include "testableframe.h"
24
25 class CheckListBoxTestCase : public ItemContainerTestCase, public CppUnit::TestCase
26 {
27 public:
28 CheckListBoxTestCase() { }
29
30 virtual void setUp();
31 virtual void tearDown();
32
33 private:
34 virtual wxItemContainer *GetContainer() const { return m_check; }
35 virtual wxWindow *GetContainerWindow() const { return m_check; }
36
37 CPPUNIT_TEST_SUITE( CheckListBoxTestCase );
38 wxITEM_CONTAINER_TESTS();
39 CPPUNIT_TEST( Check );
40 CPPUNIT_TEST_SUITE_END();
41
42 void Check();
43
44 wxCheckListBox* m_check;
45
46 DECLARE_NO_COPY_CLASS(CheckListBoxTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( CheckListBoxTestCase );
51
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckListBoxTestCase, "CheckListBoxTestCase" );
54
55 void CheckListBoxTestCase::setUp()
56 {
57 m_check = new wxCheckListBox(wxTheApp->GetTopWindow(), wxID_ANY);
58 }
59
60 void CheckListBoxTestCase::tearDown()
61 {
62 wxDELETE(m_check);
63 }
64
65 void CheckListBoxTestCase::Check()
66 {
67 EventCounter toggled(m_check, wxEVT_CHECKLISTBOX);
68
69 wxArrayInt checkedItems;
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 CPPUNIT_ASSERT_EQUAL(1, m_check->GetCheckedItems(checkedItems));
88 CPPUNIT_ASSERT_EQUAL(0, checkedItems[0]);
89
90 //Make sure a double check of an items doesn't deselect it
91 m_check->Check(0);
92
93 CPPUNIT_ASSERT_EQUAL(true, m_check->IsChecked(0));
94 }
95
96 #endif // wxUSE_CHECKLISTBOX