[Groonga-commit] groonga/groonga [master] add a test for two sortby columns.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 6月 28日 (月) 12:20:25 JST


Kouhei Sutou	2010-06-28 03:20:25 +0000 (Mon, 28 Jun 2010)

  New Revision: b81ced7b470ad908058bf618dc3cabeaf6cb0fd8

  Log:
    add a test for two sortby columns.

  Added files:
    test/unit/core/test-command-select-sort.c
  Modified files:
    test/unit/core/Makefile.am

  Modified: test/unit/core/Makefile.am (+2 -0)
===================================================================
--- test/unit/core/Makefile.am    2010-06-28 02:40:07 +0000 (b7da96f)
+++ test/unit/core/Makefile.am    2010-06-28 03:20:25 +0000 (23c262b)
@@ -39,6 +39,7 @@ noinst_LTLIBRARIES =				\
 	test-command-load.la			\
 	test-command-column-list.la		\
 	test-command-select.la			\
+	test-command-select-sort.la		\
 	test-command-cache-limit.la
 endif
 
@@ -102,4 +103,5 @@ test_inspect_la_SOURCES			= test-inspect.c
 test_command_load_la_SOURCES		= test-command-load.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
 test_command_cache_limit_la_SOURCES	= test-command-cache-limit.c

  Added: test/unit/core/test-command-select-sort.c (+105 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/test-command-select-sort.c    2010-06-28 03:20:25 +0000 (c50e7df)
@@ -0,0 +1,105 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+  Copyright (C) 2010  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 "str.h"
+#include <stdio.h>
+
+#include <gcutter.h>
+
+#include "../lib/grn-assertions.h"
+
+void test_int(void);
+
+static gchar *tmp_directory;
+
+static grn_ctx *context;
+static grn_obj *database;
+
+void
+cut_startup(void)
+{
+  tmp_directory = g_build_filename(grn_test_get_base_dir(),
+                                   "tmp",
+                                   "command-select-sort",
+                                   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);
+}
+
+void
+cut_teardown(void)
+{
+  if (context) {
+    grn_obj_unlink(context, database);
+    grn_ctx_fin(context);
+    g_free(context);
+  }
+
+  remove_tmp_directory();
+}
+
+void
+test_int(void)
+{
+  assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"
+                       "column_create Sites score COLUMN_SCALAR Int32\n"
+                       "column_create Sites age COLUMN_SCALAR Int32\n"
+                       "load --table Sites\n"
+                       "[\n"
+                       "[\"_key\", \"score\", \"age\"],\n"
+                       "[\"groonga.org\", 100, 2],\n"
+                       "[\"qwik.jp/senna/FrontPageJ.html\", 100, 5],\n"
+                       "[\"2ch.net\", 10, 11]\n"
+                       "]");
+  cut_assert_equal_string(
+      "[[[3],"
+       "[[\"_key\",\"ShortText\"],"
+        "[\"score\",\"Int32\"],"
+        "[\"age\",\"Int32\"]],"
+       "[\"qwik.jp/senna/FrontPageJ.html\",100,5],"
+       "[\"groonga.org\",100,2],"
+       "[\"2ch.net\",10,11]]]",
+      send_command("select Sites "
+                   "--sortby \"-score -age\" "
+                   "--output_columns \"_key score age\""));
+}




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