Get rid of CppUnit boilerplate in MiscGUIFuncsTestCase
Simplify code by not defining an unnecessary test case class and using CATCH macros directly. No real changes.
This commit is contained in:
@@ -30,103 +30,74 @@
|
|||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// test class
|
// the tests
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class MiscGUIFuncsTestCase : public CppUnit::TestCase
|
TEST_CASE("GUI::DisplaySize", "[guifuncs]")
|
||||||
{
|
|
||||||
public:
|
|
||||||
MiscGUIFuncsTestCase() { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( MiscGUIFuncsTestCase );
|
|
||||||
CPPUNIT_TEST( DisplaySize );
|
|
||||||
CPPUNIT_TEST( URLDataObject );
|
|
||||||
CPPUNIT_TEST( ParseFileDialogFilter );
|
|
||||||
CPPUNIT_TEST( ClientToScreen );
|
|
||||||
CPPUNIT_TEST( FindWindowAtPoint );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void DisplaySize();
|
|
||||||
void URLDataObject();
|
|
||||||
void ParseFileDialogFilter();
|
|
||||||
void ClientToScreen();
|
|
||||||
void FindWindowAtPoint();
|
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(MiscGUIFuncsTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( MiscGUIFuncsTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscGUIFuncsTestCase, "MiscGUIFuncsTestCase" );
|
|
||||||
|
|
||||||
void MiscGUIFuncsTestCase::DisplaySize()
|
|
||||||
{
|
{
|
||||||
// test that different (almost) overloads return the same results
|
// test that different (almost) overloads return the same results
|
||||||
int w, h;
|
int w, h;
|
||||||
wxDisplaySize(&w, &h);
|
wxDisplaySize(&w, &h);
|
||||||
wxSize sz = wxGetDisplaySize();
|
wxSize sz = wxGetDisplaySize();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( w, sz.x );
|
CHECK( sz.x == w );
|
||||||
CPPUNIT_ASSERT_EQUAL( h, sz.y );
|
CHECK( sz.y == h );
|
||||||
|
|
||||||
// test that passing NULL works as expected, e.g. doesn't crash
|
// test that passing NULL works as expected, e.g. doesn't crash
|
||||||
wxDisplaySize(NULL, NULL);
|
wxDisplaySize(NULL, NULL);
|
||||||
wxDisplaySize(&w, NULL);
|
wxDisplaySize(&w, NULL);
|
||||||
wxDisplaySize(NULL, &h);
|
wxDisplaySize(NULL, &h);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( w, sz.x );
|
CHECK( sz.x == w );
|
||||||
CPPUNIT_ASSERT_EQUAL( h, sz.y );
|
CHECK( sz.y == h );
|
||||||
|
|
||||||
// test that display PPI is something reasonable
|
// test that display PPI is something reasonable
|
||||||
sz = wxGetDisplayPPI();
|
sz = wxGetDisplayPPI();
|
||||||
CPPUNIT_ASSERT( sz.x < 1000 );
|
CHECK( sz.x < 1000 );
|
||||||
CPPUNIT_ASSERT( sz.y < 1000 );
|
CHECK( sz.y < 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiscGUIFuncsTestCase::URLDataObject()
|
|
||||||
{
|
|
||||||
#if wxUSE_DATAOBJ
|
#if wxUSE_DATAOBJ
|
||||||
|
TEST_CASE("GUI::URLDataObject", "[guifuncs]")
|
||||||
|
{
|
||||||
// this tests for buffer overflow, see #11102
|
// this tests for buffer overflow, see #11102
|
||||||
const char * const
|
const char * const
|
||||||
url = "http://something.long.to.overwrite.plenty.memory.example.com";
|
url = "http://something.long.to.overwrite.plenty.memory.example.com";
|
||||||
wxURLDataObject * const dobj = new wxURLDataObject(url);
|
wxURLDataObject * const dobj = new wxURLDataObject(url);
|
||||||
CPPUNIT_ASSERT_EQUAL( url, dobj->GetURL() );
|
CHECK( dobj->GetURL() == url );
|
||||||
|
|
||||||
wxClipboardLocker lockClip;
|
wxClipboardLocker lockClip;
|
||||||
CPPUNIT_ASSERT( wxTheClipboard->SetData(dobj) );
|
CHECK( wxTheClipboard->SetData(dobj) );
|
||||||
wxTheClipboard->Flush();
|
wxTheClipboard->Flush();
|
||||||
#endif // wxUSE_DATAOBJ
|
|
||||||
}
|
}
|
||||||
|
#endif // wxUSE_DATAOBJ
|
||||||
|
|
||||||
void MiscGUIFuncsTestCase::ParseFileDialogFilter()
|
TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]")
|
||||||
{
|
{
|
||||||
wxArrayString descs,
|
wxArrayString descs,
|
||||||
filters;
|
filters;
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
REQUIRE
|
||||||
(
|
(
|
||||||
1,
|
|
||||||
wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters)
|
wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters)
|
||||||
|
== 1
|
||||||
);
|
);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( "Image files", descs[0] );
|
CHECK( descs[0] == "Image files" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "*.jpg;*.png", filters[0] );
|
CHECK( filters[0] == "*.jpg;*.png" );
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
REQUIRE
|
||||||
(
|
(
|
||||||
2,
|
|
||||||
wxParseCommonDialogsFilter
|
wxParseCommonDialogsFilter
|
||||||
(
|
(
|
||||||
"All files (*.*)|*.*|Python source (*.py)|*.py",
|
"All files (*.*)|*.*|Python source (*.py)|*.py",
|
||||||
descs, filters
|
descs, filters
|
||||||
)
|
)
|
||||||
|
== 2
|
||||||
);
|
);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( "*.*", filters[0] );
|
CHECK( filters[0] == "*.*" );
|
||||||
CPPUNIT_ASSERT_EQUAL( "*.py", filters[1] );
|
CHECK( filters[1] == "*.py" );
|
||||||
|
|
||||||
// Test some invalid ones too.
|
// Test some invalid ones too.
|
||||||
WX_ASSERT_FAILS_WITH_ASSERT
|
WX_ASSERT_FAILS_WITH_ASSERT
|
||||||
@@ -139,10 +110,10 @@ void MiscGUIFuncsTestCase::ParseFileDialogFilter()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiscGUIFuncsTestCase::ClientToScreen()
|
TEST_CASE("GUI::ClientToScreen", "[guifuncs]")
|
||||||
{
|
{
|
||||||
wxWindow* const tlw = wxTheApp->GetTopWindow();
|
wxWindow* const tlw = wxTheApp->GetTopWindow();
|
||||||
CPPUNIT_ASSERT( tlw );
|
REQUIRE( tlw );
|
||||||
|
|
||||||
wxScopedPtr<wxPanel> const
|
wxScopedPtr<wxPanel> const
|
||||||
p1(new wxPanel(tlw, wxID_ANY, wxPoint(0, 0), wxSize(100, 50)));
|
p1(new wxPanel(tlw, wxID_ANY, wxPoint(0, 0), wxSize(100, 50)));
|
||||||
@@ -156,17 +127,9 @@ void MiscGUIFuncsTestCase::ClientToScreen()
|
|||||||
|
|
||||||
const wxPoint tlwOrig = tlw->ClientToScreen(wxPoint(0, 0));
|
const wxPoint tlwOrig = tlw->ClientToScreen(wxPoint(0, 0));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CHECK( p2->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(0, 50) );
|
||||||
(
|
|
||||||
tlwOrig + wxPoint(0, 50),
|
|
||||||
p2->ClientToScreen(wxPoint(0, 0))
|
|
||||||
);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CHECK( b->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(10, 60) );
|
||||||
(
|
|
||||||
tlwOrig + wxPoint(10, 60),
|
|
||||||
b->ClientToScreen(wxPoint(0, 0))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -195,10 +158,10 @@ wxString GetLabelOfWindowAtPoint(wxWindow* parent, int x, int y)
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
void MiscGUIFuncsTestCase::FindWindowAtPoint()
|
TEST_CASE("GUI::FindWindowAtPoint", "[guifuncs]")
|
||||||
{
|
{
|
||||||
wxWindow* const parent = wxTheApp->GetTopWindow();
|
wxWindow* const parent = wxTheApp->GetTopWindow();
|
||||||
CPPUNIT_ASSERT( parent );
|
REQUIRE( parent );
|
||||||
|
|
||||||
// Set a label to allow distinguishing it from the other windows in the
|
// Set a label to allow distinguishing it from the other windows in the
|
||||||
// assertion messages.
|
// assertion messages.
|
||||||
@@ -213,56 +176,28 @@ void MiscGUIFuncsTestCase::FindWindowAtPoint()
|
|||||||
// We need this to realize the windows created above under wxGTK.
|
// We need this to realize the windows created above under wxGTK.
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("No window for a point outside of the window");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 900, 900) == "NONE" );
|
||||||
"No window for a point outside of the window",
|
|
||||||
"NONE",
|
|
||||||
GetLabelOfWindowAtPoint(parent, 900, 900)
|
|
||||||
);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO( "Point over a child control corresponds to it" );
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 11, 11) == btn1->GetLabel() );
|
||||||
"Point over a child control corresponds to it",
|
|
||||||
btn1->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 11, 11)
|
|
||||||
);
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Point outside of any child control returns the TLW itself");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 5, 5) == parent->GetLabel() );
|
||||||
"Point outside of any child control returns the TLW itself",
|
|
||||||
parent->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 5, 5)
|
|
||||||
);
|
|
||||||
|
|
||||||
btn2->Disable();
|
btn2->Disable();
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Point over a disabled child control still corresponds to it");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == btn2->GetLabel() );
|
||||||
"Point over a disabled child control still corresponds to it",
|
|
||||||
btn2->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 11, 91)
|
|
||||||
);
|
|
||||||
|
|
||||||
btn2->Hide();
|
btn2->Hide();
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Point over a hidden child control doesn't take it into account");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == parent->GetLabel() );
|
||||||
"Point over a hidden child control doesn't take it into account",
|
|
||||||
parent->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 11, 91)
|
|
||||||
);
|
|
||||||
|
|
||||||
btn2->Show();
|
btn2->Show();
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Point over child control corresponds to the child");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() );
|
||||||
"Point over child control corresponds to the child",
|
|
||||||
btn3->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 31, 111)
|
|
||||||
);
|
|
||||||
|
|
||||||
btn3->Disable();
|
btn3->Disable();
|
||||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
INFO("Point over disabled child controls still corresponds to this child");
|
||||||
(
|
CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() );
|
||||||
"Point over disabled child controls still corresponds to this child",
|
|
||||||
btn3->GetLabel(),
|
|
||||||
GetLabelOfWindowAtPoint(parent, 31, 111)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user