53 startup_hash_common();
59 shutdown_hash_common();
65 setup_hash_common(
"hash");
73 g_array_free(ids,
TRUE);
81 teardown_hash_common();
85 set_key_size_to_zero(
void)
91 set_value_size_to_zero(
void)
97 set_variable_size(
void)
104 set_tiny_flags_and_variable_size(
void)
111 set_not_uint32_key_size(
void)
114 key_size = not_uint32_key_size;
118 set_tiny_flags_and_not_uint32_key_size(
void)
121 set_not_uint32_key_size();
128 cut_add_data(
"default", NULL, NULL,
129 "zero key size", set_key_size_to_zero, NULL,
130 "zero value size", set_value_size_to_zero, NULL);
146 cut_add_data(
"default", NULL, NULL,
147 "zero key size", set_key_size_to_zero, NULL,
148 "zero value size", set_value_size_to_zero, NULL);
165 const gchar *saved_default_path;
172 cut_assert_path_not_exist(saved_default_path);
174 cut_assert_path_not_exist(saved_default_path);
176 cut_assert_path_not_exist(saved_default_path);
206 test_data->
key = key;
216 g_free(test_data->
key);
227 for (i = 0; i < n; i++) {
229 key_size = strlen(test_data->
key);
232 g_array_append_val(ids,
id);
237 uint32_key_new(uint32_t key)
239 uint32_t *key_pointer;
241 key_pointer = g_new0(uint32_t, 1);
250 uint32_t *key_pointer = test_data->
key;
257 gchar *original_string = test_data->
key;
261 last = strlen(original_string);
262 if (original_string[last - 1] <
'X') {
263 original_string[last - 1]++;
265 string = g_strconcat(test_data->
key,
"A", NULL);
266 g_free(test_data->
key);
267 test_data->
key = string;
274 gchar *
string = test_data->
key;
277 for (i = 0; i < not_uint32_key_size; i++) {
278 if (
string[i] <
'~') {
283 cut_error(
"can't increment more!: %s",
string);
287 add_variable_key_size_test_data(
void)
289 cut_add_data(
"uint32 - default",
290 test_data_new(uint32_key_new(29), uint32_increment,
294 test_data_new(uint32_key_new(29), uint32_increment,
297 "variable size - short - default",
298 test_data_new(g_strdup(
"X"), string_increment,
301 "variable size - short - tiny",
302 test_data_new(g_strdup(
"X"), string_increment,
303 set_tiny_flags_and_variable_size),
305 "variable size - long - default",
306 test_data_new(g_strdup(
"must be long rather than sizeof(char *)"),
310 "variable size - long - tiny",
311 test_data_new(g_strdup(
"must be long rather than sizeof(char *)"),
313 set_tiny_flags_and_variable_size),
315 "not uint32 size - default",
316 test_data_new(g_strdup(not_uint32_size_key),
317 not_uint32_size_key_increment,
318 set_not_uint32_key_size),
320 "not uint32 size - tiny",
321 test_data_new(g_strdup(not_uint32_size_key),
322 not_uint32_size_key_increment,
323 set_tiny_flags_and_not_uint32_key_size),
330 add_variable_key_size_test_data();
344 key_size = strlen(test_data->
key);
349 #define put_sample_entry() do \
351 grn_search_flags flags; \
353 flags = GRN_TABLE_ADD; \
354 cut_assert_lookup(&sample_key, &flags); \
355 cut_assert(flags & 1); \
359 #define cut_assert_delete_by_id() do \
361 grn_search_flags flags; \
363 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
364 grn_hash_delete_by_id(context, hash, 0, NULL)); \
366 put_sample_entry(); \
369 cut_assert_lookup(&sample_key, &flags); \
371 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
372 grn_hash_delete_by_id(context, \
373 NULL, sample_id, NULL)); \
374 grn_test_assert(grn_hash_delete_by_id(context, hash, sample_id, NULL)); \
375 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
376 grn_hash_delete_by_id(context, \
377 hash, sample_id, NULL)); \
380 cut_assert_lookup_failed(&sample_key, &flags); \
386 cut_add_data(
"default", NULL, NULL,
387 "tiny", set_tiny_flags, NULL);
403 #define cut_assert_delete(key) do \
406 grn_search_flags flags; \
410 flags = GRN_TABLE_ADD; \
411 cut_assert_lookup(_key, &flags); \
413 grn_test_assert(grn_hash_delete(context, hash, _key, key_size, NULL)); \
414 grn_test_assert_equal_rc(GRN_INVALID_ARGUMENT, \
415 grn_hash_delete(context, \
416 hash, _key, key_size, NULL)); \
419 cut_assert_lookup_failed(_key, &flags); \
425 add_variable_key_size_test_data();
439 key_size = strlen(test_data->
key);
446 cut_add_data(
"default", NULL, NULL,
447 "tiny", set_tiny_flags, NULL);
455 uint32_t initial_key = 999999;
467 got_key = initial_key;
468 cut_assert_equal_int(key_size,
470 cut_assert_equal_uint(key, got_key);
476 cut_add_data(
"default", NULL, NULL,
477 "tiny", set_tiny_flags, NULL);
485 gchar set_value[] =
"ABCDE";
486 gchar initial_value[] =
"XYZ";
497 strcpy(value, set_value);
499 strcpy(got_value, initial_value);
502 cut_assert_equal_string(set_value, got_value);
508 cut_add_data(
"default", NULL, NULL,
509 "tiny", set_tiny_flags, NULL);
529 cut_assert_equal_string(
"XXX", got_value);
535 cut_add_data(
"default", NULL, NULL,
536 "tiny", set_tiny_flags, NULL);
543 grn_id nonexistence_id = 999;
562 add_variable_key_size_test_data();
570 const guint n_operations = 750;
579 test_data_add_n_data(n_operations, test_data);
582 for (i = 0; i < ids->len; i++) {
585 delete_id = g_array_index(ids,
grn_id, i);
587 cut_message(
"i = %d; id = %d", i, delete_id));
595 add_variable_key_size_test_data();
611 test_data_add_n_data(n_data, test_data);