├── html ├── .gitignore └── style.css ├── example ├── misc │ ├── .gitignore │ ├── main.cpp │ ├── CMakeLists.txt │ └── inline_test.cpp ├── ugly │ ├── .gitignore │ ├── main.cpp │ ├── CMakeLists.txt │ ├── ugly.cc │ ├── ugly.cpp │ └── line_num.cc ├── reverse │ ├── .gitignore │ ├── main.cpp │ ├── CMakeLists.txt │ ├── my_reverse_fwd.hpp │ ├── my_reverse.hpp │ ├── test.cc │ ├── test.cpp │ └── my_reverse_impl.hpp ├── stream_type │ ├── .gitignore │ ├── README │ ├── CMakeLists.txt │ └── main.cpp ├── boost_mpl_unit_test │ ├── .gitignore │ ├── main.cpp │ ├── CMakeLists.txt │ ├── quote.cpp │ ├── identity.cpp │ ├── if.cpp │ ├── eval_if.cpp │ ├── always.cpp │ ├── find.cpp │ ├── is_sequence.cpp │ ├── logical.cpp │ ├── arithmetic.cpp │ ├── comparison.cpp │ ├── list.cpp │ ├── vector_c.cpp │ ├── bind.cpp │ ├── deque.cpp │ ├── list_c.cpp │ ├── apply.cpp │ ├── set_c.cpp │ ├── vector.cpp │ ├── map.cpp │ └── set.cpp ├── metatest_example │ ├── .gitignore │ ├── main.cpp │ ├── CMakeLists.txt │ ├── double.cpp │ └── failures.cpp ├── boost_test_assertion │ ├── main.cpp │ ├── CMakeLists.txt │ ├── double.cpp │ └── failures.cpp └── CMakeLists.txt ├── .gitignore ├── test ├── no.cpp ├── yes.cpp ├── debug.cpp ├── get_type.cpp ├── has_type.cpp ├── location.cpp ├── test.cpp ├── get_value.cpp ├── has_value.cpp ├── suite_path.cpp ├── test_driver.cpp ├── test_result.cpp ├── test_suite.cpp ├── to_stream.cpp ├── xml_report.cpp ├── main.cpp ├── to_stream_mpl.cpp ├── get_type_value.cpp ├── has_type_value.cpp ├── plaintext_report.cpp ├── character_printer.cpp ├── to_stream_sequence.cpp └── CMakeLists.txt ├── .travis.yml ├── doc ├── CMakeLists.txt ├── xml_report.md ├── plaintext_report.md ├── METATEST_HERE.md ├── html_report.md ├── METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE.md ├── METATEST_DEFINE_TO_STREAM_FOR_TYPE.md ├── to_stream.md ├── location.md ├── meta_warn.md ├── meta_check.md ├── meta_require.md ├── METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE.md ├── test_driver.md ├── METATEST_ADD_TEST.md ├── to_stream_argument_list.md ├── METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS.md ├── suite_path.md ├── test_suite.md ├── build.md └── test_result.md ├── include └── metatest │ ├── plaintext_report.hpp │ ├── no.hpp │ ├── yes.hpp │ ├── main_html.hpp │ ├── config.hpp │ ├── html_report.hpp │ ├── xml_report.hpp │ ├── main.hpp │ ├── has_type.hpp │ ├── debug.hpp │ ├── get_value.hpp │ ├── has_type_value.hpp │ ├── get_type.hpp │ ├── get_type_value.hpp │ ├── test_driver.hpp │ ├── suite_path.hpp │ ├── test.hpp │ ├── location.hpp │ ├── test_suite.hpp │ ├── character_printer.hpp │ ├── has_value.hpp │ ├── boost_test.hpp │ ├── to_stream_argument_list.hpp │ ├── to_stream.hpp │ ├── test_result.hpp │ ├── to_stream_fwd.hpp │ └── to_stream_sequence.hpp ├── src ├── CMakeLists.txt ├── test_driver.cpp ├── suite_path.cpp ├── plaintext_report.cpp ├── test_suite.cpp ├── xml_report.cpp └── html_report.cpp ├── cmake ├── Documentation.cmake ├── Files.cmake ├── Pandoc.cmake └── ExampleOutput.cmake ├── README.md ├── CMakeLists.txt └── tools └── gen_toc /html/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /example/misc/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /example/ugly/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /example/reverse/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /example/stream_type/.gitignore: -------------------------------------------------------------------------------- 1 | sample 2 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /example/metatest_example/.gitignore: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /example/stream_type/README: -------------------------------------------------------------------------------- 1 | This example demonstrates how to print types at runtime. 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | bin 4 | /index.html 5 | /build.html 6 | website 7 | local.mk 8 | -------------------------------------------------------------------------------- /test/no.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/yes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/get_type.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/has_type.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/location.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | before_install: 6 | - sudo apt-get install libboost1.48-dev libboost-test1.48-dev 7 | script: 8 | - mkdir bin 9 | - cd bin 10 | - cmake .. -DCMAKE_CXX_FLAGS:STRING="-std=c++0x" 11 | - make 12 | - make test 13 | -------------------------------------------------------------------------------- /test/get_value.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/has_value.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/suite_path.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/test_driver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/test_result.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/test_suite.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/to_stream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/xml_report.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/to_stream_mpl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /example/misc/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/get_type_value.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/has_type_value.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/plaintext_report.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /example/reverse/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/character_printer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /test/to_stream_sequence.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /example/metatest_example/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | include(Documentation) 7 | 8 | generate_documentation(metatest html) 9 | 10 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /include/metatest/plaintext_report.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_PLAINTEXT_REPORT_HPP 2 | #define METATEST_PLAINTEXT_REPORT_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace metatest { 9 | 10 | METATEST_DECL bool plaintext_report(std::ostream &os_); 11 | 12 | } // namespace metatest 13 | 14 | #endif // METATEST_PLAINTEXT_REPORT_HPP 15 | 16 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_library(metatest ${SOURCES}) 8 | 9 | install(TARGETS metatest DESTINATION lib) 10 | 11 | -------------------------------------------------------------------------------- /example/boost_test_assertion/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define BOOST_TEST_DYN_LINK 7 | #define BOOST_TEST_MODULE example_test 8 | #include 9 | 10 | 11 | -------------------------------------------------------------------------------- /include/metatest/no.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_NO_HPP 2 | #define METATEST_NO_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | namespace metatest 10 | { 11 | typedef char (&no)[2]; 12 | } 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /include/metatest/yes.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_YES_HPP 2 | #define METATEST_YES_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | namespace metatest 10 | { 11 | typedef char yes; 12 | } 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | subdirs( 7 | boost_mpl_unit_test 8 | boost_test_assertion 9 | metatest_example 10 | misc 11 | reverse 12 | stream_type 13 | ugly 14 | ) 15 | 16 | -------------------------------------------------------------------------------- /example/ugly/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | int main () 10 | { 11 | metatest::html_report(std::cout); 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/ugly/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | file(GLOB SOURCES *.cpp) 7 | add_executable(ugly ${SOURCES}) 8 | 9 | target_link_libraries(ugly metatest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 10 | 11 | include(ExampleOutput) 12 | example_output(ugly ugly) 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(metatest_test ${SOURCES}) 8 | 9 | target_link_libraries(metatest_test metatest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 10 | 11 | add_test(metatest_unit_tests metatest_test) 12 | 13 | -------------------------------------------------------------------------------- /example/misc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(misc ${SOURCES}) 8 | 9 | target_link_libraries(misc metatest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 10 | 11 | include(ExampleOutput) 12 | example_text_output(misc misc) 13 | 14 | -------------------------------------------------------------------------------- /example/reverse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | file(GLOB SOURCES *.cpp) 7 | add_executable(reverse ${SOURCES}) 8 | 9 | target_link_libraries(reverse metatest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 10 | 11 | include(ExampleOutput) 12 | example_text_output(reverse reverse) 13 | 14 | 15 | -------------------------------------------------------------------------------- /include/metatest/main_html.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_MAIN_HTML_HPP 2 | #define METATEST_MAIN_HTML_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | metatest::html_report(std::cout); 15 | } 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /example/stream_type/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(stream_type ${SOURCES}) 8 | 9 | target_link_libraries(stream_type metatest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) 10 | 11 | include(ExampleOutput) 12 | example_text_output(stream_type stream_type) 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/reverse/my_reverse_fwd.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_MY_REVERSE_FWD_HPP_INCLUDED 2 | #define METATEST_MY_REVERSE_FWD_HPP_INCLUDED 3 | 4 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_2_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | template< typename Tag > struct my_reverse_impl; 10 | template< typename Sequence > struct my_reverse; 11 | 12 | #endif // METATEST_MY_REVERSE_FWD_HPP_INCLUDED 13 | 14 | -------------------------------------------------------------------------------- /include/metatest/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_CONFIG_HPP 2 | #define METATEST_CONFIG_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #ifdef METATEST_SOURCE 12 | #define METATEST_DECL BOOST_SYMBOL_EXPORT 13 | #else 14 | #define METATEST_DECL BOOST_SYMBOL_IMPORT 15 | #endif 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /cmake/Documentation.cmake: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | include(Pandoc) 7 | 8 | macro(generate_documentation LIB_NAME OUT_DIR_NAME) 9 | file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.md) 10 | pandoc_build(${LIB_NAME}_documentation 11 | ${CMAKE_CURRENT_SOURCE_DIR}/../${OUT_DIR_NAME} 12 | ${SOURCES} 13 | ) 14 | endmacro(generate_documentation) 15 | 16 | 17 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(boost_mpl_unit_test ${SOURCES}) 8 | 9 | target_link_libraries(boost_mpl_unit_test 10 | metatest 11 | ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} 12 | ) 13 | 14 | include(ExampleOutput) 15 | example_output(boost_mpl_unit_test boost_mpl_unit_test) 16 | 17 | -------------------------------------------------------------------------------- /example/metatest_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(metatest_example ${SOURCES}) 8 | 9 | target_link_libraries(metatest_example 10 | metatest 11 | ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} 12 | ) 13 | 14 | include(ExampleOutput) 15 | example_text_output(metatest_example metatest_example) 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/metatest/html_report.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_HTML_REPORT_HPP 2 | #define METATEST_HTML_REPORT_HPP 3 | 4 | // Copyright Endre Tamas Sajo (baja@inf.elte.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace metatest { 14 | 15 | METATEST_DECL bool html_report(std::ostream &os_); 16 | 17 | } // namespace metatest 18 | 19 | #endif // METATEST_HTML_REPORT_H 20 | 21 | -------------------------------------------------------------------------------- /include/metatest/xml_report.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_XML_REPORT_HPP 2 | #define METATEST_XML_REPORT_HPP 3 | 4 | // Copyright Endre Tamas Sajo (baja@inf.elte.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace metatest { 14 | 15 | METATEST_DECL bool xml_report(std::ostream &os_); 16 | 17 | } // namespace metatest 18 | 19 | #endif // METATEST_XML_REPORT_HPP 20 | 21 | -------------------------------------------------------------------------------- /example/boost_test_assertion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | aux_source_directory(. SOURCES) 7 | add_executable(boost_test_assertion ${SOURCES}) 8 | 9 | target_link_libraries(boost_test_assertion 10 | metatest 11 | ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} 12 | ) 13 | 14 | include(ExampleOutput) 15 | example_text_output(boost_test_assertion boost_test_assertion) 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/metatest/main.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_MAIN_HPP 2 | #define METATEST_MAIN_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | int main() 15 | { 16 | using metatest::plaintext_report; 17 | using std::cout; 18 | 19 | return plaintext_report(cout) ? 0 : 1; 20 | } 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /include/metatest/has_type.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_HAS_TYPE_HPP 2 | #define METATEST_HAS_TYPE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace metatest 14 | { 15 | BOOST_MPL_HAS_XXX_TRAIT_DEF(type) 16 | } 17 | 18 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, metatest::has_type, "has_type") 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /include/metatest/debug.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_DEBUG_HPP 2 | #define METATEST_DEBUG_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace metatest 14 | { 15 | template 16 | struct debug 17 | { 18 | debug() 19 | { 20 | to_stream::run(std::cout) << std::endl; 21 | exit(0); 22 | } 23 | }; 24 | } 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /example/reverse/my_reverse.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_MY_REVERSE_HPP_INCLUDED 2 | #define METATEST_MY_REVERSE_HPP_INCLUDED 3 | 4 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_2_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include "my_reverse_fwd.hpp" 10 | #include "my_reverse_impl.hpp" 11 | 12 | #include 13 | 14 | template< typename Sequence > 15 | struct my_reverse 16 | : my_reverse_impl< 17 | typename boost::mpl::sequence_tag::type 18 | >::template apply 19 | {}; 20 | 21 | #endif // METATEST_MY_REVERSE_HPP_INCLUDED 22 | -------------------------------------------------------------------------------- /doc/xml_report.md: -------------------------------------------------------------------------------- 1 | # metatest::xml_report 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | bool xml_report(std::ostream &os_) 7 | ``` 8 | 9 | ## Description 10 | 11 | Displays the test results as an xml document. Returns `true` when there 12 | was no failed test case. 13 | 14 | ## Header 15 | 16 | ```cpp 17 | #include 18 | ``` 19 | 20 | 27 | 28 | [[up]](index.html) 29 | 30 | 31 | -------------------------------------------------------------------------------- /cmake/Files.cmake: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | macro(dir PATH) 7 | get_filename_component(P ${PATH} ABSOLUTE) 8 | add_custom_command( 9 | OUTPUT ${P} 10 | COMMAND mkdir -p ${P} 11 | ) 12 | endmacro(dir) 13 | 14 | macro(copy_file SRC_PATH FILENAME DST_PATH) 15 | get_filename_component(P ${DST_PATH} ABSOLUTE) 16 | set(DST ${P}/${FILENAME}) 17 | set(SRC ${SRC_PATH}/${FILENAME}) 18 | 19 | add_custom_command( 20 | OUTPUT ${DST} 21 | COMMAND cp ${SRC} ${DST} 22 | DEPENDS ${SRC} ${P} ${ARGN} 23 | ) 24 | endmacro(copy_file) 25 | 26 | -------------------------------------------------------------------------------- /doc/plaintext_report.md: -------------------------------------------------------------------------------- 1 | # metatest::plaintext_report 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | bool plaintext_report(std::ostream &os_) 7 | ``` 8 | 9 | ## Description 10 | 11 | Displays the test results in a plain-text format. Returns `true` when there 12 | was no failed test case. 13 | 14 | ## Header 15 | 16 | ```cpp 17 | #include 18 | ``` 19 | 20 | 27 | 28 | [[up]](index.html) 29 | 30 | 31 | -------------------------------------------------------------------------------- /include/metatest/get_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_GET_VALUE_HPP 2 | #define METATEST_GET_VALUE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace metatest 16 | { 17 | template 18 | struct get_value : 19 | boost::mpl::eval_if::type, T, Default> 20 | {}; 21 | } 22 | 23 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(2, metatest::get_value, "get_value") 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /doc/METATEST_HERE.md: -------------------------------------------------------------------------------- 1 | # METATEST_HERE 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_HERE \ 7 | // unspecified 8 | ``` 9 | 10 | ## Description 11 | 12 | Macro for constructing a [`location`](location.html) value, representing 13 | the source location that invokes `METATEST_HERE`. 14 | 15 | ## Header 16 | 17 | ```cpp 18 | #include 19 | ``` 20 | 21 | 28 | 29 | [[up]](index.html) 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /include/metatest/has_type_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_HAS_TYPE_VALUE_HPP 2 | #define METATEST_HAS_TYPE_VALUE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace metatest 14 | { 15 | template 16 | struct has_type_value : 17 | has_value::type, ValueType> 18 | {}; 19 | } 20 | 21 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE( 22 | 2, 23 | metatest::has_type_value, 24 | "has_type_value" 25 | ) 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /include/metatest/get_type.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_GET_TYPE_HPP 2 | #define METATEST_GET_TYPE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace metatest 17 | { 18 | template 19 | struct get_type : 20 | boost::mpl::eval_if< 21 | typename has_type::type, 22 | T, 23 | boost::mpl::identity 24 | > 25 | {}; 26 | } 27 | 28 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(2, metatest::get_type, "get_type") 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /doc/html_report.md: -------------------------------------------------------------------------------- 1 | # metatest::html_report 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | bool html_report(std::ostream &os_) 7 | ``` 8 | 9 | ## Description 10 | 11 | Displays the test results as an HTML document. Returns `true` when there 12 | was no failed test case. The HTML document assumes that 13 | [`jquery.js`](http://jquery.com/) is in the same directory as the generated HTML 14 | document itself. 15 | 16 | ## Header 17 | 18 | ```cpp 19 | #include 20 | ``` 21 | 22 | 29 | 30 | [[up]](index.html) 31 | 32 | 33 | -------------------------------------------------------------------------------- /include/metatest/get_type_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_GET_TYPE_VALUE_HPP 2 | #define METATEST_GET_TYPE_VALUE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace metatest 17 | { 18 | template 19 | struct get_type_value : 20 | get_value< 21 | typename get_type >::type, 22 | Default 23 | > 24 | {}; 25 | } 26 | 27 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE( 28 | 2, 29 | metatest::get_type_value, 30 | "get_type_value" 31 | ) 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /cmake/Pandoc.cmake: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | find_program(PANDOC pandoc) 7 | set(GEN_TOC ${PROJECT_SOURCE_DIR}/tools/gen_toc) 8 | 9 | macro(pandoc_build TARGET_NAME OUTDIR) 10 | set(OUTFILES) 11 | foreach(IT ${ARGN}) 12 | get_filename_component(FILENAME ${IT} NAME_WE) 13 | set(OUTFILE ${OUTDIR}/${FILENAME}.html) 14 | set(OUTFILES ${OUTFILES} ${OUTFILE}) 15 | add_custom_command( 16 | OUTPUT ${OUTFILE} 17 | COMMAND 18 | ${GEN_TOC} -i ${IT} -o - -t pandoc_html | 19 | ${PANDOC} --from markdown --to html -c style.css -o ${OUTFILE} 20 | DEPENDS ${IT} 21 | ) 22 | endforeach(IT) 23 | add_custom_target(${TARGET_NAME} DEPENDS ${OUTFILES}) 24 | endmacro(pandoc_build) 25 | 26 | -------------------------------------------------------------------------------- /doc/METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE.md: -------------------------------------------------------------------------------- 1 | # METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(name) \ 7 | // unspecified 8 | ``` 9 | 10 | ## Description 11 | 12 | Defines an overload of [`to_stream`](to_stream.html) for the type `name`. 13 | 14 | ## Header 15 | 16 | ```cpp 17 | #include 18 | ``` 19 | 20 | ## Example 21 | 22 | ```cpp 23 | class custom_type; 24 | 25 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(custom_type) 26 | ``` 27 | 28 | 35 | 36 | [[up]](index.html) 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/test_driver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define METATEST_SOURCE 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | using metatest::test_driver; 14 | using metatest::test_suite; 15 | using metatest::test_result; 16 | using metatest::suite_path; 17 | 18 | test_driver& test_driver::instance() 19 | { 20 | return boost::unit_test::singleton::instance(); 21 | } 22 | 23 | void test_driver::add(const suite_path& suite_, const test_result& result_) 24 | { 25 | _suite.add(suite_.begin(), suite_.end(), result_); 26 | } 27 | 28 | const test_suite& test_driver::suite() const 29 | { 30 | return _suite; 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /include/metatest/test_driver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TEST_DRIVER_HPP 2 | #define METATEST_TEST_DRIVER_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.-2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | 19 | namespace metatest 20 | { 21 | class test_driver 22 | { 23 | public: 24 | METATEST_DECL static test_driver& instance(); 25 | 26 | METATEST_DECL const test_suite& suite() const; 27 | 28 | METATEST_DECL void add(const suite_path& suite_,const test_result& result_); 29 | private: 30 | test_suite _suite; 31 | }; 32 | } 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /example/metatest_example/double.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using metatest::suite_path; 15 | 16 | using boost::mpl::equal_to; 17 | using boost::mpl::int_; 18 | 19 | // Metafunction to test 20 | template 21 | struct double_ : boost::mpl::times > {}; 22 | 23 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, double_, "double_") 24 | 25 | namespace 26 | { 27 | const suite_path suite("example"); 28 | 29 | typedef equal_to >::type, int_<26> > test_success; 30 | } 31 | 32 | METATEST_ADD_TEST(suite, test_success) 33 | 34 | 35 | -------------------------------------------------------------------------------- /example/ugly/ugly.cc: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace boost; 15 | using namespace mpl; 16 | 17 | MPL_TEST_CASE() 18 | { 19 | typedef front< vector > f; 20 | 21 | MPL_ASSERT(( is_same )); 22 | } 23 | 24 | MPL_TEST_CASE() 25 | { 26 | typedef size< vector > s; 27 | 28 | MPL_ASSERT_RELATION(s, ==, 3); 29 | } 30 | 31 | MPL_TEST_CASE() 32 | { 33 | typedef vector v1; 34 | typedef pop_front::type v2; 35 | 36 | MPL_ASSERT(( is_same< v2, vector > )); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/suite_path.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define METATEST_SOURCE 7 | 8 | #include 9 | 10 | using metatest::suite_path; 11 | 12 | using std::string; 13 | 14 | suite_path::suite_path() 15 | {} 16 | 17 | suite_path::suite_path(const std::string& p_) : 18 | _elements(1, p_) 19 | {} 20 | 21 | suite_path::suite_path(const std::list& p_) : 22 | _elements(p_) 23 | {} 24 | 25 | suite_path::iterator suite_path::begin() const 26 | { 27 | return _elements.begin(); 28 | } 29 | 30 | suite_path::iterator suite_path::end() const 31 | { 32 | return _elements.end(); 33 | } 34 | 35 | suite_path suite_path::operator()(const std::string& e_) const 36 | { 37 | suite_path result(*this); 38 | result._elements.push_back(e_); 39 | return result; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /example/boost_test_assertion/double.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define BOOST_TEST_DYN_LINK 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | using metatest::meta_require; 18 | 19 | using boost::mpl::equal_to; 20 | using boost::mpl::int_; 21 | 22 | // Metafunction to test 23 | template 24 | struct double_ : boost::mpl::times > {}; 25 | 26 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, double_, "double_") 27 | 28 | BOOST_AUTO_TEST_CASE(example) 29 | { 30 | meta_require< 31 | equal_to >::type, int_<26> > 32 | >(METATEST_HERE, "test_success"); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /doc/METATEST_DEFINE_TO_STREAM_FOR_TYPE.md: -------------------------------------------------------------------------------- 1 | # METATEST_DEFINE_TO_STREAM_FOR_TYPE 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_DEFINE_TO_STREAM_FOR_TYPE(name, display_name) \ 7 | // unspecified 8 | ``` 9 | 10 | ## Description 11 | 12 | Defines an overload of [`to_stream`](to_stream.html) for the type `name`. 13 | `display_name` is a constant expression that can be displayed in a stream 14 | using `operator<<`. 15 | 16 | ## Header 17 | 18 | ```cpp 19 | #include 20 | ``` 21 | 22 | ## Example 23 | 24 | ```cpp 25 | class custom_type; 26 | 27 | METATEST_DEFINE_TO_STREAM_FOR_TYPE(custom_type, "custom_type") 28 | ``` 29 | 30 | 37 | 38 | [[up]](index.html) 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /include/metatest/suite_path.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_SUITE_PATH_HPP 2 | #define METATEST_SUITE_PATH_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace metatest 15 | { 16 | class suite_path 17 | { 18 | private: 19 | typedef std::list elements; 20 | public: 21 | typedef elements::const_iterator iterator; 22 | 23 | METATEST_DECL suite_path(); 24 | METATEST_DECL suite_path(const std::string& p_); 25 | METATEST_DECL suite_path(const std::list& p_); 26 | 27 | METATEST_DECL iterator begin() const; 28 | METATEST_DECL iterator end() const; 29 | 30 | METATEST_DECL suite_path operator()(const std::string& e_) const; 31 | private: 32 | elements _elements; 33 | }; 34 | } 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | metatest 2 | ======== 3 | 4 | [![Build Status](https://secure.travis-ci.org/sabel83/metatest.png?branch=master "Build Status")](http://travis-ci.org/sabel83/metatest) 5 | 6 | Introduction 7 | ------------ 8 | 9 | Metatest is a unit testing framework for C++ template metaprograms. It can be 10 | integrated into other C++ unit testing frameworks and has its own reporting 11 | capabilities as well. There are no special steps in the compilation of unit 12 | tests compared to other C++ code. 13 | 14 | Documentation 15 | ------------- 16 | 17 | The documentation of the library can be automatically generated by running the 18 | `website` target. It is also available [here](http://abel.web.elte.hu/metatest). 19 | 20 | Getting the library 21 | ------------------- 22 | 23 | * Download the source code from [github](http://github.com/sabel83/metatest). 24 | * [build and install](http://abel.web.elte.hu/metatest/build.html) the library 25 | 26 | License 27 | ------- 28 | 29 | The libraries are published under the 30 | [Boost Software License](http://www.boost.org/LICENSE_1_0.txt). 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/to_stream.md: -------------------------------------------------------------------------------- 1 | # metatest::to_stream 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | template 7 | struct to_stream 8 | { 9 | static std::ostream& run(std::ostream& o_); 10 | }; 11 | ``` 12 | 13 | ## Description 14 | 15 | Tool for pretty-printing types at runtime. It takes the type as a compile-time 16 | and the stream to print it to as a runtime argument. Pretty-printing support for 17 | new types can be added by specialising this template and providing the `run` 18 | method in the specialisation. 19 | 20 | ## Header 21 | 22 | ```cpp 23 | #include 24 | ``` 25 | 26 | ## Example 27 | 28 | ```cpp 29 | int main() 30 | { 31 | to_stream::run(std::cout); 32 | } 33 | ``` 34 | 35 | 42 | 43 | [[up]](index.html) 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/reverse/test.cc: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Abel Sinkovics (abel@sinkovics.hu) 2011. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_2_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include "my_reverse.hpp" 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | MPL_TEST_CASE() 15 | { 16 | using namespace boost; 17 | using namespace mpl; 18 | 19 | typedef vector<> empty; 20 | typedef vector one; 21 | typedef vector four; 22 | 23 | typedef vector four_r; 24 | 25 | MPL_ASSERT((equal< my_reverse::type, empty >)); 26 | MPL_ASSERT((equal< my_reverse::type, one >)); 27 | MPL_ASSERT((equal< my_reverse::type, four_r >)); 28 | 29 | MPL_ASSERT((equal< my_reverse::type, one >)); 30 | MPL_ASSERT((equal< my_reverse::type, empty >)); 31 | MPL_ASSERT((equal< my_reverse::type, four >)); 32 | } 33 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/quote.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace 12 | { 13 | const metatest::suite_path suite ("quote"); 14 | 15 | using namespace boost::mpl; 16 | using boost::is_same; 17 | 18 | template 19 | struct f1 20 | { 21 | typedef T type; 22 | }; 23 | 24 | template 25 | struct f5 26 | { 27 | #if defined(BOOST_MPL_CFG_NO_IMPLICIT_METAFUNCTIONS) 28 | typedef f5 type; 29 | #endif 30 | }; 31 | 32 | typedef quote1::apply::type q1; 33 | typedef quote5::apply::type q5; 34 | 35 | typedef is_same t1; 36 | typedef is_same > t5; 37 | } 38 | 39 | METATEST_ADD_TEST (suite, t1) 40 | METATEST_ADD_TEST (suite, t5) 41 | 42 | -------------------------------------------------------------------------------- /example/ugly/ugly.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace boost; 15 | using namespace mpl; 16 | 17 | namespace 18 | { 19 | const metatest::suite_path suite ("ugly"); 20 | 21 | namespace testcase_1 22 | { 23 | typedef front< vector > f; 24 | 25 | typedef is_same test1; 26 | METATEST_ADD_TEST(suite, test1) 27 | } 28 | 29 | namespace testcase_2 30 | { 31 | typedef size< vector > s; 32 | 33 | typedef equal_to< s, int_<3> > test2; 34 | METATEST_ADD_TEST(suite, test2) 35 | } 36 | 37 | namespace testcase_3 38 | { 39 | typedef vector v1; 40 | typedef pop_front::type v2; 41 | 42 | typedef is_same< v2, vector > test3; 43 | METATEST_ADD_TEST(suite, test3) 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /include/metatest/test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TEST_HPP 2 | #define METATEST_TEST_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | #ifdef METATEST_ADD_TEST 13 | #error METATEST_ADD_TEST already defined 14 | #endif 15 | // We have to use a namespace not used anywhere else to avoid 16 | // test cases being replaced by other classes in the background 17 | #define METATEST_ADD_TEST(suite, name) \ 18 | namespace metatest_test_cases \ 19 | { \ 20 | namespace \ 21 | { \ 22 | struct name##_executor \ 23 | { \ 24 | name##_executor() \ 25 | { \ 26 | metatest::test_driver::instance().add( \ 27 | (suite), \ 28 | metatest::test_result::build(METATEST_HERE, #name) \ 29 | ); \ 30 | } \ 31 | \ 32 | static name##_executor instance; \ 33 | }; \ 34 | \ 35 | name##_executor name##_executor::instance; \ 36 | } \ 37 | } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /include/metatest/location.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_LOCATION_HPP 2 | #define METATEST_LOCATION_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010-2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace metatest 13 | { 14 | #ifdef METATEST_HERE 15 | #error METATEST_HERE already defined 16 | #endif 17 | #define METATEST_HERE (metatest::location(__FILE__, __LINE__)) 18 | 19 | class location 20 | { 21 | public: 22 | location(const std::string& filename_, int line_number_) : 23 | _filename(filename_), 24 | _line_number(line_number_) 25 | {} 26 | 27 | const std::string& filename() const 28 | { 29 | return _filename; 30 | } 31 | 32 | int line_number() const 33 | { 34 | return _line_number; 35 | } 36 | private: 37 | std::string _filename; 38 | int _line_number; 39 | }; 40 | 41 | inline std::ostream& operator<<(std::ostream& out_, const location& l_) 42 | { 43 | return out_ << l_.filename() << ":" << l_.line_number(); 44 | } 45 | } 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/identity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace 13 | { 14 | const metatest::suite_path suite ("identity"); 15 | 16 | using boost::is_same; 17 | using boost::mpl::_1; 18 | using boost::mpl::apply1; 19 | using boost::mpl::apply; 20 | using boost::mpl::identity; 21 | using boost::mpl::make_identity; 22 | 23 | typedef is_same< apply1, char>::type, char > t1; 24 | typedef is_same< apply1, int>::type, int > t2; 25 | 26 | typedef is_same< 27 | apply1< make_identity<>, char >::type 28 | , identity 29 | > t3; 30 | 31 | typedef is_same< 32 | apply1< make_identity<_1>, int >::type 33 | , identity 34 | > t4; 35 | } 36 | 37 | METATEST_ADD_TEST (suite, t1) 38 | METATEST_ADD_TEST (suite, t2) 39 | METATEST_ADD_TEST (suite, t3) 40 | METATEST_ADD_TEST (suite, t4) 41 | 42 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/if.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("if"); 16 | 17 | using namespace boost::mpl; 18 | 19 | typedef equal_to< 20 | if_, int_<2> >::type 21 | , int_<1> 22 | > test_if_true; 23 | 24 | typedef equal_to< 25 | if_c, int_<2> >::type 26 | , int_<1> 27 | > test_if_c_true; 28 | 29 | typedef equal_to< 30 | if_, int_<2> >::type 31 | , int_<2> 32 | > test_if_false; 33 | 34 | typedef equal_to< 35 | if_c, int_<2> >::type 36 | , int_<2> 37 | > test_if_c_false; 38 | } 39 | 40 | METATEST_ADD_TEST (suite, test_if_true) 41 | METATEST_ADD_TEST (suite, test_if_c_true) 42 | METATEST_ADD_TEST (suite, test_if_false) 43 | METATEST_ADD_TEST (suite, test_if_c_false) 44 | 45 | -------------------------------------------------------------------------------- /example/misc/inline_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | 10 | template 11 | struct remove_parentheses_helper 12 | { typedef T type; }; 13 | 14 | template 15 | struct remove_parentheses_helper 16 | { typedef T type; }; 17 | 18 | #define REMOVE_PARENTHESES(t) \ 19 | remove_parentheses_helper::type 20 | 21 | #define METATEST_TEST_IF_EQUAL(a, b, suite, test_name) \ 22 | namespace \ 23 | { \ 24 | typedef boost::mpl::equal_to < \ 25 | REMOVE_PARENTHESES(a) \ 26 | , REMOVE_PARENTHESES(b) \ 27 | > test_name; \ 28 | } \ 29 | METATEST_ADD_TEST(suite, test_name) 30 | 31 | #include 32 | 33 | namespace 34 | { 35 | const metatest::suite_path suite ("inline_test"); 36 | using namespace boost::mpl; 37 | } 38 | 39 | METATEST_TEST_IF_EQUAL((int_<0>), (int_<0>), suite, test1) 40 | 41 | namespace 42 | { 43 | typedef equal_to, int_<0> > test2; 44 | } 45 | 46 | METATEST_ADD_TEST(suite, test2) 47 | 48 | -------------------------------------------------------------------------------- /doc/location.md: -------------------------------------------------------------------------------- 1 | # metatest::location 2 | 3 | `location` instances represent locations in the source code. Instances are 4 | immutable, thus their state can not be changed after construction. 5 | 6 | A special macro, [`METATEST_HERE`](METATEST_HERE.html) represents the current 7 | location. 8 | 9 | ## Header 10 | 11 | ```cpp 12 | #include 13 | ``` 14 | 15 | ## Constructors 16 | 17 | ```cpp 18 | location::location(const std::string& filename_, int line_number_) 19 | ``` 20 | 21 | Creates a new instance with the specified properties. 22 | 23 | ## Methods 24 | 25 | None of the methods throws an exception. 26 | 27 | ```cpp 28 | const std::string& location::filename() const 29 | ``` 30 | 31 | Name of the file, where the test case was registered. 32 | 33 | ```cpp 34 | int location::line_number() const 35 | ``` 36 | 37 | Line number, where the test case was registered. 38 | 39 | 46 | 47 | [[up]](index.html) 48 | 49 | 50 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/eval_if.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("eval_if"); 16 | 17 | using namespace boost::mpl; 18 | using boost::is_same; 19 | 20 | typedef is_same< 21 | eval_if< true_, identity, identity >::type 22 | , char 23 | > t1; 24 | 25 | typedef is_same< 26 | eval_if_c< true, identity, identity >::type 27 | , char 28 | > t2; 29 | 30 | typedef is_same< 31 | eval_if< false_, identity, identity >::type 32 | , long 33 | > t3; 34 | 35 | typedef is_same< 36 | eval_if_c< false, identity, identity >::type 37 | , long 38 | > t4; 39 | } 40 | 41 | METATEST_ADD_TEST (suite, t1) 42 | METATEST_ADD_TEST (suite, t2) 43 | METATEST_ADD_TEST (suite, t3) 44 | METATEST_ADD_TEST (suite, t4) 45 | 46 | -------------------------------------------------------------------------------- /doc/meta_warn.md: -------------------------------------------------------------------------------- 1 | # metatest::meta_warn 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | template 7 | void meta_warn(const location& location_, const std::string& name_); 8 | 9 | template 10 | void meta_warn(const location& location_); 11 | ``` 12 | 13 | This template function simplifies passing template metaprogrmaming assertions to 14 | Boost.Test. It creates a [`test_result`](test_result.html) from 15 | the `Pred` predicate using `location_` and `name_` when available. The 16 | success/failure flag and the reason string of the result is then passed to a 17 | Boost.Test `WARN` assertion. 18 | 19 | ## Header 20 | 21 | ```cpp 22 | #include 23 | ``` 24 | 25 | ## Example 26 | 27 | ```cpp 28 | BOOST_AUTO_TEST_CASE(example) 29 | { 30 | meta_warn< 31 | boost::mpl::equal_to, function_to_test::type> 32 | >(METATEST_HERE); 33 | } 34 | ``` 35 | 36 | 43 | 44 | [[up]](index.html) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/meta_check.md: -------------------------------------------------------------------------------- 1 | # metatest::meta_check 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | template 7 | void meta_check(const location& location_, const std::string& name_); 8 | 9 | template 10 | void meta_check(const location& location_); 11 | ``` 12 | 13 | This template function simplifies passing template metaprogrmaming assertions to 14 | Boost.Test. It creates a [`test_result`](test_result.html) from the `Pred` 15 | predicate using `location_` and `name_` when available. The success/failure flag 16 | and the reason string of the result is then passed to a Boost.Test `CHECK` 17 | assertion. 18 | 19 | ## Header 20 | 21 | ```cpp 22 | #include 23 | ``` 24 | 25 | ## Example 26 | 27 | ```cpp 28 | BOOST_AUTO_TEST_CASE(example) 29 | { 30 | meta_check< 31 | boost::mpl::equal_to, function_to_test::type> 32 | >(METATEST_HERE); 33 | } 34 | ``` 35 | 36 | 43 | 44 | [[up]](index.html) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /include/metatest/test_suite.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TEST_FIXTURE_HPP 2 | #define METATEST_TEST_FIXTURE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace metatest 19 | { 20 | class test_driver; 21 | 22 | class test_suite 23 | { 24 | public: 25 | friend class test_driver; 26 | 27 | typedef std::map suite_map; 28 | typedef std::list result_list; 29 | 30 | METATEST_DECL size_t failure_count() const; 31 | METATEST_DECL size_t count() const; 32 | 33 | METATEST_DECL const suite_map& suites() const; 34 | METATEST_DECL const result_list& results() const; 35 | private: 36 | suite_map _suites; 37 | result_list _results; 38 | 39 | void add( 40 | suite_path::iterator begin_, 41 | suite_path::iterator end_, 42 | const test_result& result_ 43 | ); 44 | }; 45 | } 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /doc/meta_require.md: -------------------------------------------------------------------------------- 1 | # metatest::meta_require 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | template 7 | void meta_require(const location& location_, const std::string& name_); 8 | 9 | template 10 | void meta_require(const location& location_); 11 | ``` 12 | 13 | This template function simplifies passing template metaprogrmaming assertions to 14 | Boost.Test. It creates a [`test_result`](test_result.html) from 15 | the `Pred` predicate using `location_` and `name_` when available. The 16 | success/failure flag and the reason string of the result is then passed to a 17 | Boost.Test `REQUIRE` assertion. 18 | 19 | ## Header 20 | 21 | ```cpp 22 | #include 23 | ``` 24 | 25 | ## Example 26 | 27 | ```cpp 28 | BOOST_AUTO_TEST_CASE(example) 29 | { 30 | meta_require< 31 | boost::mpl::equal_to, function_to_test::type> 32 | >(METATEST_HERE); 33 | } 34 | ``` 35 | 36 | 43 | 44 | [[up]](index.html) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(arg_num, name, display_name) \ 7 | // unspecified 8 | ``` 9 | 10 | ## Description 11 | 12 | Defines an overload of [`to_stream`](to_stream.html) for instances of the 13 | template `name` taking `arg_num` arguments, where `arg_num` is an integer value. 14 | `display_name` is a constant expression that can be displayed in a stream 15 | using `operator<<`. It is displayed as the name of the template. 16 | [`to_stream`](to_stream.html) is called recursively for the template 17 | arguments. 18 | 19 | ## Header 20 | 21 | ```cpp 22 | #include 23 | ``` 24 | 25 | ## Example 26 | 27 | ```cpp 28 | template 29 | class custom_template; 30 | 31 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(3, custom_template, "custom_template") 32 | ``` 33 | 34 | 41 | 42 | [[up]](index.html) 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /doc/test_driver.md: -------------------------------------------------------------------------------- 1 | # metatest::test_driver 2 | 3 | Class of a singleton object representing the entire hierarchy of the test 4 | suites. The singleton object can be used to access the root the hierarchy. 5 | 6 | ## Header 7 | 8 | ```cpp 9 | #include 10 | ``` 11 | 12 | ## Methods 13 | 14 | None of the methods throws an exception. 15 | 16 | ```cpp 17 | static test_driver& test_driver::instance() 18 | ``` 19 | 20 | The singleton `test_driver` instance. 21 | 22 | ```cpp 23 | const test_suite& test_driver::suite() const 24 | ``` 25 | 26 | Root of the test suite hierarchy. 27 | 28 | ```cpp 29 | void test_driver::add( 30 | const suite_path& suite_, 31 | const test_result& result_ 32 | ) 33 | ``` 34 | 35 | Add a new test result to a test suite. 36 | 37 | ## Example 38 | 39 | ```cpp 40 | int process_results(const test_suite& root_); 41 | 42 | int main() 43 | { 44 | return process_results(test_driver::instance().suite()); 45 | } 46 | ``` 47 | 48 | 55 | 56 | [[up]](index.html) 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/always.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("always"); 16 | 17 | using namespace boost::mpl; 18 | 19 | typedef always always_true; 20 | typedef always > always_10; 21 | 22 | typedef apply1 test_apply_f; 23 | typedef apply2 test_apply_f_f; 24 | typedef apply3 test_apply_f_f_f; 25 | 26 | typedef apply1 >::type test_apply_0; 27 | typedef apply2, int_<0> >::type test_apply_0_0; 28 | typedef apply3, int_<0>, int_<0> >::type test_apply_0_0_0; 29 | } 30 | 31 | METATEST_ADD_TEST(suite, test_apply_f) 32 | METATEST_ADD_TEST(suite, test_apply_f_f) 33 | METATEST_ADD_TEST(suite, test_apply_f_f_f) 34 | 35 | METATEST_ADD_TEST(suite, test_apply_0) 36 | METATEST_ADD_TEST(suite, test_apply_0_0) 37 | METATEST_ADD_TEST(suite, test_apply_0_0_0) 38 | 39 | -------------------------------------------------------------------------------- /doc/METATEST_ADD_TEST.md: -------------------------------------------------------------------------------- 1 | # METATEST_ADD_TEST 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_ADD_TEST(path, test) \ 7 | // unspecified 8 | ``` 9 | 10 | 11 | ## Description 12 | 13 | Macro for registering a test case. `path` is a 14 | [`suite_path`](suite_path.html) instance, `test` is a nullary template 15 | metafunction evaluating to a boxed boolean value, the success of the test case. 16 | 17 | At runtime, the test case is guaranteed to be registered in the test hierarchy 18 | before `main` is called. 19 | 20 | ## Header 21 | 22 | ```cpp 23 | #include 24 | ``` 25 | 26 | ## Example 27 | 28 | ```cpp 29 | using boost::mpl::is_equal; 30 | using boost::mpl::int_; 31 | 32 | template 33 | struct metafunction_to_test; 34 | 35 | const suite_path suite = suite_path("test")("suite"); 36 | 37 | typedef 38 | is_equal, metafunction_to_test, int_<83>>> 39 | test_case; 40 | 41 | METATEST_ADD_TEST(suite, test_case) 42 | ``` 43 | 44 | 51 | 52 | [[up]](index.html) 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /example/reverse/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include "my_reverse.hpp" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("my_reverse"); 16 | 17 | using namespace boost; 18 | using namespace mpl; 19 | 20 | typedef vector<> empty; 21 | typedef vector one; 22 | typedef vector four; 23 | 24 | typedef vector four_r; 25 | 26 | typedef equal< my_reverse::type, empty > empty_test; 27 | typedef equal< my_reverse::type, one > one_test; 28 | typedef equal< my_reverse::type, four_r > four_test; 29 | 30 | typedef equal< my_reverse::type, one > empty_test_failing; 31 | typedef equal< my_reverse::type, empty > one_test_failing; 32 | typedef equal< my_reverse::type, four > four_test_failing; 33 | } 34 | 35 | METATEST_ADD_TEST(suite, empty_test) 36 | METATEST_ADD_TEST(suite, one_test) 37 | METATEST_ADD_TEST(suite, four_test) 38 | 39 | METATEST_ADD_TEST(suite, empty_test_failing) 40 | METATEST_ADD_TEST(suite, one_test_failing) 41 | METATEST_ADD_TEST(suite, four_test_failing) 42 | 43 | -------------------------------------------------------------------------------- /doc/to_stream_argument_list.md: -------------------------------------------------------------------------------- 1 | # metates::to_stream_argument_list 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | template < 7 | class T1, 8 | // ... 9 | class Tn 10 | > 11 | struct to_stream_argument_list 12 | { 13 | static std::ostream& run(std::ostream&); 14 | // unspecified 15 | }; 16 | ``` 17 | 18 | ## Description 19 | 20 | Tool for pretty-printing template arguments of a template instance. It takes 21 | the arguments of the instance as template arguments and uses 22 | [`to_stream`](to_stream.html) for pretty-printing them. 23 | 24 | ## Header 25 | 26 | ```cpp 27 | #include 28 | ``` 29 | 30 | ## Example 31 | 32 | ```cpp 33 | template 34 | struct plus 35 | { 36 | // implementation of the plus metafunction 37 | 38 | struct to_stream 39 | { 40 | // display "plus" 41 | static std::ostream& run(std::ostream& o) 42 | { 43 | o << "plus<"; 44 | to_stream_argument_list::run(o); 45 | return o << ">"; 46 | } 47 | }; 48 | } 49 | ``` 50 | 51 | 58 | 59 | [[up]](index.html) 60 | 61 | 62 | -------------------------------------------------------------------------------- /example/ugly/line_num.cc: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | // MPL_TEST_CASE and various asserts use preprocessor line number information 13 | // to guarantee unique names 14 | 15 | #line 1 16 | MPL_TEST_CASE() 17 | { 18 | using namespace boost::mpl; 19 | typedef vector2 v2; 20 | 21 | #line 1 22 | MPL_ASSERT(( equal )); 23 | 24 | #line 1 25 | MPL_ASSERT(( equal )); 26 | } 27 | 28 | #line 1 29 | MPL_TEST_CASE() 30 | { 31 | using namespace boost::mpl; 32 | typedef vector3 v3; 33 | MPL_ASSERT(( equal )); 34 | } 35 | 36 | // $ g++ -c line_num.cpp 37 | // line_num.cpp: In function ‘void test1()’: 38 | // line_num.cpp:1: error: conflicting declaration ‘mpl_assertion_in_line_1’ 39 | // line_num.cpp:1: error: ‘mpl_assertion_in_line_1’ has a previous declaration as 40 | // ‘test1():: mpl_assertion_in_line_1’ 41 | // line_num.cpp: In function ‘void test1()’: 42 | // line_num.cpp:1: error: redefinition of ‘void test1()’ 43 | // line_num.cpp:1: error: ‘void test1()’ previously defined here 44 | 45 | -------------------------------------------------------------------------------- /cmake/ExampleOutput.cmake: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | macro(example_output EXAMPLE_NAME) 7 | if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") 8 | set(BINARY ${EXAMPLE_NAME}) 9 | set(HTML ${CMAKE_CURRENT_SOURCE_DIR}/../../html/example_${EXAMPLE_NAME}.html) 10 | set(CMD ${CMAKE_CURRENT_BINARY_DIR}/${BINARY}) 11 | add_custom_command( 12 | OUTPUT ${HTML} 13 | COMMAND ${CMD} > ${HTML} 14 | DEPENDS ${CMD} 15 | ) 16 | add_custom_target(example_${EXAMPLE_NAME}_output DEPENDS ${HTML}) 17 | endif() 18 | endmacro(example_output) 19 | 20 | macro(example_text_output EXAMPLE_NAME) 21 | if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") 22 | set(BINARY ${EXAMPLE_NAME}) 23 | set(HTML ${CMAKE_CURRENT_SOURCE_DIR}/../../html/example_${EXAMPLE_NAME}.html) 24 | set(CMD ${CMAKE_CURRENT_BINARY_DIR}/${BINARY}) 25 | add_custom_command( 26 | OUTPUT ${HTML} 27 | COMMAND echo '${EXAMPLE_NAME}' > ${HTML} 28 | COMMAND ${CMD} | sed 's/\\&/\\&/g' | sed 's/ /\\ /g' | sed 's//\\>/g' | sed 's/$$//' >> ${HTML} 29 | COMMAND echo '' >> ${HTML} 30 | DEPENDS ${CMD} 31 | ) 32 | add_custom_target(example_${EXAMPLE_NAME}_output DEPENDS ${HTML}) 33 | endif() 34 | endmacro(example_text_output) 35 | 36 | 37 | -------------------------------------------------------------------------------- /include/metatest/character_printer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_CHARACTER_PRINTER_HPP 2 | #define METATEST_CHARACTER_PRINTER_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | namespace metatest 12 | { 13 | class character_printer 14 | { 15 | public: 16 | character_printer(std::ostream& o_) : _o(o_) {} 17 | 18 | void operator()(unsigned char c_) 19 | { 20 | switch (c_) 21 | { 22 | case '\0': _o << "\\0"; break; 23 | case '\n': _o << "\\n"; break; 24 | case '\t': _o << "\\t"; break; 25 | case '\b': _o << "\\b"; break; 26 | case '\v': _o << "\\v"; break; 27 | case '\r': _o << "\\r"; break; 28 | case '\f': _o << "\\f"; break; 29 | case '\a': _o << "\\a"; break; 30 | case '\\': _o << "\\\\"; break; 31 | case '\?': _o << "\\?"; break; 32 | case '\'': _o << "\\\'"; break; 33 | case '\"': _o << "\\\""; break; 34 | default: 35 | if (c_ > 31 && c_ != 127) 36 | { 37 | _o << c_; 38 | } 39 | else 40 | { 41 | using std::ios_base; 42 | using std::ios; 43 | 44 | _o << "\\x"; 45 | 46 | const ios_base::fmtflags f = _o.flags(); 47 | _o.flags(ios::hex); 48 | _o << (c_ & 0xf0) << (c_ & 0x0f); 49 | _o.flags(f); 50 | } 51 | } 52 | } 53 | private: 54 | std::ostream& _o; 55 | }; 56 | } 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/find.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace 17 | { 18 | const metatest::suite_path suite ("arithmetic"); 19 | 20 | using namespace boost::mpl; 21 | using boost::is_same; 22 | 23 | typedef list::type types; 24 | typedef list_c values; 25 | 26 | typedef find::type types_iter; 27 | typedef find< values, integral_c >::type values_iter; 28 | 29 | typedef begin::type types_first; 30 | typedef begin::type values_first; 31 | 32 | typedef is_same< deref::type, short > test_deref_1; 33 | typedef equal_to< deref::type, int_<7> > test_deref_2; 34 | 35 | //typedef equal_to< 36 | // distance 37 | // , int_<3> 38 | // > test_distance_1; 39 | 40 | //typedef equal_to< 41 | // distance 42 | // , int_<4> 43 | // > test_distance_2; 44 | } 45 | 46 | METATEST_ADD_TEST(suite, test_deref_1) 47 | METATEST_ADD_TEST(suite, test_deref_2) 48 | 49 | //METATEST_ADD_TEST(suite, test_distance_1) 50 | //METATEST_ADD_TEST(suite, test_distance_2) 51 | 52 | -------------------------------------------------------------------------------- /doc/METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS.md: -------------------------------------------------------------------------------- 1 | # METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS 2 | 3 | ## Synopsis 4 | 5 | ```cpp 6 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS( 7 | min_arg_num, 8 | max_arg_num, 9 | name, 10 | display_name 11 | ) \ 12 | // unspecified 13 | ``` 14 | 15 | ## Description 16 | 17 | Defines an overload of [`to_stream`](to_stream.html) for instances of the 18 | template `name` taking `max_arg_num` arguments. The last 19 | `max_arg_num - min_arg_num` template arguments have default values, thus 20 | the template can be instantiated with `min_arg_num`, `min_arg_num + 1`, ... 21 | `max_arg_num` number of arguments. `min_arg_num` and `max_arg_num` are integer 22 | values. `display_name` is a constant expression that can be displayed in a 23 | stream using `operator<<`. It is displayed as the name of the template. 24 | [`to_stream`](to_stream.html) is called recursively for the template arguments. 25 | 26 | ## Header 27 | 28 | ```cpp 29 | #include 30 | ``` 31 | 32 | ## Example 33 | 34 | ```cpp 35 | template 36 | class custom_template; 37 | 38 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS( 39 | 1, 40 | 3, 41 | custom_template, 42 | "custom_template" 43 | ) 44 | ``` 45 | 46 | 53 | 54 | [[up]](index.html) 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/is_sequence.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace 16 | { 17 | const metatest::suite_path suite ("is_sequence"); 18 | 19 | using namespace boost::mpl; 20 | 21 | template struct std_vector 22 | { 23 | T* begin(); 24 | }; 25 | 26 | struct UDT {}; 27 | 28 | typedef not_ > > test1; 29 | typedef not_ > > test2; 30 | typedef not_ > test3; 31 | typedef not_ > test4; 32 | typedef not_ > test5; 33 | typedef not_ > test6; 34 | typedef is_sequence< range_c > test7; 35 | typedef is_sequence< list<> > test8; 36 | typedef is_sequence< list > test9; 37 | typedef is_sequence< vector<> > test10; 38 | typedef is_sequence< vector > test11; 39 | } 40 | 41 | METATEST_ADD_TEST(suite, test1) 42 | METATEST_ADD_TEST(suite, test2) 43 | METATEST_ADD_TEST(suite, test3) 44 | METATEST_ADD_TEST(suite, test4) 45 | METATEST_ADD_TEST(suite, test5) 46 | METATEST_ADD_TEST(suite, test6) 47 | METATEST_ADD_TEST(suite, test7) 48 | METATEST_ADD_TEST(suite, test8) 49 | METATEST_ADD_TEST(suite, test9) 50 | METATEST_ADD_TEST(suite, test10) 51 | METATEST_ADD_TEST(suite, test11) 52 | 53 | -------------------------------------------------------------------------------- /example/boost_test_assertion/failures.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define BOOST_TEST_DYN_LINK 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | using metatest::meta_check; 21 | 22 | using boost::mpl::true_; 23 | using boost::mpl::false_; 24 | using boost::mpl::equal_to; 25 | using boost::mpl::int_; 26 | using boost::mpl::plus; 27 | using boost::mpl::not_; 28 | using boost::mpl::and_; 29 | using boost::mpl::or_; 30 | 31 | using boost::is_same; 32 | 33 | // Bad metafunction: no "type" 34 | template 35 | struct bad {}; 36 | 37 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, bad, "bad") 38 | 39 | // Bad metafunction for a test case: no "type::value" 40 | template 41 | struct bad2 42 | { 43 | struct type {}; 44 | }; 45 | 46 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, bad2, "bad2") 47 | 48 | BOOST_AUTO_TEST_CASE(example_failure) 49 | { 50 | meta_check >(METATEST_HERE, "test_no_type"); 51 | 52 | meta_check >(METATEST_HERE, "test_no_type_value"); 53 | 54 | meta_check(METATEST_HERE); 55 | 56 | meta_check, plus, int_<2> >::type> >(METATEST_HERE); 57 | 58 | meta_check >(METATEST_HERE); 59 | 60 | meta_check, true_> > >(METATEST_HERE); 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /include/metatest/has_value.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_HAS_VALUE_HPP 2 | #define METATEST_HAS_VALUE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace metatest 19 | { 20 | // Based on C++ Template Metaprogramming, chapter 9.10 21 | template 22 | struct has_value 23 | { 24 | struct type 25 | { 26 | template 27 | struct value_wrapper; 28 | 29 | // It needs an extra int argument to remove ambiguity between 30 | // this version and the one with ... 31 | template 32 | static 33 | typename 34 | boost::mpl::apply_wrap1< 35 | boost::mpl::always, 36 | boost::mpl::integral_c 37 | >::type 38 | tester(T*, int); 39 | 40 | // I have to pass a T* argument to make Visual C++ accept it 41 | template 42 | static no tester(T*, ...); 43 | 44 | static const bool 45 | value = 46 | sizeof( 47 | has_value::type::tester(static_cast(0), 13) 48 | ) 49 | == sizeof(yes); 50 | }; 51 | }; 52 | } 53 | 54 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(2, metatest::has_value, "has_value") 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /doc/suite_path.md: -------------------------------------------------------------------------------- 1 | # metatest::suite_path 2 | 3 | `suite_path` instances represent locations in the test suite hierarchy. 4 | Instances are immutable, thus their state can not be changed after 5 | construction. 6 | 7 | ## Header 8 | 9 | ```cpp 10 | #include 11 | ``` 12 | 13 | ## Types 14 | 15 | ```cpp 16 | suite_path::iterator 17 | ``` 18 | 19 | Bi-directional, read-only iterator of the elements of the path. 20 | 21 | ## Constructors 22 | 23 | ```cpp 24 | suite_path::suite_path() 25 | ``` 26 | 27 | Construct an empty path. 28 | 29 | ```cpp 30 | suite_path::suite_path(const std::string &) 31 | ``` 32 | 33 | Construct a single element path. 34 | 35 | ```cpp 36 | suite_path::suite_path(const std::list &) 37 | ``` 38 | 39 | Construct a path with multiple elements. 40 | 41 | ## Methods 42 | 43 | None of the methods throws an exception. 44 | 45 | ```cpp 46 | suite_path::iterator suite_path::begin() const 47 | ``` 48 | 49 | Iterator to the first element. 50 | 51 | ```cpp 52 | suite_path::iterator suite_path::end() const 53 | ``` 54 | 55 | Iterator pointing after the last element. 56 | 57 | ```cpp 58 | suite_path suite_path::operator()(const std::string &) const 59 | ``` 60 | 61 | Append a new element to the end of the path. 62 | 63 | ## Example 64 | 65 | ```cpp 66 | const suite_path suite = suite_path("util")("curry"); 67 | ``` 68 | 69 | 76 | 77 | [[up]](index.html) 78 | 79 | 80 | -------------------------------------------------------------------------------- /doc/test_suite.md: -------------------------------------------------------------------------------- 1 | # metatest::test_suite 2 | 3 | `suite_path` instances represent locations in the test suite hierarchy. 4 | Instances are immutable, thus their state can not be changed after 5 | construction. 6 | 7 | ## Header 8 | 9 | ```cpp 10 | #include 11 | ``` 12 | 13 | ## Types 14 | 15 | ```cpp 16 | suite_path::suite_map 17 | ``` 18 | 19 | Associative container mapping `std::string` keys to `test_suite` values. 20 | 21 | ```cpp 22 | suite_path::result_list 23 | ``` 24 | 25 | Container of [`test_result`](test_result.html) values. 26 | 27 | ## Constructors 28 | 29 | No public constructors are available. 30 | 31 | ## Methods 32 | 33 | None of the methods throws an exception. 34 | 35 | ```cpp 36 | size_t test_suite::failure_count() const 37 | ``` 38 | 39 | Number of failed tests. 40 | 41 | ```cpp 42 | size_t test_suite::count() const 43 | ``` 44 | 45 | Number of all tests. 46 | 47 | ```cpp 48 | const test_suite::suite_map& test_suite::suites() const 49 | ``` 50 | 51 | Suites which have the current suite as parent. 52 | 53 | ```cpp 54 | const test_suite::result_list& test_suite::results() const 55 | ``` 56 | 57 | Result objects corresponding to the tests within the current suite. 58 | 59 | ## Example 60 | 61 | ```cpp 62 | int process_results(const test_suite& root_) 63 | { 64 | return root_.failure_count() == 0 ? 0 : 1; 65 | } 66 | ``` 67 | 68 | 75 | 76 | [[up]](index.html) 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/plaintext_report.cpp: -------------------------------------------------------------------------------- 1 | #define METATEST_SOURCE 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | namespace metatest { 12 | 13 | namespace 14 | { 15 | void display(ostream& out_, const string& path_, const test_suite& f_) 16 | { 17 | using std::endl; 18 | 19 | for ( 20 | test_suite::suite_map::const_iterator 21 | i = f_.suites().begin(), 22 | e = f_.suites().end(); 23 | i != e; 24 | ++i 25 | ) 26 | { 27 | display(out_, path_ + i->first + "::", i->second); 28 | } 29 | 30 | for ( 31 | test_suite::result_list::const_iterator 32 | i = f_.results().begin(), 33 | e = f_.results().end(); 34 | i != e; 35 | ++i 36 | ) 37 | { 38 | out_ << " " << path_ << i->get_name() << ": "; 39 | if (i->success()) 40 | { 41 | out_ << "OK"; 42 | } 43 | else 44 | { 45 | out_ << "FAIL (" << i->get_location() << ")"; 46 | if (i->has_reason()) 47 | { 48 | out_ << endl << "\t" << i->get_reason(); 49 | } 50 | } 51 | out_ << endl; 52 | } 53 | } 54 | } 55 | 56 | bool plaintext_report(std::ostream& out_) 57 | { 58 | using std::endl; 59 | 60 | const test_suite& suite = test_driver::instance().suite(); 61 | 62 | out_ << "The following tests have been executed:" << endl; 63 | 64 | display(out_, "", suite); 65 | 66 | out_ << "========================" << endl; 67 | out_ << "Number of tests: " << suite.count() << endl; 68 | out_ << "Number of failures: " << suite.failure_count() << endl; 69 | 70 | return suite.failure_count() == 0; 71 | } 72 | 73 | } // namespace metatest 74 | 75 | -------------------------------------------------------------------------------- /example/reverse/my_reverse_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_MY_REVERSE_IMPL_HPP_INCLUDED 2 | #define METATEST_MY_REVERSE_IMPL_HPP_INCLUDED 3 | 4 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_2_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | template< typename Tag > struct my_reverse_impl {}; 17 | 18 | template< typename First, typename Last, typename Accum > 19 | struct my_accum_reverse_impl; 20 | 21 | #if defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES) 22 | template<> 23 | struct my_reverse_impl< 24 | boost::mpl::aux::vector_tag 25 | > 26 | #else 27 | template 28 | struct my_reverse_impl< 29 | boost::mpl::aux::vector_tag 30 | > 31 | #endif 32 | { 33 | template< typename Vector > struct apply 34 | : my_accum_reverse_impl< 35 | typename boost::mpl::begin::type 36 | , typename boost::mpl::end::type 37 | , boost::mpl::vector<> 38 | > 39 | {}; 40 | }; 41 | 42 | template< typename First, typename Last, typename Accum > 43 | struct my_accum_reverse_impl 44 | : my_accum_reverse_impl< 45 | typename boost::mpl::next::type 46 | , Last 47 | , typename boost::mpl::push_front< 48 | Accum 49 | , typename boost::mpl::deref::type 50 | >::type 51 | > 52 | {}; 53 | 54 | template< typename Last, typename Accum > 55 | struct my_accum_reverse_impl< Last, Last, Accum > 56 | : Accum 57 | {}; 58 | 59 | #endif // METATEST_MY_REVERSE_IMPL_HPP_INCLUDED 60 | 61 | -------------------------------------------------------------------------------- /include/metatest/boost_test.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_BOOST_TEST_HPP 2 | #define METATEST_BOOST_TEST_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | namespace metatest 13 | { 14 | template 15 | void meta_warn(const location& location_, const std::string& name_) 16 | { 17 | const test_result result = test_result::build(location_, name_); 18 | BOOST_WARN_MESSAGE(result.success(), result); 19 | } 20 | 21 | template 22 | void meta_warn(const location& location_) 23 | { 24 | const test_result result = test_result::build(location_); 25 | BOOST_WARN_MESSAGE(result.success(), result); 26 | } 27 | 28 | template 29 | void meta_check(const location& location_, const std::string& name_) 30 | { 31 | const test_result result = test_result::build(location_, name_); 32 | BOOST_CHECK_MESSAGE(result.success(), result); 33 | } 34 | 35 | template 36 | void meta_check(const location& location_) 37 | { 38 | const test_result result = test_result::build(location_); 39 | BOOST_CHECK_MESSAGE(result.success(), result); 40 | } 41 | 42 | template 43 | void meta_require(const location& location_, const std::string& name_) 44 | { 45 | const test_result result = test_result::build(location_, name_); 46 | BOOST_REQUIRE_MESSAGE(result.success(), result); 47 | } 48 | 49 | template 50 | void meta_require(const location& location_) 51 | { 52 | const test_result result = test_result::build(location_); 53 | BOOST_REQUIRE_MESSAGE(result.success(), result); 54 | } 55 | } 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | cmake_minimum_required(VERSION 2.6) 7 | project(metatest) 8 | 9 | find_package(Boost COMPONENTS unit_test_framework REQUIRED) 10 | include_directories(${Boost_INCLUDE_DIR}) 11 | link_directories(${Boost_LIBRARY_DIRS}) 12 | 13 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 14 | include(Pandoc) 15 | include(Files) 16 | 17 | enable_testing() 18 | 19 | include_directories("include") 20 | 21 | set(BUILD_SHARED_LIBS ON) 22 | 23 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 24 | subdirs(src test example) 25 | else() 26 | # Documentation generation is supported on Unix only 27 | subdirs(src test example doc) 28 | 29 | # metatest code samples 30 | foreach(E 31 | boost_mpl_unit_test 32 | metatest_example 33 | stream_type 34 | boost_test_assertion 35 | ugly 36 | misc 37 | reverse 38 | ) 39 | set(EXAMPLE_OUTPUTS ${EXAMPLE_OUTPUTS} example_${E}_output) 40 | endforeach(E) 41 | 42 | add_custom_target(website DEPENDS metatest_documentation ${EXAMPLE_OUTPUTS}) 43 | endif() 44 | 45 | 46 | # Installation 47 | macro(install_with_dir PREFIX_TO_CUT) 48 | 49 | string(LENGTH ${PREFIX_TO_CUT} PREFIX_LEN) 50 | 51 | foreach(F ${ARGN}) 52 | string(REGEX MATCH "(.*)[/\\]" DIR ${F}) 53 | string(LENGTH ${DIR} DIR_LEN) 54 | math(EXPR DIR_KEEP "${DIR_LEN} - ${PREFIX_LEN}") 55 | string(SUBSTRING ${DIR} ${PREFIX_LEN} ${DIR_KEEP} DIR2) 56 | install(FILES ${F} DESTINATION include/${DIR2}) 57 | endforeach(F) 58 | 59 | endmacro(install_with_dir) 60 | 61 | 62 | file(GLOB_RECURSE HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) 63 | install_with_dir(${CMAKE_CURRENT_SOURCE_DIR} ${HEADER_FILES}) 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /example/metatest_example/failures.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | using metatest::suite_path; 18 | 19 | using boost::mpl::true_; 20 | using boost::mpl::false_; 21 | using boost::mpl::equal_to; 22 | using boost::mpl::int_; 23 | using boost::mpl::plus; 24 | using boost::mpl::not_; 25 | using boost::mpl::and_; 26 | using boost::mpl::or_; 27 | 28 | using boost::is_same; 29 | 30 | // Bad metafunction: no "type" 31 | template 32 | struct bad {}; 33 | 34 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, bad, "bad") 35 | 36 | // Bad metafunction for a test case: no "type::value" 37 | template 38 | struct bad2 39 | { 40 | struct type {}; 41 | }; 42 | 43 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(1, bad2, "bad2") 44 | 45 | namespace 46 | { 47 | const suite_path suite("example_failure"); 48 | 49 | typedef bad test_no_type; 50 | 51 | typedef bad2 test_no_type_value; 52 | 53 | typedef false_ test_fail; 54 | 55 | typedef 56 | equal_to, plus, int_<27> >::type> 57 | test_fail_with_to_equal; 58 | 59 | typedef is_same test_fail_with_is_same; 60 | 61 | typedef not_, true_> > test_fail_complex_expression; 62 | } 63 | 64 | METATEST_ADD_TEST(suite, test_no_type) 65 | METATEST_ADD_TEST(suite, test_no_type_value) 66 | METATEST_ADD_TEST(suite, test_fail) 67 | METATEST_ADD_TEST(suite, test_fail_with_to_equal) 68 | METATEST_ADD_TEST(suite, test_fail_with_is_same) 69 | METATEST_ADD_TEST(suite, test_fail_complex_expression) 70 | 71 | 72 | -------------------------------------------------------------------------------- /doc/build.md: -------------------------------------------------------------------------------- 1 | # Building metatest 2 | 3 | ## Building the library on Linux 4 | 5 | * `mkdir bin && cd bin && cmake ..` sets the build directory up 6 | * `make` builds the code 7 | * `make test` runs the unit tests 8 | * `make website` generates the documentation 9 | * `make install` installs it on the system 10 | 11 | ### Using a custom compiler 12 | 13 | `cmake` should be given the following command line arguments:
14 | `cmake .. -DCMAKE_CXX_COMPILER:STRING=""` 15 | 16 | ### Enabling C++11 during compilation 17 | 18 | `cmake` should be given the following command line arguments:
19 | `cmake .. -DCMAKE_CXX_FLAGS:STRING="-std=c$$++$$0x"` 20 | 21 | ### Using a custom Boost version 22 | 23 | `cmake` should be given the following command line arguments:
24 | `cmake .. -DCMAKE_CXX_FLAGS:STRING="-I" -DCMAKE_SHARED_LINKER_FLAGS:STRING="-L"` 25 | 26 | ### Installing into a custom directory 27 | 28 | `cmake` should be given the following command line arguments:
29 | `cmake .. -DCMAKE_INSTALL_PREFIX:PATH=` 30 | 31 | ### Building the library on Windows 32 | 33 | * Start the CMake gui. 34 | * Set _Where is the source code_ to the root directory of the metatest source 35 | code. 36 | * Set _Where to build the binaries_ to the directory where you would like to 37 | build the binaries to. It may be the "bin" directory of the metatest source 38 | code. 39 | * Click on _Configure_ and choose the compiler to use. 40 | * Click on _Generate_ to generate the solution file. 41 | * Open the generated solution in your development environment and build it. 42 | * When you run the unit tests and the examples on Windows, make sure you have 43 | `metatest.dll` on your `PATH`. 44 | 45 | 51 | 52 | [[up]](index.html) 53 | 54 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/logical.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace 11 | { 12 | const metatest::suite_path suite ("logical"); 13 | 14 | using boost::mpl::equal_to; 15 | using boost::mpl::true_; 16 | using boost::mpl::false_; 17 | using boost::mpl::and_; 18 | using boost::mpl::or_; 19 | using boost::mpl::not_; 20 | 21 | struct unknown; 22 | 23 | typedef equal_to, false_> test_not_1; 24 | typedef equal_to, true_> test_not_2; 25 | typedef not_ test_not_3; 26 | typedef not_< not_ > test_not_4; 27 | 28 | typedef and_ test_and_1; 29 | typedef not_< and_ > test_and_2; 30 | typedef not_< and_ > test_and_3; 31 | typedef not_< and_ > test_and_4; 32 | typedef not_< and_ > test_and_5; 33 | typedef not_< and_ > test_and_6; 34 | 35 | typedef or_ test_or_1; 36 | typedef or_ test_or_2; 37 | typedef or_ test_or_3; 38 | typedef not_< or_ > test_or_4; 39 | typedef or_ test_or_5; 40 | typedef or_ test_or_6; 41 | } 42 | 43 | METATEST_ADD_TEST(suite, test_not_1) 44 | METATEST_ADD_TEST(suite, test_not_2) 45 | METATEST_ADD_TEST(suite, test_not_3) 46 | METATEST_ADD_TEST(suite, test_not_4) 47 | 48 | METATEST_ADD_TEST(suite, test_and_1) 49 | METATEST_ADD_TEST(suite, test_and_2) 50 | METATEST_ADD_TEST(suite, test_and_3) 51 | METATEST_ADD_TEST(suite, test_and_4) 52 | METATEST_ADD_TEST(suite, test_and_5) 53 | METATEST_ADD_TEST(suite, test_and_6) 54 | 55 | METATEST_ADD_TEST(suite, test_or_1) 56 | METATEST_ADD_TEST(suite, test_or_2) 57 | METATEST_ADD_TEST(suite, test_or_3) 58 | METATEST_ADD_TEST(suite, test_or_4) 59 | METATEST_ADD_TEST(suite, test_or_5) 60 | METATEST_ADD_TEST(suite, test_or_6) 61 | 62 | -------------------------------------------------------------------------------- /src/test_suite.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define METATEST_SOURCE 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using metatest::test_suite; 16 | using metatest::suite_path; 17 | using metatest::test_result; 18 | 19 | size_t test_suite::failure_count() const 20 | { 21 | using std::count_if; 22 | using boost::bind; 23 | 24 | const size_t this_suite = 25 | static_cast( 26 | count_if( 27 | _results.begin(), 28 | _results.end(), 29 | !bind(&test_result::success, _1) 30 | ) 31 | ); 32 | 33 | size_t children = 0; 34 | for ( 35 | suite_map::const_iterator i = _suites.begin(), e = _suites.end(); 36 | i != e; 37 | ++i 38 | ) 39 | { 40 | children += i->second.failure_count(); 41 | } 42 | 43 | return this_suite + children; 44 | } 45 | 46 | size_t test_suite::count() const 47 | { 48 | using std::count_if; 49 | using boost::bind; 50 | 51 | const size_t this_suite = _results.size(); 52 | 53 | size_t children = 0; 54 | for ( 55 | suite_map::const_iterator i = _suites.begin(), e = _suites.end(); 56 | i != e; 57 | ++i 58 | ) 59 | { 60 | children += i->second.count(); 61 | } 62 | 63 | return this_suite + children; 64 | } 65 | 66 | const test_suite::suite_map& test_suite::suites() const 67 | { 68 | return _suites; 69 | } 70 | 71 | const test_suite::result_list& test_suite::results() const 72 | { 73 | return _results; 74 | } 75 | 76 | void test_suite::add( 77 | suite_path::iterator begin_, 78 | suite_path::iterator end_, 79 | const test_result& result_ 80 | ) 81 | { 82 | if (begin_ == end_) 83 | { 84 | _results.push_back(result_); 85 | } 86 | else 87 | { 88 | suite_path::iterator tail_begin(begin_); 89 | ++tail_begin; 90 | _suites[*begin_].add(tail_begin, end_, result_); 91 | } 92 | } 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /html/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. 3 | * Distributed under the Boost Software License, Version 1.0. 4 | * (See accompanying file LICENSE_1_0.txt or copy at 5 | * http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | body { 9 | margin-left: 10%; 10 | margin-right: 10%; 11 | } 12 | 13 | img { 14 | width: 100%; 15 | } 16 | 17 | a:link { 18 | text-decoration: none; 19 | } 20 | 21 | pre.sourceCode, table, blockquote { 22 | border-style: solid; 23 | border-width: 2px; 24 | border-radius: 10px; 25 | 26 | /* Gradient generated with: http://www.colorzilla.com/gradient-editor/ */ 27 | background: #fafafa; /* Old browsers */ 28 | background: -moz-linear-gradient(-45deg, #fafafa 0%, #f0f0f0 100%); /* FF3.6+ */ 29 | background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,#fafafa), color-stop(100%,#f0f0f0)); /* Chrome,Safari4+ */ 30 | background: -webkit-linear-gradient(-45deg, #fafafa 0%,#f0f0f0 100%); /* Chrome10+,Safari5.1+ */ 31 | background: -o-linear-gradient(-45deg, #fafafa 0%,#f0f0f0 100%); /* Opera 11.10+ */ 32 | background: -ms-linear-gradient(-45deg, #fafafa 0%,#f0f0f0 100%); /* IE10+ */ 33 | background: linear-gradient(135deg, #fafafa 0%,#f0f0f0 100%); /* W3C */ 34 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fafafa', endColorstr='#f0f0f0',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ 35 | } 36 | 37 | pre.sourceCode, table, td { 38 | border-color: #c0c0c0; 39 | } 40 | 41 | pre.sourceCode { 42 | padding: 10px; 43 | } 44 | 45 | p.caption { 46 | text-align: center; 47 | font-size: 80%; 48 | } 49 | 50 | h1 { 51 | text-align: center; 52 | } 53 | 54 | td { 55 | padding: 5px; 56 | border-width: 1px; 57 | border-style: dotted; 58 | } 59 | 60 | td:last-child { 61 | border-right-style: none; 62 | } 63 | 64 | td:first-child { 65 | border-left-style: none; 66 | } 67 | 68 | tr:last-child>td { 69 | border-bottom-style: none; 70 | } 71 | 72 | tr:first-child>td { 73 | border-top-style: none; 74 | } 75 | 76 | blockquote { 77 | border-color: #d0d0d0; 78 | 79 | padding: 10px; 80 | } 81 | 82 | p.copyright { 83 | font-size: 80%; 84 | } 85 | 86 | 87 | -------------------------------------------------------------------------------- /doc/test_result.md: -------------------------------------------------------------------------------- 1 | # metatest::test_result 2 | 3 | `test_result` instances represent results of a compile-time tests at runtime. 4 | Instances are immutable, thus their state can not be changed after 5 | construction. 6 | 7 | ## Header 8 | 9 | ```cpp 10 | #include 11 | ``` 12 | 13 | ## Constructors 14 | 15 | ```cpp 16 | test_result::test_result( 17 | const std::string& name_, 18 | const location& location_, 19 | bool success_, 20 | const std::string& reason_ 21 | ) 22 | ``` 23 | 24 | Creates a new instance with the specified properties. 25 | 26 | ## Methods 27 | 28 | None of the methods throws an exception. 29 | 30 | ```cpp 31 | bool test_result::has_name() const 32 | ``` 33 | 34 | Whether the result object has a name. 35 | 36 | ```cpp 37 | const std::string& test_result::get_name() const 38 | ``` 39 | 40 | Name of the current test. 41 | 42 | ```cpp 43 | const location& test_result::get_location() const 44 | ``` 45 | 46 | Location of the test body within the source. 47 | 48 | ```cpp 49 | bool test_result::success() const 50 | ``` 51 | 52 | Success/fail status. 53 | 54 | ```cpp 55 | bool test_result::has_reason() const 56 | ``` 57 | 58 | Whether the result object has a description. 59 | 60 | ```cpp 61 | const std::string& test_result::get_reason() const 62 | ``` 63 | 64 | Description of the test result. 65 | 66 | ```cpp 67 | template 68 | static test_result test_result::build( 69 | const location& location_, 70 | const std::string& name_ = std::string() 71 | ) 72 | ``` 73 | 74 | Builds a `test_result` instance by evaluating the predicate. 75 | 76 | ## Operators 77 | 78 | ```cpp 79 | std::ostream& operator<<(std::ostream& o_, const test_result& result_); 80 | ``` 81 | 82 | Pretty-prints the test result to the stream. 83 | 84 | 91 | 92 | [[up]](index.html) 93 | 94 | 95 | -------------------------------------------------------------------------------- /src/xml_report.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas Sajo (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define METATEST_SOURCE 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | namespace metatest { 17 | 18 | namespace 19 | { 20 | void display(ostream& out_, const string&, const test_suite& f_) 21 | { 22 | using std::endl; 23 | 24 | for ( 25 | test_suite::suite_map::const_iterator 26 | i = f_.suites().begin(), 27 | e = f_.suites().end(); 28 | i != e; 29 | ++i 30 | ) 31 | { 32 | out_ << "first << "\">\n"; 33 | display(out_, "", i->second); 34 | out_ << "\n"; 35 | } 36 | 37 | for ( 38 | test_suite::result_list::const_iterator 39 | i = f_.results().begin(), 40 | e = f_.results().end(); 41 | i != e; 42 | ++i 43 | ) 44 | { 45 | out_ 46 | << "get_name() << "\" " 47 | << "status=\"" << (i->success() ? "ok" : "fail") << "\">\n"; 48 | 49 | if (i->has_reason()) 50 | { 51 | const std::string &reason = i->get_reason(); 52 | 53 | for (std::string::const_iterator it = reason.begin(); 54 | it != reason.end(); ++it) 55 | { 56 | if ('<' == *it) out_ << "<"; 57 | else if ('>' == *it) out_ << ">"; 58 | else if ('&' == *it) out_ << "&"; 59 | else out_ << *it; 60 | } 61 | } 62 | 63 | out_ << "\n"; 64 | } 65 | } 66 | } 67 | 68 | bool xml_report(std::ostream& out_) 69 | { 70 | using std::endl; 71 | 72 | const test_suite& suite = test_driver::instance().suite(); 73 | 74 | out_ 75 | << "\n"; 79 | 80 | display(out_, "", suite); 81 | 82 | out_ << "\n"; 83 | 84 | return suite.failure_count() == 0; 85 | } 86 | 87 | } // namespace metatest 88 | 89 | -------------------------------------------------------------------------------- /include/metatest/to_stream_argument_list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TO_STREAM_ARGUMENT_LIST_HPP 2 | #define METATEST_TO_STREAM_ARGUMENT_LIST_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace metatest 17 | { 18 | #ifndef METATEST_TO_STREAM_ARGUMENT_LIST_MAX_ARG 19 | #define MEATEST_TO_STREAM_ARGUMENT_LIST_MAX_ARG 20 20 | #endif 21 | 22 | struct to_stream_argument_list_no_arg; 23 | 24 | namespace impl 25 | { 26 | template 27 | struct to_stream_arg 28 | { 29 | static void run(std::ostream& o) 30 | { 31 | if (N > 0) 32 | { 33 | o << ", "; 34 | } 35 | to_stream::run(o); 36 | } 37 | }; 38 | 39 | template 40 | struct to_stream_arg 41 | { 42 | static void run(std::ostream&) {} 43 | }; 44 | } 45 | 46 | #ifdef METATEST_TO_STREAM_CASE 47 | #error METATEST_TO_STREAM_CASE already defined 48 | #endif 49 | #define METATEST_TO_STREAM_CASE(z, n, unused) \ 50 | metatest::impl::to_stream_arg::run(o); 51 | 52 | template < 53 | BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( 54 | METATEST_TO_STREAM_ARGUMENT_LIST_MAX_ARG, 55 | class T, 56 | to_stream_argument_list_no_arg 57 | ) 58 | > 59 | struct to_stream_argument_list 60 | { 61 | static std::ostream& run(std::ostream& o) 62 | { 63 | BOOST_PP_REPEAT( 64 | METATEST_TO_STREAM_ARGUMENT_LIST_MAX_ARG, 65 | METATEST_TO_STREAM_CASE, 66 | ~ 67 | ); 68 | return o; 69 | } 70 | 71 | struct to_stream 72 | { 73 | static std::ostream& run(std::ostream& o) 74 | { 75 | o << "to_stream_argument_list<"; 76 | to_stream_argument_list< 77 | BOOST_PP_ENUM_PARAMS(METATEST_TO_STREAM_ARGUMENT_LIST_MAX_ARG, T) 78 | >::run(o); 79 | return o << ">"; 80 | } 81 | }; 82 | }; 83 | 84 | #undef METATEST_TO_STREAM_CASE 85 | } 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/arithmetic.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace 12 | { 13 | const metatest::suite_path suite ("arithmetic"); 14 | 15 | using namespace boost::mpl; 16 | 17 | typedef int_<0> _0; 18 | typedef int_<1> _1; 19 | typedef int_<3> _3; 20 | typedef int_<10> _10; 21 | typedef int_<-10> _neg10; 22 | 23 | typedef equal_to<_10, plus<_0, _10> > test_0_plus_10; 24 | typedef equal_to<_10, plus<_10, _0> > test_10_plus_0; 25 | 26 | typedef equal_to<_neg10, minus<_0,_10> > test_0_minus_10; 27 | typedef equal_to<_10, minus<_10,_0> > test_10_minus_0; 28 | 29 | typedef equal_to<_10, times<_1,_10> > test_1_times_10; 30 | typedef equal_to<_10, times<_10,_1> > test_10_times_1; 31 | typedef equal_to<_10, multiplies<_1,_10> > test_1_mult_10; 32 | typedef equal_to<_10, multiplies<_10,_1> > test_10_mult_1; 33 | 34 | typedef equal_to<_10, divides<_10,_1> > test_10_div_1; 35 | 36 | typedef equal_to<_0, modulus<_10,_1> > test_10_mod_1; 37 | typedef equal_to<_1, modulus<_10,_3> > test_10_mod_3; 38 | 39 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 40 | typedef equal_to, minus<_10,_1,_10> > test_10_minus_1_minus_10; 41 | typedef equal_to, plus<_10,_1,_10> > test_10_plus_1_plus_10; 42 | typedef equal_to<_1, divides<_10,_1,_10> > test_10_div_1_div_10; 43 | #endif 44 | 45 | typedef equal_to<_neg10, negate<_10> > test_negate_10; 46 | } 47 | 48 | METATEST_ADD_TEST(suite, test_0_plus_10) 49 | METATEST_ADD_TEST(suite, test_10_plus_0) 50 | METATEST_ADD_TEST(suite, test_0_minus_10) 51 | METATEST_ADD_TEST(suite, test_10_minus_0) 52 | METATEST_ADD_TEST(suite, test_1_times_10) 53 | METATEST_ADD_TEST(suite, test_10_times_1) 54 | METATEST_ADD_TEST(suite, test_1_mult_10) 55 | METATEST_ADD_TEST(suite, test_10_mult_1) 56 | METATEST_ADD_TEST(suite, test_10_div_1) 57 | METATEST_ADD_TEST(suite, test_10_mod_1) 58 | METATEST_ADD_TEST(suite, test_10_mod_3) 59 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) 60 | METATEST_ADD_TEST(suite, test_10_minus_1_minus_10) 61 | METATEST_ADD_TEST(suite, test_10_plus_1_plus_10) 62 | METATEST_ADD_TEST(suite, test_10_div_1_div_10) 63 | #endif 64 | METATEST_ADD_TEST(suite, test_negate_10) 65 | 66 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/comparison.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace 13 | { 14 | const metatest::suite_path suite ("comparison"); 15 | 16 | using namespace boost::mpl; 17 | 18 | typedef int_<0> _0; 19 | typedef int_<10> _10; 20 | 21 | typedef not_ > test_equal_to_1; 22 | typedef not_ > test_equal_to_2; 23 | typedef equal_to <_10, _10> test_equal_to_3; 24 | 25 | typedef not_equal_to <_0, _10> test_not_equal_to_1; 26 | typedef not_equal_to <_10, _0> test_not_equal_to_2; 27 | typedef not_ > test_not_equal_to_3; 28 | 29 | typedef less <_0, _10> test_less_1; 30 | typedef not_ > test_less_2; 31 | typedef not_ > test_less_3; 32 | 33 | typedef less_equal <_0, _10> test_less_equal_1; 34 | typedef not_ > test_less_equal_2; 35 | typedef less_equal <_10, _10> test_less_equal_3; 36 | 37 | typedef not_ > test_greater_1; 38 | typedef greater <_10, _0> test_greater_2; 39 | typedef not_ > test_greater_3; 40 | 41 | typedef not_ > test_greater_equal_1; 42 | typedef greater_equal <_10, _0> test_greater_equal_2; 43 | typedef greater_equal <_10, _10> test_greater_equal_3; 44 | } 45 | 46 | METATEST_ADD_TEST(suite, test_equal_to_1) 47 | METATEST_ADD_TEST(suite, test_equal_to_2) 48 | METATEST_ADD_TEST(suite, test_equal_to_3) 49 | 50 | METATEST_ADD_TEST(suite, test_not_equal_to_1) 51 | METATEST_ADD_TEST(suite, test_not_equal_to_2) 52 | METATEST_ADD_TEST(suite, test_not_equal_to_3) 53 | 54 | METATEST_ADD_TEST(suite, test_less_1) 55 | METATEST_ADD_TEST(suite, test_less_2) 56 | METATEST_ADD_TEST(suite, test_less_3) 57 | 58 | METATEST_ADD_TEST(suite, test_less_equal_1) 59 | METATEST_ADD_TEST(suite, test_less_equal_2) 60 | METATEST_ADD_TEST(suite, test_less_equal_3) 61 | 62 | METATEST_ADD_TEST(suite, test_greater_1) 63 | METATEST_ADD_TEST(suite, test_greater_2) 64 | METATEST_ADD_TEST(suite, test_greater_3) 65 | 66 | METATEST_ADD_TEST(suite, test_greater_equal_1) 67 | METATEST_ADD_TEST(suite, test_greater_equal_2) 68 | METATEST_ADD_TEST(suite, test_greater_equal_3) 69 | 70 | -------------------------------------------------------------------------------- /include/metatest/to_stream.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TO_STREAM_HPP 2 | #define METATEST_TO_STREAM_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace metatest 16 | { 17 | template 18 | struct to_stream 19 | { 20 | typedef to_stream type; 21 | 22 | static std::ostream& run(std::ostream& o_) 23 | { 24 | // I can't use typeid, because it breaks for non-defined types 25 | return o_ << "???"; 26 | } 27 | }; 28 | 29 | template 30 | struct to_stream 31 | { 32 | typedef to_stream type; 33 | 34 | static std::ostream& run(std::ostream& o_) 35 | { 36 | return to_stream::run(o_) << "*"; 37 | } 38 | }; 39 | 40 | template 41 | struct to_stream 42 | { 43 | typedef to_stream type; 44 | 45 | static std::ostream& run(std::ostream& o_) 46 | { 47 | return to_stream::run(o_) << "[]"; 48 | } 49 | }; 50 | 51 | template 52 | struct to_stream 53 | { 54 | typedef to_stream type; 55 | 56 | static std::ostream& run(std::ostream& o_) 57 | { 58 | return to_stream::run(o_) << "&"; 59 | } 60 | }; 61 | 62 | template 63 | struct to_stream 64 | { 65 | typedef to_stream type; 66 | 67 | static std::ostream& run(std::ostream& o_) 68 | { 69 | return to_stream::run(o_ << "const "); 70 | } 71 | }; 72 | 73 | template 74 | struct to_stream 75 | { 76 | typedef to_stream type; 77 | 78 | static std::ostream& run(std::ostream& o_) 79 | { 80 | return to_stream::run(o_) << "* const"; 81 | } 82 | }; 83 | } 84 | 85 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(char) 86 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(signed char) 87 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(unsigned char) 88 | 89 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(short) 90 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(unsigned short) 91 | 92 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(int) 93 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(unsigned int) 94 | 95 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(long) 96 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(unsigned long) 97 | 98 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(float) 99 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(double) 100 | 101 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(bool) 102 | 103 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(void) 104 | 105 | #ifndef METATEST_NO_TO_STREAM_MPL 106 | #include 107 | #endif 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/list.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace 20 | { 21 | const metatest::suite_path suite ("list"); 22 | 23 | using namespace boost::mpl; 24 | using boost::is_same; 25 | 26 | typedef list0<> l0; 27 | typedef list1 l1; 28 | typedef list2 l2; 29 | typedef list9 l9; 30 | 31 | typedef equal_to< size, int_<0> > test_size_1; 32 | typedef equal_to< size, int_<1> > test_size_2; 33 | typedef equal_to< size, int_<2> > test_size_3; 34 | typedef equal_to< size, int_<9> > test_size_4; 35 | 36 | typedef empty test_empty_1; 37 | typedef not_ > test_empty_2; 38 | typedef not_ > test_empty_3; 39 | typedef not_ > test_empty_4; 40 | 41 | typedef is_same::type, char> test_front_1; 42 | typedef is_same::type, char> test_front_2; 43 | typedef is_same::type, char> test_front_3; 44 | 45 | typedef is_same< 46 | deref< begin::type >::type 47 | , char 48 | > test_iter_1; 49 | 50 | typedef is_same< 51 | deref< next::type>::type >::type 52 | , long 53 | > test_iter_2; 54 | 55 | typedef is_same< 56 | next< next::type>::type >::type 57 | , end::type 58 | > test_iter_3; 59 | 60 | typedef is_same< 61 | front< 62 | push_front::type 63 | >::type 64 | , char 65 | > test_push_front_1; 66 | 67 | typedef is_same< 68 | front< 69 | push_front< 70 | push_front::type 71 | , long 72 | >::type 73 | >::type 74 | , long 75 | > test_push_front_2; 76 | } 77 | 78 | METATEST_ADD_TEST(suite, test_size_1) 79 | METATEST_ADD_TEST(suite, test_size_2) 80 | METATEST_ADD_TEST(suite, test_size_3) 81 | METATEST_ADD_TEST(suite, test_size_4) 82 | 83 | METATEST_ADD_TEST(suite, test_empty_1) 84 | METATEST_ADD_TEST(suite, test_empty_2) 85 | METATEST_ADD_TEST(suite, test_empty_3) 86 | METATEST_ADD_TEST(suite, test_empty_4) 87 | 88 | METATEST_ADD_TEST(suite, test_front_1) 89 | METATEST_ADD_TEST(suite, test_front_2) 90 | METATEST_ADD_TEST(suite, test_front_3) 91 | 92 | METATEST_ADD_TEST(suite, test_iter_1) 93 | METATEST_ADD_TEST(suite, test_iter_2) 94 | METATEST_ADD_TEST(suite, test_iter_3) 95 | 96 | METATEST_ADD_TEST(suite, test_push_front_1) 97 | METATEST_ADD_TEST(suite, test_push_front_2) 98 | 99 | -------------------------------------------------------------------------------- /include/metatest/test_result.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TEST_RESULT_HPP 2 | #define METATEST_TEST_RESULT_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010-2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace metatest 19 | { 20 | class test_result 21 | { 22 | public: 23 | test_result( 24 | const std::string& name_, 25 | const location& location_, 26 | bool success_, 27 | const std::string& reason_ 28 | ) : 29 | _name(name_), 30 | _location(location_), 31 | _success(success_), 32 | _reason(reason_) 33 | {} 34 | 35 | bool has_name() const 36 | { 37 | return _name != ""; 38 | } 39 | 40 | const std::string& get_name() const 41 | { 42 | return _name; 43 | } 44 | 45 | const location& get_location() const 46 | { 47 | return _location; 48 | } 49 | 50 | bool success() const 51 | { 52 | return _success; 53 | } 54 | 55 | const std::string& get_reason() const 56 | { 57 | return _reason; 58 | } 59 | 60 | bool has_reason() const 61 | { 62 | return _reason != ""; 63 | } 64 | 65 | template 66 | static test_result build( 67 | const location& location_, 68 | const std::string& name_ = std::string() 69 | ) 70 | { 71 | using std::ostringstream; 72 | using std::string; 73 | using boost::mpl::false_; 74 | 75 | const bool has_t = has_type::type::value; 76 | const bool has_v = has_type_value::type::value; 77 | const bool result = get_type_value::type::value; 78 | 79 | ostringstream s; 80 | to_stream::run(s); 81 | 82 | const bool success = has_t && has_v && result; 83 | 84 | const string reason = 85 | has_t ? 86 | ( 87 | has_v ? 88 | s.str() : 89 | string("Result of test case has no nested boolean value") 90 | ) 91 | : 92 | string("Test case has no nested type"); 93 | 94 | return test_result(name_, location_, success, reason); 95 | } 96 | private: 97 | std::string _name; 98 | location _location; 99 | bool _success; 100 | std::string _reason; 101 | }; 102 | 103 | inline std::ostream& operator<<(std::ostream& o_, const test_result& r_) 104 | { 105 | using std::string; 106 | 107 | return o_ 108 | << r_.get_location() << ": " 109 | << (r_.has_name() ? r_.get_name() + " " : string()) 110 | << (r_.success() ? "ok " : "failed ") 111 | << (r_.has_reason() ? "(" + r_.get_reason() + ")" : string()); 112 | } 113 | } 114 | 115 | #endif 116 | 117 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/vector_c.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("vector_c"); 16 | 17 | using namespace boost::mpl; 18 | using boost::is_same; 19 | 20 | #if !BOOST_WORKAROUND(BOOST_MSVC, <=1200) 21 | namespace testcase_1 22 | { 23 | typedef is_same< vector_c::value_type, bool > t1; 24 | typedef is_same< vector_c::value_type, bool > t2; 25 | typedef equal_to< front< vector_c >::type, true_ > t3; 26 | typedef equal_to< front< vector_c >::type, false_ > t4; 27 | 28 | METATEST_ADD_TEST (suite, t1) 29 | METATEST_ADD_TEST (suite, t2) 30 | METATEST_ADD_TEST (suite, t3) 31 | METATEST_ADD_TEST (suite, t4) 32 | } 33 | #endif 34 | 35 | namespace testcase_2 36 | { 37 | typedef vector_c v1; 38 | typedef vector_c v2; 39 | typedef vector_c v3; 40 | 41 | typedef is_same test_value_type_1; 42 | typedef is_same test_value_type_2; 43 | typedef is_same test_value_type_3; 44 | 45 | typedef equal_to< size, int_<1> > test_size_1; 46 | typedef equal_to< size, int_<2> > test_size_2; 47 | typedef equal_to< size, int_<3> > test_size_3; 48 | 49 | typedef equal_to< front::type, int_<-1> > test_front_1; 50 | typedef equal_to< front::type, int_<0> > test_front_2; 51 | typedef equal_to< front::type, int_<1> > test_front_3; 52 | 53 | METATEST_ADD_TEST (suite, test_value_type_1) 54 | METATEST_ADD_TEST (suite, test_value_type_2) 55 | METATEST_ADD_TEST (suite, test_value_type_3) 56 | 57 | METATEST_ADD_TEST (suite, test_size_1) 58 | METATEST_ADD_TEST (suite, test_size_2) 59 | METATEST_ADD_TEST (suite, test_size_3) 60 | 61 | METATEST_ADD_TEST (suite, test_front_1) 62 | METATEST_ADD_TEST (suite, test_front_2) 63 | METATEST_ADD_TEST (suite, test_front_3) 64 | } 65 | 66 | namespace testcase_3 67 | { 68 | typedef vector_c v1; 69 | typedef vector_c v2; 70 | 71 | typedef is_same< v1::value_type, unsigned > test_value_type_1; 72 | typedef is_same< v2::value_type, unsigned > test_value_type_2; 73 | 74 | typedef equal_to< size, int_<1> > test_size_1; 75 | typedef equal_to< size, int_<2> > test_size_2; 76 | 77 | typedef equal_to< front::type, int_<0> > test_front_1; 78 | typedef equal_to< front::type, int_<1> > test_front_2; 79 | 80 | METATEST_ADD_TEST (suite, test_value_type_1) 81 | METATEST_ADD_TEST (suite, test_value_type_2) 82 | 83 | METATEST_ADD_TEST (suite, test_size_1) 84 | METATEST_ADD_TEST (suite, test_size_2) 85 | 86 | METATEST_ADD_TEST (suite, test_front_1) 87 | METATEST_ADD_TEST (suite, test_front_2) 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /include/metatest/to_stream_fwd.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_METATEST_TO_STREAM_FWD_HPP 2 | #define METATEST_METATEST_TO_STREAM_FWD_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace metatest 16 | { 17 | template 18 | struct to_stream; 19 | } 20 | 21 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_TYPE 22 | #error METATEST_DEFINE_TO_STREAM_FOR_TYPE already defined 23 | #endif 24 | #define METATEST_DEFINE_TO_STREAM_FOR_TYPE(t, name) \ 25 | namespace metatest \ 26 | { \ 27 | template <> \ 28 | struct to_stream \ 29 | { \ 30 | typedef to_stream type; \ 31 | \ 32 | static std::ostream& run(std::ostream& o_) \ 33 | { \ 34 | return o_ << name; \ 35 | } \ 36 | }; \ 37 | } 38 | 39 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE 40 | #error METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE already defined 41 | #endif 42 | #define METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(t) \ 43 | METATEST_DEFINE_TO_STREAM_FOR_TYPE(t, #t) 44 | 45 | // "if"'s condition will be a compile-time constant expression. 46 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_N 47 | #error METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_N already defined 48 | #endif 49 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_N(z, n, unused) \ 50 | if ((n) > 0) { \ 51 | o_ << ", "; \ 52 | } \ 53 | to_stream::run(o_); 54 | 55 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE 56 | #error METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE already defined 57 | #endif 58 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE(n, t, name) \ 59 | namespace metatest \ 60 | { \ 61 | template \ 62 | struct to_stream > \ 63 | { \ 64 | typedef to_stream type; \ 65 | \ 66 | static std::ostream& run(std::ostream& o_) \ 67 | { \ 68 | o_ << name << "<"; \ 69 | BOOST_PP_REPEAT(n, METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_N, ~) \ 70 | return o_ << ">"; \ 71 | } \ 72 | }; \ 73 | } 74 | 75 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS_N 76 | #error METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS_N already defined 77 | #endif 78 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS_N(z, n, args) \ 79 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE( \ 80 | n, \ 81 | BOOST_PP_ARRAY_ELEM(0, args), \ 82 | BOOST_PP_ARRAY_ELEM(1, args) \ 83 | ) 84 | 85 | #ifdef METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS 86 | #error METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS already defined 87 | #endif 88 | #define METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS( \ 89 | n_min, \ 90 | n_max, \ 91 | t, \ 92 | name \ 93 | ) \ 94 | BOOST_PP_REPEAT_FROM_TO( \ 95 | n_min, \ 96 | n_max, \ 97 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE_WITH_DEFAULTS_N, \ 98 | (2, (t, name))\ 99 | ) 100 | 101 | 102 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE( 103 | 1, 104 | metatest::to_stream, 105 | "to_stream" 106 | ) 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/bind.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | namespace 19 | { 20 | const metatest::suite_path suite ("bind"); 21 | 22 | using namespace boost::mpl; 23 | using boost::is_same; 24 | 25 | struct f1 26 | { 27 | template struct apply 28 | { typedef T1 type; }; 29 | }; 30 | 31 | struct f5 32 | { 33 | template 34 | struct apply 35 | { typedef T5 type; }; 36 | }; 37 | 38 | namespace testcase_1 39 | { 40 | typedef is_same< 41 | apply_wrap1< bind1, int >::type 42 | , int 43 | > basic1; 44 | 45 | typedef is_same< 46 | apply_wrap5< bind1, void,void,void,void,int >::type 47 | , int 48 | > basic2; 49 | 50 | typedef is_same< 51 | apply_wrap5< 52 | bind5 53 | , void,void,void,void,int 54 | >::type 55 | , int 56 | > basic3; 57 | 58 | typedef is_same< 59 | apply_wrap5< 60 | bind5 61 | , int,void,void,void,void 62 | >::type 63 | , int 64 | > basic4; 65 | 66 | METATEST_ADD_TEST(suite, basic1) 67 | METATEST_ADD_TEST(suite, basic2) 68 | METATEST_ADD_TEST(suite, basic3) 69 | METATEST_ADD_TEST(suite, basic4) 70 | } 71 | 72 | namespace testcase_2 73 | { 74 | typedef is_same< 75 | apply_wrap0< bind1 >::type 76 | , int 77 | > full1; 78 | 79 | typedef is_same< 80 | apply_wrap0< bind5 >::type 81 | , int 82 | > full2; 83 | 84 | METATEST_ADD_TEST(suite, full1) 85 | METATEST_ADD_TEST(suite, full2) 86 | } 87 | 88 | namespace testcase_3 89 | { 90 | typedef is_same< 91 | apply_wrap5< 92 | bind5< f5,_1,_2,_3,_4,bind1 > 93 | , int,void,void,void,void 94 | >::type 95 | , int 96 | > composition1; 97 | 98 | typedef is_same< 99 | apply_wrap5< 100 | bind5< f5,_1,_2,_3,_4,bind1 > 101 | , void,void,void,void,int 102 | >::type 103 | , int 104 | > composition2; 105 | 106 | METATEST_ADD_TEST(suite, composition1) 107 | METATEST_ADD_TEST(suite, composition2) 108 | } 109 | 110 | //#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \0 111 | // && !defined(BOOST_MPL_CFG_NO_TEMPLATE_TEMPLATE_PARAMETERS) \0 112 | // && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) 113 | namespace testcase_4 114 | { 115 | typedef bind3< quote3, _1, bind1< quote1, _2 >, _3 > f; 116 | 117 | typedef is_same< 118 | apply_wrap3, int>::type 119 | , int_<1> 120 | > if1; 121 | 122 | typedef is_same< 123 | apply_wrap3 >::type 124 | , int_<0> 125 | > if2; 126 | 127 | METATEST_ADD_TEST(suite, if1) 128 | METATEST_ADD_TEST(suite, if2) 129 | } 130 | //#endif 131 | } 132 | 133 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/deque.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | namespace 21 | { 22 | const metatest::suite_path suite ("deque"); 23 | 24 | using namespace boost; 25 | using namespace mpl; 26 | 27 | namespace testcase_2 28 | { 29 | typedef deque<> d0; 30 | typedef deque d1; 31 | typedef deque d2; 32 | typedef deque d9; 33 | 34 | typedef equal_to< size, int_<0> > test_size_1; 35 | typedef equal_to< size, int_<1> > test_size_2; 36 | typedef equal_to< size, int_<2> > test_size_3; 37 | typedef equal_to< size, int_<9> > test_size_4; 38 | 39 | typedef empty test_empty_1; 40 | typedef not_< empty > test_empty_2; 41 | typedef not_< empty > test_empty_3; 42 | typedef not_< empty > test_empty_4; 43 | 44 | typedef is_same< front::type, char > test_front_1; 45 | typedef is_same< front::type, char > test_front_2; 46 | typedef is_same< front::type, char > test_front_3; 47 | 48 | typedef is_same< back::type, char > test_back_1; 49 | typedef is_same< back::type, long > test_back_2; 50 | typedef is_same< back::type, int > test_back_3; 51 | 52 | METATEST_ADD_TEST(suite, test_size_1) 53 | METATEST_ADD_TEST(suite, test_size_2) 54 | METATEST_ADD_TEST(suite, test_size_3) 55 | METATEST_ADD_TEST(suite, test_size_4) 56 | METATEST_ADD_TEST(suite, test_empty_1) 57 | METATEST_ADD_TEST(suite, test_empty_2) 58 | METATEST_ADD_TEST(suite, test_empty_3) 59 | METATEST_ADD_TEST(suite, test_empty_4) 60 | METATEST_ADD_TEST(suite, test_front_1) 61 | METATEST_ADD_TEST(suite, test_front_2) 62 | METATEST_ADD_TEST(suite, test_front_3) 63 | METATEST_ADD_TEST(suite, test_back_1) 64 | METATEST_ADD_TEST(suite, test_back_2) 65 | METATEST_ADD_TEST(suite, test_back_3) 66 | } 67 | 68 | namespace testcase_1 69 | { 70 | typedef deque d2; 71 | 72 | typedef begin::type i1; 73 | typedef next::type i2; 74 | typedef next::type i3; 75 | 76 | typedef is_same< deref::type, char > test_iter_1; 77 | typedef is_same< deref::type, long > test_iter_2; 78 | typedef is_same< i3, end::type > test_iter_3; 79 | 80 | METATEST_ADD_TEST(suite, test_iter_1) 81 | METATEST_ADD_TEST(suite, test_iter_2) 82 | METATEST_ADD_TEST(suite, test_iter_3) 83 | } 84 | 85 | namespace testcase_3 86 | { 87 | typedef deque<> d0; 88 | typedef push_back::type d1; 89 | typedef push_front::type d2; 90 | typedef push_back::type d3; 91 | 92 | typedef is_same< back::type, int > test_push_1; 93 | typedef is_same< back::type, int > test_push_2; 94 | typedef is_same< front::type, char > test_push_3; 95 | typedef is_same< back::type, long > test_push_4; 96 | 97 | METATEST_ADD_TEST(suite, test_push_1) 98 | METATEST_ADD_TEST(suite, test_push_2) 99 | METATEST_ADD_TEST(suite, test_push_3) 100 | METATEST_ADD_TEST(suite, test_push_4) 101 | } 102 | } 103 | 104 | -------------------------------------------------------------------------------- /tools/gen_toc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at 6 | # http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import re 9 | import sys 10 | import optparse 11 | 12 | def anchor(c, toc_type): 13 | if c == ' ': 14 | return '-' 15 | elif c == '.': 16 | if toc_type == 'pandoc_html': 17 | return '.' 18 | else: 19 | return '' 20 | elif c in [':', '`']: 21 | return '' 22 | else: 23 | return c.lower() 24 | 25 | def index_anchor(a, n): 26 | return '%s-%d' % (a, n) 27 | 28 | class Header: 29 | def __init__(self, s, prev_anchors, toc_type): 30 | [pre, title] = s.split(' ', 1) 31 | self.depth = len(pre) - 1 32 | self.title = title.strip() 33 | self.anchor = ''.join([anchor(c, toc_type) for c in self.title]) 34 | if self.anchor in prev_anchors: 35 | i = 1 36 | while index_anchor(self.anchor, i) in prev_anchors: 37 | i = i + 1 38 | self.anchor = index_anchor(self.anchor, i) 39 | 40 | def toc_line(self, indent): 41 | return \ 42 | '%s- [%s](#%s)' % (' ' * (self.depth+indent), self.title, self.anchor) 43 | 44 | def is_header(s): 45 | return re.compile('^[#]+ ').search(s) 46 | 47 | def collect_headers(doc, toc_type): 48 | header_lines = [s for s in doc if is_header(s)] 49 | headers = [] 50 | anchors = [] 51 | for s in header_lines: 52 | h = Header(s, anchors, toc_type) 53 | headers.append(h) 54 | anchors.append(h.anchor) 55 | return headers 56 | 57 | def generate_toc(headers, toc_title): 58 | return \ 59 | '\n'.join( \ 60 | [h.toc_line(-1) for h in headers if h.depth > 0 and h.title != toc_title]\ 61 | ) + '\n' 62 | 63 | def generate_doc(f, doc, toc_title, toc_type): 64 | in_toc = False 65 | for s in doc: 66 | if in_toc: 67 | if is_header(s): 68 | f.write(s) 69 | in_toc = False 70 | else: 71 | if is_header(s) and Header(s, [], toc_type).title == toc_title: 72 | in_toc = True 73 | if toc_type != 'none': 74 | f.write(s + '\n') 75 | f.write(generate_toc(collect_headers(doc, toc_type), toc_title)) 76 | f.write('\n') 77 | else: 78 | f.write(s) 79 | 80 | def main(): 81 | accepted_types = ['github', 'pandoc_html', 'none'] 82 | parser = optparse.OptionParser() 83 | parser.add_option( 84 | '-i', '--input', 85 | action='store', 86 | dest='input', 87 | help='The file to process' 88 | ) 89 | parser.add_option( 90 | '-o', '--output', 91 | action='store', 92 | dest='output', 93 | help='The file to write the result into. It defaults to the input file. To write output to stdout use: -' 94 | ) 95 | parser.add_option( 96 | '-t', '--type', 97 | action='store', 98 | dest='type', 99 | default='github', 100 | help='Type of TOC. Possible values: %s. Default: %s' 101 | % (', '.join(accepted_types), 'github') 102 | ) 103 | 104 | (options, args) = parser.parse_args() 105 | if options.output == None: 106 | options.output = options.input 107 | 108 | if options.input == None: 109 | parser.error('No input file specified') 110 | elif not options.type in accepted_types: 111 | parser.error('Invalid type: %s' % (options.type)) 112 | else: 113 | toc_title = 'Table of contents' 114 | doc = open(options.input, 'r').readlines() 115 | if options.output == '-': 116 | f = sys.stdout 117 | else: 118 | f = open(options.output, 'w') 119 | generate_doc(f, doc, toc_title, options.type) 120 | 121 | if __name__ == '__main__': 122 | main() 123 | 124 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/list_c.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace 14 | { 15 | const metatest::suite_path suite ("list_c"); 16 | 17 | using namespace boost; 18 | using namespace mpl; 19 | 20 | #if !BOOST_WORKAROUND(BOOST_MSVC,<= 1200) 21 | namespace testcase_1 22 | { 23 | typedef list_c::type l1; 24 | typedef list_c::type l2; 25 | 26 | typedef is_same< l1::value_type, bool > test_value_type_1; 27 | typedef is_same< l2::value_type, bool > test_value_type_2; 28 | 29 | typedef equal_to< front::type, true_ > test_front_1; 30 | typedef equal_to< front::type, false_ > test_front_2; 31 | 32 | METATEST_ADD_TEST(suite, test_value_type_1) 33 | METATEST_ADD_TEST(suite, test_value_type_2) 34 | METATEST_ADD_TEST(suite, test_front_1) 35 | METATEST_ADD_TEST(suite, test_front_2) 36 | } 37 | #endif 38 | 39 | namespace testcase_2 40 | { 41 | typedef list_c::type l1; 42 | typedef list_c::type l2; 43 | typedef list_c::type l3; 44 | 45 | typedef is_same test_value_type_1; 46 | typedef is_same test_value_type_2; 47 | typedef is_same test_value_type_3; 48 | 49 | typedef equal_to< size, int_<1> > test_size_1; 50 | typedef equal_to< size, int_<2> > test_size_2; 51 | typedef equal_to< size, int_<3> > test_size_3; 52 | 53 | typedef equal_to< front::type, int_<-1> > test_front_1; 54 | typedef equal_to< front::type, int_<0> > test_front_2; 55 | typedef equal_to< front::type, int_<1> > test_front_3; 56 | 57 | METATEST_ADD_TEST(suite, test_value_type_1) 58 | METATEST_ADD_TEST(suite, test_value_type_2) 59 | METATEST_ADD_TEST(suite, test_value_type_3) 60 | 61 | METATEST_ADD_TEST(suite, test_size_1) 62 | METATEST_ADD_TEST(suite, test_size_2) 63 | METATEST_ADD_TEST(suite, test_size_3) 64 | 65 | METATEST_ADD_TEST(suite, test_front_1) 66 | METATEST_ADD_TEST(suite, test_front_2) 67 | METATEST_ADD_TEST(suite, test_front_3) 68 | } 69 | 70 | namespace testcase_3 71 | { 72 | typedef list_c::type l1; 73 | typedef list_c::type l2; 74 | 75 | typedef is_same test_value_type_1; 76 | typedef is_same test_value_type_2; 77 | 78 | typedef equal_to< size, int_<1> > test_size_1; 79 | typedef equal_to< size, int_<2> > test_size_2; 80 | 81 | typedef equal_to< front::type, int_<0> > test_front_1; 82 | typedef equal_to< front::type, int_<1> > test_front_2; 83 | 84 | METATEST_ADD_TEST(suite, test_value_type_1) 85 | METATEST_ADD_TEST(suite, test_value_type_2) 86 | METATEST_ADD_TEST(suite, test_size_1) 87 | METATEST_ADD_TEST(suite, test_size_2) 88 | METATEST_ADD_TEST(suite, test_front_1) 89 | METATEST_ADD_TEST(suite, test_front_2) 90 | } 91 | 92 | namespace testcase_4 93 | { 94 | typedef list_c l2; 95 | 96 | typedef is_same test_value_type_1; 97 | 98 | typedef begin::type i1; 99 | typedef next::type i2; 100 | typedef next::type i3; 101 | 102 | typedef equal_to< deref::type, int_<2> > test_iterator_1; 103 | typedef equal_to< deref::type, int_<1> > test_iterator_2; 104 | typedef is_same::type> test_iterator_3; 105 | 106 | METATEST_ADD_TEST(suite, test_value_type_1) 107 | METATEST_ADD_TEST(suite, test_iterator_1) 108 | METATEST_ADD_TEST(suite, test_iterator_2) 109 | METATEST_ADD_TEST(suite, test_iterator_3) 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/apply.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace 15 | { 16 | const metatest::suite_path suite ("apply"); 17 | 18 | using namespace boost::mpl; 19 | using boost::is_same; 20 | 21 | template struct std_vector 22 | { 23 | #if defined(BOOST_MPL_CFG_NO_IMPLICIT_METAFUNCTIONS) 24 | typedef std_vector type; 25 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1, std_vector, (T)) 26 | #endif 27 | }; 28 | 29 | typedef plus, int_<3> > plus_2_3; 30 | typedef is_same< 31 | plus_2_3 32 | , lambda::type 33 | > test1; 34 | 35 | typedef is_same< 36 | std_vector 37 | , lambda< std_vector >::type 38 | > test2; 39 | 40 | typedef is_same< 41 | apply_wrap1< 42 | lambda< std_vector<_1> >::type 43 | , int>::type 44 | , std_vector 45 | > test3; 46 | 47 | typedef equal_to< 48 | apply2< plus<_1, _2>, int_<2>, int_<3> >::type 49 | , int_<5> 50 | > test4; 51 | 52 | typedef is_same< 53 | apply1< _1, plus<_1, _2> >::type 54 | , plus<_1, _2> 55 | > test5; 56 | 57 | typedef equal_to< 58 | apply2< 59 | apply1< _1, plus<_1, _2> >::type 60 | , int_<2> 61 | , int_<3> 62 | >::type 63 | , int_<5> 64 | > test6; 65 | 66 | typedef is_same< 67 | apply_wrap1< 68 | lambda< lambda<_1> >::type 69 | , std_vector 70 | >::type 71 | , std_vector 72 | > test7; 73 | 74 | typedef is_same< 75 | apply_wrap1< 76 | apply_wrap1< 77 | lambda< lambda<_1> >::type 78 | , std_vector<_1> 79 | >::type 80 | , int 81 | >::type 82 | , std_vector 83 | > test8; 84 | 85 | typedef is_same< 86 | apply1< _1, std_vector >::type 87 | , std_vector 88 | > test9; 89 | 90 | typedef is_same< 91 | apply1< 92 | apply1< _1, std_vector<_1> >::type 93 | , int 94 | >::type 95 | , std_vector 96 | > test10; 97 | 98 | typedef is_same< 99 | apply1< 100 | lambda<_1> 101 | , std_vector 102 | >::type 103 | , std_vector 104 | > test11; 105 | 106 | typedef is_same< 107 | apply_wrap1< 108 | apply1< 109 | lambda<_1> 110 | , std_vector<_1> 111 | >::type 112 | , int 113 | >::type 114 | , std_vector 115 | > test12; 116 | 117 | typedef equal_to< 118 | apply_wrap2< 119 | apply1< 120 | lambda<_1> 121 | , plus<_1, _2> 122 | >::type 123 | , int_<2> 124 | , int_<3> 125 | >::type 126 | , int_<5> 127 | > test13; 128 | 129 | typedef is_same< 130 | bind2, _1, _1> 131 | , lambda< bind2, _1, _1> >::type 132 | > test14; 133 | 134 | #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) 135 | typedef equal_to< 136 | apply_wrap1< 137 | lambda< 138 | lambda< bind2, _1, _1> > 139 | >::type::type 140 | , int_<5> 141 | >::type 142 | , int_<10> 143 | > test15; 144 | #endif 145 | 146 | typedef equal_to< 147 | apply1< 148 | bind2, _1, _1> 149 | , int_<5> 150 | >::type 151 | , int_<10> 152 | > test16; 153 | 154 | typedef equal_to< 155 | apply_wrap2< 156 | apply1< 157 | _1, lambda< plus<_1, _2> > 158 | >::type::type 159 | , int_<2> 160 | , int_<3> 161 | >::type 162 | , int_<5> 163 | > test17; 164 | } 165 | 166 | METATEST_ADD_TEST(suite, test1) 167 | METATEST_ADD_TEST(suite, test2) 168 | METATEST_ADD_TEST(suite, test3) 169 | METATEST_ADD_TEST(suite, test4) 170 | METATEST_ADD_TEST(suite, test5) 171 | METATEST_ADD_TEST(suite, test6) 172 | METATEST_ADD_TEST(suite, test7) 173 | METATEST_ADD_TEST(suite, test8) 174 | METATEST_ADD_TEST(suite, test9) 175 | METATEST_ADD_TEST(suite, test10) 176 | METATEST_ADD_TEST(suite, test11) 177 | METATEST_ADD_TEST(suite, test12) 178 | METATEST_ADD_TEST(suite, test13) 179 | METATEST_ADD_TEST(suite, test14) 180 | #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) 181 | METATEST_ADD_TEST(suite, test15) 182 | #endif 183 | METATEST_ADD_TEST(suite, test16) 184 | METATEST_ADD_TEST(suite, test17) 185 | 186 | -------------------------------------------------------------------------------- /src/html_report.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas Sajo (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #define METATEST_SOURCE 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | namespace metatest { 19 | 20 | namespace 21 | { 22 | template 23 | void escaped_output(ostream& out_, InputIt begin_, InputIt end_) 24 | { 25 | for (InputIt c = begin_; c != end_; ++c) 26 | { 27 | switch (*c) 28 | { 29 | case '<': out_ << "<"; break; 30 | case '>': out_ << ">"; break; 31 | case '&': out_ << "&"; break; 32 | default: out_ << *c; 33 | } 34 | } 35 | } 36 | 37 | class indent 38 | { 39 | public: 40 | explicit indent(int depth_) : 41 | _s(depth_ * indent_spaces, ' ') 42 | {} 43 | 44 | indent operator+(int n_) const 45 | { 46 | return indent(_s + string(n_ * indent_spaces, ' ')); 47 | } 48 | 49 | friend ostream& operator<<(ostream& out_, indent i_) 50 | { 51 | return out_ << i_._s; 52 | } 53 | private: 54 | static const int indent_spaces = 2; 55 | string _s; 56 | 57 | explicit indent(string s_) : 58 | _s(s_) 59 | {} 60 | }; 61 | 62 | const char* success_or_failure_html(bool success_) 63 | { 64 | return 65 | success_ ? 66 | " OK" 67 | : " FAILED"; 68 | } 69 | 70 | void display( 71 | ostream& out_, 72 | const string& name_, 73 | const test_suite& f_, 74 | indent indent_ 75 | ) 76 | { 77 | const indent i(indent_); 78 | const indent ii(name_ == "" ? indent_ : indent_ + 1); 79 | 80 | if (name_ != "") 81 | { 82 | out_ << i << "

