Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-tiny-array.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2012 Brazil Inc.
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 <glib/gstdio.h>
21 
22 #include "../lib/grn-assertions.h"
23 
24 #include <string.h>
25 
26 #include <hash.h>
27 
28 static grn_ctx ctx;
29 
30 void
31 cut_setup(void)
32 {
33  grn_ctx_init(&ctx, 0);
34 }
35 
36 void
38 {
39  grn_ctx_fin(&ctx);
40 }
41 
42 void
43 test_basic_operations(uint16_t element_size, uint16_t flags)
44 {
45  grn_id id;
46  grn_tiny_array array;
47  grn_tiny_array_init(&ctx, &array, element_size, flags);
48  cut_assert_null(grn_tiny_array_at(&array, 0));
49  for (id = 1; id < (1 << 8); id++) {
50  void * const ptr = grn_tiny_array_at(&array, id);
51  cut_assert_not_null(ptr);
52  memset(ptr, (unsigned char)id, element_size);
53  }
54  for (id = 1; id < (1 << 8); id++) {
55  uint16_t byte_id;
56  const unsigned char expected_byte = (unsigned char)id;
57  const unsigned char * const ptr =
58  (const unsigned char *)grn_tiny_array_at(&array, id);
59  for (byte_id = 0; byte_id < element_size; byte_id++) {
60  cut_assert_equal_int(expected_byte, ptr[byte_id]);
61  }
62  }
63  grn_tiny_array_fin(&array);
64 }
65 
66 void
67 test_at(void)
68 {
69  uint16_t element_size;
70  for (element_size = 1; element_size < 16; element_size++) {
71  test_basic_operations(element_size, 0);
72  }
73 }
74 
75 void
76 test_id(void)
77 {
78  grn_id id;
79  grn_tiny_array array;
80  grn_tiny_array_init(&ctx, &array, sizeof(int), GRN_TINY_ARRAY_CLEAR);
81  grn_test_assert_equal_id(&ctx, (grn_id)0, grn_tiny_array_id(&array, NULL));
82  for (id = 1; id < (1 << 10); id++) {
83  const void * const ptr = grn_tiny_array_at(&array, id);
84  cut_assert_not_null(ptr);
85  grn_test_assert_equal_id(&ctx, (grn_id)id, grn_tiny_array_id(&array, ptr));
86  }
87  grn_tiny_array_fin(&array);
88 }
89 
90 void
92 {
93  grn_id id;
94  grn_tiny_array array;
95  grn_tiny_array_init(&ctx, &array, sizeof(int), GRN_TINY_ARRAY_CLEAR);
96  for (id = 1; id < (1 << 10); id++) {
97  const int expected_value = 0;
98  const int * const value_ptr = (const int *)grn_tiny_array_at(&array, id);
99  cut_assert_not_null(value_ptr);
100  cut_assert_equal_memory(&expected_value, sizeof(expected_value),
101  value_ptr, sizeof(int));
102  }
103  grn_tiny_array_fin(&array);
104 
105  {
106  uint16_t element_size;
107  for (element_size = 1; element_size < 16; element_size++) {
109  }
110  }
111 }
112 
113 void
115 {
116  /* TODO: A multi-threaded test should be done. */
117 
118  uint16_t element_size;
119  for (element_size = 1; element_size < 16; element_size++) {
121  }
122 }
123 
124 void
126 {
127  uint16_t element_size;
128  for (element_size = 1; element_size < 16; element_size++) {
130  }
131 }