1 #include "MallocBufferLengthTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <DataIO.h> 4 #include <stdio.h> 5 6 MallocBufferLengthTest::MallocBufferLengthTest(std::string name) : 7 BTestCase(name) 8 { 9 } 10 11 12 13 MallocBufferLengthTest::~MallocBufferLengthTest() 14 { 15 } 16 17 18 void 19 MallocBufferLengthTest::PerformTest(void) 20 { 21 BMallocIO mem; 22 size_t size; 23 size_t bufLen; 24 status_t error; 25 off_t offset; 26 char writeBuf[11] = "0123456789"; 27 28 NextSubTest(); 29 bufLen = mem.BufferLength(); 30 CPPUNIT_ASSERT(bufLen == 0); 31 32 NextSubTest(); 33 size = mem.Write(writeBuf, 10); 34 bufLen = mem.BufferLength(); 35 CPPUNIT_ASSERT(bufLen == 10); 36 CPPUNIT_ASSERT(size = 10); 37 38 NextSubTest(); 39 error = mem.SetSize(0); 40 bufLen = mem.BufferLength(); 41 CPPUNIT_ASSERT(bufLen == 0); 42 CPPUNIT_ASSERT(error == B_OK); 43 44 //This is for the BResource crashing bug 45 NextSubTest(); 46 error = mem.SetSize(200); 47 bufLen = mem.BufferLength(); 48 offset = mem.Seek(0, SEEK_END); 49 CPPUNIT_ASSERT(bufLen == 200); 50 CPPUNIT_ASSERT(error == B_OK); 51 CPPUNIT_ASSERT(offset == 200); 52 53 NextSubTest(); 54 offset = mem.Seek(0, SEEK_END); 55 error = mem.SetSize(100); 56 bufLen = mem.BufferLength(); 57 CPPUNIT_ASSERT(bufLen == 100); 58 CPPUNIT_ASSERT(mem.Position() == offset); 59 } 60 61 62 CppUnit::Test *MallocBufferLengthTest::suite(void) 63 { 64 typedef CppUnit::TestCaller<MallocBufferLengthTest> 65 MallocBufferLengthTestCaller; 66 67 return(new MallocBufferLengthTestCaller("BMallocIO::BufferLength Test", &MallocBufferLengthTest::PerformTest)); 68 } 69