Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-array.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2011-2012 Brazil
4  Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License version 2.1 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include <gcutter.h>
21 #include <cppcutter.h>
22 
23 #include <grn-assertions.h>
24 #include <dat/array.hpp>
25 
26 namespace test_dat_array
27 {
29  {
30  char buf[] = "This is a pen.";
31 
33 
34  array.assign(buf, sizeof(buf));
35  cppcut_assert_equal(buf, array.ptr());
36  cppcut_assert_equal(sizeof(buf), static_cast<size_t>(array.size()));
37 
38  for (std::size_t i = 0; i < sizeof(buf); ++i) {
39  cppcut_assert_equal(buf[i], array[i]);
40  cppcut_assert_equal(buf[i],
41  static_cast<const grn::dat::Array<char> &>(array)[i]);
42  }
43  cppcut_assert_equal(buf, array.begin());
44  cppcut_assert_equal(buf,
45  static_cast<const grn::dat::Array<char> &>(array).begin());
46  cppcut_assert_equal((buf + sizeof(buf)), array.end());
47  cppcut_assert_equal((buf + sizeof(buf)),
48  static_cast<const grn::dat::Array<char> &>(array).end());
49  }
50 
52  {
53  char buf[] = "This is a pen.";
54 
56 
57  array.assign(buf);
58  cppcut_assert_equal(buf, array.ptr());
59  cppcut_assert_equal(sizeof(buf), static_cast<size_t>(array.size()));
60  }
61 
62  void test_copy(void)
63  {
64  char buf[] = "This is a pen.";
65 
66  grn::dat::Array<char> clone(buf);
67  cppcut_assert_equal(buf, clone.ptr());
68  cppcut_assert_equal(sizeof(buf), static_cast<size_t>(clone.size()));
69  }
70 
72  {
73  char buf[] = "This is a pen.";
74 
75  grn::dat::Array<char> clone(buf, sizeof(buf));
76  cppcut_assert_equal(buf, clone.ptr());
77  cppcut_assert_equal(sizeof(buf), static_cast<size_t>(clone.size()));
78  }
79 }