svnno****@sourc*****
svnno****@sourc*****
Mon Jan 26 09:31:46 JST 2009
Revision: 3566 http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3566 Author: ikezoe Date: 2009-01-26 09:31:46 +0900 (Mon, 26 Jan 2009) Log Message: ----------- more test. Modified Paths: -------------- kazehakase/trunk/test/Makefile.am Added Paths: ----------- kazehakase/trunk/test/fixtures/ kazehakase/trunk/test/fixtures/bookmarks.xml kazehakase/trunk/test/kz-test-suite.c kazehakase/trunk/test/kz-test-utils.c kazehakase/trunk/test/kz-test-utils.h kazehakase/trunk/test/test-root-bookmark.c Modified: kazehakase/trunk/test/Makefile.am =================================================================== --- kazehakase/trunk/test/Makefile.am 2009-01-25 01:07:23 UTC (rev 3565) +++ kazehakase/trunk/test/Makefile.am 2009-01-26 00:31:46 UTC (rev 3566) @@ -3,9 +3,12 @@ TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)" noinst_LTLIBRARIES = \ + suite_kz_test.la \ + kz_test_utils.la \ test-bookmark.la \ test-bookmark-folder.la \ - test-bookmark-separator.la + test-bookmark-separator.la \ + test-root-bookmark.la endif EXTRA_DIST = \ @@ -26,9 +29,16 @@ $(top_builddir)/src/libkazehakase.la $(GCUTTER_LIBS) +suite_kz_test_la_SOURCES = kz-test-suite.c + +kz_test_utils_headers = kz-test-utils.h +kz_test_utils_la_SOURCES = kz-test-utils.c + test_bookmark_la_SOURCES = test-bookmark.c test_bookmark_folder_la_SOURCES = test-bookmark-folder.c test_bookmark_separator_la_SOURCES = test-bookmark-separator.c +test_root_bookmark_la_SOURCES = test-root-bookmark.c +test_root_bookmark_la_LIBADD = kz_test_utils.la echo-cutter: @echo $(CUTTER) Added: kazehakase/trunk/test/fixtures/bookmarks.xml =================================================================== --- kazehakase/trunk/test/fixtures/bookmarks.xml (rev 0) +++ kazehakase/trunk/test/fixtures/bookmarks.xml 2009-01-26 00:31:46 UTC (rev 3566) @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<xbel version="1.0" folded="none" xmlns:kz="http://kazehakase.sourceforge.jp/2004"> + <title>Bookmarks</title> + <bookmark href="http://kazehakase.sourceforge.jp/"> + <title>Kazehakase</title> + </bookmark> +</xbel> Added: kazehakase/trunk/test/kz-test-suite.c =================================================================== --- kazehakase/trunk/test/kz-test-suite.c (rev 0) +++ kazehakase/trunk/test/kz-test-suite.c 2009-01-26 00:31:46 UTC (rev 3566) @@ -0,0 +1,26 @@ +#include <gcutter.h> + +#include "src/bookmarks/kz-bookmark.h" +#include "src/bookmarks/kz-bookmarks-enum-types.h" + +void kz_test_warmup (void); + +static gboolean +kz_bookmark_type_equal_func (gconstpointer v1, gconstpointer v2) +{ + KzBookmarkType *type1 = (KzBookmarkType*)v1; + KzBookmarkType *type2 = (KzBookmarkType*)v2; + + return (*type1 == *type2); +} + +void +kz_test_warmup (void) +{ + gcut_value_register_equal_func(KZ_TYPE_BOOKMARK_TYPE, KZ_TYPE_BOOKMARK_TYPE, + kz_bookmark_type_equal_func); +} + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: kazehakase/trunk/test/kz-test-utils.c =================================================================== --- kazehakase/trunk/test/kz-test-utils.c (rev 0) +++ kazehakase/trunk/test/kz-test-utils.c 2009-01-26 00:31:46 UTC (rev 3566) @@ -0,0 +1,148 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2008 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + * + */ + +#include "kz-test-utils.h" +#include "src/bookmarks/kz-bookmark.h" +#include "src/bookmarks/kz-bookmarks-enum-types.h" + +void kz_test_warmup (void); + +static gboolean +kz_bookmark_type_equal_func (gconstpointer v1, gconstpointer v2) +{ + KzBookmarkType type1 = GPOINTER_TO_INT(v1); + KzBookmarkType type2 = GPOINTER_TO_INT(v2); +return TRUE; + + return (type1 == type2); +} + +void +kz_test_warmup (void) +{ +g_warning("hige"); + gcut_value_register_equal_func(KZ_TYPE_BOOKMARK_TYPE, KZ_TYPE_BOOKMARK_TYPE, + kz_bookmark_type_equal_func); +} + +static gchar *base_dir = NULL; +const gchar * +kz_test_get_base_dir (void) +{ + const gchar *dir; + + if (base_dir) + return base_dir; + + dir = g_getenv("BASE_DIR"); + if (!dir) + dir = "."; + + if (g_path_is_absolute(dir)) { + base_dir = g_strdup(dir); + } else { + gchar *current_dir; + + current_dir = g_get_current_dir(); + base_dir = g_build_filename(current_dir, dir, NULL); + g_free(current_dir); + } + + return base_dir; +} + +static gboolean +kz_test_equal_bookmark (KzBookmark *expected, KzBookmark *actual) +{ + GParamSpec **expected_param_specs, **actual_param_specs; + GObjectClass *expected_object_class; + GObjectClass *actual_object_class; + guint i, n_expected_properties, n_actual_properties; + + if (G_OBJECT_TYPE(expected) != G_OBJECT_TYPE(actual)) + return FALSE; + + expected_object_class = G_OBJECT_CLASS(KZ_BOOKMARK_GET_CLASS(expected)); + actual_object_class = G_OBJECT_CLASS(KZ_BOOKMARK_GET_CLASS(actual)); + + expected_param_specs = g_object_class_list_properties(expected_object_class, + &n_expected_properties); + actual_param_specs = g_object_class_list_properties(actual_object_class, + &n_actual_properties); + cut_take_memory(expected_param_specs); + cut_take_memory(actual_param_specs); + + if (n_expected_properties != n_actual_properties) + return FALSE; + + for (i = 0; i < n_expected_properties; i++) { + GParamSpec *actual_param_spec; + GValue expected_value = {0}, actual_value = {0}; + actual_param_spec = g_object_class_find_property(actual_object_class, + expected_param_specs[i]->name); + if (!actual_param_spec) + return FALSE; + g_value_init(&expected_value, expected_param_specs[i]->value_type); + g_value_init(&actual_value, expected_param_specs[i]->value_type); + g_object_get_property(G_OBJECT(expected), expected_param_specs[i]->name, + &expected_value); + g_object_get_property(G_OBJECT(expected), expected_param_specs[i]->name, + &actual_value); + if (!gcut_value_equal(&expected_value, &actual_value)) { + g_print("%s\n%s\n", G_VALUE_TYPE_NAME(&expected_value), + G_VALUE_TYPE_NAME(&actual_value)); + return FALSE; + } + } + return TRUE; +} + +void +kz_assert_equal_bookmark_helper (KzBookmark *expected, + KzBookmark *actual, + const gchar *expression_expected, + const gchar *expression_actual) +{ + if (kz_test_equal_bookmark(expected, actual)) { + cut_test_pass(); + } else { + gchar *inspected_expected, *inspected_actual; + const gchar *message; + + inspected_expected = gcut_object_inspect(G_OBJECT(expected)); + inspected_actual = gcut_object_inspect(G_OBJECT(actual)); + message = cut_take_printf("<%s> == <%s>\n" + "expected: <%s>\n" + " actual: <%s>", + expression_expected, expression_actual, + inspected_expected, + inspected_actual); + if (expected && actual) + message = cut_append_diff(message, + inspected_expected, inspected_actual); + g_free(inspected_expected); + g_free(inspected_actual); + cut_test_fail(message); + } +} + + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: kazehakase/trunk/test/kz-test-utils.h =================================================================== --- kazehakase/trunk/test/kz-test-utils.h (rev 0) +++ kazehakase/trunk/test/kz-test-utils.h 2009-01-26 00:31:46 UTC (rev 3566) @@ -0,0 +1,49 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2008 Kouhei Sutou <kou****@cozmi*****> + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __KZ_TEST_UTILS_H__ +#define __KZ_TEST_UTILS_H__ + +#include <gcutter.h> +#include "src/bookmarks/kz-bookmark.h" + +G_BEGIN_DECLS + +const gchar *kz_test_get_base_dir (void); + +#define kz_assert_equal_bookmark(expected, actual, ...) do \ +{ \ + cut_trace_with_info_expression( \ + kz_assert_equal_bookmark_helper((expected), (actual), \ + #expected, #actual), \ + kz_assert_equal_bookmark(expected, actual, __VA_ARGS__)); \ +} while (0) + +void kz_assert_equal_bookmark_helper (KzBookmark *expected, + KzBookmark *actual, + const gchar *expression_expected, + const gchar *expression_actual); + +G_END_DECLS + +#endif /* __KZ_TEST_UTILS_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: kazehakase/trunk/test/test-root-bookmark.c =================================================================== --- kazehakase/trunk/test/test-root-bookmark.c (rev 0) +++ kazehakase/trunk/test/test-root-bookmark.c 2009-01-26 00:31:46 UTC (rev 3566) @@ -0,0 +1,52 @@ +#include "src/bookmarks/kz-root-bookmark.h" + +#include <gcutter.h> + +#include "kz-test-utils.h" + +void test_new (void); + +static KzRootBookmark *root; +static KzBookmark *expected; +static gchar *bookmark_file; + +void +setup (void) +{ + root = NULL; + expected = NULL; + + bookmark_file = g_build_filename(kz_test_get_base_dir(), + "fixtures", "bookmarks.xml", + NULL); +} + +void +teardown (void) +{ + if (root) + g_object_unref(root); + if (expected) + g_object_unref(expected); + + g_free(bookmark_file); +} + +void +test_new (void) +{ + root = kz_root_bookmark_new(bookmark_file, NULL, NULL, NULL); + cut_assert(root); + cut_assert_true(kz_bookmark_has_children(KZ_BOOKMARK(root))); + + cut_assert(root->menu); + cut_assert_equal_string("Bookmarks", kz_bookmark_get_title(root->menu)); + + expected = KZ_BOOKMARK(kz_bookmark_file_new(bookmark_file, "Bookmarks", "XBEL")); + + kz_assert_equal_bookmark(expected, root->menu); +} + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/