00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRCheckBoxClickEvent.h"
00015 #endif
00016
00017 #include "CRCheckBoxClickEvent.h"
00018
00019 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00020 #include <wxGuiTest/CRCppEmitter.h>
00021
00022 using namespace wxTst;
00023
00024
00025 CRCheckBoxClickEvent::CRCheckBoxClickEvent (wxEvent *event) :
00026 CRCapturedEvent (event), m_isChecked(false)
00027 {
00028
00029 }
00030
00031
00032 CRCheckBoxClickEvent::~CRCheckBoxClickEvent ()
00033 {
00034
00035 }
00036
00037
00038 void CRCheckBoxClickEvent::Process (CRCapturedEvent** WXUNUSED(pendingEvt))
00039 {
00040 wxWindow *wdwEvtObject = wxDynamicCast (m_event->GetEventObject (), wxWindow);
00041 wxASSERT (wdwEvtObject != NULL);
00042
00043 CRWindowHierarchyHandler *hierarchy = CRWindowHierarchyHandler::GetInstance ();
00044 wxASSERT (hierarchy != NULL);
00045
00046 m_checkBoxName = wdwEvtObject->GetName ();
00047 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00048 wxASSERT (!m_containerName.IsEmpty ());
00049
00050 wxASSERT (m_event->IsCommandEvent ());
00051 wxCommandEvent *cmdEvt = wxDynamicCast (m_event, wxCommandEvent);
00052 wxASSERT (cmdEvt != NULL);
00053 m_isChecked = cmdEvt->IsChecked ();
00054 }
00055
00056
00057 void CRCheckBoxClickEvent::EmitCpp ()
00058 {
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 CRCppEmitter *emitter = CRCppEmitter::GetInstance ();
00082
00083 wxString containerVarName = emitter->AddContainerLookupCode (
00084 m_containerName, wxString::Format (_T("check box '%s'"), m_checkBoxName.c_str ()));
00085
00086 wxString checkBoxWdwVarName = emitter->MakeVarName (m_checkBoxName, _T("Wdw"));
00087
00088 wxString str;
00089 str << _T("wxWindow *") << checkBoxWdwVarName << _T(" = ") << containerVarName <<
00090 _T("->FindWindow (");
00091 str << _T("_T(\"") << m_checkBoxName << _T("\"));");
00092 emitter->AddCode (str);
00093
00094 str.Clear ();
00095 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Window for check box '") <<
00096 m_checkBoxName << _T("' not found\", ") <<
00097 checkBoxWdwVarName << _T(" != NULL);");
00098 emitter->AddCode (str);
00099
00100 wxString checkBoxVarName = emitter->MakeVarName (m_checkBoxName);
00101
00102 str.Clear ();
00103 str << _T("wxCheckBox *") << checkBoxVarName << _T(" = wxDynamicCast (") <<
00104 checkBoxWdwVarName << _T(", wxCheckBox);");
00105 emitter->AddCode (str);
00106
00107 str.Clear ();
00108 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for check box '") <<
00109 m_checkBoxName << _T("' failed\", ") << checkBoxVarName << _T(" != NULL);");
00110 emitter->AddCode (str);
00111
00112 wxString isCheckedBoolStr = m_isChecked ? _T("true") : _T("false");
00113 str.Clear ();
00114 str << _T("wxTst::EventSimulationHelper::SetCheckboxState (") <<
00115 checkBoxVarName << _T(", ") << isCheckedBoolStr << _T(");");
00116 emitter->AddCode (str);
00117
00118 str.Clear ();
00119 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00120 emitter->AddCode (str);
00121 }
00122