Merge branch 'fix-and-run-tests-with-asan'

Fix issues found by address/leak sanitizers in the unit tests and add
Travis CI build running tests built with ASAN to ensure they don't
reappear in the future.

See https://github.com/wxWidgets/wxWidgets/pull/2086
This commit is contained in:
Vadim Zeitlin
2020-10-19 21:16:27 +02:00
14 changed files with 151 additions and 27 deletions

View File

@@ -652,6 +652,8 @@ void wxAnyTestCase::wxVariantConversions()
CPPUNIT_ASSERT(variant.GetCount() == 2);
CPPUNIT_ASSERT(variant[0].GetLong() == 15);
CPPUNIT_ASSERT(variant[1].GetString() == "abc");
// Avoid the memory leak.
WX_CLEAR_LIST(wxAnyList, anyList);
any = wxAny(vCustomType);
CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxVariantData*));

View File

@@ -22,6 +22,7 @@
#if wxUSE_FILESYSTEM
#include "wx/fs_mem.h"
#include "wx/scopedptr.h"
// ----------------------------------------------------------------------------
// helpers
@@ -186,16 +187,16 @@ TEST_CASE("wxFileSystem::MemoryFSHandler", "[filesys][memoryfshandler][find]")
AutoMemoryFSHandler()
: m_handler(new wxMemoryFSHandler())
{
wxFileSystem::AddHandler(m_handler);
wxFileSystem::AddHandler(m_handler.get());
}
~AutoMemoryFSHandler()
{
wxFileSystem::RemoveHandler(m_handler);
wxFileSystem::RemoveHandler(m_handler.get());
}
private:
wxMemoryFSHandler* const m_handler;
wxScopedPtr<wxMemoryFSHandler> const m_handler;
} autoMemoryFSHandler;
wxMemoryFSHandler::AddFile("foo.txt", "foo contents");

View File

@@ -20,15 +20,13 @@
#endif // WX_PRECOMP
#include "wx/html/winpars.h"
#include "wx/scopedptr.h"
// Test that parsing invalid HTML simply fails but doesn't crash for example.
TEST_CASE("wxHtmlParser::ParseInvalid", "[html][parser][error]")
{
class NullParser : public wxHtmlWinParser
{
public:
virtual wxObject *GetProduct() wxOVERRIDE { return NULL; }
protected:
virtual void AddText(const wxString& WXUNUSED(txt)) wxOVERRIDE { }
};
@@ -37,17 +35,17 @@ TEST_CASE("wxHtmlParser::ParseInvalid", "[html][parser][error]")
wxMemoryDC dc;
p.SetDC(&dc);
p.Parse("<");
p.Parse("<foo");
p.Parse("<!--");
p.Parse("<!---");
delete p.Parse("<");
delete p.Parse("<foo");
delete p.Parse("<!--");
delete p.Parse("<!---");
}
TEST_CASE("wxHtmlCell::Detach", "[html][cell]")
{
wxMemoryDC dc;
wxHtmlContainerCell* const top = new wxHtmlContainerCell(NULL);
wxScopedPtr<wxHtmlContainerCell> const top(new wxHtmlContainerCell(NULL));
wxHtmlContainerCell* const cont = new wxHtmlContainerCell(NULL);
wxHtmlCell* const cell1 = new wxHtmlWordCell("Hello", dc);
wxHtmlCell* const cell2 = new wxHtmlColourCell(*wxRED);

View File

@@ -1147,7 +1147,7 @@ void MBConvTestCase::TestDecoder(
// make sure the correct output length was calculated
WX_ASSERT_EQUAL_MESSAGE
(
("while converting \"%s\"", multiBuffer),
("while converting \"%s\"", inputCopy),
wideChars,
outputWritten
);

View File

@@ -17,6 +17,7 @@
#endif // WX_PRECOMP
#include "wx/accel.h"
#include "wx/scopedptr.h"
namespace
{
@@ -35,11 +36,11 @@ void CheckAccelEntry(const wxAcceleratorEntry& accel, int keycode, int flags)
*/
TEST_CASE( "wxAcceleratorEntry::Create", "[accelentry]" )
{
wxAcceleratorEntry* pa;
wxScopedPtr<wxAcceleratorEntry> pa;
SECTION( "Correct behavior" )
{
pa = wxAcceleratorEntry::Create("Foo\tCtrl+Z");
pa.reset( wxAcceleratorEntry::Create("Foo\tCtrl+Z") );
CHECK( pa );
CHECK( pa->IsOk() );
@@ -48,21 +49,21 @@ TEST_CASE( "wxAcceleratorEntry::Create", "[accelentry]" )
SECTION( "Tab missing" )
{
pa = wxAcceleratorEntry::Create("Shift-Q");
pa.reset( wxAcceleratorEntry::Create("Shift-Q") );
CHECK( !pa );
}
SECTION( "No accelerator key specified" )
{
pa = wxAcceleratorEntry::Create("bloordyblop");
pa.reset( wxAcceleratorEntry::Create("bloordyblop") );
CHECK( !pa );
}
SECTION( "Display name parsing" )
{
pa = wxAcceleratorEntry::Create("Test\tBackSpace");
pa.reset( wxAcceleratorEntry::Create("Test\tBackSpace") );
CHECK( pa );
CHECK( pa->IsOk() );

View File

@@ -20,6 +20,7 @@
#endif // WX_PRECOMP
#include "wx/menu.h"
#include "wx/scopedptr.h"
#include "wx/translation.h"
#include "wx/uiaction.h"
@@ -624,7 +625,9 @@ namespace
void VerifyAccelAssigned( wxString labelText, int keycode )
{
wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( labelText );
const wxScopedPtr<wxAcceleratorEntry> entry(
wxAcceleratorEntry::Create( labelText )
);
CHECK( entry );
CHECK( entry->GetKeyCode() == keycode );