Yuto Hayamizu
y.hay****@gmail*****
2009年 8月 18日 (火) 10:52:25 JST
はじめまして. はやみずといいます. クリアコードのインターン中にパッチを作りました. libsoupを利用して, httpインターフェースのユニットテストを作成しました. 現在は, ベースとなる単純なテストケースを1つ作成したところなので, githubのブランチからpullしてもらえるとうれしいです. これからhttpインターフェースのテストケースを追加していく予定です. http://github.com/hayamiz/groonga/tree/master 参考までに, diffを貼り付けておきます. diff --git a/configure.ac b/configure.ac index 17c8ae7..e40e49e 100644 --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,7 @@ AC_CONFIG_FILES([Makefile test/unit/util/Makefile test/unit/core/Makefile test/unit/memcached/Makefile + test/unit/http/Makefile test/ql/Makefile test/benchmark/Makefile test/benchmark/lib/Makefile @@ -319,6 +320,13 @@ if test "$ac_cv_use_cutter" != "no"; then if test "$ac_cv_have_libmemcached_memcached_h" = "yes"; then AC_DEFINE(WITH_LIBMEMCACHED, 1, [Define to 1 if you use libmemcached]) fi + PKG_CHECK_MODULES(SOUP, libsoup-2.4, + [ac_cv_soup_exists=yes], [ac_cv_soup_exists=no]) + AM_CONDITIONAL([WITH_SOUP], + [test "$ac_cv_soup_exists" = "yes"]) + if test "$ac_cv_soup_exists" = "yes"; then + AC_DEFINE(WITH_SOUP, 1, [Define to 1 if you use libsoup]) + fi else AM_CONDITIONAL([WITH_LIBMEMCACHED], 0) fi diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index c57dabb..c2a3f2b 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -3,7 +3,8 @@ SUBDIRS = \ fixtures \ util \ core \ - memcached + memcached \ + http if WITH_CUTTER TESTS = run-test.sh diff --git a/test/unit/http/.gitignore b/test/unit/http/.gitignore new file mode 100644 index 0000000..1a5ef8d --- /dev/null +++ b/test/unit/http/.gitignore @@ -0,0 +1,5 @@ +Makefile +Makefile.in +test-http.la +test-http.lo +test-http.o diff --git a/test/unit/http/Makefile.am b/test/unit/http/Makefile.am new file mode 100644 index 0000000..7bb0730 --- /dev/null +++ b/test/unit/http/Makefile.am @@ -0,0 +1,27 @@ +if WITH_CUTTER +if WITH_SOUP +noinst_LTLIBRARIES = \ + test-http.la +endif +endif + +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/lib \ + $(GROONGA_INCLUDEDIR) + +AM_CFLAGS = \ + $(GCUTTER_CFLAGS) \ + $(SOUP_CFLAGS) \ + -DGROONGA=\"$(abs_top_builddir)/src/groonga\" + +AM_LDFLAGS = -module -rpath $(libdir) -avoid-version $(SOUP_LIBS) + +LIBS = \ + $(top_builddir)/lib/libgroonga.la \ + $(GCUTTER_LIBS) \ + $(top_builddir)/test/unit/lib/libgrn-test-utils.la \ + $(top_builddir)/test/unit/lib/libgrn-test-hash-utils.la + +test_http_la_SOURCES = test-http.c + diff --git a/test/unit/http/test-http.c b/test/unit/http/test-http.c new file mode 100644 index 0000000..2b64a66 --- /dev/null +++ b/test/unit/http/test-http.c @@ -0,0 +1,88 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2009 Yuto HAYAMIZU <y.hay****@gmail*****> + + 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 <glib/gstdio.h> +#include <libsoup/soup.h> +#include <gcutter.h> /* must be included after memcached.h */ + +#include <unistd.h> /* for exec */ +#include <sys/types.h> +#include <signal.h> + +#include "../lib/grn-assertions.h" + +#define GROONGA_TEST_PORT "4545" + +/* globals */ +static gchar *tmp_directory; + +static GCutEgg *egg; + +void +cut_setup(void) +{ + GError *error = NULL; + + tmp_directory = g_build_filename(grn_test_get_base_dir(), "tmp", NULL); + cut_remove_path(tmp_directory, NULL); + if (g_mkdir_with_parents(tmp_directory, 0700) == -1) { + cut_assert_errno(); + } + + egg = gcut_egg_new(GROONGA, "-s", + "-p", GROONGA_TEST_PORT, + "-n", + cut_take_printf("%s%s%s", + tmp_directory, + G_DIR_SEPARATOR_S, + "http.db"), + NULL); + gcut_egg_hatch(egg, &error); + gcut_assert_error(error); + + sleep(1); +} + +void +cut_teardown(void) +{ + if (egg) { + g_object_unref(egg); + } + + cut_remove_path(tmp_directory, NULL); +} + +void +test_get_root(void) +{ + SoupSession *session; + SoupMessage *message; + guint status; + + session = soup_session_sync_new(); + message = soup_message_new("GET", "http://localhost:" GROONGA_TEST_PORT "/"); + gcut_take_object(G_OBJECT(session)); + gcut_take_object(G_OBJECT(message)); + + status = soup_session_send_message(session, message); + + cut_assert_equal_uint(SOUP_STATUS_OK, status); + cut_assert_equal_string("text/javascript", soup_message_headers_get_content_type(message->response_headers, NULL)); + cut_assert_equal_memory("", 0, message->response_body->data, message->response_body->length); +}