]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/bitmaptogglebuttontest.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / tests / controls / bitmaptogglebuttontest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/bitmaptogglebuttontest.cpp
3// Purpose: wxBitmapToggleButton unit test
4// Author: Steven Lamerton
5// Created: 2010-07-17
232fdc63
VZ
6// Copyright: (c) 2010 Steven Lamerton
7///////////////////////////////////////////////////////////////////////////////
8
9#include "testprec.h"
10
663a3ae1
SL
11#if wxUSE_TOGGLEBTN
12
232fdc63
VZ
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
323d36e4
VZ
17#include "wx/tglbtn.h"
18
19#ifdef wxHAS_BITMAPTOGGLEBUTTON
20
232fdc63
VZ
21#ifndef WX_PRECOMP
22 #include "wx/app.h"
23#endif // WX_PRECOMP
24
25#include "testableframe.h"
26#include "wx/uiaction.h"
27#include "wx/artprov.h"
232fdc63
VZ
28
29class BitmapToggleButtonTestCase : public CppUnit::TestCase
30{
31public:
32 BitmapToggleButtonTestCase() { }
33
34 void setUp();
35 void tearDown();
36
37private:
38 CPPUNIT_TEST_SUITE( BitmapToggleButtonTestCase );
39 WXUISIM_TEST( Click );
40 CPPUNIT_TEST( Value );
41 CPPUNIT_TEST_SUITE_END();
42
43 void Click();
44 void Value();
45
46 wxBitmapToggleButton* m_button;
47
48 DECLARE_NO_COPY_CLASS(BitmapToggleButtonTestCase)
49};
50
51// register in the unnamed registry so that these tests are run by default
52CPPUNIT_TEST_SUITE_REGISTRATION( BitmapToggleButtonTestCase );
53
e3778b4d 54// also include in its own registry so that these tests can be run alone
232fdc63
VZ
55CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapToggleButtonTestCase,
56 "BitmapToggleButtonTestCase" );
57
58void BitmapToggleButtonTestCase::setUp()
59{
60 m_button = new wxBitmapToggleButton(wxTheApp->GetTopWindow(), wxID_ANY,
61 wxArtProvider::GetIcon(wxART_INFORMATION,
62 wxART_OTHER,
63 wxSize(32, 32)));
64 m_button->Update();
65 m_button->Refresh();
66}
67
68void BitmapToggleButtonTestCase::tearDown()
69{
70 wxDELETE(m_button);
71}
72
73void BitmapToggleButtonTestCase::Click()
74{
75#if wxUSE_UIACTIONSIMULATOR
ce7fe42e 76 EventCounter clicked(m_button, wxEVT_TOGGLEBUTTON);
232fdc63
VZ
77
78 wxUIActionSimulator sim;
79
80 //We move in slightly to account for window decorations
81 sim.MouseMove(m_button->GetScreenPosition() + wxPoint(10, 10));
82 wxYield();
83
84 sim.MouseClick();
85 wxYield();
86
744d91d4 87 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63
VZ
88 CPPUNIT_ASSERT(m_button->GetValue());
89
744d91d4 90 clicked.Clear();
232fdc63
VZ
91 wxMilliSleep(1000);
92
93 sim.MouseClick();
94 wxYield();
95
744d91d4 96 CPPUNIT_ASSERT_EQUAL(1, clicked.GetCount());
232fdc63
VZ
97 CPPUNIT_ASSERT(!m_button->GetValue());
98#endif // wxUSE_UIACTIONSIMULATOR
99}
100
101void BitmapToggleButtonTestCase::Value()
102{
ce7fe42e 103 EventCounter clicked(m_button, wxEVT_BUTTON);
232fdc63
VZ
104
105 m_button->SetValue(true);
106
107 CPPUNIT_ASSERT(m_button->GetValue());
108
109 m_button->SetValue(false);
110
111 CPPUNIT_ASSERT(!m_button->GetValue());
112
744d91d4 113 CPPUNIT_ASSERT_EQUAL( 0, clicked.GetCount() );
232fdc63 114}
663a3ae1 115
323d36e4
VZ
116#endif // wxHAS_BITMAPTOGGLEBUTTON
117
118#endif // wxUSE_TOGGLEBTN