vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / window_creation / main.cpp
blob08d6debb8a8c27609c15c290fd93d44b8084b3fe
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
6 #include <Application.h>
7 #include <Box.h>
8 #include <OS.h>
9 #include <Screen.h>
10 #include <Window.h>
13 static BRect* sFrames = NULL;
14 static uint32 sNumFrames = 0;
17 class TestApp : public BApplication {
18 public:
19 TestApp(uint32 numWindows, bool views);
20 virtual ~TestApp();
22 virtual void ReadyToRun();
24 private:
25 void _CreateFrames(uint32 numWindows);
26 int32 _WindowCreator();
27 static int32 _ThreadStarter(void* data);
29 private:
30 uint32 fFrameNum;
31 BRect fScreenFrame;
32 uint32 fNumWindows;
33 uint32 fMaxWindows;
34 bool fTestViews;
38 class TestWindow : public BWindow {
39 public:
40 TestWindow(BRect frame, bool createView);
41 virtual ~TestWindow();
45 TestApp::TestApp(uint32 numWindows, bool views)
47 BApplication("application/x.vnd-Haiku.window-creation"),
48 fScreenFrame(),
49 fNumWindows(0),
50 fMaxWindows(numWindows),
51 fTestViews(views)
54 fScreenFrame = BScreen().Frame();
55 _CreateFrames(numWindows);
59 TestApp::~TestApp()
61 delete[] sFrames;
65 void
66 TestApp::ReadyToRun()
68 thread_id thread = spawn_thread(_ThreadStarter, "Window creator",
69 B_NORMAL_PRIORITY, this);
70 resume_thread(thread);
74 void
75 TestApp::_CreateFrames(uint32 numWindows)
77 BRect frame(0, 0, 50, 50);
78 uint32 numHorizontal = (fScreenFrame.IntegerWidth() + 1)
79 / (frame.IntegerWidth() + 1);
80 uint32 numVertical = (fScreenFrame.IntegerHeight() + 1)
81 / (frame.IntegerHeight() + 1);
82 sNumFrames = numHorizontal * numVertical;
83 sFrames = new BRect[sNumFrames];
84 for (uint32 i = 0; i < sNumFrames; i++) {
85 sFrames[i] = frame;
86 frame.OffsetBy(50, 0);
87 if (!fScreenFrame.Contains(frame))
88 frame.OffsetTo(0, frame.bottom + 1);
93 int32
94 TestApp::_WindowCreator()
96 bigtime_t startTime = system_time();
98 while (fNumWindows < fMaxWindows) {
99 if (fFrameNum >= sNumFrames)
100 fFrameNum = 0;
102 BWindow* window = new TestWindow(sFrames[fFrameNum++], fTestViews);
103 window->Show();
104 fNumWindows++;
107 bigtime_t endTime = system_time();
109 printf("Test completed. %ld windows created in %lld usecs.\n", fNumWindows,
110 endTime - startTime);
112 PostMessage(B_QUIT_REQUESTED);
113 return B_OK;
117 int32
118 TestApp::_ThreadStarter(void* data)
120 return static_cast<TestApp*>(data)->_WindowCreator();
124 TestWindow::TestWindow(BRect frame, bool views)
126 BWindow(frame, "Test", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
128 if (views)
129 AddChild(new BBox(Bounds()));
133 TestWindow::~TestWindow()
139 main(int argc, char** argv)
141 uint32 numWindows = 10;
142 bool testViews = false;
143 if (argc > 1)
144 numWindows = atoi(argv[1]);
146 if (argc > 2) {
147 if (!strcmp(argv[2], "views"))
148 testViews = true;
151 TestApp app(numWindows, testViews);
152 app.Run();
154 return 0;