Exemplo n.º 1
0
bool TestList() {
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path("foo")));

    fbl::unique_ptr<StringList> list;
    list = path.List();
    EXPECT_STR_EQ(list->first(), "ba");
    EXPECT_NULL(list->next());

    ASSERT_EQ(ZX_OK, path.Push("ba"));
    list = path.List();

    EXPECT_EQ(list->length(), 2);
    list->erase_if("r");
    list->erase_if("z");
    EXPECT_TRUE(list->is_empty());

    ASSERT_EQ(ZX_OK, path.Push("z/qu/ux"));
    list = path.List();
    EXPECT_TRUE(list->is_empty());

    END_TEST;
}
// fit with expanding but without splitting
short Leaf::BestFitPath2(Stat *Stats, const Entry &ent, Path& BestPath)
{
int EntryI=ClosestOne(Stats,ent);
if (EntryI>=0) {
	BestPath.Push(EntryI,this);
	return TRUE;
	}
else if (actsize<MaxSize(Stats)) {
	BestPath.Push(actsize,this);
	return TRUE;
	}
else return FALSE;
}
Exemplo n.º 3
0
bool TestRename() {
    BEGIN_TEST;
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path("foo/ba")));

    EXPECT_NE(ZX_OK, path.Rename("", "empty"));
    EXPECT_NE(ZX_OK, path.Rename("empty", ""));

    EXPECT_NE(ZX_OK, path.Rename("missing", "found"));

    fbl::unique_fd fd(open(fixture.path("foo/ba/r").c_str(), O_RDWR));
    EXPECT_TRUE(!!fd);
    fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR));
    EXPECT_FALSE(!!fd);

    EXPECT_EQ(ZX_OK, path.Rename("r", "s"));
    fd.reset(open(fixture.path("foo/ba/r").c_str(), O_RDWR));
    EXPECT_FALSE(!!fd);
    fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR));
    EXPECT_TRUE(!!fd);

    EXPECT_EQ(ZX_OK, path.Rename("s", "r"));
    fd.reset(open(fixture.path("foo/ba/r").c_str(), O_RDWR));
    EXPECT_TRUE(!!fd);
    fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR));
    EXPECT_FALSE(!!fd);

    EXPECT_EQ(ZX_OK, path.Rename("z", "y"));
    EXPECT_NE(ZX_OK, path.Push("z/qu/ux"));
    EXPECT_EQ(ZX_OK, path.Push("y/qu/ux"));

    path.Pop();
    EXPECT_EQ(ZX_OK, path.Rename("y", "z"));
    EXPECT_NE(ZX_OK, path.Push("y/qu/ux"));
    EXPECT_EQ(ZX_OK, path.Push("z/qu/ux"));

    END_TEST;
}
// fit with expanding but without splitting
short Nonleaf::BestFitPath2(Stat *Stats, const Entry &ent, Path& BestPath)
{
int EntryI=ClosestOne(Stats,ent);
if (EntryI>=0) {
	BestPath.Push(EntryI,this);	
	if (child[EntryI]->BestFitPath2(Stats,ent,BestPath)==TRUE) 
		return TRUE;
	else 	return FALSE;
	}
else return FALSE;
}
Exemplo n.º 5
0
bool TestEnsureAndRemove() {
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path()));
    ASSERT_EQ(ZX_OK, path.Push("foo/ba/z/qu"));

    EXPECT_EQ(ZX_OK, path.Ensure(""));
    EXPECT_NE(ZX_OK, path.Ensure("x"));
    EXPECT_EQ(ZX_OK, path.Ensure("ux"));
    EXPECT_EQ(ZX_OK, path.Ensure("corge"));
    EXPECT_EQ(ZX_OK, path.Ensure("g/rault"));
    EXPECT_EQ(ZX_OK, path.Ensure("g/arply"));

    EXPECT_NE(ZX_OK, path.Remove(""));
    EXPECT_EQ(ZX_OK, path.Remove("a"));

    EXPECT_EQ(ZX_OK, path.Remove("x"));
    EXPECT_NE(ZX_OK, path.Push("x"));

    EXPECT_EQ(ZX_OK, path.Remove("corge"));
    EXPECT_NE(ZX_OK, path.Push("corge"));

    EXPECT_EQ(ZX_OK, path.Remove("g"));
    EXPECT_NE(ZX_OK, path.Push("g"));

    path.Pop();
    EXPECT_EQ(ZX_OK, path.Remove("foo"));
    EXPECT_NE(ZX_OK, path.Push("foo"));

    END_TEST;
}
Exemplo n.º 6
0
bool TestReset() {
    BEGIN_TEST;
    PathFixture fixture;
    ASSERT_TRUE(fixture.Create());

    Path path;
    ASSERT_EQ(ZX_OK, path.Push(fixture.path()));

    path.Reset();
    EXPECT_STR_EQ(path.c_str(), "/");

    END_TEST;
}