[Groonga-commit] groonga/groonga [master] add unit-tests of grn_dat.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 9日 (水) 17:46:09 JST


Susumu Yata	2011-11-09 08:46:09 +0000 (Wed, 09 Nov 2011)

  New Revision: dfde28549952d71a130b22ccd4c8241480f475d7

  Log:
    add unit-tests of grn_dat.

  Added files:
    test/unit/core/dat/test-base.cpp
    test/unit/core/dat/test-block.cpp
    test/unit/core/dat/test-check.cpp
    test/unit/core/dat/test-entry.cpp
    test/unit/core/dat/test-header.cpp
    test/unit/core/dat/test-key.cpp
    test/unit/core/dat/test-node.cpp
    test/unit/core/dat/test-vector.cpp
  Modified files:
    test/unit/core/dat/Makefile.am

  Modified: test/unit/core/dat/Makefile.am (+34 -1)
===================================================================
--- test/unit/core/dat/Makefile.am    2011-11-09 04:23:27 +0000 (c8de28d)
+++ test/unit/core/dat/Makefile.am    2011-11-09 08:46:09 +0000 (2817b8f)
@@ -1,6 +1,23 @@
 if WITH_CPPCUTTER
 noinst_LTLIBRARIES =				\
-	test-array.la
+	test-array.la				\
+	test-base.la				\
+	test-block.la				\
+	test-check.la				\
+	test-entry.la				\
+	test-header.la				\
+	test-key.la				\
+	test-node.la				\
+	test-vector.la
+
+#	test-cursor-factory.la			\
+#	test-file.la				\
+#	test-id-cursor.la			\
+#	test-key-cursor.la			\
+#	test-predictive-cursor.la		\
+#	test-prefix-cursor.la			\
+#	test-string.la				\
+#	test-trie.la
 endif
 
 INCLUDES =					\
@@ -24,3 +41,19 @@ LIBS =								\
 	$(top_builddir)/test/unit/lib/libgrn-test-hash-utils.la
 
 test_array_la_SOURCES			= test-array.cpp
