Skip to content

Commit a53f851

Browse files
committed
Allocate all wxFrame objects on the heap in tests.
This has been like this for years, but it appears to be the source of an intermittent crash when running the tests on macOS.
1 parent 9071fb7 commit a53f851

16 files changed

+343
-310
lines changed

tests/BitmapTool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using namespace REHex;
3131
class BitmapToolTest: public ::testing::Test
3232
{
3333
protected:
34-
wxFrame frame;
34+
AutoFrame frame;
3535

3636
SharedDocumentPointer doc;
3737
DocumentCtrl *doc_ctrl;
@@ -46,13 +46,13 @@ BitmapToolTest::BitmapToolTest():
4646
frame(NULL, wxID_ANY, "REHex Tests"),
4747
doc(SharedDocumentPointer::make())
4848
{
49-
doc_ctrl = new DocumentCtrl(&frame, doc);
49+
doc_ctrl = new DocumentCtrl(frame, doc);
5050

5151
/* Need a data region to avoid crashing in DocumentCtrl event handlers. */
5252
std::vector<DocumentCtrl::Region*> regions = { new DocumentCtrl::DataRegion(doc, 0, 0, 0) };
5353
doc_ctrl->replace_all_regions(regions);
5454

55-
bmtool = new BitmapTool(&frame, doc, doc_ctrl);
55+
bmtool = new BitmapTool(frame, doc, doc_ctrl);
5656
}
5757

5858
std::string BitmapToolTest::bitmap_to_string(wxBitmap bitmap)

tests/CommentTree.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Reverse Engineer's Hex Editor
2-
* Copyright (C) 2019-2024 Daniel Collins <solemnwarning@solemnwarning.net>
2+
* Copyright (C) 2019-2025 Daniel Collins <solemnwarning@solemnwarning.net>
33
*
44
* This program is free software; you can redistribute it and/or modify it
55
* under the terms of the GNU General Public License version 2 as published by
@@ -262,8 +262,8 @@ TEST(CommentTree, NoComments)
262262
{
263263
SharedDocumentPointer doc(SharedDocumentPointer::make());
264264

265-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
266-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
265+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
266+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
267267

268268
unsigned char z1k[1024];
269269
memset(z1k, 0, 1024);
@@ -283,8 +283,8 @@ TEST(CommentTree, SingleComment)
283283
{
284284
SharedDocumentPointer doc(SharedDocumentPointer::make());
285285

286-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
287-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
286+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
287+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
288288

289289
unsigned char z1k[1024];
290290
memset(z1k, 0, 1024);
@@ -311,8 +311,8 @@ TEST(CommentTree, MultipleComments)
311311
{
312312
SharedDocumentPointer doc(SharedDocumentPointer::make());
313313

314-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
315-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
314+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
315+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
316316

317317
unsigned char z1k[1024];
318318
memset(z1k, 0, 1024);
@@ -345,8 +345,8 @@ TEST(CommentTree, Heirarchy)
345345
{
346346
SharedDocumentPointer doc(SharedDocumentPointer::make());
347347

348-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
349-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
348+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
349+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
350350

351351
unsigned char z1k[1024];
352352
memset(z1k, 0, 1024);
@@ -396,8 +396,8 @@ TEST(CommentTree, EraseRootCommentNoChildren)
396396
{
397397
SharedDocumentPointer doc(SharedDocumentPointer::make());
398398

399-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
400-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
399+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
400+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
401401

402402
unsigned char z1k[1024];
403403
memset(z1k, 0, 1024);
@@ -431,8 +431,8 @@ TEST(CommentTree, EraseRootCommentWithChildren)
431431
{
432432
SharedDocumentPointer doc(SharedDocumentPointer::make());
433433

434-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
435-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
434+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
435+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
436436

437437
unsigned char z1k[1024];
438438
memset(z1k, 0, 1024);
@@ -492,8 +492,8 @@ TEST(CommentTree, EraseNestedCommentNoChildren)
492492
{
493493
SharedDocumentPointer doc(SharedDocumentPointer::make());
494494

495-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
496-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
495+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
496+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
497497

498498
unsigned char z1k[1024];
499499
memset(z1k, 0, 1024);
@@ -523,8 +523,8 @@ TEST(CommentTree, EraseNestedCommentWithChildren)
523523
{
524524
SharedDocumentPointer doc(SharedDocumentPointer::make());
525525

526-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
527-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
526+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
527+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
528528

529529
unsigned char z1k[1024];
530530
memset(z1k, 0, 1024);
@@ -558,8 +558,8 @@ TEST(CommentTree, AddCommentRoot)
558558
{
559559
SharedDocumentPointer doc(SharedDocumentPointer::make());
560560

561-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
562-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
561+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
562+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
563563

564564
unsigned char z1k[1024];
565565
memset(z1k, 0, 1024);
@@ -595,8 +595,8 @@ TEST(CommentTree, AddNestedComment)
595595
{
596596
SharedDocumentPointer doc(SharedDocumentPointer::make());
597597

598-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
599-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
598+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
599+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
600600

601601
unsigned char z1k[1024];
602602
memset(z1k, 0, 1024);
@@ -634,8 +634,8 @@ TEST(CommentTree, AddContainingComment)
634634
{
635635
SharedDocumentPointer doc(SharedDocumentPointer::make());
636636

637-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
638-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
637+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
638+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
639639

640640
unsigned char z1k[1024];
641641
memset(z1k, 0, 1024);
@@ -723,8 +723,8 @@ TEST(CommentTree, ModifyComment)
723723
{
724724
SharedDocumentPointer doc(SharedDocumentPointer::make());
725725

726-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
727-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
726+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
727+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
728728

729729
unsigned char z1k[1024];
730730
memset(z1k, 0, 1024);
@@ -759,8 +759,8 @@ TEST(CommentTree, SetFilter)
759759
{
760760
SharedDocumentPointer doc(SharedDocumentPointer::make());
761761

762-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
763-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
762+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
763+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
764764

765765
unsigned char z1k[1024];
766766
memset(z1k, 0, 1024);
@@ -793,8 +793,8 @@ TEST(CommentTree, ClearFilter)
793793
{
794794
SharedDocumentPointer doc(SharedDocumentPointer::make());
795795

796-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
797-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
796+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
797+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
798798

799799
unsigned char z1k[1024];
800800
memset(z1k, 0, 1024);
@@ -841,8 +841,8 @@ TEST(CommentTree, ChangeFilter)
841841
{
842842
SharedDocumentPointer doc(SharedDocumentPointer::make());
843843

844-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
845-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
844+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
845+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
846846

847847
unsigned char z1k[1024];
848848
memset(z1k, 0, 1024);
@@ -887,8 +887,8 @@ TEST(CommentTree, FilterMatchesRootNode)
887887
{
888888
SharedDocumentPointer doc(SharedDocumentPointer::make());
889889

890-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
891-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
890+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
891+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
892892

893893
unsigned char z1k[1024];
894894
memset(z1k, 0, 1024);
@@ -922,8 +922,8 @@ TEST(CommentTree, FilterMatchesIntermediateNode)
922922
{
923923
SharedDocumentPointer doc(SharedDocumentPointer::make());
924924

925-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
926-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
925+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
926+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
927927

928928
unsigned char z1k[1024];
929929
memset(z1k, 0, 1024);
@@ -961,8 +961,8 @@ TEST(CommentTree, FilterMatchesDeepNode)
961961
{
962962
SharedDocumentPointer doc(SharedDocumentPointer::make());
963963

964-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
965-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
964+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
965+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame.frame, doc);
966966

967967
unsigned char z1k[1024];
968968
memset(z1k, 0, 1024);

tests/ConsoleBuffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <wx/timer.h>
2727

2828
#include "../src/ConsoleBuffer.hpp"
29+
#include "testutil.hpp"
2930

3031
using namespace REHex;
3132

@@ -48,20 +49,19 @@ class ConsoleBufferTest: public ::testing::Test
4849
ConsoleBuffer cbuffer;
4950
std::vector<std::string> events;
5051

51-
wxFrame frame;
52+
AutoFrame frame;
5253
wxTimer timer;
5354

5455
ConsoleBufferTest():
5556
cbuffer(64),
56-
frame(NULL, wxID_ANY, "REHex Tests"),
57-
timer(&frame, wxID_ANY)
57+
frame(NULL, wxID_ANY, "REHex Tests")
5858
{
59-
frame.Bind(wxEVT_IDLE, [](wxIdleEvent &event)
59+
frame->Bind(wxEVT_IDLE, [](wxIdleEvent &event)
6060
{
6161
wxTheApp->ExitMainLoop();
6262
});
6363

64-
frame.Bind(wxEVT_TIMER, [](wxTimerEvent &event)
64+
timer.Bind(wxEVT_TIMER, [](wxTimerEvent &event)
6565
{
6666
wxTheApp->ExitMainLoop();
6767
});

tests/DiffWindow.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Reverse Engineer's Hex Editor
2-
* Copyright (C) 2020-2024 Daniel Collins <solemnwarning@solemnwarning.net>
2+
* Copyright (C) 2020-2025 Daniel Collins <solemnwarning@solemnwarning.net>
33
*
44
* This program is free software; you can redistribute it and/or modify it
55
* under the terms of the GNU General Public License version 2 as published by
@@ -26,13 +26,14 @@
2626
#include "../src/DocumentCtrl.hpp"
2727
#include "../src/SafeWindowPointer.hpp"
2828
#include "../src/SharedDocumentPointer.hpp"
29+
#include "testutil.hpp"
2930

3031
using namespace REHex;
3132

3233
class DiffWindowTest: public ::testing::Test
3334
{
3435
protected:
35-
wxFrame frame;
36+
AutoFrame frame;
3637

3738
SharedDocumentPointer doc1;
3839
DocumentCtrl *main_doc_ctrl1;
@@ -72,10 +73,10 @@ class DiffWindowTest: public ::testing::Test
7273
doc1->insert_data(0, doc1_buf, sizeof(doc1_buf));
7374
doc2->insert_data(0, doc2_buf, sizeof(doc2_buf));
7475

75-
main_doc_ctrl1 = new DocumentCtrl(&frame, doc1);
76-
main_doc_ctrl2 = new DocumentCtrl(&frame, doc2);
76+
main_doc_ctrl1 = new DocumentCtrl(frame, doc1);
77+
main_doc_ctrl2 = new DocumentCtrl(frame, doc2);
7778

78-
diff_window = new DiffWindow(&frame);
79+
diff_window = new DiffWindow(frame);
7980
diff_window->set_folding(false);
8081
}
8182
};

tests/DisassemblyRegion.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Reverse Engineer's Hex Editor
2-
* Copyright (C) 2020-2024 Daniel Collins <solemnwarning@solemnwarning.net>
2+
* Copyright (C) 2020-2025 Daniel Collins <solemnwarning@solemnwarning.net>
33
*
44
* This program is free software; you can redistribute it and/or modify it
55
* under the terms of the GNU General Public License version 2 as published by
@@ -24,6 +24,7 @@
2424
#include "../src/document.hpp"
2525
#include "../src/DocumentCtrl.hpp"
2626
#include "../src/SharedDocumentPointer.hpp"
27+
#include "testutil.hpp"
2728

2829
using namespace REHex;
2930

@@ -859,8 +860,8 @@ TEST(DisassemblyRegion, CopyWholeInstructions)
859860
/* Check the region is fully processed. */
860861
ASSERT_EQ(region->unprocessed_offset_rel(), 0x125BE);
861862

862-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
863-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
863+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
864+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame, doc);
864865

865866
std::vector<DocumentCtrl::Region*> regions(&region, &region + 1);
866867
doc_ctrl->replace_all_regions(regions);
@@ -908,8 +909,8 @@ TEST(DisassemblyRegion, CopyInHexView)
908909
/* Check the region is fully processed. */
909910
ASSERT_EQ(region->unprocessed_offset_rel(), 0x125BE);
910911

911-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
912-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
912+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
913+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame, doc);
913914

914915
std::vector<DocumentCtrl::Region*> regions(&region, &region + 1);
915916
doc_ctrl->replace_all_regions(regions);
@@ -942,8 +943,8 @@ TEST(DisassemblyRegion, CopyPartialInstructions)
942943
/* Check the region is fully processed. */
943944
ASSERT_EQ(region->unprocessed_offset_rel(), 0x125BE);
944945

945-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
946-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
946+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
947+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame, doc);
947948

948949
std::vector<DocumentCtrl::Region*> regions(&region, &region + 1);
949950
doc_ctrl->replace_all_regions(regions);
@@ -989,8 +990,8 @@ TEST(DisassemblyRegion, CopyPartialInstruction)
989990
/* Check the region is fully processed. */
990991
ASSERT_EQ(region->unprocessed_offset_rel(), 0x125BE);
991992

992-
wxFrame frame(NULL, wxID_ANY, "REHex Tests");
993-
DocumentCtrl *doc_ctrl = new DocumentCtrl(&frame, doc);
993+
AutoFrame frame(NULL, wxID_ANY, "REHex Tests");
994+
DocumentCtrl *doc_ctrl = new DocumentCtrl(frame, doc);
994995

995996
std::vector<DocumentCtrl::Region*> regions(&region, &region + 1);
996997
doc_ctrl->replace_all_regions(regions);

tests/DocumentCtrl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
#include "../src/document.hpp"
2525
#include "../src/DocumentCtrl.hpp"
2626
#include "../src/SharedDocumentPointer.hpp"
27+
#include "testutil.hpp"
2728

2829
using namespace REHex;
2930

3031
class DocumentCtrlTest: public ::testing::Test
3132
{
3233
protected:
33-
wxFrame frame;
34+
AutoFrame frame;
3435

3536
SharedDocumentPointer doc;
3637
DocumentCtrl *doc_ctrl;
@@ -45,7 +46,7 @@ DocumentCtrlTest::DocumentCtrlTest():
4546
frame(NULL, wxID_ANY, "REHex Tests"),
4647
doc(SharedDocumentPointer::make())
4748
{
48-
doc_ctrl = new DocumentCtrl(&frame, doc);
49+
doc_ctrl = new DocumentCtrl(frame, doc);
4950

5051
/* Need a data region to avoid crashing during wxEVT_SIZE handler. */
5152
std::vector<DocumentCtrl::Region*> regions = { new DocumentCtrl::DataRegion(doc, 0, 0, 0) };

0 commit comments

Comments
 (0)