2 * Copyright (C) 2008-2009 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
11 #include <Application.h>
14 #include "DrawingModeToString.h"
15 #include "TestWindow.h"
18 #include "HorizontalLineTest.h"
19 #include "RandomLineTest.h"
20 #include "StringTest.h"
21 #include "VerticalLineTest.h"
29 const test_info kTestInfos
[] = {
30 { "HorizontalLines", HorizontalLineTest::CreateTest
},
31 { "RandomLines", RandomLineTest::CreateTest
},
32 { "Strings", StringTest::CreateTest
},
33 { "VerticalLines", VerticalLineTest::CreateTest
},
38 class Benchmark
: public BApplication
{
40 Benchmark(Test
* test
, drawing_mode mode
, bool clipping
)
41 : BApplication("application/x-vnd.haiku-benchmark"),
45 fUseClipping(clipping
)
54 virtual void ReadyToRun()
59 BRect frame
= screen
.Frame();
60 frame
.left
= (frame
.left
+ frame
.right
- width
) / 2;
61 frame
.top
= (frame
.top
+ frame
.bottom
- width
) / 2;
62 frame
.right
= frame
.left
+ width
- 1;
63 frame
.bottom
= frame
.top
+ height
- 1;
65 fTestWindow
= new TestWindow(frame
, fTest
, fDrawingMode
,
66 fUseClipping
, BMessenger(this));
69 virtual bool QuitRequested()
71 if (fTestWindow
!= NULL
)
72 fTestWindow
->SetAllowedToQuit(true);
73 return BApplication::QuitRequested();
76 virtual void MessageReceived(BMessage
* message
)
78 switch (message
->what
) {
79 case MSG_TEST_CANCELED
:
80 printf("Test canceled early.\n");
82 case MSG_TEST_FINISHED
:
84 fTest
->PrintResults(fTestWindow
->View());
85 fTestWindow
->Unlock();
86 PostMessage(B_QUIT_REQUESTED
);
89 BApplication::MessageReceived(message
);
96 TestWindow
* fTestWindow
;
97 drawing_mode fDrawingMode
;
103 print_test_list(bool error
)
105 FILE* out
= (error
? stderr
: stdout
);
107 fprintf(out
, "available tests:\n");
109 for (int32 i
= 0; kTestInfos
[i
].name
; i
++)
110 fprintf(out
, " %s\n", kTestInfos
[i
].name
);
115 main(int argc
, char** argv
)
118 const char* testName
;
120 fprintf(stderr
, "Usage: %s <test name>\n", argv
[0]);
121 print_test_list(true);
129 bool clipping
= false;
130 drawing_mode mode
= B_OP_COPY
;
133 drawing_mode possibleMode
;
134 if (strcmp(argv
[0], "--clipping") == 0 || strcmp(argv
[0], "-c") == 0) {
136 } else if (ToDrawingMode(argv
[0], possibleMode
)) {
144 // find and create the test
147 for (int32 i
= 0; kTestInfos
[i
].name
; i
++) {
148 if (strcmp(testName
, kTestInfos
[i
].name
) == 0) {
149 test
= (kTestInfos
[i
].create
)();
153 } catch (std::bad_alloc
) {
154 fprintf(stderr
, "Insufficient memory to create the test. Sorry.\n");
159 fprintf(stderr
, "Error: Invalid test name: \"%s\"\n", testName
);
160 print_test_list(true);
164 Benchmark
app(test
, mode
, clipping
);