1 // DataIOTest.cpp 2 3 #include <string.h> 4 #include <BufferedDataIO.h> 5 6 #include <TestShell.h> 7 8 #include "DataIOTest.h" 9 10 11 CppUnit::Test* 12 DataIOTest::Suite() { 13 CppUnit::TestSuite *suite = new CppUnit::TestSuite(); 14 typedef CppUnit::TestCaller<DataIOTest> TC; 15 16 suite->addTest(new TC("BResourceString::BufferedDataIO Test", 17 &DataIOTest::BufferedDataIOTest)); 18 19 return suite; 20 } 21 22 23 void 24 DataIOTest::BufferedDataIOTest() 25 { 26 // very basic test 27 NextSubTest(); 28 { 29 BMallocIO mallocIO; 30 CPPUNIT_ASSERT(mallocIO.SetSize(1024) == B_OK); 31 32 BBufferedDataIO bufferedDataIO(mallocIO, 8, false); 33 CPPUNIT_ASSERT(bufferedDataIO.InitCheck() == B_OK); 34 35 CPPUNIT_ASSERT(bufferedDataIO.Write("test ", 5) == 5); 36 CPPUNIT_ASSERT(bufferedDataIO.Write("test ", 5) == 5); 37 CPPUNIT_ASSERT(bufferedDataIO.Write("test ", 5) == 5); 38 39 CPPUNIT_ASSERT(bufferedDataIO.Flush() == B_OK); 40 41 CPPUNIT_ASSERT(bufferedDataIO.Write("longer-test", 12) == 12); 42 43 CPPUNIT_ASSERT(mallocIO.Position() == 27); 44 CPPUNIT_ASSERT(memcmp(mallocIO.Buffer(), "test test test longer-test", 27) == 0); 45 } 46 } 47