xref: /haiku/src/tests/kits/support/bmemoryio/MallocWriteTest.cpp (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 #include "MallocWriteTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <DataIO.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 MallocWriteTest::MallocWriteTest(std::string name) :
8 		BTestCase(name)
9 {
10 }
11 
12 
13 
14 MallocWriteTest::~MallocWriteTest()
15 {
16 }
17 
18 
19 void
20 MallocWriteTest::PerformTest(void)
21 {
22 	const char *writeBuf = "ABCDEFG";
23 
24 	BMallocIO mem;
25 	ssize_t err;
26 	off_t pos;
27 
28 	NextSubTest();
29 	err = mem.Write(writeBuf, 7);
30 	CPPUNIT_ASSERT(err == 7); // Check how much data we wrote
31 
32 	NextSubTest();
33 	err = mem.WriteAt(0, writeBuf, 4);
34 	CPPUNIT_ASSERT(err == 4);
35 
36 	NextSubTest();
37 	err = mem.WriteAt(34, writeBuf, 256);
38 	CPPUNIT_ASSERT(err == 256);
39 }
40 
41 
42 CppUnit::Test *MallocWriteTest::suite(void)
43 {
44 	typedef CppUnit::TestCaller<MallocWriteTest>
45 		MallocWriteTestCaller;
46 
47 	return(new MallocWriteTestCaller("BMallocIO::Write Test", &MallocWriteTest::PerformTest));
48 }
49