+test_base_la_SOURCES			= test-base.cpp
+test_block_la_SOURCES			= test-block.cpp
+test_check_la_SOURCES			= test-check.cpp
+#test_cursor_factory_la_SOURCES		= test-cursor-factory.cpp
+test_entry_la_SOURCES			= test-entry.cpp
+#test_file_la_SOURCES			= test-file.cpp
+test_header_la_SOURCES			= test-header.cpp
+#test_id_cursor_la_SOURCES		= test-id-cursor.cpp
+#test_key_cursor_la_SOURCES		= test-key-cursor.cpp
+test_key_la_SOURCES			= test-key.cpp
+test_node_la_SOURCES			= test-node.cpp
+#test_predictive_cursor_la_SOURCES	= test-predictive-cursor.cpp
+#test_prefix_cursor_la_SOURCES		= test-prefix-cursor.cpp
+#test_string_la_SOURCES			= test-string.cpp
+#test_trie_la_SOURCES			= test-trie.cpp
+test_vector_la_SOURCES			= test-vector.cpp

  Added: test/unit/core/dat/test-base.cpp (+52 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-base.cpp    2011-11-09 08:46:09 +0000 (84b8b4c)
@@ -0,0 +1,52 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/base.hpp>
+
+namespace test_dat_base
+{
+  void test_initial_values(void)
+  {
+    grn::dat::Base base;
+
+    cppcut_assert_equal(base.is_linker(), false);
+    cppcut_assert_equal(base.offset(), static_cast<grn::dat::UInt32>(0));
+  }
+
+  void test_linker(void)
+  {
+    grn::dat::Base base;
+
+    base.set_key_pos(100);
+    cppcut_assert_equal(base.is_linker(), true);
+    cppcut_assert_equal(base.key_pos(), static_cast<grn::dat::UInt32>(100));
+  }
+
+  void test_nonlinker(void)
+  {
+    grn::dat::Base base;
+
+    base.set_offset(1000);
+    cppcut_assert_equal(base.is_linker(), false);
+    cppcut_assert_equal(base.offset(), static_cast<grn::dat::UInt32>(1000));
+  }
+}

  Added: test/unit/core/dat/test-block.cpp (+68 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-block.cpp    2011-11-09 08:46:09 +0000 (a95ec99)
@@ -0,0 +1,68 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/block.hpp>
+
+namespace test_dat_block
+{
+  void test_initial_values(void)
+  {
+    const grn::dat::Block block;
+
+    cppcut_assert_equal(block.next(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(block.prev(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(block.level(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(block.failure_count(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(block.first_phantom(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(block.num_phantoms(), static_cast<grn::dat::UInt32>(0));
+  }
+
+  void test_link_management(void)
+  {
+    grn::dat::Block block;
+
+    block.set_next(101);
+    block.set_prev(99);
+    cppcut_assert_equal(block.next(), static_cast<grn::dat::UInt32>(101));
+    cppcut_assert_equal(block.prev(), static_cast<grn::dat::UInt32>(99));
+  }
+
+  void test_level_management(void)
+  {
+    grn::dat::Block block;
+
+    block.set_level(grn::dat::MAX_BLOCK_LEVEL);
+    block.set_failure_count(grn::dat::MAX_FAILURE_COUNT);
+    cppcut_assert_equal(block.level(), grn::dat::MAX_BLOCK_LEVEL);
+    cppcut_assert_equal(block.failure_count(), grn::dat::MAX_FAILURE_COUNT);
+  }
+
+  void test_phantoms_management(void)
+  {
+    grn::dat::Block block;
+
+    block.set_first_phantom(37);
+    block.set_num_phantoms(89);
+    cppcut_assert_equal(block.first_phantom(), static_cast<grn::dat::UInt32>(37));
+    cppcut_assert_equal(block.num_phantoms(), static_cast<grn::dat::UInt32>(89));
+  }
+}

  Added: test/unit/core/dat/test-check.cpp (+86 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-check.cpp    2011-11-09 08:46:09 +0000 (8145906)
@@ -0,0 +1,86 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/check.hpp>
+
+namespace test_dat_check
+{
+  void test_initial_values(void)
+  {
+    const grn::dat::Check check;
+
+    cppcut_assert_equal(check.is_offset(), false);
+    cppcut_assert_equal(check.except_is_offset(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(check.is_phantom(), false);
+    cppcut_assert_equal(check.label(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(check.child(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(check.sibling(), static_cast<grn::dat::UInt32>(0));
+  }
+
+  void test_phantomize(void)
+  {
+    grn::dat::Check check;
+
+    check.set_is_phantom(true);
+    cppcut_assert_equal(check.is_phantom(), true);
+    cppcut_assert_equal(check.next(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(check.prev(), static_cast<grn::dat::UInt32>(0));
+
+    check.set_next(101);
+    check.set_prev(99);
+    cppcut_assert_equal(check.next(), static_cast<grn::dat::UInt32>(101));
+    cppcut_assert_equal(check.prev(), static_cast<grn::dat::UInt32>(99));
+  }
+
+  void test_unphantomize(void)
+  {
+    grn::dat::Check check;
+
+    check.set_is_phantom(true);
+    check.set_is_phantom(false);
+    cppcut_assert_equal(check.is_phantom(), false);
+    cppcut_assert_equal(check.child(), grn::dat::INVALID_LABEL);
+    cppcut_assert_equal(check.sibling(), grn::dat::INVALID_LABEL);
+  }
+
+  void test_nonphantom(void)
+  {
+    grn::dat::Check check;
+
+    check.set_is_offset(true);
+    cppcut_assert_equal(check.is_offset(), true);
+
+    check.set_label('a');
+    cppcut_assert_equal(check.label(), static_cast<grn::dat::UInt32>('a'));
+
+    check.set_child('b');
+    cppcut_assert_equal(check.child(), static_cast<grn::dat::UInt32>('b'));
+
+    check.set_sibling('c');
+    cppcut_assert_equal(check.sibling(), static_cast<grn::dat::UInt32>('c'));
+
+    cppcut_assert_equal(check.is_offset(), true);
+    cppcut_assert_equal(check.except_is_offset(),
+                        'a' | (static_cast<grn::dat::UInt32>('b' << 9)) | (static_cast<grn::dat::UInt32>('c' << 18)));
+    cppcut_assert_equal(check.is_phantom(), false);
+  }
+}

  Added: test/unit/core/dat/test-entry.cpp (+52 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-entry.cpp    2011-11-09 08:46:09 +0000 (c33c125)
@@ -0,0 +1,52 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/entry.hpp>
+
+namespace test_dat_entry
+{
+  void test_initial_values(void)
+  {
+    const grn::dat::Entry entry;
+
+    cppcut_assert_equal(entry.is_valid(), false);
+    cppcut_assert_equal(entry.next(), static_cast<grn::dat::UInt32>(0));
+  }
+
+  void test_valid_entry(void)
+  {
+    grn::dat::Entry entry;
+
+    entry.set_key_pos(100);
+    cppcut_assert_equal(entry.is_valid(), true);
+    cppcut_assert_equal(entry.key_pos(), static_cast<grn::dat::UInt32>(100));
+  }
+
+  void test_invalid_entry(void)
+  {
+    grn::dat::Entry entry;
+
+    entry.set_next(200);
+    cppcut_assert_equal(entry.is_valid(), false);
+    cppcut_assert_equal(entry.next(), static_cast<grn::dat::UInt32>(200));
+  }
+}

  Added: test/unit/core/dat/test-header.cpp (+104 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-header.cpp    2011-11-09 08:46:09 +0000 (637780a)
@@ -0,0 +1,104 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/header.hpp>
+
+namespace test_dat_header
+{
+  void test_initial_values(void)
+  {
+    const grn::dat::Header header;
+
+    cppcut_assert_equal(header.file_size(), static_cast<grn::dat::UInt64>(0));
+    cppcut_assert_equal(header.total_key_length(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.min_key_id(), grn::dat::MIN_KEY_ID);
+    cppcut_assert_equal(header.next_key_id(), grn::dat::MIN_KEY_ID);
+    cppcut_assert_equal(header.max_key_id(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.num_keys(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.max_num_keys(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.num_nodes(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.num_phantoms(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.num_zombies(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.max_num_nodes(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.num_blocks(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.max_num_blocks(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.next_key_pos(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(header.key_buf_size(), static_cast<grn::dat::UInt32>(0));
+    for (grn::dat::UInt32 i = 0; i <= grn::dat::MAX_BLOCK_LEVEL; ++i) {
+      cppcut_assert_equal(header.ith_leader(i), grn::dat::INVALID_LEADER);
+    }
+  }
+
+  void test_const_values(void)
+  {
+    grn::dat::Header header;
+
+    header.set_file_size(10000);
+    header.set_max_num_keys(30);
+    header.set_max_num_blocks(20);
+    header.set_key_buf_size(800);
+
+    cppcut_assert_equal(header.file_size(), static_cast<grn::dat::UInt64>(10000));
+    cppcut_assert_equal(header.max_num_keys(), static_cast<grn::dat::UInt32>(30));
+    cppcut_assert_equal(header.max_num_nodes(), (grn::dat::BLOCK_SIZE * 20));
+    cppcut_assert_equal(header.max_num_blocks(), static_cast<grn::dat::UInt32>(20));
+    cppcut_assert_equal(header.key_buf_size(), static_cast<grn::dat::UInt32>(800));
+  }
+
+  void test_mutable_values(void)
+  {
+    grn::dat::Header header;
+
+    header.set_file_size(1000000);
+    header.set_max_num_keys(100);
+    header.set_max_num_blocks(50);
+    header.set_key_buf_size(100000);
+
+    header.set_total_key_length(500);
+    header.set_next_key_id(15);
+    header.set_max_key_id(14);
+    header.set_num_keys(20);
+    header.set_num_phantoms(200);
+    header.set_num_zombies(300);
+    header.set_num_blocks(10);
+    header.set_next_key_pos(400);
+
+    cppcut_assert_equal(header.total_key_length(), static_cast<grn::dat::UInt32>(500));
+    cppcut_assert_equal(header.min_key_id(), grn::dat::MIN_KEY_ID);
+    cppcut_assert_equal(header.next_key_id(), static_cast<grn::dat::UInt32>(15));
+    cppcut_assert_equal(header.max_key_id(), static_cast<grn::dat::UInt32>(14));
+    cppcut_assert_equal(header.num_keys(), static_cast<grn::dat::UInt32>(20));
+    cppcut_assert_equal(header.num_nodes(), (grn::dat::BLOCK_SIZE * 10));
+    cppcut_assert_equal(header.num_phantoms(), static_cast<grn::dat::UInt32>(200));
+    cppcut_assert_equal(header.num_zombies(), static_cast<grn::dat::UInt32>(300));
+    cppcut_assert_equal(header.num_blocks(), static_cast<grn::dat::UInt32>(10));
+    cppcut_assert_equal(header.next_key_pos(), static_cast<grn::dat::UInt32>(400));
+
+    for (grn::dat::UInt32 i = 0; i <= grn::dat::MAX_BLOCK_LEVEL; ++i) {
+      header.set_ith_leader(i, i + 1);
+    }
+
+    for (grn::dat::UInt32 i = 0; i <= grn::dat::MAX_BLOCK_LEVEL; ++i) {
+      cppcut_assert_equal(header.ith_leader(i), (i + 1));
+    }
+  }
+}

  Added: test/unit/core/dat/test-key.cpp (+62 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-key.cpp    2011-11-09 08:46:09 +0000 (9f94952)
@@ -0,0 +1,62 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/key.hpp>
+
+#include <cstring>
+
+namespace test_dat_key
+{
+  void test_size_estimation(void)
+  {
+    cppcut_assert_equal(grn::dat::Key::estimate_size(0),
+                        static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(grn::dat::Key::estimate_size(3),
+                        static_cast<grn::dat::UInt32>(2));
+
+    cppcut_assert_equal(grn::dat::Key::estimate_size(4),
+                        static_cast<grn::dat::UInt32>(3));
+    cppcut_assert_equal(grn::dat::Key::estimate_size(7),
+                        static_cast<grn::dat::UInt32>(3));
+  }
+
+  void test_invalid_key(void)
+  {
+    const grn::dat::Key &key = grn::dat::Key::invalid_key();
+
+    cppcut_assert_equal(key.id(), grn::dat::INVALID_KEY_ID);
+    cppcut_assert_equal(key.length(), static_cast<grn::dat::UInt32>(0));
+    cut_assert(key.ptr() != static_cast<const void *>(NULL));
+  }
+
+  void test_creation(void)
+  {
+    grn::dat::UInt32 buf[16];
+    const grn::dat::Key &key = grn::dat::Key::create(buf, 123, "groonga", 7);
+
+    cut_assert(key.str() == grn::dat::String("groonga"));
+    cppcut_assert_equal(key.id(), static_cast<grn::dat::UInt32>(123));
+    cppcut_assert_equal(key.length(), static_cast<grn::dat::UInt32>(7));
+    cppcut_assert_equal(std::memcmp(key.ptr(), "groonga", 7), 0);
+    cppcut_assert_equal(key.ptr(), static_cast<const void *>(reinterpret_cast<char *>(buf) + 5));
+  }
+}

  Added: test/unit/core/dat/test-node.cpp (+87 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-node.cpp    2011-11-09 08:46:09 +0000 (620229b)
@@ -0,0 +1,87 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/node.hpp>
+
+namespace test_dat_node
+{
+  void test_base(void)
+  {
+    grn::dat::Node node;
+    grn::dat::Base base;
+
+    cut_assert(node.base() == base);
+
+    node.set_key_pos(100);
+    base.set_key_pos(100);
+    cut_assert(node.base() == base);
+    cppcut_assert_equal(node.is_linker(), base.is_linker());
+    cppcut_assert_equal(node.key_pos(), base.key_pos());
+
+    node.set_offset(1000);
+    base.set_offset(1000);
+    cut_assert(node.base() == base);
+    cppcut_assert_equal(node.is_linker(), base.is_linker());
+    cppcut_assert_equal(node.offset(), base.offset());
+  }
+
+  void test_check(void)
+  {
+    grn::dat::Node node;
+    grn::dat::Check check;
+
+    cut_assert(node.check() == check);
+
+    node.set_is_offset(true);
+    check.set_is_offset(true);
+    cut_assert(node.check() == check);
+    cppcut_assert_equal(node.is_offset(), check.is_offset());
+
+    node.set_offset(grn::dat::INVALID_OFFSET);
+
+    node.set_is_phantom(true);
+    check.set_is_phantom(true);
+    cut_assert(node.check() == check);
+    cppcut_assert_equal(node.is_phantom(), check.is_phantom());
+
+    node.set_next(101);
+    node.set_prev(99);
+    check.set_next(101);
+    check.set_prev(99);
+    cut_assert(node.check() == check);
+    cppcut_assert_equal(node.next(), check.next());
+    cppcut_assert_equal(node.prev(), check.prev());
+
+    node.set_is_phantom(false);
+    check.set_is_phantom(false);
+    cut_assert(node.check() == check);
+    cppcut_assert_equal(node.is_phantom(), check.is_phantom());
+    cppcut_assert_equal(node.label(), check.label());
+    cppcut_assert_equal(node.child(), check.child());
+    cppcut_assert_equal(node.sibling(), check.sibling());
+
+    node.set_label('a');
+    check.set_label('a');
+    cut_assert(node.check() == check);
+    cppcut_assert_equal(node.label(), check.label());
+  }
+}

  Added: test/unit/core/dat/test-vector.cpp (+242 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-vector.cpp    2011-11-09 08:46:09 +0000 (59ad073)
@@ -0,0 +1,242 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/vector.hpp>
+
+namespace
+{
+  class Counter {
+   public:
+    Counter() {
+      ++constructor_count;
+    }
+    Counter(const Counter &) {
+      ++copy_count;
+    }
+    ~Counter() {
+      ++destructor_count;
+    }
+
+    static int constructor_count;
+    static int copy_count;
+    static int destructor_count;
+  };
+
+  int Counter::constructor_count = 0;
+  int Counter::copy_count = 0;
+  int Counter::destructor_count = 0;
+}
+
+namespace test_dat_vector
+{
+  void test_empty_vector(void)
+  {
+    const grn::dat::Vector<grn::dat::UInt32> vec;
+
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(0));
+  }
+
+  void test_reserve(void)
+  {
+    grn::dat::Vector<grn::dat::UInt32> vec;
+
+    vec.reserve(1);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(1));
+
+    vec.reserve(2);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(2));
+
+    vec.reserve(3);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(4));
+
+    vec.reserve(100);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(100));
+
+    vec.reserve(101);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(200));
+
+    vec.reserve(0);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(200));
+  }
+
+  void test_resize(void)
+  {
+    grn::dat::Vector<grn::dat::UInt32> vec;
+
+    vec.resize(1);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(1));
+
+    vec.resize(2);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(2));
+
+    vec.resize(3);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(3));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(4));
+
+    vec.resize(100);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(100));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(100));
+
+    vec.resize(101);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(101));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(200));
+
+    vec.resize(0);
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(200));
+  }
+
+  void test_push_pop(void)
+  {
+    grn::dat::Vector<grn::dat::UInt32> vec;
+
+    vec.push_back();
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(1));
+
+    vec.pop_back();
+    cppcut_assert_equal(vec.empty(), true);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(1));
+
+    vec.push_back(5);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(1));
+
+    cppcut_assert_equal(vec.front(), static_cast<grn::dat::UInt32>(5));
+    cppcut_assert_equal(vec.back(), static_cast<grn::dat::UInt32>(5));
+
+    vec.push_back(123);
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(2));
+
+    cppcut_assert_equal(vec.front(), static_cast<grn::dat::UInt32>(5));
+    cppcut_assert_equal(vec.back(), static_cast<grn::dat::UInt32>(123));
+
+    vec.pop_back();
+    cppcut_assert_equal(vec.empty(), false);
+    cppcut_assert_equal(vec.size(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(vec.capacity(), static_cast<grn::dat::UInt32>(2));
+
+    cppcut_assert_equal(vec.front(), static_cast<grn::dat::UInt32>(5));
+    cppcut_assert_equal(vec.back(), static_cast<grn::dat::UInt32>(5));
+
+    vec.clear();
+
+    for (grn::dat::UInt32 i = 0; i < 1000; ++i) {
+      vec.push_back(i);
+      cppcut_assert_equal(vec.back(), i);
+      cppcut_assert_equal(vec.size(), i + 1);
+    }
+    for (grn::dat::UInt32 i = 0; i < 1000; ++i) {
+      cppcut_assert_equal(vec.size(), 1000 - i);
+      cppcut_assert_equal(vec.back(), 999 - i);
+      vec.pop_back();
+    }
+  }
+
+  void test_index_access(void)
+  {
+    grn::dat::Vector<grn::dat::UInt32> vec;
+
+    vec.resize(100);
+    for (grn::dat::UInt32 i = 0; i < vec.size(); ++i) {
+      vec[i] = i;
+    }
+    for (grn::dat::UInt32 i = 0; i < vec.size(); ++i) {
+      cppcut_assert_equal(vec[i], i);
+      cppcut_assert_equal(const_cast<const grn::dat::Vector<grn::dat::UInt32> &>(vec)[i], i);
+      cppcut_assert_equal(&vec[i], vec.begin() + i);
+      cppcut_assert_equal(&vec[i], vec.end() - vec.size() + i);
+    }
+  }
+
+  void test_object_management(void)
+  {
+    grn::dat::Vector<Counter> vec;
+
+    cppcut_assert_equal(Counter::constructor_count, 0);
+    cppcut_assert_equal(Counter::copy_count, 0);
+    cppcut_assert_equal(Counter::destructor_count, 0);
+
+    vec.push_back();
+
+    cppcut_assert_equal(Counter::constructor_count, 1);
+    cppcut_assert_equal(Counter::copy_count, 0);
+    cppcut_assert_equal(Counter::destructor_count, 0);
+
+    vec.pop_back();
+
+    cppcut_assert_equal(Counter::constructor_count, 1);
+    cppcut_assert_equal(Counter::copy_count, 0);
+    cppcut_assert_equal(Counter::destructor_count, 1);
+
+    vec.resize(10);
+
+    cppcut_assert_equal(Counter::constructor_count, 11);
+    cppcut_assert_equal(Counter::copy_count, 0);
+    cppcut_assert_equal(Counter::destructor_count, 1);
+
+    vec.pop_back();
+
+    cppcut_assert_equal(Counter::constructor_count, 11);
+    cppcut_assert_equal(Counter::copy_count, 0);
+    cppcut_assert_equal(Counter::destructor_count, 2);
+
+    vec.resize(11);
+
+    cppcut_assert_equal(Counter::constructor_count, 13);
+    cppcut_assert_equal(Counter::copy_count, 9);
+    cppcut_assert_equal(Counter::destructor_count, 11);
+
+    vec.clear();
+
+    cppcut_assert_equal(Counter::constructor_count, 13);
+    cppcut_assert_equal(Counter::copy_count, 9);
+    cppcut_assert_equal(Counter::destructor_count, 22);
+  }
+}




Groonga-commit メーリングリストの案内
Back to archive index