forked from slic3r/Slic3r
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start building tests with Catch; also use ON/OFF syntax for build opt…
…ions. testableframe borrowed from wxWidgets tests.
- Loading branch information
1 parent
333a27a
commit 5bcf807
Showing
6 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "test/catch.hpp" | ||
|
||
#ifndef WX_PRECOMP | ||
#include "wx/app.h" | ||
#include "wx/checkbox.h" | ||
#endif // WX_PRECOMP | ||
|
||
#include "testableframe.h" | ||
|
||
TEST_CASE( "Dummy" ) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file | ||
#include "test/catch.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Name: testableframe.cpp | ||
// Purpose: An improved wxFrame for unit-testing | ||
// Author: Steven Lamerton | ||
// Copyright: (c) 2010 Steven Lamerton | ||
// Licence: wxWindows licence | ||
/////////////////////////////////////////////////////////////////////////////// | ||
#ifdef __BORLANDC__ | ||
#pragma hdrstop | ||
#endif | ||
|
||
#include "wx/app.h" | ||
#include "testableframe.h" | ||
|
||
wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame") | ||
{ | ||
// Use fixed position to facilitate debugging. | ||
Move(200, 200); | ||
|
||
Show(); | ||
} | ||
|
||
void wxTestableFrame::OnEvent(wxEvent& evt) | ||
{ | ||
m_count[evt.GetEventType()]++; | ||
|
||
if(! evt.IsCommandEvent() ) | ||
evt.Skip(); | ||
} | ||
|
||
int wxTestableFrame::GetEventCount(wxEventType type) | ||
{ | ||
return m_count[type]; | ||
} | ||
|
||
void wxTestableFrame::ClearEventCount(wxEventType type) | ||
{ | ||
m_count[type] = 0; | ||
} | ||
|
||
EventCounter::EventCounter(wxWindow* win, wxEventType type) : m_type(type), | ||
m_win(win) | ||
|
||
{ | ||
m_frame = wxStaticCast(wxTheApp->GetTopWindow(), wxTestableFrame); | ||
|
||
m_win->Connect(m_type, wxEventHandler(wxTestableFrame::OnEvent), | ||
NULL, m_frame); | ||
} | ||
|
||
EventCounter::~EventCounter() | ||
{ | ||
m_win->Disconnect(m_type, wxEventHandler(wxTestableFrame::OnEvent), | ||
NULL, m_frame); | ||
|
||
//This stops spurious counts from previous tests | ||
Clear(); | ||
|
||
m_frame = NULL; | ||
m_win = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// Name: testableframe.h | ||
// Purpose: An improved wxFrame for unit-testing | ||
// Author: Steven Lamerton | ||
// Copyright: (c) 2010 Steven Lamerton | ||
// Licence: wxWindows licence | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "wx/frame.h" | ||
#include "wx/hashmap.h" | ||
#include "wx/event.h" | ||
|
||
class wxTestableFrame : public wxFrame | ||
{ | ||
public: | ||
wxTestableFrame(); | ||
|
||
void OnEvent(wxEvent& evt); | ||
|
||
private: | ||
friend class EventCounter; | ||
|
||
int GetEventCount(wxEventType type); | ||
void ClearEventCount(wxEventType type); | ||
|
||
wxLongToLongHashMap m_count; | ||
}; | ||
|
||
class EventCounter | ||
{ | ||
public: | ||
EventCounter(wxWindow* win, wxEventType type); | ||
~EventCounter(); | ||
|
||
int GetCount() { return m_frame->GetEventCount(m_type); } | ||
void Clear() { m_frame->ClearEventCount(m_type); } | ||
|
||
private: | ||
wxEventType m_type; | ||
wxTestableFrame* m_frame; | ||
wxWindow* m_win; | ||
}; |