// Copyright Paul A. Bristow 2015. // Copyright Christopher Kormanyos 2015. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) //! \file /*!\brief Example of a Very Contrived Test for a list of types and their respective values.\n It checks that the numeric_limits for the type is in accord with the expected value that is contained in a dataset, array or list that can be indexed by the test_type. */ //! \sa http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/tests_organization/test_cases/test_organization_templates.html#ref_BOOST_AUTO_TEST_CASE_TEMPLATE #define BOOST_TEST_MODULE test_types_values #define BOOST_LIB_DIAGNOSTIC #include #include // for mpl::list #include #include #include #include #include int index = 0; // Global so that can be accessed by digits_test // List of types to test. typedef boost::mpl::list test_types; // Container for expected values of std::numeric_limits::digits for the types above. // It's size must match the size of the list of types to test. std::array type_values { { 8-1, 16-1, 32-1, 32-1, 64-1 } }; // Similarly OK for an array of any value type, including char std::array type_strings { { "char", "short", "int", "long", "long long" } }; std::array type_std_strings { { "char", "short", "int", "long", "long long" } }; template void digits_test() { int digits = type_values[index]; // 8 if T == char, 16 if T == short, 32 if T == int ... BOOST_CHECK_EQUAL(std::numeric_limits::digits, digits); // Test for corresponding value. index++; // ready for next type. return; } // void digits_test() BOOST_AUTO_TEST_CASE_TEMPLATE(my_test, T, test_types) { // Test for a value that is same for all T - works fine. BOOST_CHECK_EQUAL(std::numeric_limits::radix, 2); // Find the expected value for the type T from the array type_values. digits_test(); } // BOOST_AUTO_TEST_CASE_TEMPLATE(my_test, T, test_types) /* Output: Running 5 test cases... 1> 1> *** No errors detected */