[Groonga-commit] groonga/groonga [master] [test] add missing file.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 5月 27日 (金) 18:54:22 JST


Kouhei Sutou	2011-05-27 09:54:22 +0000 (Fri, 27 May 2011)

  New Revision: 5f247a7e20902c6c884e374f6313374c37fe0390

  Log:
    [test] add missing file.

  Added files:
    test/unit/core/test-object.c
  Modified files:
    test/unit/core/Makefile.am

  Modified: test/unit/core/Makefile.am (+2 -2)
===================================================================
--- test/unit/core/Makefile.am    2011-05-27 06:13:01 +0000 (b50c5fa)
+++ test/unit/core/Makefile.am    2011-05-27 09:54:22 +0000 (6200fb0)
@@ -56,8 +56,8 @@ noinst_LTLIBRARIES =				\
 	test-command-dump.la			\
 	test-command-truncate.la		\
 	test-geo.la				\
-	test-accessor.la
-#	test-object.la
+	test-accessor.la			\
+	test-object.la
 endif
 
 INCLUDES =			\

  Added: test/unit/core/test-object.c (+119 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-object.c    2011-05-27 09:54:22 +0000 (e4c6cfc)
@@ -0,0 +1,119 @@
+/* -*- 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 "../../../config.h"
+
+#include <groonga.h>
+
+#include <gcutter.h>
+#include <glib/gstdio.h>
+
+#include "../lib/grn-assertions.h"
+
+void data_is_builtin(void);
+void test_is_builtin(gconstpointer data);
+
+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(),
+                                   "object",
+                                   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
+data_is_builtin(void)
+{
+#define ADD_DATUM(expected, name)                                       \
+  gcut_add_datum((expected ? "built-in -" #name : "custom - " #name),   \
+                 "expected", G_TYPE_BOOLEAN, expected,                  \
+                 "name", G_TYPE_STRING, name,                           \
+                 NULL)
+
+  ADD_DATUM(TRUE, "TokenBigram");
+#ifdef WITH_MECAB
+  ADD_DATUM(TRUE, "TokenMecab");
+#endif
+  ADD_DATUM(FALSE, "Users");
+  ADD_DATUM(FALSE, "Users.name");
+  ADD_DATUM(FALSE, "suggest");
+
+#undef ADD_DATUM
+}
+
+void
+test_is_builtin(gconstpointer data)
+{
+  const gchar *name;
+  grn_obj *object;
+
+  assert_send_command("register suggest/suggest");
+  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
+  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
+
+  name = gcut_data_get_string(data, "name");
+  object = grn_ctx_get(context, name, strlen(name));
+  if (gcut_data_get_string(data, "expected")) {
+    cut_assert_true(grn_obj_is_builtin(context, object));
+  } else {
+    cut_assert_false(grn_obj_is_builtin(context, object));
+  }
+}




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