"; 83 | escaped_output(out_, name_.begin(), name_.end()); 84 | out_ 85 | << success_or_failure_html(f_.failure_count() == 0) << "

\n" 86 | << i << "
\n" 87 | ; 88 | } 89 | 90 | for (test_suite::suite_map::const_iterator s = f_.suites().begin(); 91 | s != f_.suites().end(); 92 | ++s) 93 | { 94 | display(out_, s->first, s->second, ii); 95 | } 96 | 97 | for (test_suite::result_list::const_iterator j = f_.results().begin(); 98 | j != f_.results().end(); 99 | ++j) 100 | { 101 | out_ << ii << "

"; 102 | escaped_output(out_, j->get_name().begin(), j->get_name().end()); 103 | out_ << success_or_failure_html(j->success()) << "

\n"; 104 | 105 | out_ << ii << "
"; 106 | 107 | if (j->has_reason()) 108 | { 109 | const string &reason = j->get_reason(); 110 | escaped_output(out_, reason.begin(), reason.end()); 111 | } 112 | 113 | out_ << "
\n"; 114 | } 115 | 116 | if (name_ != "") 117 | { 118 | out_ << i << "
\n"; 119 | } 120 | } 121 | } 122 | 123 | bool html_report(std::ostream& out_) 124 | { 125 | using std::endl; 126 | 127 | const test_suite& suite = test_driver::instance().suite(); 128 | const string jquery = "jquery.js"; 129 | 130 | const indent i(1); 131 | const indent ii(2); 132 | const indent iii(3); 133 | const indent iiii(4); 134 | 135 | out_ 136 | << "\n" 137 | "\n" 138 | << i << "\n" 139 | << i << "Metatest report\n" 140 | << i << "\n" 141 | << i << "\n" 149 | << i << "\n" 163 | << "\n" 164 | "\n" 165 | << i << "

