Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-key.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/key.hpp>
24 
25 #include <cstring>
26 #include <iostream>
27 
28 #include "test-string.hpp"
29 
30 namespace test_dat_key
31 {
33  {
34  cppcut_assert_equal(grn::dat::UInt32(2), grn::dat::Key::estimate_size(0));
35  cppcut_assert_equal(grn::dat::UInt32(2), grn::dat::Key::estimate_size(3));
36 
37  cppcut_assert_equal(grn::dat::UInt32(3), grn::dat::Key::estimate_size(4));
38  cppcut_assert_equal(grn::dat::UInt32(3), grn::dat::Key::estimate_size(7));
39  }
40 
41  void test_invalid_key(void)
42  {
44 
45  cppcut_assert_equal(grn::dat::INVALID_KEY_ID, key.id());
46  cppcut_assert_equal(grn::dat::UInt32(0), key.length());
47  cppcut_assert_not_null(key.ptr());
48  }
49 
50  void test_creation(void)
51  {
52  grn::dat::UInt32 buf[16];
53  const grn::dat::Key &key = grn::dat::Key::create(buf, 123, "groonga", 7);
54 
55  cppcut_assert_equal(grn::dat::String("groonga"), key.str());
56  cppcut_assert_equal(grn::dat::UInt32(123), key.id());
57  cppcut_assert_equal(grn::dat::UInt32(7), key.length());
58  cppcut_assert_equal(0, std::memcmp(key.ptr(), "groonga", 7));
59  cppcut_assert_equal(reinterpret_cast<const char *>(buf) + 5,
60  static_cast<const char *>(key.ptr()));
61  }
62 }