#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string>
using std::string;
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <Path.h>
#include <SymLink.h>
#include "DirectoryTest.h"
DirectoryTest::Test*
DirectoryTest::Suite()
{
CppUnit::TestSuite *suite = new CppUnit::TestSuite();
typedef CppUnit::TestCaller<DirectoryTest> TC;
NodeTest::AddBaseClassTests<DirectoryTest>("BDirectory::", suite);
suite->addTest( new TC("BDirectory::Init Test 1",
&DirectoryTest::InitTest1) );
suite->addTest( new TC("BDirectory::Init Test 2",
&DirectoryTest::InitTest2) );
suite->addTest( new TC("BDirectory::GetEntry Test",
&DirectoryTest::GetEntryTest) );
suite->addTest( new TC("BDirectory::IsRoot Test",
&DirectoryTest::IsRootTest) );
suite->addTest( new TC("BDirectory::FindEntry Test",
&DirectoryTest::FindEntryTest) );
suite->addTest( new TC("BDirectory::Contains Test",
&DirectoryTest::ContainsTest) );
suite->addTest( new TC("BDirectory::GetStatFor Test",
&DirectoryTest::GetStatForTest) );
suite->addTest( new TC("BDirectory::EntryIteration Test",
&DirectoryTest::EntryIterationTest) );
suite->addTest( new TC("BDirectory::Creation Test",
&DirectoryTest::EntryCreationTest) );
suite->addTest( new TC("BDirectory::Assignment Test",
&DirectoryTest::AssignmentTest) );
suite->addTest( new TC("BDirectory::CreateDirectory Test",
&DirectoryTest::CreateDirectoryTest) );
return suite;
}
void
DirectoryTest::CreateRONodes(TestNodes& testEntries)
{
testEntries.clear();
const char *filename;
filename = "/";
testEntries.add(new BDirectory(filename), filename);
filename = "/boot";
testEntries.add(new BDirectory(filename), filename);
filename = "/boot/home";
testEntries.add(new BDirectory(filename), filename);
filename = existingDirname;
testEntries.add(new BDirectory(filename), filename);
}
void
DirectoryTest::CreateRWNodes(TestNodes& testEntries)
{
testEntries.clear();
const char *filename;
filename = existingDirname;
testEntries.add(new BDirectory(filename), filename);
filename = existingSubDirname;
testEntries.add(new BDirectory(filename), filename);
}
void
DirectoryTest::CreateUninitializedNodes(TestNodes& testEntries)
{
testEntries.clear();
testEntries.add(new BDirectory, "");
}
void DirectoryTest::setUp()
{
NodeTest::setUp();
}
void DirectoryTest::tearDown()
{
NodeTest::tearDown();
}
void
DirectoryTest::InitTest1()
{
const char *existingFile = existingFilename;
const char *existingSuperFile = existingSuperFilename;
const char *existingRelFile = existingRelFilename;
const char *existing = existingDirname;
const char *existingSub = existingSubDirname;
const char *existingRelSub = existingRelSubDirname;
const char *nonExisting = nonExistingDirname;
const char *nonExistingSuper = nonExistingSuperDirname;
const char *nonExistingRel = nonExistingRelDirname;
NextSubTest();
{
BDirectory dir;
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
}
NextSubTest();
{
BDirectory dir(existing);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
NextSubTest();
{
BDirectory dir(nonExisting);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir((const char *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BDirectory dir("");
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir(existingFile);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BDirectory dir(tooLongEntryname);
CPPUNIT_ASSERT( dir.InitCheck() == B_NAME_TOO_LONG );
}
NextSubTest();
{
BDirectory dir(fileDirname);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BEntry entry(existing);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BDirectory dir(&entry);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
NextSubTest();
{
BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BDirectory dir(&entry);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir((BEntry *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BEntry entry;
BDirectory dir(&entry);
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
}
NextSubTest();
{
BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BDirectory dir(&entry);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BEntry entry(tooLongEntryname);
CPPUNIT_ASSERT( equals(entry.InitCheck(), E2BIG, B_NAME_TOO_LONG) );
BDirectory dir(&entry);
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
}
NextSubTest();
{
BEntry entry(existing);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
BDirectory dir(&ref);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
NextSubTest();
{
BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
BDirectory dir(&ref);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir((entry_ref *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
BDirectory dir(&ref);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BNode node(existing);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
node_ref nref;
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
BDirectory dir(&nref);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
NextSubTest();
{
BDirectory dir((node_ref *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BNode node(existingFile);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
node_ref nref;
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
BDirectory dir(&nref);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, existingRelSub);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
}
NextSubTest();
{
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, existingSub);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BDirectory pathDir(nonExistingSuper);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, nonExistingRel);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
NextSubTest();
{
BDirectory dir((BDirectory *)NULL, (const char *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BDirectory dir((BDirectory *)NULL, existingSub);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, (const char *)NULL);
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
}
NextSubTest();
{
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, "");
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
}
NextSubTest();
{
BDirectory pathDir(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, existingRelFile);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
}
NextSubTest();
{
BDirectory pathDir(tooLongSuperEntryname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, tooLongRelEntryname);
CPPUNIT_ASSERT( dir.InitCheck() == B_NAME_TOO_LONG );
}
NextSubTest();
{
BDirectory pathDir(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BDirectory dir(&pathDir, fileRelDirname);
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
}
}
void
DirectoryTest::InitTest2()
{
const char *existingFile = existingFilename;
const char *existingSuperFile = existingSuperFilename;
const char *existingRelFile = existingRelFilename;
const char *existing = existingDirname;
const char *existingSub = existingSubDirname;
const char *existingRelSub = existingRelSubDirname;
const char *nonExisting = nonExistingDirname;
const char *nonExistingSuper = nonExistingSuperDirname;
const char *nonExistingRel = nonExistingRelDirname;
BDirectory dir;
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((const char *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("") == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT_EQUAL(dir.SetTo(existingFile), B_NOT_A_DIRECTORY);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(tooLongEntryname) == B_NAME_TOO_LONG );
CPPUNIT_ASSERT( dir.InitCheck() == B_NAME_TOO_LONG );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT_EQUAL(dir.SetTo(fileDirname), B_ENTRY_NOT_FOUND);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
dir.Unset();
NextSubTest();
BEntry entry(existing);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
NextSubTest();
entry.SetTo(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((BEntry *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
entry.Unset();
CPPUNIT_ASSERT( equals(dir.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
dir.Unset();
NextSubTest();
entry.SetTo(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.SetTo(&entry), B_NOT_A_DIRECTORY);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
NextSubTest();
entry.SetTo(tooLongEntryname);
CPPUNIT_ASSERT( equals(entry.InitCheck(), E2BIG, B_NAME_TOO_LONG) );
CPPUNIT_ASSERT( equals(dir.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(dir.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
dir.Unset();
NextSubTest();
entry.SetTo(existing);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
NextSubTest();
entry.SetTo(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&ref) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((entry_ref *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
entry.SetTo(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.SetTo(&ref), B_NOT_A_DIRECTORY);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
NextSubTest();
BNode node(existing);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
node_ref nref;
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&nref) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((node_ref *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.GetNodeRef(&nref) == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.SetTo(&nref), B_NOT_A_DIRECTORY);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
NextSubTest();
BDirectory pathDir(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, existingRelSub) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
dir.Unset();
NextSubTest();
pathDir.SetTo(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, existingSub) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
pathDir.SetTo(nonExistingSuper);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, nonExistingRel) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((BDirectory *)NULL, (const char *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo((BDirectory *)NULL, existingSub) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
pathDir.SetTo(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, (const char *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.InitCheck() == B_BAD_VALUE );
dir.Unset();
NextSubTest();
pathDir.SetTo(existing);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.SetTo(&pathDir, ""), B_ENTRY_NOT_FOUND);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_ENTRY_NOT_FOUND);
dir.Unset();
NextSubTest();
pathDir.SetTo(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.SetTo(&pathDir, existingRelFile),
B_NOT_A_DIRECTORY);
CPPUNIT_ASSERT_EQUAL(dir.InitCheck(), B_NOT_A_DIRECTORY);
dir.Unset();
NextSubTest();
pathDir.SetTo(tooLongSuperEntryname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, tooLongRelEntryname)
== B_NAME_TOO_LONG );
CPPUNIT_ASSERT( dir.InitCheck() == B_NAME_TOO_LONG );
dir.Unset();
NextSubTest();
pathDir.SetTo(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.SetTo(&pathDir, fileRelDirname) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
dir.Unset();
}
void
DirectoryTest::GetEntryTest()
{
const char *existing = existingDirname;
const char *nonExisting = nonExistingDirname;
NextSubTest();
BDirectory dir;
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
BEntry entry;
CPPUNIT_ASSERT( dir.GetEntry(&entry) == B_NO_INIT );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.GetEntry(&entry) == B_OK );
CPPUNIT_ASSERT( entry == BEntry(existing) );
dir.Unset();
entry.Unset();
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.GetEntry((BEntry *)NULL) == B_BAD_VALUE );
dir.Unset();
entry.Unset();
#endif
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.GetEntry(&entry) == B_NO_INIT );
dir.Unset();
entry.Unset();
}
void
DirectoryTest::IsRootTest()
{
NextSubTest();
BDirectory dir;
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.IsRootDirectory() == false );
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/boot") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.IsRootDirectory() == true );
NextSubTest();
CPPUNIT_ASSERT(dir.SetTo("/boot/system") == B_OK);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT_EQUAL(dir.IsRootDirectory(), true);
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/tmp") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.IsRootDirectory() == false );
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.IsRootDirectory() == true );
}
void
DirectoryTest::FindEntryTest()
{
const char *existingFile = existingFilename;
const char *existing = existingDirname;
const char *existingSub = existingSubDirname;
const char *existingRelSub = existingRelSubDirname;
const char *nonExisting = nonExistingDirname;
const char *nonExistingSuper = nonExistingSuperDirname;
const char *nonExistingRel = nonExistingRelDirname;
const char *dirLink = dirLinkname;
const char *badLink = badLinkname;
const char *cyclicLink1 = cyclicLinkname1;
BPath normalizedExistingPath(existing, NULL, true);
CPPUNIT_ASSERT_EQUAL(normalizedExistingPath.InitCheck(), B_OK);
BPath normalizedExistingSubPath(existingSub, NULL, true);
CPPUNIT_ASSERT_EQUAL(normalizedExistingSubPath.InitCheck(), B_OK);
BPath normalizedDirLinkPath(dirLink, NULL, true);
CPPUNIT_ASSERT_EQUAL(normalizedDirLinkPath.InitCheck(), B_OK);
BPath normalizedBadLinkPath(badLink, NULL, true);
CPPUNIT_ASSERT_EQUAL(normalizedBadLinkPath.InitCheck(), B_OK);
BPath normalizedCyclicLink1(cyclicLink1, NULL, true);
CPPUNIT_ASSERT_EQUAL(normalizedCyclicLink1.InitCheck(), B_OK);
NextSubTest();
BDirectory dir;
BEntry entry;
BPath path;
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(existing, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != existing);
CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.FindEntry(existing, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != existing);
CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
chdir(existing);
CPPUNIT_ASSERT( dir.FindEntry(existingRelSub, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != existingSub);
CPPUNIT_ASSERT(path == normalizedExistingSubPath);
dir.Unset();
entry.Unset();
path.Unset();
chdir("/");
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSub) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
chdir(existing);
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( dir.FindEntry(existingRelSub, &entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( entry.InitCheck() == B_NO_INIT );
dir.Unset();
entry.Unset();
path.Unset();
chdir("/");
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExistingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
chdir(existing);
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( dir.FindEntry(nonExistingRel, &entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( entry.InitCheck() == B_NO_INIT );
dir.Unset();
entry.Unset();
path.Unset();
chdir("/");
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.FindEntry(existingRelSub, NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( dir.FindEntry(NULL, &entry) == B_BAD_VALUE );
CPPUNIT_ASSERT(entry.InitCheck() == B_OK);
CPPUNIT_ASSERT( dir.FindEntry(NULL, NULL) == B_BAD_VALUE );
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(dirLink, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != dirLink);
CPPUNIT_ASSERT(path == normalizedDirLinkPath);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(dirLink, &entry, true) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != existing);
CPPUNIT_ASSERT(path == normalizedExistingPath);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(badLink, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != badLink);
CPPUNIT_ASSERT(path == normalizedBadLinkPath);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(badLink, &entry, true) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( equals(entry.InitCheck(), B_ENTRY_NOT_FOUND, B_NO_INIT) );
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(cyclicLink1, &entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT(path != cyclicLink1);
CPPUNIT_ASSERT(path == normalizedCyclicLink1);
dir.Unset();
entry.Unset();
path.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.FindEntry(cyclicLink1, &entry, true) == B_LINK_LIMIT );
CPPUNIT_ASSERT( entry.InitCheck() == B_LINK_LIMIT );
dir.Unset();
entry.Unset();
path.Unset();
}
void
DirectoryTest::ContainsTest()
{
const char *existingFile = existingFilename;
const char *existingSuperFile = existingSuperFilename;
const char *existingRelFile = existingRelFilename;
const char *existing = existingDirname;
const char *existingSuper = existingSuperDirname;
const char *existingSub = existingSubDirname;
const char *existingRelSub = existingRelSubDirname;
const char *nonExisting = nonExistingDirname;
const char *dirLink = dirLinkname;
const char *dirSuperLink = dirSuperLinkname;
NextSubTest();
BDirectory dir(existing);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingSub) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
#if TEST_R5
CPPUNIT_ASSERT( dir.Contains(existing) == true );
#else
CPPUNIT_ASSERT( dir.Contains(existing) == false );
#endif
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.Contains(nonExisting) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
#if TEST_R5
CPPUNIT_ASSERT( dir.Contains(existing) == true );
#else
CPPUNIT_ASSERT( dir.Contains(existing) == false );
#endif
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.Contains(nonExisting) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains((const char*)NULL) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.Contains((const char*)NULL) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingSub) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingRelSub) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existing) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existing, B_DIRECTORY_NODE) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existing, B_FILE_NODE) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingFile, B_FILE_NODE) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingFile, B_SYMLINK_NODE) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(dirLink, B_SYMLINK_NODE) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(dirLink, B_DIRECTORY_NODE) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingRelFile, B_FILE_NODE) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(existingRelFile, B_SYMLINK_NODE) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
BEntry entry(existingSub);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains(&entry) == true );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.Contains(&entry) == false );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry) == false );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry) == false );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry) == false );
dir.Unset();
entry.Unset();
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.Contains((const BEntry*)NULL) == false );
dir.Unset();
#endif
NextSubTest();
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.Contains((const BEntry*)NULL) == false );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existingSub) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry) == true );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK);
CPPUNIT_ASSERT( equals(dir.Contains(&entry), false, true) );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_DIRECTORY_NODE) == true );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_FILE_NODE) == false );
dir.Unset();
entry.Unset();
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_FILE_NODE) == true );
dir.Unset();
entry.Unset();
#endif
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_SYMLINK_NODE) == false );
dir.Unset();
entry.Unset();
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(dirLink) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_SYMLINK_NODE) == true );
dir.Unset();
entry.Unset();
#endif
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.SetTo(dirLink) == B_OK);
CPPUNIT_ASSERT( dir.Contains(&entry, B_DIRECTORY_NODE) == false );
dir.Unset();
entry.Unset();
#endif
}
void
DirectoryTest::GetStatForTest()
{
const char *existing = existingDirname;
const char *existingSuper = existingSuperDirname;
const char *existingRel = existingRelDirname;
const char *nonExisting = nonExistingDirname;
NextSubTest();
BDirectory dir;
BEntry entry;
struct stat stat1, stat2;
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( dir.GetStatFor(existing, &stat1) == B_NO_INIT );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.InitCheck() == B_ENTRY_NOT_FOUND );
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.GetStatFor(existing, &stat1) == B_NO_INIT );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.GetStatFor(existing, &stat1) == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( entry.GetStat(&stat2) == B_OK );
CPPUNIT_ASSERT( stat1 == stat2 );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(existingSuper) == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.GetStatFor(existingRel, &stat1) == B_OK );
CPPUNIT_ASSERT( entry.SetTo(existing) == B_OK );
CPPUNIT_ASSERT( entry.GetStat(&stat2) == B_OK );
CPPUNIT_ASSERT( stat1 == stat2 );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.GetStatFor(nonExisting, &stat1) == B_ENTRY_NOT_FOUND );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
memset(&stat1, 0, sizeof(struct stat));
memset(&stat2, 0, sizeof(struct stat));
CPPUNIT_ASSERT( dir.GetStatFor(NULL, &stat1) == B_OK );
CPPUNIT_ASSERT( entry.SetTo("/") == B_OK );
CPPUNIT_ASSERT( entry.GetStat(&stat2) == B_OK );
CPPUNIT_ASSERT( stat1 == stat2 );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( dir.GetStatFor("", &stat1) == B_ENTRY_NOT_FOUND );
dir.Unset();
entry.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo("/") == B_OK );
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
CPPUNIT_ASSERT( equals(dir.GetStatFor(existing, NULL), B_BAD_ADDRESS,
B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(dir.GetStatFor(NULL, NULL), B_BAD_ADDRESS,
B_BAD_VALUE) );
dir.Unset();
entry.Unset();
}
void
DirectoryTest::EntryIterationTest()
{
const char *existingFile = existingFilename;
const char *nonExisting = nonExistingDirname;
const char *testDir1 = testDirname1;
execCommand(string("mkdir ") + testDir1);
TestSet testSet;
testSet.add(".");
testSet.add("..");
NextSubTest();
BDirectory dir(testDir1);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
BEntry entry;
CPPUNIT_ASSERT( dir.GetNextEntry(&entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
NextSubTest();
entry_ref ref;
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
CPPUNIT_ASSERT( dir.GetNextRef(&ref) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
NextSubTest();
size_t bufSize = (sizeof(dirent) + B_FILE_NAME_LENGTH) * 10;
char buffer[bufSize];
dirent *ents = (dirent *)buffer;
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
while (dir.GetNextDirents(ents, bufSize, 1) == 1)
CPPUNIT_ASSERT( testSet.test(ents->d_name) == true );
CPPUNIT_ASSERT( testSet.testDone() == true );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
testSet.rewind();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
CPPUNIT_ASSERT( dir.CountEntries() == 0 );
dir.Unset();
string dirPathName(string(testDir1) + "/");
string entryName("file1");
execCommand(string("touch ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("file2");
execCommand(string("touch ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("file3");
execCommand(string("touch ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("dir1");
execCommand(string("mkdir ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("dir2");
execCommand(string("mkdir ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("dir3");
execCommand(string("mkdir ") + dirPathName + entryName);
testSet.add(entryName);
entryName = ("link1");
execCommand(string("ln -s ") + existingFile + " "
+ dirPathName + entryName);
testSet.add(entryName);
entryName = ("link2");
execCommand(string("ln -s ") + existingFile + " "
+ dirPathName + entryName);
testSet.add(entryName);
entryName = ("link3");
execCommand(string("ln -s ") + existingFile + " "
+ dirPathName + entryName);
testSet.add(entryName);
NextSubTest();
testSet.test(".");
testSet.test("..");
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
while (dir.GetNextEntry(&entry) == B_OK) {
BPath path;
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT( testSet.test(path.Leaf()) == true );
}
CPPUNIT_ASSERT( testSet.testDone() == true );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
testSet.rewind();
NextSubTest();
testSet.test(".");
testSet.test("..");
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
while (dir.GetNextRef(&ref) == B_OK)
CPPUNIT_ASSERT( testSet.test(ref.name) == true );
CPPUNIT_ASSERT( testSet.testDone() == true );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
testSet.rewind();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
while (dir.GetNextDirents(ents, bufSize, 1) == 1)
CPPUNIT_ASSERT( testSet.test(ents->d_name) == true );
CPPUNIT_ASSERT( testSet.testDone() == true );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
testSet.rewind();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
CPPUNIT_ASSERT( dir.CountEntries() == 9 );
CPPUNIT_ASSERT( dir.GetNextRef(&ref) == B_OK );
CPPUNIT_ASSERT( dir.CountEntries() == 9 );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
while (dir.GetNextDirents(ents, bufSize, 1) == 1) {
CPPUNIT_ASSERT( testSet.test(ents->d_name) == true );
if (dir.GetNextRef(&ref) == B_OK)
CPPUNIT_ASSERT( testSet.test(ref.name) == true );
if (dir.GetNextEntry(&entry) == B_OK) {
BPath path;
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&path) == B_OK );
CPPUNIT_ASSERT( testSet.test(path.Leaf()) == true );
}
}
testSet.test(".", false);
testSet.test("..", false);
CPPUNIT_ASSERT( testSet.testDone() == true );
CPPUNIT_ASSERT( dir.Rewind() == B_OK );
dir.Unset();
entry.Unset();
testSet.rewind();
NextSubTest();
dir.Unset();
CPPUNIT_ASSERT( dir.GetNextEntry(&entry) == B_FILE_ERROR );
CPPUNIT_ASSERT( equals(dir.GetNextRef(&ref), B_NO_INIT, B_FILE_ERROR) );
CPPUNIT_ASSERT( dir.Rewind() == B_FILE_ERROR );
CPPUNIT_ASSERT( dir.GetNextDirents(ents, bufSize, 1) == B_FILE_ERROR );
CPPUNIT_ASSERT( dir.CountEntries() == B_FILE_ERROR );
dir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( dir.GetNextEntry(&entry) == B_FILE_ERROR );
CPPUNIT_ASSERT( equals(dir.GetNextRef(&ref), B_NO_INIT, B_FILE_ERROR) );
CPPUNIT_ASSERT( dir.Rewind() == B_FILE_ERROR );
CPPUNIT_ASSERT( dir.GetNextDirents(ents, bufSize, 1) == B_FILE_ERROR );
CPPUNIT_ASSERT( dir.CountEntries() == B_FILE_ERROR );
dir.Unset();
#if !TEST_R5
NextSubTest();
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
CPPUNIT_ASSERT( dir.GetNextEntry(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( dir.GetNextRef(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( equals(dir.GetNextDirents(NULL, bufSize, 1),
B_BAD_ADDRESS, B_BAD_VALUE) );
dir.Unset();
#endif
NextSubTest();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
entryName = ("link1");
execCommand(string("ln -s ") + existingFile + " "
+ dirPathName + entryName);
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
CPPUNIT_ASSERT( dir.GetNextEntry(&entry, true) == B_OK );
BPath path;
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BEntry entry2(existingFile);
CPPUNIT_ASSERT( entry2.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry == entry2 );
dir.Unset();
entry.Unset();
}
void
DirectoryTest::EntryCreationTest()
{
#ifdef TEST_R5
Outputf("(test currently omitted due to build errors related to BSymLink::SetTo())\n");
#else
const char *existingFile = existingFilename;
const char *existing = existingDirname;
const char *testDir1 = testDirname1;
execCommand(string("mkdir ") + testDir1);
BDirectory dir(testDir1);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
NextSubTest();
BDirectory subdir;
string dirPathName(string(testDir1) + "/");
string entryName("subdir1");
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir) == B_OK );
CPPUNIT_ASSERT( subdir.InitCheck() == B_OK );
BEntry entry;
CPPUNIT_ASSERT( subdir.GetEntry(&entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry == BEntry((dirPathName + entryName).c_str()) );
subdir.Unset();
CPPUNIT_ASSERT( subdir.SetTo((dirPathName + entryName).c_str()) == B_OK );
subdir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( subdir.InitCheck() == B_NO_INIT );
subdir.Unset();
NextSubTest();
BFile file;
entryName = "file1";
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo((dirPathName + entryName).c_str(),
B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, false) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo((dirPathName + entryName).c_str(),
B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( file.InitCheck() == B_NO_INIT );
file.Unset();
NextSubTest();
BSymLink link;
entryName = "link1";
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_OK );
CPPUNIT_ASSERT( link.InitCheck() == B_OK );
link.Unset();
CPPUNIT_ASSERT( link.SetTo((dirPathName + entryName).c_str()) == B_OK );
link.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
link.Unset();
dir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
CPPUNIT_ASSERT( dir.SetTo(existing) == B_OK );
NextSubTest();
entryName = dirPathName + "subdir1";
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir) == B_OK );
CPPUNIT_ASSERT( subdir.InitCheck() == B_OK );
CPPUNIT_ASSERT( subdir.GetEntry(&entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry == BEntry(entryName.c_str()) );
subdir.Unset();
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( subdir.InitCheck() == B_NO_INIT );
subdir.Unset();
NextSubTest();
entryName = dirPathName + "file1";
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, false) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( file.InitCheck() == B_NO_INIT );
file.Unset();
NextSubTest();
entryName = dirPathName + "link1";
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_OK );
CPPUNIT_ASSERT( link.InitCheck() == B_OK );
link.Unset();
CPPUNIT_ASSERT( link.SetTo(entryName.c_str()) == B_OK );
link.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
link.Unset();
dir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
NextSubTest();
entryName = dirPathName + "subdir1";
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir) == B_OK );
CPPUNIT_ASSERT( subdir.InitCheck() == B_OK );
CPPUNIT_ASSERT( subdir.GetEntry(&entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry == BEntry(entryName.c_str()) );
subdir.Unset();
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( subdir.InitCheck() == B_NO_INIT );
subdir.Unset();
NextSubTest();
entryName = dirPathName + "file1";
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, false) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( file.InitCheck() == B_NO_INIT );
file.Unset();
NextSubTest();
entryName = dirPathName + "link1";
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_OK );
CPPUNIT_ASSERT( link.InitCheck() == B_OK );
link.Unset();
CPPUNIT_ASSERT( link.SetTo(entryName.c_str()) == B_OK );
link.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
link.Unset();
dir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
chdir(testDir1);
NextSubTest();
entryName = "subdir1";
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir) == B_OK );
CPPUNIT_ASSERT( subdir.InitCheck() == B_OK );
CPPUNIT_ASSERT( subdir.GetEntry(&entry) == B_OK );
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( entry == BEntry((dirPathName + entryName).c_str()) );
subdir.Unset();
CPPUNIT_ASSERT( subdir.SetTo((dirPathName + entryName).c_str()) == B_OK );
subdir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), &subdir)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( subdir.InitCheck() == B_NO_INIT );
subdir.Unset();
NextSubTest();
entryName = "file1";
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo((dirPathName + entryName).c_str(),
B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, false) == B_OK );
CPPUNIT_ASSERT( file.InitCheck() == B_OK );
file.Unset();
CPPUNIT_ASSERT( file.SetTo((dirPathName + entryName).c_str(),
B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), &file, true)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( file.InitCheck() == B_NO_INIT );
file.Unset();
NextSubTest();
entryName = "link1";
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_OK );
CPPUNIT_ASSERT( link.InitCheck() == B_OK );
link.Unset();
CPPUNIT_ASSERT( link.SetTo((dirPathName + entryName).c_str()) == B_OK );
link.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, &link)
== B_FILE_EXISTS );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
link.Unset();
chdir("/");
dir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
CPPUNIT_ASSERT( dir.SetTo(testDir1) == B_OK );
NextSubTest();
entryName = "subdir1";
CPPUNIT_ASSERT( equals(dir.CreateDirectory(NULL, &subdir),
B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( subdir.InitCheck() == B_NO_INIT );
subdir.Unset();
NextSubTest();
entryName = "file1";
CPPUNIT_ASSERT( equals(dir.CreateFile(NULL, &file), B_ENTRY_NOT_FOUND,
B_BAD_VALUE) );
CPPUNIT_ASSERT( file.InitCheck() == B_NO_INIT );
file.Unset();
NextSubTest();
entryName = "link1";
CPPUNIT_ASSERT( equals(dir.CreateSymLink(NULL, existingFile, &link),
B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( equals(dir.CreateSymLink(entryName.c_str(), NULL, &link),
B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
link.Unset();
dir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
NextSubTest();
entryName = dirPathName + "subdir1";
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), NULL) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateDirectory(entryName.c_str(), NULL)
== B_FILE_EXISTS );
subdir.Unset();
NextSubTest();
entryName = dirPathName + "file1";
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), NULL, true) == B_OK );
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), NULL, false) == B_OK );
CPPUNIT_ASSERT( file.SetTo(entryName.c_str(), B_READ_ONLY) == B_OK );
file.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateFile(entryName.c_str(), NULL, true)
== B_FILE_EXISTS );
NextSubTest();
entryName = dirPathName + "link1";
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, NULL)
== B_OK );
CPPUNIT_ASSERT( link.SetTo(entryName.c_str()) == B_OK );
link.Unset();
NextSubTest();
CPPUNIT_ASSERT( dir.CreateSymLink(entryName.c_str(), existingFile, NULL)
== B_FILE_EXISTS );
#endif
}
void
DirectoryTest::AssignmentTest()
{
const char *existing = existingDirname;
NextSubTest();
{
BDirectory dir;
CPPUNIT_ASSERT( dir.InitCheck() == B_NO_INIT );
BDirectory dir2(dir);
CPPUNIT_ASSERT( equals(dir2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
}
NextSubTest();
{
BDirectory dir(existing);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
BDirectory dir2(dir);
CPPUNIT_ASSERT( dir2.InitCheck() == B_OK );
}
NextSubTest();
{
BDirectory dir;
BDirectory dir2;
dir2 = dir;
CPPUNIT_ASSERT( equals(dir2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
}
NextSubTest();
{
BDirectory dir;
BDirectory dir2(existing);
CPPUNIT_ASSERT( dir2.InitCheck() == B_OK );
dir2 = dir;
CPPUNIT_ASSERT( equals(dir2.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
}
NextSubTest();
{
BDirectory dir(existing);
CPPUNIT_ASSERT( dir.InitCheck() == B_OK );
BDirectory dir2;
dir2 = dir;
CPPUNIT_ASSERT( dir2.InitCheck() == B_OK );
}
}
void
DirectoryTest::CreateDirectoryTest()
{
const char *existingFile = existingFilename;
const char *testDir1 = testDirname1;
const char *dirLink = dirLinkname;
const char *fileLink = fileLinkname;
execCommand(string("mkdir ") + testDir1);
NextSubTest();
string dirPathName(string(testDir1) + "/");
string entryName(dirPathName + "subdir1/subdir1.1");
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
BDirectory subdir;
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
entryName = dirPathName + "subdir2";
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
entryName = dirPathName;
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
execCommand(string("rm -rf ") + testDir1);
execCommand(string("mkdir ") + testDir1);
chdir(testDir1);
NextSubTest();
entryName = "subdir1/subdir1.1";
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
entryName = "subdir2";
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
NextSubTest();
entryName = ".";
CPPUNIT_ASSERT( create_directory(entryName.c_str(), 0x1ff) == B_OK );
CPPUNIT_ASSERT( subdir.SetTo(entryName.c_str()) == B_OK );
subdir.Unset();
chdir("/");
NextSubTest();
CPPUNIT_ASSERT( equals(create_directory(existingFile, 0x1ff), B_BAD_VALUE,
B_NOT_A_DIRECTORY) );
CPPUNIT_ASSERT( equals(create_directory(fileLink, 0x1ff), B_BAD_VALUE,
B_NOT_A_DIRECTORY) );
CPPUNIT_ASSERT( create_directory(dirLink, 0x1ff) == B_OK );
NextSubTest();
CPPUNIT_ASSERT( create_directory(NULL, 0x1ff) == B_BAD_VALUE );
}