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)
|
||||
{ SetId(format); return *this; }
|
||||
|
||||
// comparison (note that we rely on implicit conversions for comparison
|
||||
// with wxDataFormatId, but have to provide them explicitly for comparison
|
||||
// with NativeFormat to avoid ambiguity between comparing from it to
|
||||
// wxDataFormat or vice versa)
|
||||
// comparison
|
||||
bool operator==(wxDataFormatId type) const
|
||||
{ return m_type == type; }
|
||||
bool operator!=(wxDataFormatId type) const
|
||||
{ return m_type != type; }
|
||||
bool operator==(NativeFormat format) const
|
||||
{ return m_format == (NativeFormat)format; }
|
||||
bool operator!=(NativeFormat format) const
|
||||
|
||||
@@ -70,6 +70,13 @@ TEST_CASE("GUI::URLDataObject", "[guifuncs]")
|
||||
CHECK( wxTheClipboard->SetData(dobj) );
|
||||
wxTheClipboard->Flush();
|
||||
}
|
||||
|
||||
TEST_CASE("GUI::DataFormatCompare", "[guifuncs][dataformat]")
|
||||
{
|
||||
const wxDataFormat df(wxDF_TEXT);
|
||||
CHECK( df == wxDF_TEXT );
|
||||
CHECK( df != wxDF_INVALID );
|
||||
}
|
||||
#endif // wxUSE_DATAOBJ
|
||||
|
||||
TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]")
|
||||
|
||||
Reference in New Issue
Block a user