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