#include <sys/stat.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <Statable.h>
#include <Entry.h>
#include <Node.h>
#include <Volume.h>
#include "StatableTest.h"
void
StatableTest::setUp()
{
BasicTest::setUp();
}
void
StatableTest::tearDown()
{
BasicTest::tearDown();
}
void
StatableTest::GetStatTest()
{
TestStatables testEntries;
BStatable *statable;
string entryName;
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1, st2;
CPPUNIT_ASSERT( statable->GetStat(&st1) == B_OK );
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st2) == 0 );
CPPUNIT_ASSERT( st1 == st2 );
}
testEntries.delete_all();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1;
CPPUNIT_ASSERT( statable->GetStat(&st1) == B_NO_INIT );
}
testEntries.delete_all();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); )
CPPUNIT_ASSERT( statable->GetStat(NULL) != B_OK );
testEntries.delete_all();
}
void
StatableTest::IsXYZTest()
{
TestStatables testEntries;
BStatable *statable;
string entryName;
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 );
CPPUNIT_ASSERT( statable->IsDirectory() == S_ISDIR(st.st_mode) );
CPPUNIT_ASSERT( statable->IsFile() == S_ISREG(st.st_mode) );
CPPUNIT_ASSERT( statable->IsSymLink() == S_ISLNK(st.st_mode) );
}
testEntries.delete_all();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
CPPUNIT_ASSERT( statable->IsDirectory() == false );
CPPUNIT_ASSERT( statable->IsFile() == false );
CPPUNIT_ASSERT( statable->IsSymLink() == false );
}
testEntries.delete_all();
}
void
StatableTest::GetXYZTest()
{
TestStatables testEntries;
BStatable *statable;
string entryName;
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
node_ref ref;
uid_t owner;
gid_t group;
mode_t perms;
off_t size;
time_t mtime;
time_t ctime;
#if !TEST_R5 && !TEST_OBOS
time_t atime;
#endif
BVolume volume;
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 );
CPPUNIT_ASSERT( statable->GetNodeRef(&ref) == B_OK );
CPPUNIT_ASSERT( statable->GetOwner(&owner) == B_OK );
CPPUNIT_ASSERT( statable->GetGroup(&group) == B_OK );
CPPUNIT_ASSERT( statable->GetPermissions(&perms) == B_OK );
CPPUNIT_ASSERT( statable->GetSize(&size) == B_OK );
CPPUNIT_ASSERT( statable->GetModificationTime(&mtime) == B_OK );
CPPUNIT_ASSERT( statable->GetCreationTime(&ctime) == B_OK );
#if !TEST_R5 && !TEST_OBOS
CPPUNIT_ASSERT( statable->GetAccessTime(&atime) == B_OK );
#endif
CPPUNIT_ASSERT( statable->GetVolume(&volume) == B_OK );
CPPUNIT_ASSERT( ref.device == st.st_dev && ref.node == st.st_ino );
CPPUNIT_ASSERT( owner == st.st_uid );
CPPUNIT_ASSERT( group == st.st_gid );
CPPUNIT_ASSERT( (perms & S_IUMSK) == (st.st_mode & S_IUMSK) );
CPPUNIT_ASSERT( size == st.st_size );
CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime );
#if !TEST_R5 && !TEST_OBOS
CPPUNIT_ASSERT( atime == st.st_atime );
#endif
CPPUNIT_ASSERT( volume == BVolume(st.st_dev) );
}
testEntries.delete_all();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
node_ref ref;
uid_t owner;
gid_t group;
mode_t perms;
off_t size;
time_t mtime;
time_t ctime;
time_t atime;
BVolume volume;
CPPUNIT_ASSERT( statable->GetNodeRef(&ref) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetOwner(&owner) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetGroup(&group) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetPermissions(&perms) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetSize(&size) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetModificationTime(&mtime) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetCreationTime(&ctime) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetAccessTime(&atime) == B_NO_INIT );
CPPUNIT_ASSERT( statable->GetVolume(&volume) == B_NO_INIT );
}
testEntries.delete_all();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
#if !TEST_R5
CPPUNIT_ASSERT( statable->GetNodeRef(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetOwner(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetGroup(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetPermissions(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetSize(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetModificationTime(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetCreationTime(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetAccessTime(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetVolume(NULL) == B_BAD_VALUE );
#endif
}
testEntries.delete_all();
}
void
StatableTest::SetXYZTest()
{
TestStatables testEntries;
BStatable *statable;
string entryName;
NextSubTest();
CreateRWStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
uid_t owner = 0xdad;
gid_t group = 0xdee;
mode_t perms = 0x0ab;
time_t mtime = 1234567;
time_t ctime = 654321;
#if !TEST_R5 && !TEST_OBOS
time_t atime = 2345678;
#endif
CPPUNIT_ASSERT( statable->SetOwner(owner) == B_OK );
CPPUNIT_ASSERT( statable->SetGroup(group) == B_OK );
CPPUNIT_ASSERT( statable->SetPermissions(perms) == B_OK );
CPPUNIT_ASSERT( statable->SetModificationTime(mtime) == B_OK );
CPPUNIT_ASSERT( statable->SetCreationTime(ctime) == B_OK );
#if !TEST_R5 && !TEST_OBOS
CPPUNIT_ASSERT( statable->SetAccessTime(atime) == B_OK );
#endif
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 );
CPPUNIT_ASSERT( owner == st.st_uid );
CPPUNIT_ASSERT( group == st.st_gid );
CPPUNIT_ASSERT( perms == (st.st_mode & S_IUMSK) );
CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime );
#if !TEST_R5 && !TEST_OBOS
CPPUNIT_ASSERT( atime == st.st_atime );
#endif
}
testEntries.delete_all();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
uid_t owner = 0xdad;
gid_t group = 0xdee;
mode_t perms = 0x0ab;
time_t mtime = 1234567;
time_t ctime = 654321;
time_t atime = 2345678;
CPPUNIT_ASSERT( statable->SetOwner(owner) != B_OK );
CPPUNIT_ASSERT( statable->SetGroup(group) != B_OK );
CPPUNIT_ASSERT( statable->SetPermissions(perms) != B_OK );
CPPUNIT_ASSERT( statable->SetModificationTime(mtime) != B_OK );
CPPUNIT_ASSERT( statable->SetCreationTime(ctime) != B_OK );
CPPUNIT_ASSERT( statable->SetAccessTime(atime) != B_OK );
}
testEntries.delete_all();
}