vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / app / bmessagerunner / GetInfoTester.cpp
blob51d6613c2912b84a10085b2785cdcb72b7846228
1 //------------------------------------------------------------------------------
2 // GetInfoTester.cpp
3 //
4 //------------------------------------------------------------------------------
6 // Standard Includes -----------------------------------------------------------
7 #include <stdio.h>
9 // System Includes -------------------------------------------------------------
10 #include <Application.h>
11 #include <Handler.h>
12 #include <Looper.h>
13 #include <Message.h>
14 #include <MessageRunner.h>
15 #include <Messenger.h>
16 #include <OS.h>
18 // Project Includes ------------------------------------------------------------
19 #include <TestShell.h>
20 #include <TestUtils.h>
21 #include <cppunit/TestAssert.h>
23 // Local Includes --------------------------------------------------------------
24 #include "MessageRunnerTestHelpers.h"
25 #include "GetInfoTester.h"
27 // Local Defines ---------------------------------------------------------------
29 // Globals ---------------------------------------------------------------------
31 //------------------------------------------------------------------------------
33 #ifndef TEST_R5
34 static const char *kTesterSignature
35 = "application/x-vnd.obos-messagerunner-getinfo-test";
36 #endif
38 static const bigtime_t kMinTimeInterval = 50000;
41 status_t GetInfo(bigtime_t *interval, int32 *count) const
42 @case 1 object is properly initialized, interval or count are NULL
43 @results Should return B_OK.
44 InitCheck() should return B_OK.
46 void GetInfoTester::GetInfo1()
48 // R5: crashes when passing a NULL parameter.
49 #ifndef TEST_R5
50 MessageRunnerTestApp app(kTesterSignature);
51 BMessenger target;
52 BMessage message(MSG_RUNNER_MESSAGE);
53 bigtime_t interval = 100000;
54 int32 count = 5;
55 BMessageRunner runner(target, &message, interval, count);
56 CHK(runner.InitCheck() == B_OK);
57 bigtime_t readInterval = 0;
58 int32 readCount = 0;
59 CHK(runner.GetInfo(&readInterval, NULL) == B_OK);
60 CHK(readInterval == interval);
61 CHK(runner.GetInfo(NULL, &readCount) == B_OK);
62 CHK(readCount == count);
63 CHK(runner.GetInfo(NULL, NULL) == B_OK);
64 #endif
68 status_t GetInfo(bigtime_t *interval, int32 *count) const
69 @case 2 object is not properly initialized, interval or count are
70 NULL
71 @results Should return B_BAD_VALUE.
72 InitCheck() should return B_ERROR.
74 void GetInfoTester::GetInfo2()
76 // R5: crashes when passing a NULL parameter.
77 #ifndef TEST_R5
78 MessageRunnerTestApp app(kTesterSignature);
79 BMessenger target;
80 BMessage message(MSG_RUNNER_MESSAGE);
81 bigtime_t interval = 100000;
82 int32 count = 0;
83 BMessageRunner runner(target, &message, interval, count);
84 CHK(runner.InitCheck() == B_ERROR);
85 bigtime_t readInterval = 0;
86 int32 readCount = 0;
87 CHK(runner.GetInfo(&readInterval, NULL) == B_BAD_VALUE);
88 CHK(runner.GetInfo(NULL, &readCount) == B_BAD_VALUE);
89 CHK(runner.GetInfo(NULL, NULL) == B_BAD_VALUE);
90 #endif
94 Test* GetInfoTester::Suite()
96 TestSuite* SuiteOfTests = new TestSuite;
98 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo1);
99 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo2);
101 return SuiteOfTests;