1 //------------------------------------------------------------------------------ 2 // GetInfoTester.cpp 3 // 4 //------------------------------------------------------------------------------ 5 6 // Standard Includes ----------------------------------------------------------- 7 #include <stdio.h> 8 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> 17 18 // Project Includes ------------------------------------------------------------ 19 #include <TestShell.h> 20 #include <TestUtils.h> 21 #include <cppunit/TestAssert.h> 22 23 // Local Includes -------------------------------------------------------------- 24 #include "MessageRunnerTestHelpers.h" 25 #include "GetInfoTester.h" 26 27 // Local Defines --------------------------------------------------------------- 28 29 // Globals --------------------------------------------------------------------- 30 31 //------------------------------------------------------------------------------ 32 33 static const char *kTesterSignature 34 = "application/x-vnd.obos-messagerunner-getinfo-test"; 35 36 static const bigtime_t kMinTimeInterval = 50000; 37 38 /* 39 status_t GetInfo(bigtime_t *interval, int32 *count) const 40 @case 1 object is properly initialized, interval or count are NULL 41 @results Should return B_OK. 42 InitCheck() should return B_OK. 43 */ 44 void GetInfoTester::GetInfo1() 45 { 46 // R5: crashes when passing a NULL parameter. 47 #ifndef TEST_R5 48 MessageRunnerTestApp app(kTesterSignature); 49 BMessenger target; 50 BMessage message(MSG_RUNNER_MESSAGE); 51 bigtime_t interval = 100000; 52 int32 count = 5; 53 BMessageRunner runner(target, &message, interval, count); 54 CHK(runner.InitCheck() == B_OK); 55 bigtime_t readInterval = 0; 56 int32 readCount = 0; 57 CHK(runner.GetInfo(&readInterval, NULL) == B_OK); 58 CHK(readInterval == interval); 59 CHK(runner.GetInfo(NULL, &readCount) == B_OK); 60 CHK(readCount == count); 61 CHK(runner.GetInfo(NULL, NULL) == B_OK); 62 #endif 63 } 64 65 /* 66 status_t GetInfo(bigtime_t *interval, int32 *count) const 67 @case 2 object is not properly initialized, interval or count are 68 NULL 69 @results Should return B_BAD_VALUE. 70 InitCheck() should return B_ERROR. 71 */ 72 void GetInfoTester::GetInfo2() 73 { 74 // R5: crashes when passing a NULL parameter. 75 #ifndef TEST_R5 76 MessageRunnerTestApp app(kTesterSignature); 77 BMessenger target; 78 BMessage message(MSG_RUNNER_MESSAGE); 79 bigtime_t interval = 100000; 80 int32 count = 0; 81 BMessageRunner runner(target, &message, interval, count); 82 CHK(runner.InitCheck() == B_ERROR); 83 bigtime_t readInterval = 0; 84 int32 readCount = 0; 85 CHK(runner.GetInfo(&readInterval, NULL) == B_BAD_VALUE); 86 CHK(runner.GetInfo(NULL, &readCount) == B_BAD_VALUE); 87 CHK(runner.GetInfo(NULL, NULL) == B_BAD_VALUE); 88 #endif 89 } 90 91 92 Test* GetInfoTester::Suite() 93 { 94 TestSuite* SuiteOfTests = new TestSuite; 95 96 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo1); 97 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo2); 98 99 return SuiteOfTests; 100 } 101 102