[Groonga-commit] groonga/groonga [master] add more information to invalid name error. fixes #935

Back to archive index

null+****@clear***** null+****@clear*****
2011年 5月 27日 (金) 15:13:01 JST


Kouhei Sutou	2011-05-27 06:13:01 +0000 (Fri, 27 May 2011)

  New Revision: ea823f82545155b9dec4de3a3fea9dcfad08e105

  Log:
    add more information to invalid name error. fixes #935

  Added files:
    test/unit/core/test-command-column-create.c
    test/unit/core/test-command-table-create.c
  Modified files:
    lib/db.c
    lib/db.h
    lib/expr.c
    test/unit/core/Makefile.am
    test/unit/core/test-table.c

  Modified: lib/db.c (+5 -5)
===================================================================
--- lib/db.c    2011-05-27 02:17:55 +0000 (9471747)
+++ lib/db.c    2011-05-27 06:13:01 +0000 (755b6a8)
@@ -306,7 +306,7 @@ grn_type_create(grn_ctx *ctx, const char *name, unsigned name_size,
   }
   GRN_API_ENTER;
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[type][create]", name, name_size);
     GRN_API_RETURN(NULL);
   }
   if (!GRN_DB_P(db)) {
@@ -359,7 +359,7 @@ grn_proc_create(grn_ctx *ctx, const char *name, unsigned name_size, grn_proc_typ
   GRN_API_ENTER;
   range = path ? grn_plugin_get(ctx, path) : GRN_ID_NIL;
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[proc][create]", name, name_size);
     GRN_API_RETURN(NULL);
   }
   if (!GRN_DB_P(db)) {
@@ -495,7 +495,7 @@ grn_table_create(grn_ctx *ctx, const char *name, unsigned name_size,
   }
   GRN_API_ENTER;
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[table][create]", name, name_size);
     GRN_API_RETURN(NULL);
   }
   if (!GRN_DB_P(db)) {
@@ -2822,7 +2822,7 @@ grn_column_create(grn_ctx *ctx, grn_obj *table,
     GRN_LOG(ctx, GRN_LOG_NOTICE, "DDL:column_create %.*s %.*s", s, n, name_size, name);
   }
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[column][create]", name, name_size);
     goto exit;
   }
   if ((domain = DB_OBJ(table)->id)) {
@@ -2934,7 +2934,7 @@ grn_column_open(grn_ctx *ctx, grn_obj *table,
     goto exit;
   }
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[column][open]", name, name_size);
     goto exit;
   }
   if ((domain = DB_OBJ(table)->id)) {

  Modified: lib/db.h (+1 -1)
===================================================================
--- lib/db.h    2011-05-27 02:17:55 +0000 (cd4e0aa)
+++ lib/db.h    2011-05-27 06:13:01 +0000 (a79435b)
@@ -349,7 +349,7 @@ grn_obj *grn_column_open(grn_ctx *ctx, grn_obj *table,
 grn_rc grn_obj_rename(grn_ctx *ctx, const char *old_path, const char *new_path);
 
 grn_rc grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size);
-#define GRN_DB_CHECK_NAME_ERR(name, name_size) ERR(GRN_INVALID_ARGUMENT, "name can't start with '%c' and 0-9, and contains only 0-9, A-Z, a-z, or _: <%.*s>", GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
+#define GRN_DB_CHECK_NAME_ERR(error_context, name, name_size) ERR(GRN_INVALID_ARGUMENT, "%s: name can't start with '%c' and 0-9, and contains only 0-9, A-Z, a-z, or _: <%.*s>", error_context, GRN_DB_PSEUDO_COLUMN_PREFIX, name_size, name)
 
 #define GRN_DB_P(s) ((s) && ((grn_db *)s)->obj.header.type == GRN_DB)
 #define GRN_DB_PERSISTENT_P(s) (((grn_db *)s)->specs)

  Modified: lib/expr.c (+1 -1)
===================================================================
--- lib/expr.c    2011-05-27 02:17:55 +0000 (569818a)
+++ lib/expr.c    2011-05-27 06:13:01 +0000 (c33a58c)
@@ -547,7 +547,7 @@ grn_expr_create(grn_ctx *ctx, const char *name, unsigned name_size)
   }
   GRN_API_ENTER;
   if (grn_db_check_name(ctx, name, name_size)) {
-    GRN_DB_CHECK_NAME_ERR(name, name_size);
+    GRN_DB_CHECK_NAME_ERR("[expr][create]", name, name_size);
     GRN_API_RETURN(NULL);
   }
   if (!GRN_DB_P(db)) {

  Modified: test/unit/core/Makefile.am (+4 -0)
===================================================================
--- test/unit/core/Makefile.am    2011-05-27 02:17:55 +0000 (c527897)
+++ test/unit/core/Makefile.am    2011-05-27 06:13:01 +0000 (b50c5fa)
@@ -40,7 +40,9 @@ noinst_LTLIBRARIES =				\
 	test-table-sort-key-from-str.la		\
 	test-inspect.la				\
 	test-command-load.la			\
+	test-command-table-create.la		\
 	test-command-table-list.la		\
+	test-command-column-create.la		\
 	test-command-column-list.la		\
 	test-command-select.la			\
 	test-command-select-sort.la		\
@@ -119,7 +121,9 @@ test_log_la_SOURCES			= test-log.c
 test_table_sort_key_from_str_la_SOURCES	= test-table-sort-key-from-str.c
 test_inspect_la_SOURCES			= test-inspect.c
 test_command_load_la_SOURCES		= test-command-load.c
+test_command_table_create_la_SOURCES	= test-command-table-create.c
 test_command_table_list_la_SOURCES	= test-command-table-list.c
+test_command_column_create_la_SOURCES	= test-command-column-create.c
 test_command_column_list_la_SOURCES	= test-command-column-list.c
 test_command_select_la_SOURCES		= test-command-select.c
 test_command_select_sort_la_SOURCES	= test-command-select-sort.c

  Added: test/unit/core/test-command-column-create.c (+89 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-column-create.c    2011-05-27 06:13:01 +0000 (59099e5)
@@ -0,0 +1,89 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  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 <str.h>
+
+void test_invalid_name(void);
+
+static gchar *tmp_directory;
+static const gchar *database_path;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+                                   "column-create",
+                                   NULL);
+}
+
+void
+cut_shutdown(void)
+{
+  g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+  cut_remove_path(tmp_directory, NULL);
+}
+
+void
+cut_setup(void)
+{
+  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);
+}
+
+void
+cut_teardown(void)
+{
+  if (context) {
+    grn_obj_close(context, database);
+    grn_ctx_fin(context);
+    g_free(context);
+  }
+
+  remove_tmp_directory();
+}
+
+void
+test_invalid_name(void)
+{
+  assert_send_command("table_create Users");
+  grn_test_assert_send_command_error(
+    context,
+    GRN_INVALID_ARGUMENT,
+    "[column][create]: name can't start with '_' and 0-9, "
+    "and contains only 0-9, A-Z, a-z, or _: <_name>",
+    "column_create Users _name COLUMN_SCALAR ShortText");
+}

  Added: test/unit/core/test-command-table-create.c (+88 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-table-create.c    2011-05-27 06:13:01 +0000 (549a713)
@@ -0,0 +1,88 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2011  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 <str.h>
+
+void test_invalid_name(void);
+
+static gchar *tmp_directory;
+static const gchar *database_path;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+                                   "table-create",
+                                   NULL);
+}
+
+void
+cut_shutdown(void)
+{
+  g_free(tmp_directory);
+}
+
+static void
+remove_tmp_directory(void)
+{
+  cut_remove_path(tmp_directory, NULL);
+}
+
+void
+cut_setup(void)
+{
+  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);
+}
+
+void
+cut_teardown(void)
+{
+  if (context) {
+    grn_obj_close(context, database);
+    grn_ctx_fin(context);
+    g_free(context);
+  }
+
+  remove_tmp_directory();
+}
+
+void
+test_invalid_name(void)
+{
+  grn_test_assert_send_command_error(
+    context,
+    GRN_INVALID_ARGUMENT,
+    "[table][create]: name can't start with '_' and 0-9, "
+    "and contains only 0-9, A-Z, a-z, or _: <_Users>",
+    "table_create _Users");
+}

  Modified: test/unit/core/test-table.c (+1 -1)
===================================================================
--- test/unit/core/test-table.c    2011-05-27 02:17:55 +0000 (8bf7aac)
+++ test/unit/core/test-table.c    2011-05-27 06:13:01 +0000 (a50d192)
@@ -418,7 +418,7 @@ test_create_with_invalid_name(gpointer data)
                            NULL, NULL);
   grn_test_assert_error(
     GRN_INVALID_ARGUMENT,
-    cut_take_printf("name can't start with '_' and "
+    cut_take_printf("[table][create]: name can't start with '_' and "
                     "0-9, and contains only 0-9, A-Z, a-z, or _: <%s>",
                     table_name),
     context);




Groonga-commit メーリングリストの案内
Back to archive index