1 #include "SetSizeTest.h" 2 #include "cppunit/TestCaller.h" 3 #include <DataIO.h> 4 #include <stdio.h> 5 #include <string.h> 6 7 SetSizeTest::SetSizeTest(std::string name) : 8 BTestCase(name) 9 { 10 } 11 12 13 14 SetSizeTest::~SetSizeTest() 15 { 16 } 17 18 19 void 20 SetSizeTest::PerformTest(void) 21 { 22 char buf[20] = "0123456789ABCDEFGHI"; 23 char readBuf[10]; 24 25 memset(readBuf, 0, 10); 26 27 BMemoryIO mem(buf, 10); 28 ssize_t size; 29 off_t pos; 30 status_t err; 31 32 NextSubTest(); 33 err = mem.SetSize(5); 34 pos = mem.Seek(0, SEEK_END); 35 size = mem.WriteAt(10, readBuf, 3); 36 CPPUNIT_ASSERT(err == B_OK); 37 CPPUNIT_ASSERT(pos == 5); 38 CPPUNIT_ASSERT(size == 0); 39 40 NextSubTest(); 41 err = mem.SetSize(10); 42 pos = mem.Seek(0, SEEK_END); 43 size = mem.WriteAt(5, readBuf, 6); 44 CPPUNIT_ASSERT(err == B_OK); 45 CPPUNIT_ASSERT(pos == 10); 46 CPPUNIT_ASSERT(size == 5); 47 48 NextSubTest(); 49 err = mem.SetSize(20); 50 CPPUNIT_ASSERT(err == B_ERROR); 51 } 52 53 54 CppUnit::Test *SetSizeTest::suite(void) 55 { 56 typedef CppUnit::TestCaller<SetSizeTest> 57 SetSizeTestCaller; 58 59 return(new SetSizeTestCaller("BMemoryIO::SetSize Test", &SetSizeTest::PerformTest)); 60 } 61