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