null+****@clear*****
null+****@clear*****
2010年 6月 24日 (木) 11:49:15 JST
Kouhei Sutou 2010-06-24 02:49:15 +0000 (Thu, 24 Jun 2010) New Revision: 7c9ed8830323c3d60d055ea347ec57605be714b8 Log: add a test for cache_limit command. Added files: test/unit/core/test-command-cache-limit.c Modified files: test/unit/core/Makefile.am Modified: test/unit/core/Makefile.am (+3 -1) =================================================================== --- test/unit/core/Makefile.am 2010-06-24 02:11:13 +0000 (469ac00) +++ test/unit/core/Makefile.am 2010-06-24 02:49:15 +0000 (ddb2d18) @@ -38,7 +38,8 @@ noinst_LTLIBRARIES = \ test-inspect.la \ test-command-load.la \ test-command-column-list.la \ - test-command-select.la + test-command-select.la \ + test-command-cache-limit.la endif INCLUDES = \ @@ -101,3 +102,4 @@ test_inspect_la_SOURCES = test-inspect.c test_command_load_la_SOURCES = test-command-load.c test_command_column_list_la_SOURCES = test-command-column-list.c test_command_select_la_SOURCES = test-command-select.c +test_command_cache_limit_la_SOURCES = test-command-cache-limit.c Added: test/unit/core/test-command-cache-limit.c (+107 -0) 100644 =================================================================== --- /dev/null +++ test/unit/core/test-command-cache-limit.c 2010-06-24 02:49:15 +0000 (cdfdc2d) @@ -0,0 +1,107 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2010 Kouhei Sutou <kou****@clear*****> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <gcutter.h> +#include <glib/gstdio.h> + +#include "../lib/grn-assertions.h" + +#include <ctx.h> + +void test_get(void); +void test_set(void); +void test_set_minus(void); + +static gchar *tmp_directory; + +static grn_ctx *context; +static grn_obj *database; + +static uint32_t default_cache_n_entries; + +void +cut_startup(void) +{ + tmp_directory = g_build_filename(grn_test_get_base_dir(), + "tmp", + "cache-limit", + NULL); + default_cache_n_entries = *grn_cache_max_nentries(); +} + +void +cut_shutdown(void) +{ + g_free(tmp_directory); +} + +static void +remove_tmp_directory(void) +{ + cut_remove_path(tmp_directory, NULL); +} + +void +cut_setup(void) +{ + const gchar *database_path; + uint32_t *cache_max_n_entries; + + 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); + + cache_max_n_entries = grn_cache_max_nentries(); + *cache_max_n_entries = default_cache_n_entries; +} + +void +cut_teardown(void) +{ + if (context) { + grn_ctx_fin(context); + g_free(context); + } + + remove_tmp_directory(); +} + +void +test_get(void) +{ + cut_assert_equal_string("100", send_command("cache_limit")); +} + +void +test_set(void) +{ + cut_assert_equal_string("100", send_command("cache_limit --max 1000")); + cut_assert_equal_string("1000", send_command("cache_limit")); +} + +void +test_set_minus(void) +{ + cut_assert_equal_string("100", send_command("cache_limit --max -1")); + cut_assert_equal_string("should report error", send_command("cache_limit")); +}