Fix comparing wxDataFormat with wxDF_INVALID in wxGTK
Define wxDataFormat::operator==(wxDataFormatId) instead of relying on the implicit conversion from wxDataFormatId to wxDataFormat, as this can't be done when the format ID is wxDF_INVALID because creating wxDataFormat results in an assert failure in this case, while comparing with wxDF_INVALID is clearly a perfectly valid operation. Add a unit test checking for this. Closes #22213.
This commit is contained in:
@@ -33,10 +33,11 @@ public:
|
|||||||
wxDataFormat& operator=(NativeFormat format)
|
wxDataFormat& operator=(NativeFormat format)
|
||||||
{ SetId(format); return *this; }
|
{ SetId(format); return *this; }
|
||||||
|
|
||||||
// comparison (note that we rely on implicit conversions for comparison
|
// comparison
|
||||||
// with wxDataFormatId, but have to provide them explicitly for comparison
|
bool operator==(wxDataFormatId type) const
|
||||||
// with NativeFormat to avoid ambiguity between comparing from it to
|
{ return m_type == type; }
|
||||||
// wxDataFormat or vice versa)
|
bool operator!=(wxDataFormatId type) const
|
||||||
|
{ return m_type != type; }
|
||||||
bool operator==(NativeFormat format) const
|
bool operator==(NativeFormat format) const
|
||||||
{ return m_format == (NativeFormat)format; }
|
{ return m_format == (NativeFormat)format; }
|
||||||
bool operator!=(NativeFormat format) const
|
bool operator!=(NativeFormat format) const
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ TEST_CASE("GUI::URLDataObject", "[guifuncs]")
|
|||||||
CHECK( wxTheClipboard->SetData(dobj) );
|
CHECK( wxTheClipboard->SetData(dobj) );
|
||||||
wxTheClipboard->Flush();
|
wxTheClipboard->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("GUI::DataFormatCompare", "[guifuncs][dataformat]")
|
||||||
|
{
|
||||||
|
const wxDataFormat df(wxDF_TEXT);
|
||||||
|
CHECK( df == wxDF_TEXT );
|
||||||
|
CHECK( df != wxDF_INVALID );
|
||||||
|
}
|
||||||
#endif // wxUSE_DATAOBJ
|
#endif // wxUSE_DATAOBJ
|
||||||
|
|
||||||
TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]")
|
TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]")
|
||||||
|
|||||||
Reference in New Issue
Block a user