|
From: Kouhei S. <nul...@cl...> - 2014-01-20 14:12:06
|
Kouhei Sutou 2014-01-20 23:10:43 +0900 (Mon, 20 Jan 2014) New Revision: 75065737aba1dbd7e66c71c4825fb85fd2a65b54 https://github.com/clear-code/cutter/commit/75065737aba1dbd7e66c71c4825fb85fd2a65b54 Message: Support unhandled C++ exception handling in iterated test Added files: cppcutter/cppcut-iterated-test.h cppcutter/cppcut-test-invoke.cpp cppcutter/cppcut-test-invoke.h cppcutter/cppcut-test-iterator.cpp cppcutter/cppcut-test-iterator.h test/cppcutter/test-cppcut-iterated-test.cpp Copied files: cppcutter/cppcut-iterated-test.cpp (from cppcutter/cppcut-test.cpp) Modified files: cppcutter/Makefile.am cppcutter/cppcut-test.cpp cutter/cut-loader.c cutter/cut-loader.h cutter/cut-test-iterator.c cutter/cut-test-iterator.h module/loader-customizer/cut-exception-loader-customizer.c test/cppcutter/Makefile.am Modified: cppcutter/Makefile.am (+12 -3) =================================================================== --- cppcutter/Makefile.am 2014-01-20 23:09:34 +0900 (8ea5952) +++ cppcutter/Makefile.am 2014-01-20 23:10:43 +0900 (3842a25) @@ -16,8 +16,13 @@ cppcutter_public_headers = \ cppcut-assertions.h \ cppcut-assertions-helper.h \ cppcut-macros.h \ - cppcut-message.h \ - cppcut-test.h + cppcut-message.h + +cppcutter_private_headers = \ + cppcut-test.h \ + cppcut-test-iterator.h \ + cppcut-iterated-test.h \ + cppcut-test-invoke.h pkginclude_HEADERS = \ cppcutter.h @@ -29,10 +34,14 @@ cppcutter_include_HEADERS = \ libcppcutter_sources = \ cppcut-assertions-helper.cpp \ cppcut-message.cpp \ - cppcut-test.cpp + cppcut-test.cpp \ + cppcut-test-iterator.cpp \ + cppcut-iterated-test.cpp \ + cppcut-test-invoke.cpp libcppcutter_la_SOURCES = \ $(cppcutter_public_headers) \ + $(cppcutter_private_headers) \ $(libcppcutter_sources) libcppcutter_la_LDFLAGS = \ Copied: cppcutter/cppcut-iterated-test.cpp (+17 -31) 54% =================================================================== --- cppcutter/cppcut-test.cpp 2014-01-20 23:09:34 +0900 (866d685) +++ cppcutter/cppcut-iterated-test.cpp 2014-01-20 23:10:43 +0900 (fbcf336) @@ -1,7 +1,6 @@ /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> - * Copyright (C) 2014 Kazuhiro Yamato <kz...@gm...> * * 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 @@ -22,23 +21,19 @@ # include <config.h> #endif -#include <exception> -#include <typeinfo> - -#include "cppcut-test.h" - -#include <cutter.h> +#include "cppcut-iterated-test.h" +#include "cppcut-test-invoke.h" G_BEGIN_DECLS -G_DEFINE_TYPE(CppCutTest, cppcut_test, CUT_TYPE_TEST) +G_DEFINE_TYPE(CppCutIteratedTest, cppcut_iterated_test, CUT_TYPE_ITERATED_TEST) static void invoke (CutTest *test, CutTestContext *test_context, CutRunContext *run_context); static void -cppcut_test_class_init (CppCutTestClass *klass) +cppcut_iterated_test_class_init (CppCutIteratedTestClass *klass) { CutTestClass *cut_test_class; @@ -48,42 +43,33 @@ cppcut_test_class_init (CppCutTestClass *klass) } static void -cppcut_test_init (CppCutTest *test) +cppcut_iterated_test_init (CppCutIteratedTest *test) { } -CppCutTest * -cppcut_test_new (const gchar *name, CutTestFunction function) +CppCutIteratedTest * +cppcut_iterated_test_new (const gchar *name, + CutIteratedTestFunction function, + CutTestData *data) { gpointer object; - object = g_object_new(CPPCUT_TYPE_TEST, - "element-name", "test", + object = g_object_new(CPPCUT_TYPE_ITERATED_TEST, + "element-name", "iterated-test", "name", name, - "test-function", function, + "iterated-test-function", function, + "data", data, NULL); - return CPPCUT_TEST(object); + return CPPCUT_ITERATED_TEST(object); } static void invoke (CutTest *test, CutTestContext *test_context, CutRunContext *run_context) { - CutTestClass *cut_test_class = CUT_TEST_CLASS(cppcut_test_parent_class); + CutTestClass *cut_test_class; - try { - cut_test_class->invoke(test, test_context, run_context); - } catch (const std::exception &exception) { - const gchar *message; - message = cut_take_printf("Unhandled C++ standard exception is thrown: " - "<%s>: %s", - typeid(exception).name(), - exception.what()); - cut_test_terminate(ERROR, message); - } catch (...) { - const gchar *message; - message = "Unhandled C++ non-standard exception is thrown"; - cut_test_terminate(ERROR, message); - } + cut_test_class = CUT_TEST_CLASS(cppcut_iterated_test_parent_class); + cut::test::invoke(cut_test_class, test, test_context, run_context); } G_END_DECLS Added: cppcutter/cppcut-iterated-test.h (+83 -0) 100644 =================================================================== --- /dev/null +++ cppcutter/cppcut-iterated-test.h 2014-01-20 23:10:43 +0900 (06ca2c0) @@ -0,0 +1,83 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __CPPCUT_ITERATED_TEST_H__ +#define __CPPCUT_ITERATED_TEST_H__ + +#include <glib-object.h> + +#include <cutter/cut-iterated-test.h> + +/** + * SECTION: cppcut-iterated-test + * @title: Iterated test class for C++. + * @short_description: Adds C++ exception support to CutIteratedTest. + * + */ + +G_BEGIN_DECLS + +#define CPPCUT_TYPE_ITERATED_TEST \ + (cppcut_iterated_test_get_type()) +#define CPPCUT_ITERATED_TEST(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + CPPCUT_TYPE_ITERATED_TEST, \ + CppCutIteratedTest)) +#define CPPCUT_ITERATED_TEST_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + CPPCUT_TYPE_ITERATED_TEST, \ + CppCutIteratedTestClass)) +#define CPPCUT_IS_ITERATED_TEST(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + CPPCUT_TYPE_ITERATED_TEST)) +#define CPPCUT_IS_ITERATED_TEST_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + CPPCUT_TYPE_ITERATED_TEST)) +#define CPPCUT_ITERATED_TEST_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + CPPCUT_TYPE_ITERATED_TEST, \ + CppCutIteratedTestClass)) + +typedef struct _CppCutIteratedTest CppCutIteratedTest; +typedef struct _CppCutIteratedTestClass CppCutIteratedTestClass; + +struct _CppCutIteratedTest +{ + CutIteratedTest object; +}; + +struct _CppCutIteratedTestClass +{ + CutIteratedTestClass parent_class; +}; + +GType cppcut_iterated_test_get_type (void) G_GNUC_CONST; + +CppCutIteratedTest * + cppcut_iterated_test_new (const gchar *name, + CutIteratedTestFunction function, + CutTestData *data); + +G_END_DECLS + +#endif /* __CPPCUT_ITERATED_TEST_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: cppcutter/cppcut-test-invoke.cpp (+56 -0) 100644 =================================================================== --- /dev/null +++ cppcutter/cppcut-test-invoke.cpp 2014-01-20 23:10:43 +0900 (26ffb91) @@ -0,0 +1,56 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * Copyright (C) 2014 Kazuhiro Yamato <kz...@gm...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <exception> +#include <typeinfo> + +#include "cppcut-test-invoke.h" + +#include <cutter.h> + +void +cut::test::invoke (CutTestClass *cut_test_class, + CutTest *test, + CutTestContext *test_context, + CutRunContext *run_context) +{ + try { + cut_test_class->invoke(test, test_context, run_context); + } catch (const std::exception &exception) { + const gchar *message; + message = cut_take_printf("Unhandled C++ standard exception is thrown: " + "<%s>: %s", + typeid(exception).name(), + exception.what()); + cut_test_terminate(ERROR, message); + } catch (...) { + const gchar *message; + message = "Unhandled C++ non-standard exception is thrown"; + cut_test_terminate(ERROR, message); + } +} + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: cppcutter/cppcut-test-invoke.h (+40 -0) 100644 =================================================================== --- /dev/null +++ cppcutter/cppcut-test-invoke.h 2014-01-20 23:10:43 +0900 (35d5cf0) @@ -0,0 +1,40 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __CPPCUT_TEST_INVOKE_H__ +#define __CPPCUT_TEST_INVOKE_H__ + +#include <cutter/cut-test.h> + +namespace cut +{ + namespace test + { + void invoke (CutTestClass *cut_test_class, + CutTest *test, + CutTestContext *test_context, + CutRunContext *run_context); + } +} + +#endif /* __CPPCUT_TEST_INVOKE_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: cppcutter/cppcut-test-iterator.cpp (+86 -0) 100644 =================================================================== --- /dev/null +++ cppcutter/cppcut-test-iterator.cpp 2014-01-20 23:10:43 +0900 (804d8f4) @@ -0,0 +1,86 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "cppcut-test-iterator.h" +#include "cppcut-iterated-test.h" + +G_BEGIN_DECLS + +G_DEFINE_TYPE(CppCutTestIterator, cppcut_test_iterator, CUT_TYPE_TEST_ITERATOR) + +static CutIteratedTest * + create_iterated_test (CutTestIterator *test_iterator, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutTestData *test_data); + +static void +cppcut_test_iterator_class_init (CppCutTestIteratorClass *klass) +{ + CutTestIteratorClass *cut_test_iterator_class; + + cut_test_iterator_class = CUT_TEST_ITERATOR_CLASS(klass); + + cut_test_iterator_class->create_iterated_test = create_iterated_test; +} + +static void +cppcut_test_iterator_init (CppCutTestIterator *test) +{ +} + +CppCutTestIterator * +cppcut_test_iterator_new (const gchar *name, + CutIteratedTestFunction test_function, + CutDataSetupFunction data_setup_function) +{ + gpointer object; + + object = g_object_new(CPPCUT_TYPE_TEST_ITERATOR, + "element-name", "test-iterator", + "name", name, + "iterated-test-function", test_function, + "data-setup-function", data_setup_function, + NULL); + return CPPCUT_TEST_ITERATOR(object); +} + +static CutIteratedTest * +create_iterated_test (CutTestIterator *test_iterator, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutTestData *test_data) +{ + CppCutIteratedTest *iterated_test; + + iterated_test = cppcut_iterated_test_new(name, + iterated_test_function, + test_data); + return CUT_ITERATED_TEST(iterated_test); +} + +G_END_DECLS + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Added: cppcutter/cppcut-test-iterator.h (+83 -0) 100644 =================================================================== --- /dev/null +++ cppcutter/cppcut-test-iterator.h 2014-01-20 23:10:43 +0900 (6e54099) @@ -0,0 +1,83 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __CPPCUT_TEST_ITERATOR_H__ +#define __CPPCUT_TEST_ITERATOR_H__ + +#include <glib-object.h> + +#include <cutter/cut-test-iterator.h> + +/** + * SECTION: cppcut-test-iterator + * @title: TestIterator class for C++. + * @short_description: Creates CppCutIteratedTest. + * + */ + +G_BEGIN_DECLS + +#define CPPCUT_TYPE_TEST_ITERATOR \ + (cppcut_test_iterator_get_type()) +#define CPPCUT_TEST_ITERATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + CPPCUT_TYPE_TEST_ITERATOR, \ + CppCutTestIterator)) +#define CPPCUT_TEST_ITERATOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + CPPCUT_TYPE_TEST_ITERATOR, \ + CppCutTestIteratorClass)) +#define CPPCUT_IS_TEST_ITERATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + CPPCUT_TYPE_TEST_ITERATOR)) +#define CPPCUT_IS_TEST_ITERATOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + CPPCUT_TYPE_TEST_ITERATOR)) +#define CPPCUT_TEST_ITERATOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + CPPCUT_TYPE_TEST_ITERATOR, \ + CppCutTestIteratorClass)) + +typedef struct _CppCutTestIterator CppCutTestIterator; +typedef struct _CppCutTestIteratorClass CppCutTestIteratorClass; + +struct _CppCutTestIterator +{ + CutTestIterator object; +}; + +struct _CppCutTestIteratorClass +{ + CutTestIteratorClass parent_class; +}; + +GType cppcut_test_iterator_get_type (void) G_GNUC_CONST; + +CppCutTestIterator * + cppcut_test_iterator_new (const gchar *name, + CutIteratedTestFunction test_function, + CutDataSetupFunction data_setup_function); + +G_END_DECLS + +#endif /* __CPPCUT_TEST_ITERATOR_H__ */ + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4 +*/ Modified: cppcutter/cppcut-test.cpp (+2 -18) =================================================================== --- cppcutter/cppcut-test.cpp 2014-01-20 23:09:34 +0900 (866d685) +++ cppcutter/cppcut-test.cpp 2014-01-20 23:10:43 +0900 (f13d33a) @@ -1,7 +1,6 @@ /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> - * Copyright (C) 2014 Kazuhiro Yamato <kz...@gm...> * * 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 @@ -22,10 +21,8 @@ # include <config.h> #endif -#include <exception> -#include <typeinfo> - #include "cppcut-test.h" +#include "cppcut-test-invoke.h" #include <cutter.h> @@ -70,20 +67,7 @@ invoke (CutTest *test, CutTestContext *test_context, CutRunContext *run_context) { CutTestClass *cut_test_class = CUT_TEST_CLASS(cppcut_test_parent_class); - try { - cut_test_class->invoke(test, test_context, run_context); - } catch (const std::exception &exception) { - const gchar *message; - message = cut_take_printf("Unhandled C++ standard exception is thrown: " - "<%s>: %s", - typeid(exception).name(), - exception.what()); - cut_test_terminate(ERROR, message); - } catch (...) { - const gchar *message; - message = "Unhandled C++ non-standard exception is thrown"; - cut_test_terminate(ERROR, message); - } + cut::test::invoke(cut_test_class, test, test_context, run_context); } G_END_DECLS Modified: cutter/cut-loader.c (+41 -6) =================================================================== --- cutter/cut-loader.c 2014-01-20 23:09:34 +0900 (bab89b5) +++ cutter/cut-loader.c 2014-01-20 23:10:43 +0900 (e830270) @@ -82,6 +82,8 @@ struct _CutLoaderPrivate gchar *base_directory; CutCreateTestFunction create_test_function; gpointer create_test_function_user_data; + CutCreateTestIteratorFunction create_test_iterator_function; + gpointer create_test_iterator_function_user_data; }; enum @@ -183,6 +185,8 @@ cut_loader_init (CutLoader *loader) priv->base_directory = NULL; priv->create_test_function = NULL; priv->create_test_function_user_data = NULL; + priv->create_test_iterator_function = NULL; + priv->create_test_iterator_function_user_data = NULL; } static void @@ -341,6 +345,19 @@ cut_loader_set_create_test_function (CutLoader *loader, priv->create_test_function_user_data = user_data; } +void +cut_loader_set_create_test_iterator_function ( + CutLoader *loader, + CutCreateTestIteratorFunction create_test_iterator_function, + gpointer user_data) +{ + CutLoaderPrivate *priv; + + priv = CUT_LOADER_GET_PRIVATE(loader); + priv->create_test_iterator_function = create_test_iterator_function; + priv->create_test_iterator_function_user_data = user_data; +} + static inline const gchar * skip_cpp_namespace_gcc (const gchar *name, GString *namespaces) { @@ -1046,6 +1063,25 @@ create_test (CutLoaderPrivate *priv, } } +static CutTestIterator * +create_test_iterator (CutLoaderPrivate *priv, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutDataSetupFunction data_setup_function) +{ + if (priv->create_test_iterator_function) { + gpointer user_data = priv->create_test_iterator_function_user_data; + return priv->create_test_iterator_function(name, + iterated_test_function, + data_setup_function, + user_data); + } else { + return cut_test_iterator_new(name, + iterated_test_function, + data_setup_function); + } +} + static void register_valid_test (CutLoader *loader, CutTestCase *test_case, SymbolNames *names) @@ -1075,12 +1111,11 @@ register_valid_test (CutLoader *loader, CutTestCase *test_case, if (data_setup_function) { CutTestIterator *test_iterator; - CutIteratedTestFunction iterated_test_function; - - iterated_test_function = (CutIteratedTestFunction)test_function; - test_iterator = cut_test_iterator_new(names->test_name, - iterated_test_function, - data_setup_function); + test_iterator = + create_test_iterator(priv, + names->test_name, + (CutIteratedTestFunction)test_function, + data_setup_function); test = CUT_TEST(test_iterator); } else { test = create_test(priv, names->test_name, test_function); Modified: cutter/cut-loader.h (+14 -0) =================================================================== --- cutter/cut-loader.h 2014-01-20 23:09:34 +0900 (76ffc4d) +++ cutter/cut-loader.h 2014-01-20 23:10:43 +0900 (18be60b) @@ -41,6 +41,15 @@ typedef struct _CutLoaderClass CutLoaderClass; typedef CutTest *(*CutCreateTestFunction) (const gchar *name, CutTestFunction function, gpointer user_data); +typedef CutTestIterator * + (*CutCreateTestIteratorFunction) + (const gchar *name, + CutIteratedTestFunction + iterated_test_function, + CutDataSetupFunction + data_setup_function, + gpointer user_data); + struct _CutLoader { GObject object; @@ -69,6 +78,11 @@ void cut_loader_set_create_test_function (CutLoader *loader, CutCreateTestFunction create_test_function, gpointer user_data); +void cut_loader_set_create_test_iterator_function + (CutLoader *loader, + CutCreateTestIteratorFunction + create_test_iterator_function, + gpointer user_data); GList *cut_loader_load_test_cases (CutLoader *loader); CutTestCase *cut_loader_load_test_case (CutLoader *loader); CutTestSuite *cut_loader_load_test_suite (CutLoader *loader); Modified: cutter/cut-test-iterator.c (+26 -3) =================================================================== --- cutter/cut-test-iterator.c 2014-01-20 23:09:34 +0900 (17f141c) +++ cutter/cut-test-iterator.c 2014-01-20 23:10:43 +0900 (f1200bc) @@ -219,6 +219,27 @@ cut_test_iterator_new_empty (void) return cut_test_iterator_new(NULL, NULL, NULL); } +CutIteratedTest * +cut_test_iterator_create_iterated_test (CutTestIterator *test_iterator, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutTestData *test_data) +{ + CutTestIteratorClass *klass; + + klass = CUT_TEST_ITERATOR_GET_CLASS(test_iterator); + if (klass->create_iterated_test) { + return klass->create_iterated_test(test_iterator, + name, + iterated_test_function, + test_data); + } else { + return cut_iterated_test_new(name, + iterated_test_function, + test_data); + } +} + void cut_test_iterator_add_test (CutTestIterator *test_iterator, CutIteratedTest *test) @@ -428,9 +449,11 @@ run_iterated_tests (CutTest *test, CutTestContext *test_context, CutTestData *test_data; test_data = cut_test_context_get_current_data(test_context); - iterated_test = cut_iterated_test_new(cut_test_get_name(test), - priv->iterated_test_function, - test_data); + iterated_test = + cut_test_iterator_create_iterated_test(test_iterator, + cut_test_get_name(test), + priv->iterated_test_function, + test_data); cut_test_iterator_add_test(test_iterator, iterated_test); g_object_unref(iterated_test); Modified: cutter/cut-test-iterator.h (+13 -1) =================================================================== --- cutter/cut-test-iterator.h 2014-01-20 23:09:34 +0900 (12b42a9) +++ cutter/cut-test-iterator.h 2014-01-20 23:10:43 +0900 (344d98a) @@ -1,6 +1,6 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright (C) 2008 Kouhei Sutou <ko...@co...> + * Copyright (C) 2008-2014 Kouhei Sutou <ko...@cl...> * * 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 @@ -47,6 +47,12 @@ struct _CutTestIteratorClass { CutTestContainerClass parent_class; + CutIteratedTest * + (*create_iterated_test) + (CutTestIterator *test_iterator, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutTestData *test_data); void (*ready) (CutTestIterator *test_iterator, guint n_tests); void (*start_iterated_test) @@ -66,6 +72,12 @@ CutTestIterator *cut_test_iterator_new (const gchar *name, CutIteratedTestFunction function, CutDataSetupFunction data_setup_function); CutTestIterator *cut_test_iterator_new_empty (void); + +CutIteratedTest *cut_test_iterator_create_iterated_test + (CutTestIterator *test_iterator, + const gchar *name, + CutIteratedTestFunction iterated_test_function, + CutTestData *test_data); void cut_test_iterator_add_test (CutTestIterator *test_iterator, CutIteratedTest *test); Modified: module/loader-customizer/cut-exception-loader-customizer.c (+15 -0) =================================================================== --- module/loader-customizer/cut-exception-loader-customizer.c 2014-01-20 23:09:34 +0900 (77afcb0) +++ module/loader-customizer/cut-exception-loader-customizer.c 2014-01-20 23:10:43 +0900 (ed01c30) @@ -28,6 +28,7 @@ #include <cutter/cut-loader-customizer.h> #include <cppcutter/cppcut-test.h> +#include <cppcutter/cppcut-test-iterator.h> #define CUT_TYPE_EXCEPTION_LOADER_CUSTOMIZER \ cut_type_exception_loader_customizer @@ -142,10 +143,24 @@ create_test (const gchar *name, return CUT_TEST(cppcut_test_new(name, function)); } +static CutTestIterator * +create_test_iterator (const gchar *name, + CutIteratedTestFunction function, + CutDataSetupFunction data_setup_function, + gpointer user_data) +{ + return CUT_TEST_ITERATOR(cppcut_test_iterator_new(name, + function, + data_setup_function)); +} + static void customize (CutLoaderCustomizer *customizer, CutLoader *loader) { cut_loader_set_create_test_function(loader, create_test, NULL); + cut_loader_set_create_test_iterator_function(loader, + create_test_iterator, + NULL); } /* Modified: test/cppcutter/Makefile.am (+2 -1) =================================================================== --- test/cppcutter/Makefile.am 2014-01-20 23:09:34 +0900 (498f6cf) +++ test/cppcutter/Makefile.am 2014-01-20 23:10:43 +0900 (f679c92) @@ -27,4 +27,5 @@ LIBS = \ test_cppcut_la_SOURCES = \ test-cppcut-assertions.cpp \ - test-cppcut-test.cpp + test-cppcut-test.cpp \ + test-cppcut-iterated-test.cpp Added: test/cppcutter/test-cppcut-iterated-test.cpp (+159 -0) 100644 =================================================================== --- /dev/null +++ test/cppcutter/test-cppcut-iterated-test.cpp 2014-01-20 23:10:43 +0900 (0d2d687) @@ -0,0 +1,159 @@ +/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright (C) 2014 Kouhei Sutou <ko...@cl...> + * + * 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <typeinfo> + +#include <cppcutter.h> + +#include <cppcutter/cppcut-iterated-test.h> +#include <cutter/cut-test-runner.h> + +#include "../lib/cuttest-assertions.h" + +namespace cppcut_iterated_test +{ + CppCutIteratedTest *iterated_test; + CutTestData *test_data; + CutRunContext *run_context; + CutTestContext *test_context; + CutTestResult *test_result; + + static gboolean + run (void) + { + gboolean success; + + run_context = CUT_RUN_CONTEXT(cut_test_runner_new()); + + test_context = cut_test_context_new(run_context, NULL, NULL, NULL, + CUT_TEST(iterated_test)); + cut_test_context_current_push(test_context); + success = cut_test_runner_run_test(CUT_TEST_RUNNER(run_context), + CUT_TEST(iterated_test), + test_context); + cut_test_context_current_pop(); + + return success; + } + + void + cut_setup (void) + { + iterated_test = NULL; + test_data = cut_test_data_new("NULL data", NULL, NULL); + run_context = NULL; + test_context = NULL; + test_result = NULL; + } + + void + cut_teardown (void) + { + if (iterated_test) + g_object_unref(iterated_test); + if (test_data) + g_object_unref(test_data); + if (run_context) + g_object_unref(run_context); + if (test_context) + g_object_unref(test_context); + if (test_result) + g_object_unref(test_result); + } + + class StubException : public std::exception + { + public: + StubException(const char *message) : message_(message) + { + } + + virtual const char * + what(void) const throw() + { + return message_; + } + + private: + const char *message_; + }; + + static void + stub_std_exception (gconstpointer data) + { + throw StubException("std::exception family exception"); + } + + void + test_std_exception (void) + { + iterated_test = cppcut_iterated_test_new("std::exception test", + stub_std_exception, + test_data); + cut_assert_not_null(iterated_test); + + cut_assert_false(run()); + cut_assert_test_result_summary(run_context, 1, 0, 0, 0, 1, 0, 0, 0); + const gchar *system_message = + cut_take_printf("Unhandled C++ standard exception is thrown: " + "<%s>: %s", + typeid(StubException).name(), + "std::exception family exception"); + cut_assert_test_result(run_context, 0, CUT_TEST_RESULT_ERROR, + "std::exception test (NULL data)", + NULL, + system_message, + NULL, NULL, + NULL, + "void cppcut_test::stub_standard_exception()", + NULL); + } + + static void + stub_not_std_exception (gconstpointer data) + { + throw "not std::exception"; + } + + void + test_not_std_exception (void) + { + iterated_test = cppcut_iterated_test_new("not std::exception test", + stub_not_std_exception, + test_data); + cut_assert_not_null(iterated_test); + + cut_assert_false(run()); + cut_assert_test_result_summary(run_context, 1, 0, 0, 0, 1, 0, 0, 0); + const gchar *system_message = + "Unhandled C++ non-standard exception is thrown"; + cut_assert_test_result(run_context, 0, CUT_TEST_RESULT_ERROR, + "not std::exception test (NULL data)", + NULL, + system_message, + NULL, NULL, + NULL, + "void cppcut_test::stub_not_standard_exception()", + NULL); + } +} + +/* +vi:ts=4:nowrap:ai:expandtab:sw=4:ts=4 +*/ |