Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-node.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2011 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/node.hpp>
24 
25 #include <iostream>
26 
27 namespace grn
28 {
29  namespace dat
30  {
31  std::ostream &operator<<(std::ostream &stream, const grn::dat::Base &base)
32  {
33  if (base.is_linker()) {
34  stream << "linker: " << base.key_pos();
35  } else {
36  stream << "non-linker: " << base.offset();
37  }
38  return stream;
39  }
40 
41  std::ostream &operator<<(std::ostream &stream, const grn::dat::Check &check)
42  {
43  if (check.is_offset()) {
44  stream << "offset: " << check.except_is_offset() << "; ";
45  } else {
46  stream << "not offset: " << check.except_is_offset() << "; ";
47  }
48 
49  if (check.is_phantom()) {
50  stream << "phantom: " << check.next() << ", " << check.prev();
51  } else {
52  stream << "non-phantom: " << check.label()
53  << ", " << check.child() << ", " << check.sibling();
54  }
55  return stream;
56  }
57  }
58 }
59 
60 namespace test_dat_node
61 {
62  void test_base(void)
63  {
65  grn::dat::Base base;
66 
67  cppcut_assert_equal(base, node.base());
68 
69  node.set_key_pos(100);
70  base.set_key_pos(100);
71  cppcut_assert_equal(base, node.base());
72  cppcut_assert_equal(base.is_linker(), node.is_linker());
73  cppcut_assert_equal(base.key_pos(), node.key_pos());
74 
75  node.set_offset(1000);
76  base.set_offset(1000);
77  cppcut_assert_equal(base, node.base());
78  cppcut_assert_equal(base.is_linker(), node.is_linker());
79  cppcut_assert_equal(base.offset(), node.offset());
80  }
81 
82  void test_check(void)
83  {
85  grn::dat::Check check;
86 
87  cppcut_assert_equal(check, node.check());
88 
89  node.set_is_offset(true);
90  check.set_is_offset(true);
91  cppcut_assert_equal(check, node.check());
92  cppcut_assert_equal(check.is_offset(), node.is_offset());
93 
95 
96  node.set_is_phantom(true);
97  check.set_is_phantom(true);
98  cppcut_assert_equal(check, node.check());
99  cppcut_assert_equal(check.is_phantom(), node.is_phantom());
100 
101  node.set_next(101);
102  node.set_prev(99);
103  check.set_next(101);
104  check.set_prev(99);
105  cppcut_assert_equal(check, node.check());
106  cppcut_assert_equal(check.next(), node.next());
107  cppcut_assert_equal(check.prev(), node.prev());
108 
109  node.set_is_phantom(false);
110  check.set_is_phantom(false);
111  cppcut_assert_equal(check, node.check());
112  cppcut_assert_equal(check.is_phantom(), node.is_phantom());
113  cppcut_assert_equal(check.label(), node.label());
114  cppcut_assert_equal(check.child(), node.child());
115  cppcut_assert_equal(check.sibling(), node.sibling());
116 
117  node.set_label('a');
118  check.set_label('a');
119  cppcut_assert_equal(check, node.check());
120  cppcut_assert_equal(check.label(), node.label());
121  }
122 }