Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-cursor-factory.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2011-2012 Brazil
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <gcutter.h>
20 #include <cppcutter.h>
21 
22 #include <grn-assertions.h>
23 #include <dat/cursor-factory.hpp>
24 #include <dat/trie.hpp>
25 
26 #include <memory>
27 
28 namespace
29 {
30  void create_trie(grn::dat::Trie *trie)
31  {
32  trie->create();
33  cppcut_assert_equal(true, trie->insert("apple", 5));
34  cppcut_assert_equal(true, trie->insert("orange", 6));
35  cppcut_assert_equal(true, trie->insert("banana", 6));
36  cppcut_assert_equal(true, trie->insert("melon", 5));
37  }
38 }
39 
40 namespace test_dat_cursor_factory
41 {
42  void test_key_range_cursor(void)
43  {
44  grn::dat::Trie trie;
45  create_trie(&trie);
46 
47  std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
48  trie, "apple", 5, "melon", 5, 1, 2,
51  cppcut_assert_not_null(cursor.get());
52 
53  cppcut_assert_equal(grn::dat::UInt32(1), cursor->offset());
54  cppcut_assert_equal(grn::dat::UInt32(2), cursor->limit());
55  cppcut_assert_equal(grn::dat::KEY_RANGE_CURSOR |
59  cursor->flags());
60  }
61 
63  {
64  grn::dat::Trie trie;
65  create_trie(&trie);
66 
67  std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
68  trie, "apple", 5, "melon", 5, 1, 2,
70  cppcut_assert_not_null(cursor.get());
71 
72  cppcut_assert_equal(grn::dat::UInt32(1), cursor->offset());
73  cppcut_assert_equal(grn::dat::UInt32(2), cursor->limit());
74  cppcut_assert_equal(grn::dat::ID_RANGE_CURSOR |
76  cursor->flags());
77  }
78 
79  void test_prefix_cursor(void)
80  {
81  grn::dat::Trie trie;
82  create_trie(&trie);
83 
84  std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
85  trie, NULL, 3, "apple", 5, 0, 1,
87  cppcut_assert_not_null(cursor.get());
88 
89  cppcut_assert_equal(grn::dat::UInt32(0), cursor->offset());
90  cppcut_assert_equal(grn::dat::UInt32(1), cursor->limit());
92  cursor->flags());
93  }
94 
96  {
97  grn::dat::Trie trie;
98  create_trie(&trie);
99 
100  std::auto_ptr<grn::dat::Cursor> cursor(grn::dat::CursorFactory::open(
101  trie, "apple", 5, NULL, 0, 1, 2,
103  cppcut_assert_not_null(cursor.get());
104 
105  cppcut_assert_equal(grn::dat::UInt32(1), cursor->offset());
106  cppcut_assert_equal(grn::dat::UInt32(2), cursor->limit());
107  cppcut_assert_equal(grn::dat::PREDICTIVE_CURSOR |
110  cursor->flags());
111  }
112 }