Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-check.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/check.hpp>
24 
25 namespace test_dat_check
26 {
28  {
29  const grn::dat::Check check;
30 
31  cppcut_assert_equal(false, check.is_offset());
32  cppcut_assert_equal(grn::dat::UInt32(0), check.except_is_offset());
33  cppcut_assert_equal(false, check.is_phantom());
34  cppcut_assert_equal(grn::dat::UInt32(0), check.label());
35  cppcut_assert_equal(grn::dat::UInt32(0), check.child());
36  cppcut_assert_equal(grn::dat::UInt32(0), check.sibling());
37  }
38 
39  void test_phantomize(void)
40  {
41  grn::dat::Check check;
42 
43  check.set_is_phantom(true);
44  cppcut_assert_equal(true, check.is_phantom());
45  cppcut_assert_equal(grn::dat::UInt32(0), check.next());
46  cppcut_assert_equal(grn::dat::UInt32(0), check.prev());
47 
48  check.set_next(101);
49  check.set_prev(99);
50  cppcut_assert_equal(grn::dat::UInt32(101), check.next());
51  cppcut_assert_equal(grn::dat::UInt32(99), check.prev());
52  }
53 
54  void test_unphantomize(void)
55  {
56  grn::dat::Check check;
57 
58  check.set_is_phantom(true);
59  check.set_is_phantom(false);
60  cppcut_assert_equal(false, check.is_phantom());
61  cppcut_assert_equal(grn::dat::INVALID_LABEL, check.child());
62  cppcut_assert_equal(grn::dat::INVALID_LABEL, check.sibling());
63  }
64 
65  void test_nonphantom(void)
66  {
67  grn::dat::Check check;
68 
69  check.set_is_offset(true);
70  cppcut_assert_equal(true, check.is_offset());
71 
72  check.set_label('a');
73  cppcut_assert_equal(grn::dat::UInt32('a'), check.label());
74 
75  check.set_child('b');
76  cppcut_assert_equal(grn::dat::UInt32('b'), check.child());
77 
78  check.set_sibling('c');
79  cppcut_assert_equal(grn::dat::UInt32('c'), check.sibling());
80 
81  cppcut_assert_equal(true, check.is_offset());
82  const grn::dat::UInt32 expected_except_is_offset =
83  'a' | grn::dat::UInt32('b' << 9) | grn::dat::UInt32('c' << 18);
84  cppcut_assert_equal(expected_except_is_offset, check.except_is_offset());
85  cppcut_assert_equal(false, check.is_phantom());
86  }
87 }