void test_array_truncate(void) { grn_obj *table; gchar value[] = "sample value"; gchar *value_type_name = "value_type"; grn_obj *value_type; cut_omit("grn_table_truncate() is still buggy."); value_type = grn_type_create(context, value_type_name, strlen(value_type_name), 0, sizeof(value)); table = grn_table_create(context, NULL, 0, NULL, GRN_OBJ_TABLE_NO_KEY, NULL, value_type); grn_test_assert_not_nil(grn_table_add(context, table, NULL, 0, NULL)); cut_assert_equal_uint(1, grn_table_size(context, table)); grn_test_assert(grn_table_truncate(context, table)); cut_assert_equal_uint(0, grn_table_size(context, table)); }
void test_truncate_anonymous(gconstpointer data) { grn_obj_flags flags; const gchar *key; grn_obj *key_type; unsigned key_size; grn_bool array_p; int added; flags = gcut_data_get_int(data, "flags"); array_p = ((flags & GRN_OBJ_TABLE_TYPE_MASK) == GRN_OBJ_TABLE_NO_KEY); if (array_p) { key = NULL; key_size = 0; key_type = NULL; } else { key = "groonga"; key_size = strlen(key); key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT); } table = grn_table_create(context, NULL, 0, NULL, flags, key_type, NULL); if (key_type) { grn_obj_unlink(context, key_type); } grn_test_assert_not_nil(grn_table_add(context, table, key, key_size, &added)); cut_assert_true(added); cut_assert_equal_uint(1, grn_table_size(context, table)); grn_test_assert(grn_table_truncate(context, table)); cut_assert_equal_uint(0, grn_table_size(context, table)); }
void test_truncate_named(gconstpointer data) { grn_obj_flags flags; const gchar *table_name = "SearchEngines"; const gchar *key; grn_obj *key_type; unsigned key_size; const gchar *column_name = "description"; grn_obj *column_type; const gchar *column_value = "An open-source fulltext search engine"; grn_bool array_p; grn_id record_id; int added; flags = gcut_data_get_int(data, "flags"); array_p = ((flags & GRN_OBJ_TABLE_TYPE_MASK) == GRN_OBJ_TABLE_NO_KEY); if (array_p) { key = NULL; key_size = 0; key_type = NULL; } else { key = "groonga"; key_size = strlen(key); key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT); } table = grn_table_create(context, table_name, strlen(table_name), NULL, flags | GRN_OBJ_PERSISTENT, key_type, NULL); if (key_type) { grn_obj_unlink(context, key_type); } grn_test_assert_context(context); column_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT); column = grn_column_create(context, table, column_name, strlen(column_name), NULL, GRN_OBJ_COLUMN_SCALAR | GRN_OBJ_PERSISTENT, column_type); grn_obj_unlink(context, column_type); grn_test_assert_context(context); record_id = grn_table_add(context, table, key, key_size, &added); grn_test_assert_not_nil(record_id); cut_assert_true(added); grn_obj_reinit(context, &buffer, GRN_DB_SHORT_TEXT, 0); GRN_TEXT_PUTS(context, &buffer, column_value); grn_test_assert(grn_obj_set_value(context, column, record_id, &buffer, GRN_OBJ_SET)); GRN_BULK_REWIND(&buffer); grn_obj_get_value(context, column, record_id, &buffer); GRN_TEXT_PUTC(context, &buffer, '\0'); cut_assert_equal_string(column_value, GRN_TEXT_VALUE(&buffer)); cut_assert_equal_uint(1, grn_table_size(context, table)); grn_test_assert(grn_table_truncate(context, table)); GRN_BULK_REWIND(&buffer); grn_obj_get_value(context, column, record_id, &buffer); GRN_TEXT_PUTC(context, &buffer, '\0'); cut_assert_equal_string("", GRN_TEXT_VALUE(&buffer)); cut_assert_equal_uint(0, grn_table_size(context, table)); }