7 #include <Application.h>
8 #include <MessageRunner.h>
15 TEST_MANY_WINDOWS
= 0,
19 class TestApp
: public BApplication
{
21 TestApp(uint32 testMode
);
24 virtual void ReadyToRun();
25 virtual void MessageReceived(BMessage
* message
);
28 BMessageRunner
* fPulse
;
36 class TestWindow
: public BWindow
{
38 TestWindow(BRect frame
);
39 virtual ~TestWindow();
42 BMessageRunner
* fPulse
;
46 TestApp::TestApp(uint32 testMode
)
47 : BApplication("application/x.vnd-Haiku.stress-test"),
49 fFrame(10.0, 30.0, 150.0, 100.0),
50 fScreenFrame(0.0, 0.0, 640.0, 480.0),
66 BMessage
message('tick');
67 fPulse
= new BMessageRunner(be_app_messenger
, &message
, 100L);
72 TestApp::MessageReceived(BMessage
* message
)
74 static int32 count
= 0;
75 if (gMaxCount
!= 0 && ++count
> gMaxCount
)
76 PostMessage(B_QUIT_REQUESTED
);
78 switch (message
->what
) {
81 case TEST_MANY_WINDOWS
:
83 fFrame
.OffsetBy(10.0, 0.0);
84 if (fFrame
.right
> fScreenFrame
.right
) {
86 fFrame
.OffsetTo(10.0, fFrame
.top
+ 10.0);
88 if (fFrame
.bottom
> fScreenFrame
.bottom
) {
90 fFrame
.OffsetTo(10.0, 30.0);
92 int32 action
= CountWindows() > 1 ? rand() % 10 : 0;
95 new TestWindow(fFrame
);
99 BWindow
* window
= WindowAt(rand() % CountWindows());
100 if (window
->Lock()) {
101 if (window
->IsHidden())
103 window
->MoveBy(23, 19);
110 BWindow
* window
= WindowAt(rand() % CountWindows());
111 if (window
->Lock()) {
112 if (!window
->IsHidden())
120 BWindow
* window
= WindowAt(rand() % CountWindows());
121 if (window
->Lock()) {
122 if (window
->IsHidden())
129 case 4: // change workspace
131 BWindow
* window
= WindowAt(rand() % CountWindows());
132 if (window
->Lock()) {
133 if (window
->IsHidden())
135 window
->SetWorkspaces(1 << (rand() % 4));
142 BWindow
* window
= WindowAt(rand() % CountWindows());
143 if (window
->Lock()) {
144 if (window
->IsHidden())
146 window
->Minimize(true);
151 case 6: // change size
153 BWindow
* window
= WindowAt(rand() % CountWindows());
154 if (window
->Lock()) {
155 if (window
->IsHidden())
157 window
->ResizeBy(1, 2);
164 BWindow
* window
= WindowAt(rand() % CountWindows());
165 if (window
->Lock()) {
166 if (window
->IsHidden())
169 snprintf(title
, sizeof(title
), "Title %d",
171 window
->SetTitle(title
);
178 BWindow
* window
= WindowAt(rand() % CountWindows());
179 if (window
->Lock()) {
180 if (window
->IsHidden())
182 window_look looks
[] = {
183 B_DOCUMENT_WINDOW_LOOK
,
185 B_FLOATING_WINDOW_LOOK
,
187 window
->SetLook(looks
[rand() % 3]);
194 BWindow
* window
= WindowAt(rand() % CountWindows());
195 if (window
->Lock()) {
196 if (window
->IsHidden())
198 window_feel feels
[] = {
199 B_NORMAL_WINDOW_FEEL
,
200 B_FLOATING_APP_WINDOW_FEEL
,
201 B_MODAL_APP_WINDOW_FEEL
,
203 window
->SetFeel(feels
[rand() % 3]);
212 case TEST_SINGLE_WINDOW
:
217 fWindow
= new BWindow(fFrame
, "Test", B_TITLED_WINDOW
, 0);
221 PostMessage(B_QUIT_REQUESTED
);
226 BApplication::MessageReceived(message
);
231 TestWindow::TestWindow(BRect frame
)
232 : BWindow(frame
, "Test", B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS
)
236 BMessenger
self(this);
237 BMessage
message(B_QUIT_REQUESTED
);
238 fPulse
= new BMessageRunner(self
, &message
, 100000000LL, 1);
245 TestWindow::~TestWindow()
254 main(int argc
, char** argv
)
256 uint32 testMode
= TEST_SINGLE_WINDOW
;
259 if (strcmp(argv
[1], "-many") == 0)
260 testMode
= TEST_MANY_WINDOWS
;
261 else if (strcmp(argv
[1], "-single") == 0)
262 testMode
= TEST_SINGLE_WINDOW
;
265 gMaxCount
= atol(argv
[2]);
268 TestApp
app(testMode
);