1 // main.cpp 2 3 #include <Application.h> 4 #include <MessageRunner.h> 5 #include <Window.h> 6 7 #include <stdlib.h> 8 9 10 int32 gMaxCount = 0; 11 12 enum { 13 TEST_MANY_WINDOWS = 0, 14 TEST_SINGLE_WINDOW, 15 }; 16 17 class TestApp : public BApplication { 18 public: 19 TestApp(uint32 testMode); 20 virtual ~TestApp(); 21 22 virtual void ReadyToRun(); 23 virtual void MessageReceived(BMessage* message); 24 25 private: 26 BMessageRunner* fPulse; 27 BRect fFrame; 28 BRect fScreenFrame; 29 BWindow* fWindow; 30 uint32 fTestMode; 31 }; 32 33 34 class TestWindow : public BWindow { 35 public: 36 TestWindow(BRect frame); 37 virtual ~TestWindow(); 38 39 private: 40 BMessageRunner* fPulse; 41 }; 42 43 44 TestApp::TestApp(uint32 testMode) 45 : BApplication("application/x.vnd-Haiku.stress-test"), 46 fPulse(NULL), 47 fFrame(10.0, 30.0, 150.0, 100.0), 48 fScreenFrame(0.0, 0.0, 640.0, 480.0), 49 fWindow(NULL), 50 fTestMode(testMode) 51 { 52 } 53 54 55 TestApp::~TestApp() 56 { 57 delete fPulse; 58 } 59 60 61 void 62 TestApp::ReadyToRun() 63 { 64 BMessage message('tick'); 65 fPulse = new BMessageRunner(be_app_messenger, &message, 100L); 66 } 67 68 69 void 70 TestApp::MessageReceived(BMessage* message) 71 { 72 static int32 count = 0; 73 if (gMaxCount != 0 && ++count > gMaxCount) 74 PostMessage(B_QUIT_REQUESTED); 75 76 switch (message->what) { 77 case 'tick': 78 switch (fTestMode) { 79 case TEST_MANY_WINDOWS: 80 fFrame.OffsetBy(10.0, 0.0); 81 if (fFrame.right > fScreenFrame.right) { 82 // next row 83 fFrame.OffsetTo(10.0, fFrame.top + 10.0); 84 } 85 if (fFrame.bottom > fScreenFrame.bottom) { 86 // back to top 87 fFrame.OffsetTo(10.0, 30.0); 88 } 89 new TestWindow(fFrame); 90 break; 91 case TEST_SINGLE_WINDOW: 92 if (fWindow) { 93 fWindow->Lock(); 94 fWindow->Quit(); 95 } 96 fWindow = new BWindow(fFrame, "Test", B_TITLED_WINDOW, 0); 97 fWindow->Show(); 98 break; 99 default: 100 PostMessage(B_QUIT_REQUESTED); 101 break; 102 } 103 break; 104 default: 105 BApplication::MessageReceived(message); 106 } 107 } 108 109 110 TestWindow::TestWindow(BRect frame) 111 : BWindow(frame, "Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 112 { 113 Show(); 114 115 BMessenger self(this); 116 BMessage message(B_QUIT_REQUESTED); 117 fPulse = new BMessageRunner(self, &message, 10000000, 1); 118 119 if (Thread() < B_OK) 120 Quit(); 121 } 122 123 124 TestWindow::~TestWindow() 125 { 126 delete fPulse; 127 } 128 129 130 131 // main 132 int 133 main(int argc, char** argv) 134 { 135 uint32 testMode = TEST_SINGLE_WINDOW; 136 137 if (argc > 1) { 138 if (strcmp(argv[1], "-many") == 0) 139 testMode = TEST_MANY_WINDOWS; 140 else if (strcmp(argv[1], "-single") == 0) 141 testMode = TEST_SINGLE_WINDOW; 142 } 143 if (argc > 2) { 144 gMaxCount = atol(argv[2]); 145 } 146 147 TestApp app(testMode); 148 app.Run(); 149 150 return 0; 151 } 152