null+****@clear*****
null+****@clear*****
2011年 8月 9日 (火) 12:47:20 JST
Kouhei Sutou 2011-08-09 03:47:20 +0000 (Tue, 09 Aug 2011) New Revision: 0407e8ba7a1b56318a3281b0134cb768556322ea Log: [suggest][test] reduce database number of initialization. Modified files: test/unit/story/test-rurema.c Modified: test/unit/story/test-rurema.c (+26 -19) =================================================================== --- test/unit/story/test-rurema.c 2011-08-09 03:46:57 +0000 (e6819c3) +++ test/unit/story/test-rurema.c 2011-08-09 03:47:20 +0000 (cfff296) @@ -30,24 +30,37 @@ static gchar *tmp_directory; static grn_ctx *context; static grn_obj *database; +static void +remove_tmp_directory(void) +{ + cut_remove_path(tmp_directory, NULL); +} + void cut_startup(void) { tmp_directory = g_build_filename(grn_test_get_tmp_dir(), "rurema", NULL); + + remove_tmp_directory(); + g_mkdir_with_parents(tmp_directory, 0700); + + context = NULL; } void cut_shutdown(void) { - g_free(tmp_directory); -} + if (context) { + grn_obj_unlink(context, database); + grn_ctx_fin(context); + g_free(context); + } -static void -remove_tmp_directory(void) -{ - cut_remove_path(tmp_directory, NULL); + remove_tmp_directory(); + + g_free(tmp_directory); } void @@ -55,18 +68,19 @@ cut_setup(void) { const gchar *database_path; + if (context) { + return; + } + + context = g_new0(grn_ctx, 1); + grn_ctx_init(context, 0); + cut_set_fixture_data_dir(grn_test_get_base_dir(), "fixtures", "story", "rurema", NULL); - remove_tmp_directory(); - g_mkdir_with_parents(tmp_directory, 0700); - - context = g_new0(grn_ctx, 1); - grn_ctx_init(context, 0); - database_path = cut_build_path(tmp_directory, "database.groonga", NULL); database = grn_db_create(context, database_path, NULL); @@ -78,13 +92,6 @@ cut_setup(void) void cut_teardown(void) { - if (context) { - grn_obj_unlink(context, database); - grn_ctx_fin(context); - g_free(context); - } - - remove_tmp_directory(); } void