First BMemoryIO tests
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1177 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3f541a71c8
commit
14d32cf634
53
src/tests/kits/support/bmemoryio/ConstTest.cpp
Normal file
53
src/tests/kits/support/bmemoryio/ConstTest.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "ConstTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <DataIO.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ConstTest::ConstTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConstTest::~ConstTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConstTest::PerformTest(void)
|
||||
{
|
||||
const char buf[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
BMemoryIO mem(buf, 10);
|
||||
status_t err;
|
||||
|
||||
NextSubTest();
|
||||
err = mem.SetSize(4);
|
||||
CPPUNIT_ASSERT(err == B_NOT_ALLOWED);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.SetSize(20);
|
||||
CPPUNIT_ASSERT(err == B_NOT_ALLOWED);
|
||||
|
||||
NextSubTest();
|
||||
char readBuf[10] = "";
|
||||
err = mem.Write(readBuf, 3);
|
||||
CPPUNIT_ASSERT(err == B_NOT_ALLOWED);
|
||||
CPPUNIT_ASSERT(strcmp(readBuf, "") == 0);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.WriteAt(2, readBuf, 1);
|
||||
CPPUNIT_ASSERT(err == B_NOT_ALLOWED);
|
||||
CPPUNIT_ASSERT(strcmp(readBuf, "") == 0);
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *ConstTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<ConstTest>
|
||||
ConstTestCaller;
|
||||
|
||||
return(new ConstTestCaller("BMemoryIO::Const Test", &ConstTest::PerformTest));
|
||||
}
|
22
src/tests/kits/support/bmemoryio/ConstTest.h
Normal file
22
src/tests/kits/support/bmemoryio/ConstTest.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef ConstTest_H
|
||||
#define ConstTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
class ConstTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
ConstTest(std::string name = "");
|
||||
virtual ~ConstTest();
|
||||
};
|
||||
|
||||
#endif
|
24
src/tests/kits/support/bmemoryio/MemoryIOTest.cpp
Normal file
24
src/tests/kits/support/bmemoryio/MemoryIOTest.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "cppunit/Test.h"
|
||||
#include "cppunit/TestSuite.h"
|
||||
#include "MemoryIOTest.h"
|
||||
#include "ConstTest.h"
|
||||
#include "SeekTest.h"
|
||||
#include "WriteTest.h"
|
||||
|
||||
CppUnit::Test *MemoryIOTestSuite()
|
||||
{
|
||||
CppUnit::TestSuite *testSuite = new CppUnit::TestSuite();
|
||||
|
||||
testSuite->addTest(ConstTest::suite());
|
||||
testSuite->addTest(SeekTest::suite());
|
||||
testSuite->addTest(WriteTest::suite());
|
||||
|
||||
return(testSuite);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
14
src/tests/kits/support/bmemoryio/MemoryIOTest.h
Normal file
14
src/tests/kits/support/bmemoryio/MemoryIOTest.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _memoryio_test_h_
|
||||
#define _memoryio_test_h_
|
||||
|
||||
class CppUnit::Test;
|
||||
|
||||
CppUnit::Test *MemoryIOTestSuite();
|
||||
|
||||
#endif // _memoryio_test_h_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
53
src/tests/kits/support/bmemoryio/SeekTest.cpp
Normal file
53
src/tests/kits/support/bmemoryio/SeekTest.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "SeekTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <DataIO.h>
|
||||
#include <stdio.h>
|
||||
|
||||
SeekTest::SeekTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
SeekTest::~SeekTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SeekTest::PerformTest(void)
|
||||
{
|
||||
char buf[10];
|
||||
BMemoryIO mem(buf, 10);
|
||||
off_t err;
|
||||
|
||||
NextSubTest();
|
||||
err = mem.Seek(3, SEEK_SET);
|
||||
CPPUNIT_ASSERT(err == 3);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.Seek(3, SEEK_CUR);
|
||||
CPPUNIT_ASSERT(err == 6);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.Seek(0, SEEK_END);
|
||||
CPPUNIT_ASSERT(err == 10);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.Seek(-5, SEEK_END);
|
||||
CPPUNIT_ASSERT(err == 5);
|
||||
|
||||
NextSubTest();
|
||||
err = mem.Seek(5, SEEK_END);
|
||||
CPPUNIT_ASSERT(err == 15);
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *SeekTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<SeekTest>
|
||||
SeekTestCaller;
|
||||
|
||||
return(new SeekTestCaller("BMemoryIO::Seek Test", &SeekTest::PerformTest));
|
||||
}
|
22
src/tests/kits/support/bmemoryio/SeekTest.h
Normal file
22
src/tests/kits/support/bmemoryio/SeekTest.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef SeekTest_H
|
||||
#define SeekTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
class SeekTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
SeekTest(std::string name = "");
|
||||
virtual ~SeekTest();
|
||||
};
|
||||
|
||||
#endif
|
60
src/tests/kits/support/bmemoryio/WriteTest.cpp
Normal file
60
src/tests/kits/support/bmemoryio/WriteTest.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include "WriteTest.h"
|
||||
#include "cppunit/TestCaller.h"
|
||||
#include <DataIO.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
WriteTest::WriteTest(std::string name) :
|
||||
BTestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
WriteTest::~WriteTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WriteTest::PerformTest(void)
|
||||
{
|
||||
char buf[10];
|
||||
const char *writeBuf = "ABCDEFG";
|
||||
|
||||
BMemoryIO mem(buf, 10);
|
||||
|
||||
size_t err;
|
||||
off_t pos;
|
||||
|
||||
NextSubTest();
|
||||
pos = mem.Position();
|
||||
err = mem.Write(writeBuf, 7);
|
||||
CPPUNIT_ASSERT(err == 7); // Check how much data we wrote
|
||||
CPPUNIT_ASSERT(strcmp(writeBuf, buf) == 0); // Check if we wrote it correctly
|
||||
CPPUNIT_ASSERT(mem.Position() == pos + err); // Check if Position changed
|
||||
|
||||
NextSubTest();
|
||||
pos = mem.Position();
|
||||
err = mem.WriteAt(3, writeBuf, 2);
|
||||
CPPUNIT_ASSERT(err == 2);
|
||||
CPPUNIT_ASSERT(strncmp(buf + 3, writeBuf, 2) == 0);
|
||||
CPPUNIT_ASSERT(mem.Position() == pos);
|
||||
|
||||
NextSubTest();
|
||||
pos = mem.Position();
|
||||
err = mem.WriteAt(9, writeBuf, 5);
|
||||
CPPUNIT_ASSERT(err == 1);
|
||||
CPPUNIT_ASSERT(strncmp(buf + 9, writeBuf, 1) == 0);
|
||||
CPPUNIT_ASSERT(mem.Position() == pos);
|
||||
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test *WriteTest::suite(void)
|
||||
{
|
||||
typedef CppUnit::TestCaller<WriteTest>
|
||||
WriteTestCaller;
|
||||
|
||||
return(new WriteTestCaller("BMemoryIO::Write Test", &WriteTest::PerformTest));
|
||||
}
|
22
src/tests/kits/support/bmemoryio/WriteTest.h
Normal file
22
src/tests/kits/support/bmemoryio/WriteTest.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef WriteTest_H
|
||||
#define WriteTest_H
|
||||
|
||||
#include "TestCase.h"
|
||||
#include <DataIO.h>
|
||||
|
||||
|
||||
class WriteTest : public BTestCase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
static Test *suite(void);
|
||||
void PerformTest(void);
|
||||
WriteTest(std::string name = "");
|
||||
virtual ~WriteTest();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user