[Groonga-commit] groonga/groonga at 8014479 [master] Add grn_type_id_is_text_family()

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Fri Apr 8 18:47:40 JST 2016


Kouhei Sutou	2016-04-08 18:47:40 +0900 (Fri, 08 Apr 2016)

  New Revision: 8014479c15a626c0b6eb40c51144d81e19547577
  https://github.com/groonga/groonga/commit/8014479c15a626c0b6eb40c51144d81e19547577

  Message:
    Add grn_type_id_is_text_family()

  Modified files:
    include/groonga/type.h
    lib/type.c
    test/unit/core/test-type.c

  Modified: include/groonga/type.h (+4 -1)
===================================================================
--- include/groonga/type.h    2016-04-08 18:45:05 +0900 (b514603)
+++ include/groonga/type.h    2016-04-08 18:47:40 +0900 (c68dcd1)
@@ -22,11 +22,14 @@
 extern "C" {
 #endif
 
+/* Just for backward compatibility.
+   Use grn_type_id_is_text_family() instead. */
 #define GRN_TYPE_IS_TEXT_FAMILY(type)                           \
-  (GRN_DB_SHORT_TEXT <= (type) && (type) <= GRN_DB_LONG_TEXT)
+  grn_type_id_is_text_family(NULL, (type))
 
 GRN_API grn_bool grn_type_id_is_builtin(grn_ctx *ctx, grn_id id);
 GRN_API grn_bool grn_type_id_is_number_family(grn_ctx *ctx, grn_id id);
+GRN_API grn_bool grn_type_id_is_text_family(grn_ctx *ctx, grn_id id);
 
 GRN_API grn_obj *grn_type_create(grn_ctx *ctx, const char *name, unsigned int name_size,
                                  grn_obj_flags flags, unsigned int size);

  Modified: lib/type.c (+6 -0)
===================================================================
--- lib/type.c    2016-04-08 18:45:05 +0900 (d21c23e)
+++ lib/type.c    2016-04-08 18:47:40 +0900 (8c2c2d8)
@@ -31,6 +31,12 @@ grn_type_id_is_number_family(grn_ctx *ctx, grn_id id)
   return GRN_DB_INT8 <= id && id <= GRN_DB_FLOAT;
 }
 
+grn_bool
+grn_type_id_is_text_family(grn_ctx *ctx, grn_id id)
+{
+  return GRN_DB_SHORT_TEXT <= id && id <= GRN_DB_LONG_TEXT;
+}
+
 grn_obj *
 grn_type_create(grn_ctx *ctx, const char *name, unsigned int name_size,
                 grn_obj_flags flags, unsigned int size)

  Modified: test/unit/core/test-type.c (+37 -0)
===================================================================
--- test/unit/core/test-type.c    2016-04-08 18:45:05 +0900 (ed6cc3c)
+++ test/unit/core/test-type.c    2016-04-08 18:47:40 +0900 (c7c7c9e)
@@ -29,6 +29,8 @@ void data_id_is_builtin(void);
 void test_id_is_builtin(gconstpointer data);
 void data_id_is_number_family(void);
 void test_id_is_number_family(gconstpointer data);
+void data_id_is_text_family(void);
+void test_id_is_text_family(gconstpointer data);
 
 static gchar *tmp_directory;
 static const gchar *database_path;
@@ -157,3 +159,38 @@ test_id_is_number_family(gconstpointer data)
     cut_assert_false(grn_type_id_is_number_family(context, id));
   }
 }
+
+void
+data_id_is_text_family(void)
+{
+#define ADD_DATUM(expected, name)                                       \
+  gcut_add_datum((expected ? "text-family - " name : "column - " name), \
+                 "expected", G_TYPE_BOOLEAN, expected,                  \
+                 "name", G_TYPE_STRING, name,                           \
+                 NULL)
+
+  ADD_DATUM(TRUE, "ShortText");
+  ADD_DATUM(TRUE, "Text");
+  ADD_DATUM(TRUE, "LongText");
+  ADD_DATUM(FALSE, "Time");
+  ADD_DATUM(FALSE, "TokyoGeoPoint");
+
+#undef ADD_DATUM
+}
+
+void
+test_id_is_text_family(gconstpointer data)
+{
+  const gchar *name;
+  grn_obj *object;
+  grn_id id;
+
+  name = gcut_data_get_string(data, "name");
+  object = grn_ctx_get(context, name, strlen(name));
+  id = grn_obj_id(context, object);
+  if (gcut_data_get_string(data, "expected")) {
+    cut_assert_true(grn_type_id_is_text_family(context, id));
+  } else {
+    cut_assert_false(grn_type_id_is_text_family(context, id));
+  }
+}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index