[Groonga-commit] groonga/groonga at 1b057e2 [master] test: add a test for grn_operator_exec_equal()

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 10 14:50:48 JST 2015


Kouhei Sutou	2015-03-10 14:50:48 +0900 (Tue, 10 Mar 2015)

  New Revision: 1b057e263d3b815bb19723ab059e6adb15fc2d12
  https://github.com/groonga/groonga/commit/1b057e263d3b815bb19723ab059e6adb15fc2d12

  Message:
    test: add a test for grn_operator_exec_equal()

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

  Modified: test/unit/core/Makefile.am (+3 -1)
===================================================================
--- test/unit/core/Makefile.am    2015-03-10 14:27:42 +0900 (224a3fe)
+++ test/unit/core/Makefile.am    2015-03-10 14:50:48 +0900 (54dbdd5)
@@ -62,7 +62,8 @@ noinst_LTLIBRARIES =				\
 	test-rename.la				\
 	test-tokenizer.la			\
 	test-proc.la				\
-	test-uvector.la
+	test-uvector.la				\
+	test-operator.la
 endif
 
 AM_CPPFLAGS =			\
@@ -150,3 +151,4 @@ test_rename_la_SOURCES			= test-rename.c
 test_tokenizer_la_SOURCES		= test-tokenizer.c
 test_proc_la_SOURCES			= test-proc.c
 test_uvector_la_SOURCES			= test-uvector.c
+test_operator_la_SOURCES		= test-operator.c

  Added: test/unit/core/test-operator.c (+131 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-operator.c    2015-03-10 14:50:48 +0900 (4f590f3)
@@ -0,0 +1,131 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2015  Kouhei Sutou <kou �� clear-code.com>
+
+  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <groonga.h>
+
+#include <gcutter.h>
+#include <glib/gstdio.h>
+
+#include "../lib/grn-assertions.h"
+
+#define get(name) grn_ctx_get(context, name, strlen(name))
+
+void data_exec_equal_true(void);
+void test_exec_equal_true(gconstpointer data);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+static grn_obj lhs;
+static grn_obj rhs;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
+                                   "operator",
+                                   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)
+{
+  const gchar *database_path;
+
+  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);
+
+  GRN_VOID_INIT(&lhs);
+  GRN_VOID_INIT(&rhs);
+}
+
+void
+cut_teardown(void)
+{
+  GRN_OBJ_FIN(context, &lhs);
+  GRN_OBJ_FIN(context, &rhs);
+
+  grn_obj_close(context, database);
+  grn_ctx_fin(context);
+  g_free(context);
+
+  remove_tmp_directory();
+}
+
+static void
+set_one(grn_obj *value, const gchar *type)
+{
+  if (strcmp(type, "text") == 0) {
+    grn_obj_reinit(context, value, GRN_DB_TEXT, 0);
+    GRN_TEXT_SETS(context, value, "1");
+  } else if (strcmp(type, "int32") == 0) {
+    grn_obj_reinit(context, value, GRN_DB_INT32, 0);
+    GRN_INT32_SET(context, value, 1);
+  }
+}
+
+void
+data_exec_equal_true(void)
+{
+#define ADD_DATA(lhs_type, rhs_type)                            \
+  gcut_add_datum(lhs_type " == " rhs_type,                      \
+                 "lhs_type", G_TYPE_STRING, lhs_type,           \
+                 "rhs_type", G_TYPE_STRING, rhs_type,           \
+                 NULL)
+
+  ADD_DATA("text", "text");
+  ADD_DATA("text", "int32");
+  ADD_DATA("int32", "text");
+
+#undef ADD_DATA
+}
+
+void
+test_exec_equal_true(gconstpointer data)
+{
+  const gchar *lhs_type;
+  const gchar *rhs_type;
+
+  lhs_type = gcut_data_get_string(data, "lhs_type");
+  rhs_type = gcut_data_get_string(data, "rhs_type");
+
+  set_one(&lhs, lhs_type);
+  set_one(&rhs, rhs_type);
+
+  cut_assert_true(grn_operator_exec_equal(context, &lhs, &rhs));
+}
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index