[Groonga-commit] groonga/groonga [master] add a test of grn::dat::CursorFactory.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 10日 (木) 10:13:24 JST


Susumu Yata	2011-11-10 01:13:24 +0000 (Thu, 10 Nov 2011)

  New Revision: 21663ae519ca314a929630b840844daa905e1172

  Merged 770d028: Merge branch 'master' of github.com:groonga/groonga

  Log:
    add a test of grn::dat::CursorFactory.

  Added files:
    test/unit/core/dat/test-cursor-factory.cpp
  Modified files:
    test/unit/core/dat/Makefile.am

  Modified: test/unit/core/dat/Makefile.am (+2 -2)
===================================================================
--- test/unit/core/dat/Makefile.am    2011-11-10 01:08:18 +0000 (eb162b7)
+++ test/unit/core/dat/Makefile.am    2011-11-10 01:13:24 +0000 (dd6e71e)
@@ -4,6 +4,7 @@ noinst_LTLIBRARIES =				\
 	test-base.la				\
 	test-block.la				\
 	test-check.la				\
+	test-cursor-factory.la			\
 	test-entry.la				\
 	test-header.la				\
 	test-key.la				\
@@ -11,7 +12,6 @@ noinst_LTLIBRARIES =				\
 	test-string.la				\
 	test-vector.la
 
-#	test-cursor-factory.la			\
 #	test-file.la				\
 #	test-id-cursor.la			\
 #	test-key-cursor.la			\
@@ -44,7 +44,7 @@ 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_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

  Added: test/unit/core/dat/test-cursor-factory.cpp (+108 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-cursor-factory.cpp    2011-11-10 01:13:24 +0000 (a831dff)
@@ -0,0 +1,108 @@
+/* -*- 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/cursor-factory.hpp>
+#include <dat/trie.hpp>
+
+#include <memory>
+
+namespace
+{
+  void create_trie(grn::dat::Trie *trie)
+  {
+    trie->create();
+    cppcut_assert_equal(trie->insert("apple", 5), true);
+    cppcut_assert_equal(trie->insert("orange", 6), true);
+    cppcut_assert_equal(trie->insert("banana", 6), true);
+    cppcut_assert_equal(trie->insert("melon", 5), true);
+  }
+}
+
+namespace test_dat_cursor_factory
+{
+  void test_key_range_cursor(void)
+  {
+    grn::dat::Trie trie;
+    create_trie(&trie);
+
+    std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
+        trie, "apple", 5, "melon", 5, 1, 2,
+        grn::dat::KEY_RANGE_CURSOR | grn::dat::EXCEPT_LOWER_BOUND |
+        grn::dat::EXCEPT_UPPER_BOUND));
+    cut_assert(cursor.get() != static_cast<grn::dat::Cursor *>(NULL));
+
+    cppcut_assert_equal(cursor->offset(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(cursor->limit(), static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(cursor->flags(),
+                        grn::dat::KEY_RANGE_CURSOR | grn::dat::ASCENDING_CURSOR |
+                        grn::dat::EXCEPT_LOWER_BOUND | grn::dat::EXCEPT_UPPER_BOUND);
+  }
+
+  void test_id_range_cursor(void)
+  {
+    grn::dat::Trie trie;
+    create_trie(&trie);
+
+    std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
+        trie, "apple", 5, "melon", 5, 1, 2,
+        grn::dat::ID_RANGE_CURSOR | grn::dat::ASCENDING_CURSOR));
+    cut_assert(cursor.get() != static_cast<grn::dat::Cursor *>(NULL));
+
+    cppcut_assert_equal(cursor->offset(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(cursor->limit(), static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(cursor->flags(),
+                        grn::dat::ID_RANGE_CURSOR | grn::dat::ASCENDING_CURSOR);
+  }
+
+  void test_prefix_cursor(void)
+  {
+    grn::dat::Trie trie;
+    create_trie(&trie);
+
+    std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
+        trie, NULL, 3, "apple", 5, 0, 1,
+        grn::dat::PREFIX_CURSOR | grn::dat::DESCENDING_CURSOR));
+    cut_assert(cursor.get() != static_cast<grn::dat::Cursor *>(NULL));
+
+    cppcut_assert_equal(cursor->offset(), static_cast<grn::dat::UInt32>(0));
+    cppcut_assert_equal(cursor->limit(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(cursor->flags(),
+                        grn::dat::PREFIX_CURSOR | grn::dat::DESCENDING_CURSOR);
+  }
+
+  void test_predictive_cursor(void)
+  {
+    grn::dat::Trie trie;
+    create_trie(&trie);
+
+    std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
+        trie, "apple", 5, NULL, 0, 1, 2,
+        grn::dat::PREDICTIVE_CURSOR | grn::dat::EXCEPT_EXACT_MATCH));
+    cut_assert(cursor.get() != static_cast<grn::dat::Cursor *>(NULL));
+
+    cppcut_assert_equal(cursor->offset(), static_cast<grn::dat::UInt32>(1));
+    cppcut_assert_equal(cursor->limit(), static_cast<grn::dat::UInt32>(2));
+    cppcut_assert_equal(cursor->flags(),
+                        grn::dat::PREDICTIVE_CURSOR |
+                        grn::dat::ASCENDING_CURSOR | grn::dat::EXCEPT_EXACT_MATCH);
+  }
+}




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