Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-header.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/header.hpp>
24 
25 namespace test_dat_header
26 {
28  {
29  const grn::dat::Header header;
30 
31  cppcut_assert_equal(grn::dat::UInt64(0), header.file_size());
32  cppcut_assert_equal(grn::dat::UInt32(0), header.total_key_length());
33  cppcut_assert_equal(grn::dat::MIN_KEY_ID, header.min_key_id());
34  cppcut_assert_equal(grn::dat::MIN_KEY_ID, header.next_key_id());
35  cppcut_assert_equal(grn::dat::UInt32(0), header.max_key_id());
36  cppcut_assert_equal(grn::dat::UInt32(0), header.num_keys());
37  cppcut_assert_equal(grn::dat::UInt32(0), header.max_num_keys());
38  cppcut_assert_equal(grn::dat::UInt32(0), header.num_nodes());
39  cppcut_assert_equal(grn::dat::UInt32(0), header.num_phantoms());
40  cppcut_assert_equal(grn::dat::UInt32(0), header.num_zombies());
41  cppcut_assert_equal(grn::dat::UInt32(0), header.max_num_nodes());
42  cppcut_assert_equal(grn::dat::UInt32(0), header.num_blocks());
43  cppcut_assert_equal(grn::dat::UInt32(0), header.max_num_blocks());
44  cppcut_assert_equal(grn::dat::UInt32(0), header.next_key_pos());
45  cppcut_assert_equal(grn::dat::UInt32(0), header.key_buf_size());
47  cppcut_assert_equal(grn::dat::INVALID_LEADER, header.ith_leader(i));
48  }
49  }
50 
52  {
53  grn::dat::Header header;
54 
55  header.set_file_size(10000);
56  header.set_max_num_keys(30);
57  header.set_max_num_blocks(20);
58  header.set_key_buf_size(800);
59 
60  cppcut_assert_equal(grn::dat::UInt64(10000), header.file_size());
61  cppcut_assert_equal(grn::dat::UInt32(30), header.max_num_keys());
62  cppcut_assert_equal(grn::dat::BLOCK_SIZE * 20, header.max_num_nodes());
63  cppcut_assert_equal(grn::dat::UInt32(20), header.max_num_blocks());
64  cppcut_assert_equal(grn::dat::UInt32(800), header.key_buf_size());
65  }
66 
68  {
69  grn::dat::Header header;
70 
71  header.set_file_size(1000000);
72  header.set_max_num_keys(100);
73  header.set_max_num_blocks(50);
74  header.set_key_buf_size(100000);
75 
76  header.set_total_key_length(500);
77  header.set_next_key_id(15);
78  header.set_max_key_id(14);
79  header.set_num_keys(20);
80  header.set_num_phantoms(200);
81  header.set_num_zombies(300);
82  header.set_num_blocks(10);
83  header.set_next_key_pos(400);
84 
85  cppcut_assert_equal(grn::dat::UInt32(500), header.total_key_length());
86  cppcut_assert_equal(grn::dat::MIN_KEY_ID, header.min_key_id());
87  cppcut_assert_equal(grn::dat::UInt32(15), header.next_key_id());
88  cppcut_assert_equal(grn::dat::UInt32(14), header.max_key_id());
89  cppcut_assert_equal(grn::dat::UInt32(20), header.num_keys());
90  cppcut_assert_equal(grn::dat::BLOCK_SIZE * 10, header.num_nodes());
91  cppcut_assert_equal(grn::dat::UInt32(200), header.num_phantoms());
92  cppcut_assert_equal(grn::dat::UInt32(300), header.num_zombies());
93  cppcut_assert_equal(grn::dat::UInt32(10), header.num_blocks());
94  cppcut_assert_equal(grn::dat::UInt32(400), header.next_key_pos());
95 
97  header.set_ith_leader(i, i + 1);
98  }
99 
100  for (grn::dat::UInt32 i = 0; i <= grn::dat::MAX_BLOCK_LEVEL; ++i) {
101  cppcut_assert_equal(i + 1, header.ith_leader(i));
102  }
103  }
104 }