示例#1
0
TEST(GTestLinkedList, TestSize) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    ASSERT_EQ(l->size(), 1);
    l->add(456);
    ASSERT_EQ(l->size(), 2);
}
示例#2
0
TEST(GTestLinkedList, TestToString) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(false);
    l->add(String::create("foo"));
    String::CPtr s = String::create("123,false,foo");
    ASSERT_EQ(l->toString()->compareTo(s), 0);
}
示例#3
0
TEST(GTestLinkedList, TestRemove) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);
    l->remove(0);

    int v;
    to<int>(l->get(0), &v);
    ASSERT_EQ(v, 456);
    ASSERT_EQ(l->size(), 1);
}
示例#4
0
TEST(GTestLinkedList, TestError) {
    LinkedList::Ptr l = LinkedList::create();

#ifdef LIBJ_USE_EXCEPTION
    ASSERT_ANY_THROW(l->get(5));
#else
    Error::CPtr e;
    ASSERT_TRUE(to<Error::CPtr>(l->get(0), &e));
    ASSERT_TRUE(e->instanceof(Type<Error>::id()));
    ASSERT_EQ(e->code(), Error::INDEX_OUT_OF_BOUNDS);
#endif  // LIBJ_USE_EXCEPTION
}
示例#5
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());
}
TEST(GTestTypedLinkedList, TestCreate2) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(5);
    TypedLinkedList<Int>::Ptr tl =
        TypedLinkedList<Int>::create(l);
    ASSERT_TRUE(!!tl);

    l->add(7.7);
#ifdef LIBJ_USE_EXCEPTION
    ASSERT_ANY_THROW(TypedLinkedList<Int>::create(l));
#else
    tl = TypedLinkedList<Int>::create(l);
    ASSERT_FALSE(!!tl);
#endif  // LIBJ_USE_EXCEPTION
}
示例#7
0
TEST(GTestLinkedList, TestInstanceOf) {
    LinkedList::Ptr l = LinkedList::create();
    ASSERT_TRUE(l->instanceof(Type<LinkedList>::id()));
    ASSERT_TRUE(l->instanceof(Type<List>::id()));
    ASSERT_TRUE(l->instanceof(Type<Collection>::id()));
    ASSERT_TRUE(l->instanceof(Type<Mutable>::id()));
    ASSERT_TRUE(l->instanceof(Type<Object>::id()));
}
示例#8
0
TEST(GTestLinkedList, TestRemove2) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);
    l->add(789);
    ASSERT_TRUE(l->remove(static_cast<Value>(456)));
    ASSERT_FALSE(l->remove(static_cast<Value>(567)));

    int v;
    to<int>(l->get(1), &v);
    ASSERT_EQ(v, 789);
    ASSERT_EQ(l->size(), 2);
}
示例#9
0
TEST(GTestLinkedList, TestSet) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);
    l->set(0, 234);
    l->set(1, 567);

    int v;
    to<int>(l->get(0), &v);
    ASSERT_EQ(v, 234);
    to<int>(l->get(1), &v);
    ASSERT_EQ(v, 567);
    ASSERT_EQ(l->size(), 2);
}
示例#10
0
TEST(GTestLinkedList, TestAddAndGet) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);
    l->add(1, 789);

    int v;
    to<int>(l->get(0), &v);
    ASSERT_EQ(v, 123);
    to<int>(l->get(1), &v);
    ASSERT_EQ(v, 789);
    to<int>(l->get(2), &v);
    ASSERT_EQ(v, 456);
}
示例#11
0
TEST(GTestLinkedList, TestClear) {
    LinkedList::Ptr l = LinkedList::create();
    l->add(123);
    l->add(456);
    l->clear();

#ifdef LIBJ_USE_EXCEPTION
    ASSERT_ANY_THROW(l->get(0));
#else
    Error::CPtr e;
    ASSERT_TRUE(to<Error::CPtr>(l->get(0), &e));
    ASSERT_TRUE(e->instanceof(Type<Error>::id()));
#endif  // LIBJ_USE_EXCEPTION
    ASSERT_EQ(l->size(), 0);
}
示例#12
0
TEST(GTestLinkedList, TestCreate) {
    LinkedList::Ptr l = LinkedList::create();
    ASSERT_EQ(l->size(), 0);
}