testableframe.h 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: testableframe.h
  3. // Purpose: An improved wxFrame for unit-testing
  4. // Author: Steven Lamerton
  5. // Copyright: (c) 2010 Steven Lamerton
  6. // Licence: wxWindows licence
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "wx/frame.h"
  9. #include "wx/hashmap.h"
  10. #include "wx/event.h"
  11. class wxTestableFrame : public wxFrame
  12. {
  13. public:
  14. wxTestableFrame();
  15. void OnEvent(wxEvent& evt);
  16. private:
  17. friend class EventCounter;
  18. int GetEventCount(wxEventType type);
  19. void ClearEventCount(wxEventType type);
  20. wxLongToLongHashMap m_count;
  21. };
  22. class EventCounter
  23. {
  24. public:
  25. EventCounter(wxWindow* win, wxEventType type);
  26. ~EventCounter();
  27. int GetCount() { return m_frame->GetEventCount(m_type); }
  28. void Clear() { m_frame->ClearEventCount(m_type); }
  29. private:
  30. wxEventType m_type;
  31. wxTestableFrame* m_frame;
  32. wxWindow* m_win;
  33. };