示例#1
0
bool Directory::empty(const std::string& path)
{
  assert(!path.empty());
  Iterator::Ptr it = enumerate(path);
  while (it->moveNext())
    {
      if (it->name() != "." && it->name() != "..")
	return 0;
      continue;
    }
  return 1;
}
示例#2
0
void Directory::eraseContent(const std::string& name)
{
  assert(!name.empty());
  Iterator::Ptr it = enumerate(name);
  while(it->moveNext())
    {
      if (it->name() == "." || it->name() == "..")
	continue;
      const std::string& path = it->fullPath();
      if (File::isDir(path))
	{
	  eraseContent(path);
	  remove(path);
	  continue;
	}
      File::unlink(path);
    }
}
示例#3
0
文件: gtest_map.cpp 项目: k8king/libj
TEST(GTestMap, TestEntrySet) {
    Map::Ptr m = Map::create();
    String::CPtr x = String::create("x");
    String::CPtr y = String::create("y");
    m->put(x, 123);
    m->put(y, 456);

    TypedSet<Map::Entry::CPtr>::CPtr es = m->entrySet();

    // iterator
    Iterator::Ptr i = es->iterator();
    ASSERT_TRUE(i->hasNext());
    Map::Entry::CPtr e1 = toCPtr<Map::Entry>(i->next());
    Value key1 = e1->getKey();
    Value val1 = e1->getValue();
    ASSERT_TRUE(key1.equals(x) || key1.equals(y));
    ASSERT_TRUE(val1.equals(123) || val1.equals(456));

    ASSERT_TRUE(i->hasNext());
    Map::Entry::CPtr e2 = toCPtr<Map::Entry>(i->next());
    Value key2 = e2->getKey();
    Value val2 = e2->getValue();
    ASSERT_FALSE(key2.equals(key1));
    ASSERT_FALSE(val2.equals(val1));
    ASSERT_TRUE(key2.equals(x) || key2.equals(y));
    ASSERT_TRUE(val2.equals(123) || val2.equals(456));

    // reuse Map::Entry for better performance
    ASSERT_EQ(e1, e2);
    ASSERT_FALSE(i->hasNext());

    // iteratorTyped
    TypedIterator<Map::Entry::CPtr>::Ptr ti = es->iteratorTyped();
    ASSERT_TRUE(ti->hasNext());
    e1 = ti->next();
    key1 = e1->getKey();
    val1 = e1->getValue();
    ASSERT_TRUE(key1.equals(x) || key1.equals(y));
    ASSERT_TRUE(val1.equals(123) || val1.equals(456));

    ASSERT_TRUE(ti->hasNext());
    e2 = ti->next();
    key2 = e2->getKey();
    val2 = e2->getValue();
    ASSERT_FALSE(key2.equals(key1));
    ASSERT_FALSE(val2.equals(val1));
    ASSERT_TRUE(key2.equals(x) || key2.equals(y));
    ASSERT_TRUE(val2.equals(123) || val2.equals(456));

    // reuse Map::Entry for better performance
    ASSERT_EQ(e1, e2);
    ASSERT_FALSE(ti->hasNext());
}
示例#4
0
TEST(GTestArrayList, TestReverseIterator) {
    ArrayList::Ptr a = ArrayList::create();
    a->add(123);
    a->add(456);

    Iterator::Ptr itr = a->reverseIterator();
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(itr->next().equals(456));
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(itr->next().equals(123));
    ASSERT_FALSE(itr->hasNext());
}
示例#5
0
TEST(GTestSet, TestIterator) {
    Set::Ptr s = Set::create();
    s->add(123);
    s->add(456);

    int v1, v2;
    Iterator::Ptr itr = s->iterator();
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(to<int>(itr->next(), &v1));
    ASSERT_TRUE(v1 == 123 || v1 == 456);
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(to<int>(itr->next(), &v2));
    ASSERT_TRUE(v1 != v2 && (v2 == 123 || v2 == 456));
    ASSERT_FALSE(itr->hasNext());
}
示例#6
0
TEST(GTestLinkedList, TestIterator) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);

    int v;
    Iterator::Ptr itr = l->iterator();
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(to<int>(itr->next(), &v));
    ASSERT_EQ(v, 123);
    ASSERT_TRUE(itr->hasNext());
    ASSERT_TRUE(to<int>(itr->next(), &v));
    ASSERT_EQ(v, 456);
    ASSERT_FALSE(itr->hasNext());
}
示例#7
0
文件: gtest_map.cpp 项目: k8king/libj
TEST(GTestMap, TestKeySet) {
    Map::Ptr m = Map::create();
    String::CPtr x = String::create("x");
    String::CPtr y = String::create("y");
    m->put(x, 123);
    m->put(y, 456);

    Set::CPtr ks = m->keySet();
    Iterator::Ptr itr = ks->iterator();
    ASSERT_TRUE(itr->hasNext());
    String::CPtr v1 = toCPtr<String>(itr->next());
    ASSERT_TRUE(v1->equals(x) || v1->equals(y));
    ASSERT_TRUE(itr->hasNext());
    String::CPtr v2 = toCPtr<String>(itr->next());
    ASSERT_TRUE(!v1->equals(v2) && (v2->equals(x) || v2->equals(y)));
    ASSERT_FALSE(itr->hasNext());
}