Navigation Menu

Skip to content

Commit

Permalink
add mrn_close function and test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikdttr committed Jun 30, 2009
1 parent b362f88 commit cf552e5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/driver.c
Expand Up @@ -382,3 +382,16 @@ int mrn_open(grn_ctx *ctx, mrn_obj_info *info)
info->table->obj = NULL;
return -1;
}

int mrn_close(grn_ctx *ctx, mrn_obj_info *info)
{
int i;
for (i=0; i < info->n_columns; i++)
{
grn_obj_close(ctx, info->columns[i]->obj);
info->columns[i]->obj = NULL;
}
grn_obj_close(ctx, info->table->obj);
info->table->obj = NULL;
return 0;
}
39 changes: 39 additions & 0 deletions test/unit/test-driver.c
Expand Up @@ -229,3 +229,42 @@ void test_mrn_open()
grn_obj_remove(ctx, info->table->obj);
mrn_deinit_obj_info(ctx, info);
}

void test_mrn_close()
{
TEST_ENTER;
grn_obj *obj,*obj2;

mrn_obj_info *info = mrn_init_obj_info(ctx, 2);

info->table->name = "test/t1";
info->table->name_size = strlen("test/t1");
info->table->flags |= GRN_OBJ_TABLE_NO_KEY;

info->columns[0]->name = "c1";
info->columns[0]->name_size = strlen("c1");
info->columns[0]->flags |= GRN_OBJ_COLUMN_SCALAR;
info->columns[0]->type = grn_ctx_at(ctx, GRN_DB_INT32);

info->columns[1]->name = "c2";
info->columns[1]->name_size = strlen("c2");
info->columns[1]->flags |= GRN_OBJ_COLUMN_SCALAR;
info->columns[1]->type = grn_ctx_at(ctx, GRN_DB_TEXT);

cut_assert_equal_int(0, mrn_create(ctx, info));
cut_assert_equal_int(0, mrn_open(ctx, info));
cut_assert_not_null(info->table->obj);
cut_assert_not_null(info->columns[0]->obj);
cut_assert_not_null(info->columns[1]->obj);

cut_assert_equal_int(0, mrn_close(ctx, info));
cut_assert_null(info->table->obj);
cut_assert_null(info->columns[0]->obj);
cut_assert_null(info->columns[1]->obj);

cut_assert_equal_int(0, mrn_open(ctx, info));
grn_obj_remove(ctx, info->columns[1]->obj);
grn_obj_remove(ctx, info->columns[0]->obj);
grn_obj_remove(ctx, info->table->obj);
mrn_deinit_obj_info(ctx, info);
}

0 comments on commit cf552e5

Please sign in to comment.