[Groonga-commit] groonga/groonga [master] [test][truncate] add tests for truncating anonymous tables. refs #892

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 7日 (月) 14:36:45 JST


Kouhei Sutou	2011-11-07 05:36:45 +0000 (Mon, 07 Nov 2011)

  New Revision: 8806de29fb954de523c3762db9f61d22aa7cb015

  Log:
    [test][truncate] add tests for truncating anonymous tables. refs #892

  Modified files:
    test/unit/core/test-table.c

  Modified: test/unit/core/test-table.c (+54 -14)
===================================================================
--- test/unit/core/test-table.c    2011-11-07 02:34:00 +0000 (7e6e9e8)
+++ test/unit/core/test-table.c    2011-11-07 05:36:45 +0000 (7ce86c0)
@@ -37,13 +37,14 @@ void data_create_with_valid_name(void);
 void test_create_with_valid_name(gpointer data);
 void data_create_with_invalid_name(void);
 void test_create_with_invalid_name(gpointer data);
-void test_array_truncate(void);
+void data_truncate_anonymous(void);
+void test_truncate_anonymous(gconstpointer data);
 
 static gchar *tmp_directory;
 
 static grn_logger_info *logger;
 static grn_ctx *context;
-static grn_obj *database;
+static grn_obj *database, *table;
 
 void
 cut_startup(void)
@@ -80,14 +81,21 @@ cut_setup(void)
   database = grn_db_create(context,
                            cut_build_path(tmp_directory, "table.db", NULL),
                            NULL);
+
+  table = NULL;
 }
 
 void
 cut_teardown(void)
 {
+  if (table) {
+    grn_obj_unlink(context, table);
+  }
+
   grn_obj_close(context, database);
   grn_ctx_fin(context);
   g_free(context);
+
   teardown_grn_logger(logger);
   cut_remove_path(tmp_directory, NULL);
 }
@@ -459,20 +467,52 @@ test_create_with_invalid_name(gpointer data)
 }
 
 void
-test_array_truncate(void)
+data_truncate_anonymous(void)
 {
-  grn_obj *table;
-  gchar value[] = "sample value";
-  gchar *value_type_name = "value_type";
-  grn_obj *value_type;
+#define ADD_DATA(label, flags)			\
+  gcut_add_datum(label,				\
+		 "flags", G_TYPE_INT, flags,	\
+		 NULL)
 
-  value_type = grn_type_create(context,
-                               value_type_name, strlen(value_type_name),
-                               0, sizeof(value));
-  table = grn_table_create(context, NULL, 0, NULL,
-                           GRN_OBJ_TABLE_NO_KEY,
-                           NULL, value_type);
-  grn_test_assert_not_nil(grn_table_add(context, table, NULL, 0, NULL));
+  ADD_DATA("array", GRN_OBJ_TABLE_NO_KEY);
+  ADD_DATA("hash", GRN_OBJ_TABLE_HASH_KEY);
+  ADD_DATA("patricia trie", GRN_OBJ_TABLE_PAT_KEY);
+
+#undef ADD_DATA
+}
+
+void
+test_truncate_anonymous(gconstpointer data)
+{
+  grn_obj_flags flags;
+  const gchar *key;
+  grn_obj *key_type;
+  unsigned key_size;
+  grn_bool array_p;
+  int added;
+
+  flags = gcut_data_get_int(data, "flags");
+  array_p = ((flags & GRN_OBJ_TABLE_TYPE_MASK) == GRN_OBJ_TABLE_NO_KEY);
+
+  if (array_p) {
+    key = NULL;
+    key_size = 0;
+    key_type = NULL;
+  } else {
+    key = "groonga";
+    key_size = strlen(key);
+    key_type = grn_ctx_at(context, GRN_DB_SHORT_TEXT);
+  }
+  table = grn_table_create(context,
+			   NULL, 0, NULL,
+                           flags,
+                           key_type, NULL);
+  if (key_type) {
+    grn_obj_unlink(context, key_type);
+  }
+
+  grn_test_assert_not_nil(grn_table_add(context, table, key, key_size, &added));
+  cut_assert_true(added);
 
   cut_assert_equal_uint(1, grn_table_size(context, table));
   grn_test_assert(grn_table_truncate(context, table));




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