xref: /haiku/src/tests/kits/support/bmemoryio/SeekTest.cpp (revision 459a94c163f127d416a0119993ecc1205b472e0c)
1 #include "SeekTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <DataIO.h>
4 #include <stdio.h>
5 
SeekTest(std::string name)6 SeekTest::SeekTest(std::string name) :
7 		BTestCase(name)
8 {
9 }
10 
11 
12 
~SeekTest()13 SeekTest::~SeekTest()
14 {
15 }
16 
17 
18 void
PerformTest(void)19 SeekTest::PerformTest(void)
20 {
21 	char buf[10];
22 	BMemoryIO mem(buf, 10);
23 	off_t err;
24 
25 	NextSubTest();
26 	err = mem.Seek(3, SEEK_SET);
27 	CPPUNIT_ASSERT(err == 3);
28 
29 	NextSubTest();
30 	err = mem.Seek(3, SEEK_CUR);
31 	CPPUNIT_ASSERT(err == 6);
32 
33 	NextSubTest();
34 	err = mem.Seek(0, SEEK_END);
35 	CPPUNIT_ASSERT(err == 10);
36 
37 	NextSubTest();
38 	err = mem.Seek(-5, SEEK_END);
39 	CPPUNIT_ASSERT(err == 5);
40 
41 	NextSubTest();
42 	err = mem.Seek(5, SEEK_END);
43 	CPPUNIT_ASSERT(err == 15);
44 }
45 
46 
suite(void)47 CppUnit::Test *SeekTest::suite(void)
48 {
49 	typedef CppUnit::TestCaller<SeekTest>
50 		SeekTestCaller;
51 
52 	return(new SeekTestCaller("BMemoryIO::Seek Test", &SeekTest::PerformTest));
53 }
54