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 #ifndef TEST_R5 34 static const char *kTesterSignature 35 = "application/x-vnd.obos-messagerunner-getinfo-test"; 36 #endif 37 38 static const bigtime_t kMinTimeInterval = 50000; 39 40 /* 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. 45 */ 46 void GetInfoTester::GetInfo1() 47 { 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 65 } 66 67 /* 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. 73 */ 74 void GetInfoTester::GetInfo2() 75 { 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 91 } 92 93 94 Test* GetInfoTester::Suite() 95 { 96 TestSuite* SuiteOfTests = new TestSuite; 97 98 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo1); 99 ADD_TEST4(BMessageRunner, SuiteOfTests, GetInfoTester, GetInfo2); 100 101 return SuiteOfTests; 102 } 103 104