Metatest report

\n" 166 | ; 167 | 168 | display(out_, "", suite, i); 169 | 170 | out_ 171 | << "\n" 172 | "\n" 173 | ; 174 | 175 | return suite.failure_count() == 0; 176 | } 177 | 178 | } // namespace metatest 179 | 180 | -------------------------------------------------------------------------------- /example/stream_type/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | using boost::mpl::int_; 25 | 26 | class custom_test_class; 27 | class other_custom_test_class; 28 | class defined_custom_test_class {}; 29 | 30 | class custom_test_class_with_long_name; 31 | 32 | struct metafunction_class 33 | { 34 | typedef metafunction_class type; 35 | 36 | template 37 | struct apply : int_<13> {}; 38 | }; 39 | 40 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(custom_test_class) 41 | METATEST_DEFINE_TO_STREAM_FOR_TYPE( 42 | custom_test_class_with_long_name, 43 | "short_name" 44 | ) 45 | METATEST_DEFINE_TO_STREAM_FOR_SIMPLE_TYPE(metafunction_class) 46 | 47 | template 48 | struct cant_be_instantiated : T::doesnt_exist {}; 49 | 50 | METATEST_DEFINE_TO_STREAM_FOR_TEMPLATE( 51 | 1, 52 | cant_be_instantiated, 53 | "can't be instantiated" 54 | ) 55 | 56 | int main() 57 | { 58 | using std::cout; 59 | using std::endl; 60 | using metatest::to_stream; 61 | using boost::mpl::integral_c; 62 | using boost::mpl::true_; 63 | using boost::mpl::false_; 64 | using boost::mpl::int_; 65 | using boost::mpl::long_; 66 | using boost::mpl::char_; 67 | using boost::mpl::void_; 68 | using boost::mpl::string; 69 | using boost::mpl::vector_c; 70 | using boost::mpl::list_c; 71 | using boost::mpl::deque; 72 | using boost::mpl::range_c; 73 | using boost::mpl::vector; 74 | using boost::mpl::_1; 75 | using boost::mpl::apply; 76 | using boost::mpl::lambda; 77 | using boost::mpl::list; 78 | using boost::mpl::set; 79 | using boost::mpl::map; 80 | using boost::mpl::pair; 81 | using boost::mpl::push_front; 82 | using boost::mpl::insert; 83 | 84 | to_stream::run(cout) << endl; 85 | to_stream::run(cout) << endl; 86 | to_stream::run(cout) << endl; 87 | to_stream >::run(cout) << endl; 88 | 89 | to_stream::run(cout) << endl; 90 | to_stream::run(cout) << endl; 91 | to_stream::run(cout) << endl; 92 | to_stream::run(cout) << endl; 93 | to_stream::run(cout) << endl; 94 | to_stream::run(cout) << endl; 95 | to_stream::run(cout) << endl; 96 | to_stream::run(cout) << endl; 97 | to_stream::run(cout) << endl; 98 | to_stream::run(cout) << endl; 99 | to_stream::run(cout) << endl; 100 | to_stream::run(cout) << endl; 101 | to_stream::run(cout) << endl; 102 | cout << endl; 103 | 104 | to_stream >::run(cout) << endl; 105 | to_stream::run(cout) << endl; 106 | to_stream >::run(cout) << endl; 107 | to_stream >::run(cout) << endl; 108 | to_stream >::run(cout) << endl; 109 | to_stream >::run(cout) << endl; 110 | to_stream >::run(cout) << endl; 111 | to_stream >::run(cout) << endl; 112 | to_stream::run(cout) << endl; 113 | to_stream >::run(cout) << endl; 114 | to_stream >::run(cout) << endl; 115 | 116 | to_stream< 117 | map, int_<2> >, pair, int_<4> > >::type 118 | >::run(cout) << endl; 119 | to_stream::type>::run(cout) << endl; 120 | to_stream, int_<2>, int_<3> >::type>::run(cout) << endl; 121 | to_stream::type>::run(cout) << endl; 122 | to_stream, int_<2>, int_<3> >::type>::run(cout) << endl; 123 | to_stream::type>::run(cout) << endl; 124 | to_stream, int_<2>, int_<3> >::type>::run(cout) << endl; 125 | to_stream, int_<2>, int_<3> >::type>::run(cout) << endl; 126 | to_stream::type>::run(cout) << endl; 127 | to_stream >::run(cout) << endl; 128 | to_stream, int_<2>, int_<3> > >::run(cout) << endl; 129 | to_stream >::run(cout) << endl; 130 | to_stream >::run(cout) << endl; 131 | to_stream >::run(cout) << endl; 132 | to_stream >::run(cout) << endl; 133 | to_stream >::run(cout) << endl; 134 | to_stream<_1>::run(cout) << endl; 135 | to_stream >::run(cout) << endl; 136 | to_stream >::run(cout) << endl; 137 | } 138 | 139 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/set_c.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // 16 | // turns out set_c iterators not working is in fact a bug in boost 17 | // http://boost.2283326.n4.nabble.com/mpl-for-each-and-set-c-misunderstanding-or-bug-tt2565972.html 18 | // 19 | 20 | namespace 21 | { 22 | const metatest::suite_path suite ("set_c"); 23 | 24 | using namespace boost; 25 | using namespace mpl; 26 | 27 | namespace test 28 | { 29 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 30 | template< typename S, typename S::value_type k > 31 | struct at_c 32 | : at< S, integral_c >::type 33 | { }; 34 | #else 35 | template< typename S, long k > 36 | struct at_c 37 | : aux::msvc_eti_base< 38 | at< S, integral_c > 39 | > 40 | { }; 41 | #endif 42 | } 43 | 44 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200) 45 | namespace testcase_1 46 | { 47 | typedef set_c::type s1; 48 | typedef set_c::type s2; 49 | typedef set_c::type s3; 50 | 51 | typedef equal_to< size, int_<1> > test_size_1; 52 | typedef equal_to< size, int_<1> > test_size_2; 53 | typedef equal_to< size, int_<2> > test_size_3; 54 | 55 | typedef is_same test_value_type_1; 56 | typedef is_same test_value_type_2; 57 | typedef is_same test_value_type_3; 58 | 59 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 60 | typedef equal_to< test::at_c, true_ > test_at_1; 61 | typedef equal_to< test::at_c, false_ > test_at_2; 62 | typedef equal_to< test::at_c, true_ > test_at_3; 63 | typedef equal_to< test::at_c, false_ > test_at_4; 64 | 65 | typedef is_same< test::at_c::type, void_ > test_at_5; 66 | typedef is_same< test::at_c::type, void_ > test_at_6; 67 | #endif 68 | 69 | typedef begin::type first1; 70 | typedef end::type last1; 71 | typedef equal_to< distance, int_<1> > test_iterator_1; 72 | 73 | typedef begin::type first2; 74 | typedef end::type last2; 75 | typedef equal_to< distance, int_<1> > test_iterator_2; 76 | 77 | typedef begin::type first3; 78 | typedef end::type last3; 79 | typedef equal_to< distance, int_<2> > test_iterator_3; 80 | 81 | METATEST_ADD_TEST(suite, test_size_1) 82 | METATEST_ADD_TEST(suite, test_size_2) 83 | METATEST_ADD_TEST(suite, test_size_3) 84 | METATEST_ADD_TEST(suite, test_value_type_1) 85 | METATEST_ADD_TEST(suite, test_value_type_2) 86 | METATEST_ADD_TEST(suite, test_value_type_3) 87 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 88 | METATEST_ADD_TEST(suite, test_at_1) 89 | METATEST_ADD_TEST(suite, test_at_2) 90 | METATEST_ADD_TEST(suite, test_at_3) 91 | METATEST_ADD_TEST(suite, test_at_4) 92 | METATEST_ADD_TEST(suite, test_at_5) 93 | METATEST_ADD_TEST(suite, test_at_6) 94 | #endif 95 | //METATEST_ADD_TEST(suite, test_iterator_1) 96 | //METATEST_ADD_TEST(suite, test_iterator_2) 97 | //METATEST_ADD_TEST(suite, test_iterator_3) 98 | } 99 | #endif 100 | 101 | namespace testcase_2 102 | { 103 | typedef set_c::type s1; 104 | typedef set_c::type s2; 105 | 106 | typedef equal_to< size, int_<1> > test_size_1; 107 | typedef equal_to< size, int_<8> > test_size_2; 108 | 109 | typedef is_same test_value_type_1; 110 | typedef is_same test_value_type_2; 111 | 112 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 113 | typedef equal_to< test::at_c, int_<'a'> > test_at_1; 114 | typedef equal_to< test::at_c, int_<'a'> > test_at_2; 115 | typedef equal_to< test::at_c, int_<'d'> > test_at_3; 116 | typedef equal_to< test::at_c, int_<'h'> > test_at_4; 117 | 118 | typedef is_same< test::at_c::type, void_ > test_at_5; 119 | typedef is_same< test::at_c::type, void_ > test_at_6; 120 | #endif 121 | 122 | typedef begin::type first1; 123 | typedef end::type last1; 124 | typedef equal_to< distance, int_<1> > test_iterator_1; 125 | 126 | typedef begin::type first2; 127 | typedef end::type last2; 128 | typedef equal_to< distance, int_<8> > test_iterator_2; 129 | 130 | METATEST_ADD_TEST(suite, test_size_1) 131 | METATEST_ADD_TEST(suite, test_size_2) 132 | METATEST_ADD_TEST(suite, test_value_type_1) 133 | METATEST_ADD_TEST(suite, test_value_type_2) 134 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) 135 | METATEST_ADD_TEST(suite, test_at_1) 136 | METATEST_ADD_TEST(suite, test_at_2) 137 | METATEST_ADD_TEST(suite, test_at_3) 138 | METATEST_ADD_TEST(suite, test_at_4) 139 | METATEST_ADD_TEST(suite, test_at_5) 140 | METATEST_ADD_TEST(suite, test_at_6) 141 | #endif 142 | //METATEST_ADD_TEST(suite, test_iterator_1) 143 | //METATEST_ADD_TEST(suite, test_iterator_2) 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/vector.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | namespace 24 | { 25 | const metatest::suite_path suite ("vector"); 26 | 27 | using namespace boost::mpl; 28 | using boost::is_same; 29 | 30 | typedef vector0<> v0; 31 | typedef vector1 v1; 32 | typedef vector2 v2; 33 | typedef vector9 v9; 34 | 35 | typedef vector<> w0; 36 | typedef vector w1; 37 | typedef vector w2; 38 | typedef vector w9; 39 | 40 | typedef equal test_equal_1; 41 | typedef equal test_equal_2; 42 | typedef equal test_equal_3; 43 | typedef equal test_equal_4; 44 | 45 | typedef equal_to< size::type, int_<0> > test_size_1; 46 | typedef equal_to< size::type, int_<1> > test_size_2; 47 | typedef equal_to< size::type, int_<2> > test_size_3; 48 | typedef equal_to< size::type, int_<9> > test_size_4; 49 | 50 | typedef empty test_empty_1; 51 | typedef not_ > test_empty_2; 52 | typedef not_ > test_empty_3; 53 | typedef not_ > test_empty_4; 54 | 55 | typedef is_same< front::type, char > test_front_1; 56 | typedef is_same< front::type, char > test_front_2; 57 | typedef is_same< front::type, char > test_front_3; 58 | 59 | typedef is_same< back::type, char > test_back_1; 60 | typedef is_same< back::type, long > test_back_2; 61 | typedef is_same< back::type, int > test_back_3; 62 | 63 | typedef is_same< 64 | deref< begin::type >::type 65 | , char 66 | > test_iter_1; 67 | 68 | typedef is_same< 69 | deref< next::type>::type >::type 70 | , long 71 | > test_iter_2; 72 | 73 | typedef is_same< 74 | next< next::type>::type >::type 75 | , end::type 76 | > test_iter_3; 77 | 78 | typedef is_same< 79 | back< 80 | push_back::type 81 | >::type 82 | , int 83 | > test_push_1; 84 | 85 | typedef is_same< 86 | back< 87 | push_front< 88 | push_back::type 89 | , char 90 | >::type 91 | >::type 92 | , int 93 | > test_push_2; 94 | 95 | typedef is_same< 96 | front< 97 | push_back< 98 | push_front< 99 | push_back::type 100 | , char 101 | >::type 102 | , long 103 | >::type 104 | >::type 105 | , char 106 | > test_push_3; 107 | 108 | typedef is_same< 109 | back< 110 | push_back< 111 | push_front< 112 | push_back::type 113 | , char 114 | >::type 115 | , long 116 | >::type 117 | >::type 118 | , long 119 | > test_push_4; 120 | 121 | typedef equal< 122 | push_back::type 123 | , push_back::type::type 124 | > test_push_5; 125 | 126 | typedef equal< 127 | push_front< 128 | push_back::type 129 | , char 130 | >::type 131 | , push_front< 132 | push_back::type 133 | , char 134 | >::type::type 135 | > test_push_6; 136 | 137 | typedef equal< 138 | push_back< 139 | push_front< 140 | push_back::type 141 | , char 142 | >::type 143 | , long 144 | >::type 145 | , push_back< 146 | push_front< 147 | push_back::type 148 | , char 149 | >::type 150 | , long 151 | >::type::type 152 | > test_push_7; 153 | 154 | typedef is_same< back::type, int > test_pop_1; 155 | 156 | typedef is_same< 157 | back< pop_back::type >::type 158 | , long 159 | > test_pop_2; 160 | 161 | typedef is_same< 162 | back< 163 | pop_front< pop_back::type >::type 164 | >::type 165 | , long 166 | > test_pop_3; 167 | 168 | typedef is_same< 169 | front< 170 | pop_front< pop_back::type >::type 171 | >::type 172 | , bool 173 | > test_pop_4; 174 | 175 | typedef equal test_pop_5; 176 | 177 | typedef equal< 178 | pop_back::type 179 | , pop_back::type::type 180 | > test_pop_6; 181 | 182 | typedef equal< 183 | pop_front< pop_back::type >::type 184 | , pop_front< pop_back::type >::type::type 185 | > test_pop_7; 186 | 187 | typedef equal test_unnumbered_1; 188 | typedef equal test_unnumbered_2; 189 | typedef equal test_unnumbered_3; 190 | typedef equal test_unnumbered_4; 191 | 192 | typedef equal_to< size::type, int_<0> > test_unnumbered_5; 193 | typedef equal_to< size::type, int_<1> > test_unnumbered_6; 194 | typedef equal_to< size::type, int_<2> > test_unnumbered_7; 195 | typedef equal_to< size::type, int_<9> > test_unnumbered_8; 196 | } 197 | 198 | METATEST_ADD_TEST(suite, test_equal_1) 199 | METATEST_ADD_TEST(suite, test_equal_2) 200 | METATEST_ADD_TEST(suite, test_equal_3) 201 | METATEST_ADD_TEST(suite, test_equal_4) 202 | 203 | METATEST_ADD_TEST(suite, test_size_1) 204 | METATEST_ADD_TEST(suite, test_size_2) 205 | METATEST_ADD_TEST(suite, test_size_3) 206 | METATEST_ADD_TEST(suite, test_size_4) 207 | 208 | METATEST_ADD_TEST(suite, test_empty_1) 209 | METATEST_ADD_TEST(suite, test_empty_2) 210 | METATEST_ADD_TEST(suite, test_empty_3) 211 | METATEST_ADD_TEST(suite, test_empty_4) 212 | 213 | METATEST_ADD_TEST(suite, test_front_1) 214 | METATEST_ADD_TEST(suite, test_front_2) 215 | METATEST_ADD_TEST(suite, test_front_3) 216 | METATEST_ADD_TEST(suite, test_back_1) 217 | METATEST_ADD_TEST(suite, test_back_2) 218 | METATEST_ADD_TEST(suite, test_back_3) 219 | 220 | METATEST_ADD_TEST(suite, test_iter_1) 221 | METATEST_ADD_TEST(suite, test_iter_2) 222 | METATEST_ADD_TEST(suite, test_iter_3) 223 | 224 | METATEST_ADD_TEST(suite, test_push_1) 225 | METATEST_ADD_TEST(suite, test_push_2) 226 | METATEST_ADD_TEST(suite, test_push_3) 227 | METATEST_ADD_TEST(suite, test_push_4) 228 | METATEST_ADD_TEST(suite, test_push_5) 229 | METATEST_ADD_TEST(suite, test_push_6) 230 | METATEST_ADD_TEST(suite, test_push_7) 231 | 232 | METATEST_ADD_TEST(suite, test_pop_1) 233 | METATEST_ADD_TEST(suite, test_pop_2) 234 | METATEST_ADD_TEST(suite, test_pop_3) 235 | METATEST_ADD_TEST(suite, test_pop_4) 236 | METATEST_ADD_TEST(suite, test_pop_5) 237 | METATEST_ADD_TEST(suite, test_pop_6) 238 | METATEST_ADD_TEST(suite, test_pop_7) 239 | 240 | METATEST_ADD_TEST(suite, test_unnumbered_1) 241 | METATEST_ADD_TEST(suite, test_unnumbered_2) 242 | METATEST_ADD_TEST(suite, test_unnumbered_3) 243 | METATEST_ADD_TEST(suite, test_unnumbered_4) 244 | METATEST_ADD_TEST(suite, test_unnumbered_5) 245 | METATEST_ADD_TEST(suite, test_unnumbered_6) 246 | METATEST_ADD_TEST(suite, test_unnumbered_7) 247 | METATEST_ADD_TEST(suite, test_unnumbered_8) 248 | 249 | -------------------------------------------------------------------------------- /include/metatest/to_stream_sequence.hpp: -------------------------------------------------------------------------------- 1 | #ifndef METATEST_TO_STREAM_SEQUENCE_HPP 2 | #define METATEST_TO_STREAM_SEQUENCE_HPP 3 | 4 | // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011-2012. 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace metatest 34 | { 35 | struct to_stream_nothing 36 | { 37 | typedef to_stream_nothing type; 38 | 39 | static std::ostream& run(std::ostream& o_) 40 | { 41 | return o_; 42 | } 43 | }; 44 | 45 | template 46 | struct to_stream_sequence_impl; 47 | 48 | template 49 | struct to_stream_sequence : 50 | boost::mpl::if_< 51 | boost::is_same, 52 | to_stream_nothing, 53 | to_stream_sequence_impl 54 | >::type 55 | {}; 56 | 57 | template 58 | struct to_stream_sequence_impl 59 | { 60 | typedef to_stream_sequence_impl type; 61 | 62 | static std::ostream& run(std::ostream& o_) 63 | { 64 | using boost::mpl::next; 65 | using boost::mpl::deref; 66 | using boost::is_same; 67 | 68 | typedef typename next::type i_next; 69 | typedef typename deref::type deref_i; 70 | const bool is_at_end = is_same::type::value; 71 | 72 | to_stream::run(o_); 73 | o_ << (is_at_end ? "" : ", "); 74 | to_stream_sequence::run(o_); 75 | return o_; 76 | } 77 | }; 78 | 79 | 80 | template 81 | struct to_stream_sequence_values_impl; 82 | 83 | template 84 | struct to_stream_sequence_values : 85 | boost::mpl::if_< 86 | boost::is_same, 87 | to_stream_nothing, 88 | to_stream_sequence_values_impl 89 | >::type 90 | {}; 91 | 92 | template 93 | struct to_stream_sequence_values_impl 94 | { 95 | typedef to_stream_sequence_values_impl type; 96 | 97 | static std::ostream& run(std::ostream& o_) 98 | { 99 | using boost::mpl::next; 100 | using boost::mpl::deref; 101 | using boost::is_same; 102 | 103 | typedef typename next::type i_next; 104 | typedef typename deref::type deref_i; 105 | const bool is_at_end = is_same::type::value; 106 | 107 | o_ << deref_i::value << (is_at_end ? "" : ", "); 108 | to_stream_sequence_values::run(o_); 109 | return o_; 110 | } 111 | }; 112 | 113 | struct no_common_tag 114 | { 115 | typedef no_common_tag type; 116 | }; 117 | 118 | // I can't use a lambda expression, because is_same is not lazy 119 | struct common_tag_compare 120 | { 121 | typedef common_tag_compare type; 122 | 123 | template 124 | struct apply : 125 | boost::mpl::if_< 126 | boost::is_same::type>, 127 | A, 128 | no_common_tag 129 | > 130 | {}; 131 | }; 132 | 133 | template 134 | struct common_tag : 135 | boost::mpl::fold< 136 | Seq, 137 | typename boost::mpl::tag::type>::type, 138 | common_tag_compare 139 | > 140 | {}; 141 | 142 | template 143 | struct to_stream_sequence_begin 144 | { 145 | typedef to_stream_sequence_begin type; 146 | 147 | static std::ostream& run(std::ostream& o_) 148 | { 149 | using boost::mpl::begin; 150 | using boost::mpl::end; 151 | 152 | typedef typename begin::type b; 153 | typedef typename end::type e; 154 | 155 | o_ << "<"; 156 | to_stream_sequence::run(o_); 157 | return o_ << ">"; 158 | } 159 | }; 160 | 161 | // pre-condition: !empty 162 | template 163 | struct to_stream_sequence_begin 164 | { 165 | typedef to_stream_sequence_begin type; 166 | 167 | static std::ostream& run(std::ostream& o_) 168 | { 169 | using boost::mpl::begin; 170 | using boost::mpl::end; 171 | using boost::mpl::front; 172 | 173 | typedef typename front::type::value_type v_type; 174 | 175 | o_ << "_c<"; 176 | metatest::to_stream::run(o_); 177 | o_ << ", "; 178 | 179 | if (boost::is_same::type::value) 180 | { 181 | o_ << '\"'; 182 | boost::mpl::for_each(character_printer(o_)); 183 | o_ << '\"'; 184 | } 185 | else 186 | { 187 | typedef typename begin::type b; 188 | typedef typename end::type e; 189 | 190 | to_stream_sequence_values::run(o_); 191 | } 192 | 193 | return o_ << ">"; 194 | } 195 | }; 196 | 197 | template 198 | struct to_stream_seq 199 | { 200 | typedef to_stream_seq type; 201 | 202 | static std::ostream& run(std::ostream& o_) 203 | { 204 | return 205 | to_stream_sequence_begin< 206 | S, 207 | typename boost::mpl::eval_if< 208 | typename boost::mpl::empty::type, 209 | no_common_tag, 210 | common_tag 211 | >::type 212 | >::run(o_ << "mpl::" << Name::run()); 213 | } 214 | }; 215 | 216 | namespace util 217 | { 218 | // Use these classes instead of TMP strings for simplicity 219 | #ifdef METATEST_DEF_NAME 220 | #error METATEST_DEF_NAME already defined 221 | #endif 222 | #define METATEST_DEF_NAME(s) \ 223 | struct name_##s \ 224 | { \ 225 | typedef name_##s type; \ 226 | static const char* run() \ 227 | { \ 228 | return #s; \ 229 | } \ 230 | }; 231 | 232 | METATEST_DEF_NAME(list) 233 | METATEST_DEF_NAME(vector) 234 | METATEST_DEF_NAME(set) 235 | METATEST_DEF_NAME(map) 236 | METATEST_DEF_NAME(deque) 237 | 238 | #undef METATEST_DEF_NAME 239 | } 240 | 241 | #ifdef METATEST_DEF_SEQ_C 242 | #error METATEST_DEF_SEQ_C already defined 243 | #endif 244 | #define METATEST_DEF_SEQ_C(seq, limit) \ 245 | template \ 246 | struct to_stream< \ 247 | BOOST_PP_CAT(boost::mpl::seq, _c) \ 248 | > : \ 249 | to_stream_seq< \ 250 | BOOST_PP_CAT(boost::mpl::seq, _c)< \ 251 | T, \ 252 | BOOST_PP_ENUM_PARAMS(limit, N) \ 253 | >, \ 254 | BOOST_PP_CAT(metatest::util::name_, seq) \ 255 | > \ 256 | {}; 257 | 258 | #ifdef METATEST_DEF_SEQ 259 | #error METATEST_DEF_SEQ already defined 260 | #endif 261 | #define METATEST_DEF_SEQ(seq, limit) \ 262 | template \ 263 | struct to_stream > : \ 264 | to_stream_seq< \ 265 | boost::mpl::seq, \ 266 | BOOST_PP_CAT(metatest::util::name_, seq) \ 267 | > \ 268 | {}; 269 | 270 | #ifdef METATEST_DEF_SEQ_N_ITER 271 | #error METATEST_DEF_SEQ_N_ITER already defined 272 | #endif 273 | #define METATEST_DEF_SEQ_N_ITER(z, n, seq) \ 274 | template \ 275 | struct to_stream< \ 276 | BOOST_PP_CAT(boost::mpl::seq, n) \ 277 | > : \ 278 | to_stream_seq< \ 279 | BOOST_PP_CAT(boost::mpl::seq, n), \ 280 | BOOST_PP_CAT(metatest::util::name_, seq) \ 281 | > \ 282 | {}; 283 | 284 | #ifdef METATEST_DEF_SEQ_N 285 | #error METATEST_DEF_SEQ_N already defined 286 | #endif 287 | #define METATEST_DEF_SEQ_N(seq, limit) \ 288 | template \ 289 | struct to_stream > : \ 290 | to_stream_seq< \ 291 | BOOST_PP_CAT(boost::mpl::seq, 0), \ 292 | BOOST_PP_CAT(metatest::util::name_, seq) \ 293 | > \ 294 | {};\ 295 | \ 296 | BOOST_PP_REPEAT_FROM_TO( \ 297 | 1, \ 298 | limit, \ 299 | METATEST_DEF_SEQ_N_ITER, \ 300 | seq \ 301 | ) 302 | 303 | METATEST_DEF_SEQ(list, BOOST_MPL_LIMIT_LIST_SIZE) 304 | METATEST_DEF_SEQ_C(list, BOOST_MPL_LIMIT_LIST_SIZE) 305 | METATEST_DEF_SEQ_N(list, BOOST_MPL_LIMIT_VECTOR_SIZE) 306 | METATEST_DEF_SEQ(vector, BOOST_MPL_LIMIT_VECTOR_SIZE) 307 | METATEST_DEF_SEQ_C(vector, BOOST_MPL_LIMIT_VECTOR_SIZE) 308 | METATEST_DEF_SEQ_N(vector, BOOST_MPL_LIMIT_VECTOR_SIZE) 309 | METATEST_DEF_SEQ(deque, BOOST_MPL_LIMIT_VECTOR_SIZE) 310 | METATEST_DEF_SEQ(set, BOOST_MPL_LIMIT_SET_SIZE) 311 | METATEST_DEF_SEQ_C(set, BOOST_MPL_LIMIT_SET_SIZE) 312 | METATEST_DEF_SEQ_N(set, BOOST_MPL_LIMIT_SET_SIZE) 313 | METATEST_DEF_SEQ(map, BOOST_MPL_LIMIT_MAP_SIZE) 314 | METATEST_DEF_SEQ_N(map, BOOST_MPL_LIMIT_MAP_SIZE) 315 | 316 | #undef METATEST_DEF_SEQ_N_ITER 317 | #undef METATEST_DEF_SEQ_N 318 | #undef METATEST_DEF_SEQ 319 | #undef METATEST_DEF_SEQ_C 320 | } 321 | 322 | #endif 323 | 324 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/map.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace 23 | { 24 | const metatest::suite_path suite ("map"); 25 | 26 | using namespace boost::mpl; 27 | using boost::is_same; 28 | 29 | struct UDT {}; 30 | struct incomplete; 31 | 32 | namespace testcase_1 33 | { 34 | 35 | typedef map2< 36 | pair 37 | , pair 38 | > m_; 39 | 40 | typedef erase_key::type m; 41 | 42 | typedef equal_to< size, int_<1> > test_erase_1; 43 | typedef not_< empty > test_erase_2; 44 | typedef is_same< clear::type, map0<> > test_clear_1; 45 | 46 | typedef is_same< at::type, unsigned > test_at_1; 47 | typedef is_same< at::type, void_ > test_at_2; 48 | typedef contains< m, pair > test_contains_1; 49 | typedef not_< contains > > test_contains_2; 50 | typedef not_< contains > > test_contains_3; 51 | 52 | typedef not_< has_key > test_has_key_1; 53 | typedef has_key test_has_key_2; 54 | typedef not_< is_same< order::type, void_ > > test_order_1; 55 | typedef is_same< order::type, void_ > test_order_2; 56 | 57 | typedef begin::type first; 58 | typedef end::type last; 59 | 60 | typedef is_same< deref::type, pair > test_deref_1; 61 | typedef is_same< next::type, last > test_next_1; 62 | 63 | typedef insert >::type m2; 64 | 65 | typedef equal_to< size, int_<2> > test_size_1; 66 | typedef not_< empty > test_empty_1; 67 | typedef is_same< clear::type, map0<> > test_clear_2; 68 | typedef is_same< at::type, unsigned > test_at_3; 69 | typedef is_same< at::type, long> test_at_4; 70 | 71 | typedef contains< m2, pair > test_contains_4; 72 | typedef not_< contains > > test_contains_5; 73 | typedef not_< contains > > test_contains_6; 74 | typedef contains< m2, pair > test_contains_7; 75 | 76 | typedef has_key test_has_key_3; 77 | typedef not_< has_key > test_has_key_4; 78 | typedef not_< is_same::type, void_> > test_order_3; 79 | typedef not_< is_same::type, void_> > test_order_4; 80 | typedef not_< is_same::type, order::type > > test_order_5; 81 | 82 | typedef begin::type first2; 83 | typedef end::type last2; 84 | 85 | typedef is_same< deref::type, pair > test_deref_2; 86 | 87 | typedef next::type iter; 88 | typedef is_same< deref::type, pair > test_deref_3; 89 | typedef is_same< next::type, last2 > test_next_2; 90 | 91 | typedef insert >::type s2_1; 92 | typedef is_same test_insert_1; 93 | 94 | typedef insert >::type m3; 95 | typedef equal_to< size, int_<3> > test_size_2; 96 | typedef has_key test_has_key_5; 97 | typedef has_key test_has_key_6; 98 | typedef has_key test_has_key_7; 99 | typedef contains > test_contains_8; 100 | typedef contains > test_contains_9; 101 | 102 | typedef insert >::type m1; 103 | typedef equal_to< size, int_<2> > test_size_3; 104 | typedef is_same< at::type, unsigned> test_at_5; 105 | typedef is_same< at::type, long> test_at_6; 106 | 107 | typedef contains > test_contains_10; 108 | typedef not_< contains > > test_contains_11; 109 | typedef not_< contains > > test_contains_12; 110 | typedef contains > test_contains_13; 111 | 112 | typedef is_same test_insert_2; 113 | 114 | typedef erase_key::type m_1; 115 | typedef is_same test_erase_key_1; 116 | typedef equal_to< size, int_<1> > test_size_4; 117 | typedef is_same< at::type, void_> test_at_7; 118 | typedef is_same< at::type, unsigned> test_at_8; 119 | 120 | typedef erase_key::type m2_1; 121 | typedef equal_to< size, int_<2> > test_size_5; 122 | typedef is_same< at::type, void_> test_at_9; 123 | typedef is_same< at::type, unsigned> test_at_10; 124 | typedef is_same< at::type, unsigned> test_at_11; 125 | 126 | METATEST_ADD_TEST(suite, test_erase_1) 127 | METATEST_ADD_TEST(suite, test_erase_2) 128 | METATEST_ADD_TEST(suite, test_clear_1) 129 | METATEST_ADD_TEST(suite, test_at_1) 130 | METATEST_ADD_TEST(suite, test_at_2) 131 | METATEST_ADD_TEST(suite, test_contains_1) 132 | METATEST_ADD_TEST(suite, test_contains_2) 133 | METATEST_ADD_TEST(suite, test_contains_3) 134 | METATEST_ADD_TEST(suite, test_has_key_1) 135 | METATEST_ADD_TEST(suite, test_has_key_2) 136 | METATEST_ADD_TEST(suite, test_order_1) 137 | METATEST_ADD_TEST(suite, test_order_2) 138 | METATEST_ADD_TEST(suite, test_deref_1) 139 | METATEST_ADD_TEST(suite, test_next_1) 140 | METATEST_ADD_TEST(suite, test_size_1) 141 | METATEST_ADD_TEST(suite, test_empty_1) 142 | METATEST_ADD_TEST(suite, test_clear_2) 143 | METATEST_ADD_TEST(suite, test_at_3) 144 | METATEST_ADD_TEST(suite, test_at_4) 145 | METATEST_ADD_TEST(suite, test_contains_4) 146 | METATEST_ADD_TEST(suite, test_contains_5) 147 | METATEST_ADD_TEST(suite, test_contains_6) 148 | METATEST_ADD_TEST(suite, test_contains_7) 149 | METATEST_ADD_TEST(suite, test_has_key_3) 150 | METATEST_ADD_TEST(suite, test_has_key_4) 151 | METATEST_ADD_TEST(suite, test_order_3) 152 | METATEST_ADD_TEST(suite, test_order_4) 153 | METATEST_ADD_TEST(suite, test_order_5) 154 | METATEST_ADD_TEST(suite, test_deref_2) 155 | METATEST_ADD_TEST(suite, test_deref_3) 156 | METATEST_ADD_TEST(suite, test_next_2) 157 | METATEST_ADD_TEST(suite, test_insert_1) 158 | METATEST_ADD_TEST(suite, test_size_2) 159 | METATEST_ADD_TEST(suite, test_has_key_5) 160 | METATEST_ADD_TEST(suite, test_has_key_6) 161 | METATEST_ADD_TEST(suite, test_has_key_7) 162 | METATEST_ADD_TEST(suite, test_contains_8) 163 | METATEST_ADD_TEST(suite, test_contains_9) 164 | METATEST_ADD_TEST(suite, test_size_3) 165 | METATEST_ADD_TEST(suite, test_at_5) 166 | METATEST_ADD_TEST(suite, test_at_6) 167 | METATEST_ADD_TEST(suite, test_contains_10) 168 | METATEST_ADD_TEST(suite, test_contains_11) 169 | METATEST_ADD_TEST(suite, test_contains_12) 170 | METATEST_ADD_TEST(suite, test_contains_13) 171 | METATEST_ADD_TEST(suite, test_insert_2) 172 | METATEST_ADD_TEST(suite, test_erase_key_1) 173 | METATEST_ADD_TEST(suite, test_size_4) 174 | METATEST_ADD_TEST(suite, test_at_7) 175 | METATEST_ADD_TEST(suite, test_at_8) 176 | METATEST_ADD_TEST(suite, test_size_5) 177 | METATEST_ADD_TEST(suite, test_at_9) 178 | METATEST_ADD_TEST(suite, test_at_10) 179 | METATEST_ADD_TEST(suite, test_at_11) 180 | } 181 | 182 | namespace testcase_2 183 | { 184 | typedef map0<> m; 185 | 186 | typedef equal_to< size, int_<0> > test_size_1; 187 | typedef empty test_empty_1; 188 | 189 | typedef is_same< clear::type, map0<> > test_clear_1; 190 | typedef is_same< at::type, void_> test_at_1; 191 | 192 | typedef not_< has_key::type > test_has_key_1; 193 | typedef not_< has_key::type > test_has_key_2; 194 | typedef not_< has_key::type > test_has_key_3; 195 | typedef not_< has_key::type > test_has_key_4; 196 | 197 | typedef not_< has_key::type > test_has_key_5; 198 | typedef not_< has_key::type > test_has_key_6; 199 | typedef not_< has_key::type > test_has_key_7; 200 | typedef not_< has_key::type > test_has_key_8; 201 | 202 | typedef not_< has_key::type > test_has_key_9; 203 | typedef not_< has_key::type > test_has_key_10; 204 | typedef not_< has_key::type > test_has_key_11; 205 | 206 | typedef not_< has_key::type > test_has_key_12; 207 | typedef not_< has_key::type > test_has_key_13; 208 | typedef not_< has_key::type > test_has_key_14; 209 | 210 | typedef insert >::type m1; 211 | typedef equal_to< size, int_<1> > test_size_2; 212 | typedef is_same< at::type, int > test_at_2; 213 | 214 | typedef erase_key::type m0_1; 215 | typedef equal_to< size, int_<0> > test_size_3; 216 | typedef is_same< at::type, void_> test_at_3; 217 | 218 | METATEST_ADD_TEST(suite, test_size_1) 219 | METATEST_ADD_TEST(suite, test_empty_1) 220 | METATEST_ADD_TEST(suite, test_clear_1) 221 | METATEST_ADD_TEST(suite, test_at_1) 222 | METATEST_ADD_TEST(suite, test_has_key_1) 223 | METATEST_ADD_TEST(suite, test_has_key_2) 224 | METATEST_ADD_TEST(suite, test_has_key_3) 225 | METATEST_ADD_TEST(suite, test_has_key_4) 226 | METATEST_ADD_TEST(suite, test_has_key_5) 227 | METATEST_ADD_TEST(suite, test_has_key_6) 228 | METATEST_ADD_TEST(suite, test_has_key_7) 229 | METATEST_ADD_TEST(suite, test_has_key_8) 230 | METATEST_ADD_TEST(suite, test_has_key_9) 231 | METATEST_ADD_TEST(suite, test_has_key_10) 232 | METATEST_ADD_TEST(suite, test_has_key_11) 233 | METATEST_ADD_TEST(suite, test_has_key_12) 234 | METATEST_ADD_TEST(suite, test_has_key_13) 235 | METATEST_ADD_TEST(suite, test_has_key_14) 236 | METATEST_ADD_TEST(suite, test_size_2) 237 | METATEST_ADD_TEST(suite, test_at_2) 238 | METATEST_ADD_TEST(suite, test_size_3) 239 | METATEST_ADD_TEST(suite, test_at_3) 240 | } 241 | 242 | namespace testcase_3 243 | { 244 | typedef map< pair > map_of_1_pair; 245 | typedef begin::type iter_to_1_pair; 246 | 247 | typedef is_same< 248 | deref::type 249 | , pair 250 | > test_deref; 251 | 252 | typedef map< 253 | pair 254 | , pair 255 | , pair 256 | > mymap; 257 | 258 | typedef equal_to< size, int_<3> > test_size; 259 | 260 | typedef not_< 261 | is_same< 262 | find >::type 263 | , end::type 264 | > 265 | > test_find_1; 266 | 267 | typedef not_< 268 | is_same< 269 | find >::type 270 | , end::type 271 | > 272 | > test_find_2; 273 | 274 | typedef not_< 275 | is_same< 276 | find >::type 277 | , end::type 278 | > 279 | > test_find_3; 280 | 281 | typedef is_same< 282 | find::type 283 | , end::type 284 | > test_find_4; 285 | 286 | METATEST_ADD_TEST(suite, test_deref) 287 | METATEST_ADD_TEST(suite, test_size) 288 | METATEST_ADD_TEST(suite, test_find_1) 289 | METATEST_ADD_TEST(suite, test_find_2) 290 | METATEST_ADD_TEST(suite, test_find_3) 291 | METATEST_ADD_TEST(suite, test_find_4) 292 | } 293 | 294 | namespace testcase_4 295 | { 296 | typedef erase_key< 297 | map< pair, pair > 298 | , char 299 | >::type int_to_float_map; 300 | 301 | typedef insert< 302 | int_to_float_map 303 | , pair 304 | >::type with_char_too; 305 | 306 | typedef is_same< at::type, long > test_at; 307 | 308 | METATEST_ADD_TEST(suite, test_at) 309 | } 310 | } 311 | 312 | -------------------------------------------------------------------------------- /example/boost_mpl_unit_test/set.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Endre Tamas SAJO (baja@inf.elte.hu) 2011. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_2_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace 27 | { 28 | const metatest::suite_path suite ("set"); 29 | 30 | using namespace boost::mpl; 31 | using boost::is_same; 32 | 33 | struct UDT {}; 34 | struct incomplete; 35 | class abstract { public: virtual ~abstract() = 0; }; 36 | 37 | template 38 | struct empty_set_test 39 | { 40 | typedef equal_to< size, int_<0> > t1; 41 | typedef empty t2; 42 | 43 | typedef is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > t3; 44 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > t4; 45 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > t5; 46 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > t6; 47 | 48 | typedef not_< has_key > t7; 49 | typedef not_< has_key > t8; 50 | typedef not_< has_key > t9; 51 | 52 | typedef is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > t10; 53 | typedef is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > t11; 54 | typedef is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > t12; 55 | 56 | typedef BOOST_DEDUCED_TYPENAME begin::type first; 57 | typedef BOOST_DEDUCED_TYPENAME end::type last; 58 | 59 | typedef is_same t13; 60 | typedef equal_to< distance, int_<0> > t14; 61 | 62 | typedef typename and_< 63 | and_ 64 | , and_ 65 | , and_ 66 | >::type type; 67 | }; 68 | 69 | template 70 | struct int_set_test 71 | { 72 | typedef equal_to< size, int_<1> > t1; 73 | typedef not_< empty > t2; 74 | 75 | typedef is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > t3; 76 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, int > t4; 77 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > t5; 78 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > t6; 79 | 80 | typedef has_key t7; 81 | typedef not_< has_key > t8; 82 | typedef not_< has_key > t9; 83 | 84 | typedef not_< is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > > t10; 85 | typedef is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > t11; 86 | typedef is_same< BOOST_DEDUCED_TYPENAME order::type, void_ > t12; 87 | 88 | typedef BOOST_DEDUCED_TYPENAME begin::type first; 89 | typedef BOOST_DEDUCED_TYPENAME end::type last; 90 | 91 | typedef is_same< BOOST_DEDUCED_TYPENAME deref::type, int > t13; 92 | typedef is_same< BOOST_DEDUCED_TYPENAME next::type, last > t14; 93 | 94 | typedef equal_to< distance, int_<1> > t15; 95 | typedef contains t16; 96 | 97 | typedef typename and_< 98 | and_ 99 | , and_ 100 | , and_ 101 | , t16 102 | >::type type; 103 | }; 104 | 105 | template 106 | struct int_char_set_test 107 | { 108 | typedef equal_to< size, int_<2> > t1; 109 | typedef not_< empty > t2; 110 | typedef is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > t3; 111 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, int > t4; 112 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, char > t5; 113 | 114 | typedef has_key t6; 115 | typedef not_< has_key > t7; 116 | 117 | typedef not_< 118 | is_same ::type, void_> 119 | > t8; 120 | typedef not_< 121 | is_same ::type, void_> 122 | > t9; 123 | typedef is_same ::type, void_> t10; 124 | typedef not_< 125 | is_same < 126 | BOOST_DEDUCED_TYPENAME order::type 127 | , BOOST_DEDUCED_TYPENAME order::type 128 | > 129 | > t11; 130 | 131 | typedef BOOST_DEDUCED_TYPENAME begin::type first; 132 | typedef BOOST_DEDUCED_TYPENAME end::type last; 133 | 134 | typedef equal_to< distance, int_<2> > t12; 135 | typedef contains t13; 136 | typedef contains t14; 137 | 138 | typedef typename and_< 139 | and_ 140 | , and_ 141 | , and_ 142 | >::type type; 143 | }; 144 | 145 | template 146 | struct int_char_long_set_test 147 | { 148 | typedef equal_to< size, int_<3> > t1; 149 | typedef not_< empty > t2; 150 | 151 | typedef is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > t3; 152 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, int > t4; 153 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, char > t5; 154 | typedef is_same< BOOST_DEDUCED_TYPENAME at::type, long > t6; 155 | 156 | typedef has_key t7; 157 | typedef has_key t8; 158 | typedef has_key t9; 159 | 160 | typedef BOOST_DEDUCED_TYPENAME order::type o1; 161 | typedef BOOST_DEDUCED_TYPENAME order::type o2; 162 | typedef BOOST_DEDUCED_TYPENAME order::type o3; 163 | typedef not_< is_same > t10; 164 | typedef not_< is_same > t11; 165 | typedef not_< is_same > t12; 166 | typedef not_< is_same > t13; 167 | typedef not_< is_same > t14; 168 | typedef not_< is_same > t15; 169 | 170 | typedef BOOST_DEDUCED_TYPENAME begin::type first; 171 | typedef BOOST_DEDUCED_TYPENAME end::type last; 172 | typedef equal_to< distance, int_<3> > t16; 173 | 174 | typedef contains t17; 175 | typedef contains t18; 176 | typedef contains t19; 177 | 178 | typedef typename and_< 179 | and_ 180 | , and_ 181 | , and_ 182 | , and_ 183 | >::type type; 184 | }; 185 | 186 | template 187 | struct basic_set_test 188 | { 189 | typedef empty_set_test t1; 190 | typedef empty_set_test::type> t2; 191 | typedef empty_set_test< 192 | BOOST_DEDUCED_TYPENAME erase_key< 193 | BOOST_DEDUCED_TYPENAME erase_key::type 194 | , int 195 | >::type 196 | > t3; 197 | typedef empty_set_test< 198 | BOOST_DEDUCED_TYPENAME erase_key< 199 | BOOST_DEDUCED_TYPENAME erase_key< 200 | BOOST_DEDUCED_TYPENAME erase_key::type 201 | , long 202 | >::type 203 | , int 204 | >::type 205 | > t4; 206 | 207 | typedef int_set_test t5; 208 | typedef int_set_test< BOOST_DEDUCED_TYPENAME insert::type > t6; 209 | typedef int_set_test< BOOST_DEDUCED_TYPENAME erase_key::type > t7; 210 | typedef int_set_test< 211 | BOOST_DEDUCED_TYPENAME erase_key< 212 | BOOST_DEDUCED_TYPENAME erase_key::type 213 | , long 214 | >::type 215 | > t8; 216 | 217 | typedef int_char_set_test t9; 218 | typedef int_char_set_test::type> t10; 219 | typedef 220 | int_char_set_test::type> t11; 221 | typedef int_char_set_test< 222 | BOOST_DEDUCED_TYPENAME insert< 223 | BOOST_DEDUCED_TYPENAME insert::type 224 | , int 225 | >::type 226 | > t12; 227 | 228 | typedef int_char_long_set_test t13; 229 | typedef int_char_long_set_test< 230 | BOOST_DEDUCED_TYPENAME insert< 231 | BOOST_DEDUCED_TYPENAME insert< 232 | BOOST_DEDUCED_TYPENAME insert::type 233 | , long 234 | >::type 235 | , int 236 | >::type 237 | > t14; 238 | typedef int_char_long_set_test< 239 | BOOST_DEDUCED_TYPENAME insert< 240 | BOOST_DEDUCED_TYPENAME insert::type 241 | , char 242 | >::type 243 | > t15; 244 | typedef int_char_long_set_test< 245 | BOOST_DEDUCED_TYPENAME insert::type 246 | > t16; 247 | 248 | typedef typename and_< 249 | and_ 250 | , and_ 251 | , and_ 252 | , t16 253 | >::type type; 254 | }; 255 | 256 | template 257 | struct numbered_vs_variadic_set_test 258 | { 259 | typedef typename and_< 260 | is_same 261 | , is_same 262 | >::type type; 263 | }; 264 | 265 | namespace testcase_1 266 | { 267 | typedef set0<> s01; 268 | typedef set<> s02; 269 | typedef set1 s11; 270 | typedef set s12; 271 | typedef set2 s21; 272 | typedef set s22; 273 | typedef set s23; 274 | typedef set3 s31; 275 | typedef set s32; 276 | typedef set s33; 277 | typedef set s34; 278 | 279 | typedef numbered_vs_variadic_set_test test_num_var_1; 280 | typedef numbered_vs_variadic_set_test test_num_var_2; 281 | typedef numbered_vs_variadic_set_test test_num_var_3; 282 | typedef numbered_vs_variadic_set_test test_num_var_4; 283 | 284 | typedef basic_set_test test_basic_1; 285 | typedef basic_set_test test_basic_2; 286 | typedef basic_set_test test_basic_3; 287 | typedef basic_set_test test_basic_4; 288 | typedef basic_set_test test_basic_5; 289 | 290 | METATEST_ADD_TEST(suite, test_num_var_1) 291 | METATEST_ADD_TEST(suite, test_num_var_2) 292 | METATEST_ADD_TEST(suite, test_num_var_3) 293 | METATEST_ADD_TEST(suite, test_num_var_4) 294 | METATEST_ADD_TEST(suite, test_basic_1) 295 | METATEST_ADD_TEST(suite, test_basic_2) 296 | METATEST_ADD_TEST(suite, test_basic_3) 297 | METATEST_ADD_TEST(suite, test_basic_4) 298 | METATEST_ADD_TEST(suite, test_basic_5) 299 | } 300 | 301 | template 302 | struct empty_set_types_variety_test 303 | { 304 | typedef not_< has_key > t1; 305 | typedef not_< has_key > t2; 306 | typedef not_< has_key > t3; 307 | typedef not_< has_key > t4; 308 | 309 | typedef not_< has_key > t5; 310 | typedef not_< has_key > t6; 311 | typedef not_< has_key > t7; 312 | typedef not_< has_key > t8; 313 | 314 | typedef not_< has_key > t9; 315 | typedef not_< has_key > t10; 316 | typedef not_< has_key > t11; 317 | 318 | typedef not_< has_key > t12; 319 | typedef not_< has_key > t13; 320 | typedef not_< has_key > t14; 321 | 322 | typedef typename and_< 323 | and_ 324 | , and_ 325 | , and_ 326 | >::type type; 327 | }; 328 | 329 | template 330 | struct set_types_variety_test 331 | { 332 | typedef equal_to< size, int_<8> > t1; 333 | 334 | typedef has_key t2; 335 | typedef has_key t3; 336 | typedef has_key t4; 337 | typedef has_key t5; 338 | typedef has_key t6; 339 | typedef has_key t7; 340 | typedef has_key t8; 341 | typedef has_key t9; 342 | 343 | typedef not_< has_key > t10; 344 | typedef not_< has_key > t11; 345 | typedef not_< has_key > t12; 346 | typedef not_< has_key > t13; 347 | typedef not_< has_key > t14; 348 | typedef not_< has_key > t15; 349 | typedef not_< has_key > t16; 350 | typedef not_< has_key > t17; 351 | 352 | typedef typename and_< 353 | and_ 354 | , and_ 355 | , and_ 356 | , and_ 357 | >::type type; 358 | }; 359 | 360 | namespace testcase_2 361 | { 362 | typedef empty_set_types_variety_test< set<> > test_empty_types_1; 363 | typedef empty_set_types_variety_test< set<>::type > test_empty_types_2; 364 | 365 | typedef set< 366 | char, int const, long*, UDT* const, incomplete, abstract 367 | , incomplete volatile&, abstract const& 368 | > s; 369 | 370 | typedef set_types_variety_test test_types_1; 371 | typedef set_types_variety_test test_types_2; 372 | 373 | METATEST_ADD_TEST(suite, test_empty_types_1) 374 | METATEST_ADD_TEST(suite, test_empty_types_2) 375 | METATEST_ADD_TEST(suite, test_types_1) 376 | METATEST_ADD_TEST(suite, test_types_2) 377 | } 378 | 379 | template 380 | struct find_test 381 | { 382 | typedef equal_to< size, int_<3> > t1; 383 | 384 | typedef typename end::type not_found; 385 | typedef 386 | not_< is_same::type, not_found> > t2; 387 | typedef 388 | not_< is_same::type, not_found> > t3; 389 | typedef 390 | not_< is_same::type, not_found> > t4; 391 | typedef is_same::type, not_found> t5; 392 | 393 | typedef typename and_::type type; 394 | }; 395 | 396 | namespace testcase_3 397 | { 398 | typedef set s; 399 | 400 | typedef find_test test_find_1; 401 | typedef find_test test_find_2; 402 | 403 | METATEST_ADD_TEST(suite, test_find_1) 404 | METATEST_ADD_TEST(suite, test_find_2) 405 | } 406 | } 407 | 408 | --------------------------------------------------------------------------------