Fix wxAcceleratorEntry memory leaks in the menu test

Use wxScopedPtr to ensure that all the test accelerator entries are
destroyed instead of just being leaked.
This commit is contained in:
Ilya Sinitsyn 2020-10-13 10:41:57 +07:00 committed by Vadim Zeitlin
parent 18d56818f5
commit 413c05ea85
2 changed files with 10 additions and 6 deletions

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 );