diff --git a/test/arithmetic_test.cpp b/test/arithmetic_test.cpp new file mode 100644 index 0000000..ab2eeff --- /dev/null +++ b/test/arithmetic_test.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include +#include +#include +#include +#include + +#include + +// *** + +TEST(BOOST_PP_ADD(2,3) == 5) +TEST(BOOST_PP_ADD(11,BOOST_PP_SUB(BOOST_PP_LIMIT_MAG,10)) == BOOST_PP_LIMIT_MAG) + +TEST(BOOST_PP_SUB(11,0) == 11) +TEST(BOOST_PP_SUB(12,1) == 11) +TEST(BOOST_PP_SUB(3,4) == 0) + +TEST(BOOST_PP_MUL(0,1) == 0) +TEST(BOOST_PP_MUL(1,0) == 0) +TEST(BOOST_PP_MUL(1,1) == 1) +TEST(BOOST_PP_MUL(4,3) == 12) + +TEST(BOOST_PP_DIV(2,1) == 2) +TEST(BOOST_PP_DIV(0,5) == 0) +TEST(BOOST_PP_DIV(7,3) == 2) + +TEST(BOOST_PP_EQUAL(1,0) == 0) +TEST(BOOST_PP_EQUAL(10,10) == 1) + +TEST(BOOST_PP_NOT_EQUAL(3,4) == 1) +TEST(BOOST_PP_NOT_EQUAL(7,7) == 0) + +TEST(BOOST_PP_LESS_EQUAL(6,7) == 1) +TEST(BOOST_PP_LESS_EQUAL(8,1) == 0) +TEST(BOOST_PP_LESS_EQUAL(5,5) == 1) + +TEST(BOOST_PP_GREATER_EQUAL(6,7) == 0) +TEST(BOOST_PP_GREATER_EQUAL(10,10) == 1) +TEST(BOOST_PP_GREATER_EQUAL(8,1) == 1) + +TEST(BOOST_PP_LESS(2,1) == 0) +TEST(BOOST_PP_LESS(1,1) == 0) +TEST(BOOST_PP_LESS(1,2) == 1) + +TEST(BOOST_PP_GREATER(2,1) == 1) +TEST(BOOST_PP_GREATER(1,1) == 0) +TEST(BOOST_PP_GREATER(1,2) == 0) + +TEST(BOOST_PP_MIN(1,0) == 0) +TEST(BOOST_PP_MIN(1,2) == 1) + +TEST(BOOST_PP_MAX(3,2) == 3) +TEST(BOOST_PP_MAX(4,5) == 5) + +TEST(BOOST_PP_MOD(5,5) == 0) +TEST(BOOST_PP_MOD(9,5) == 4) +TEST(BOOST_PP_MOD(7,4) == 3) diff --git a/test/logical_test.cpp b/test/logical_test.cpp new file mode 100644 index 0000000..8fbe6da --- /dev/null +++ b/test/logical_test.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include + +#include + +// *** + +TEST(BOOST_PP_NOT(0) == 1) +TEST(BOOST_PP_NOT(1) == 0) + +TEST(BOOST_PP_AND(0,0) == 0) +TEST(BOOST_PP_AND(0,1) == 0) +TEST(BOOST_PP_AND(1,0) == 0) +TEST(BOOST_PP_AND(1,1) == 1) + +TEST(BOOST_PP_OR(0,0) == 0) +TEST(BOOST_PP_OR(0,1) == 1) +TEST(BOOST_PP_OR(1,0) == 1) +TEST(BOOST_PP_OR(1,1) == 1) + +TEST(BOOST_PP_XOR(0,0) == 0) +TEST(BOOST_PP_XOR(0,1) == 1) +TEST(BOOST_PP_XOR(1,0) == 1) +TEST(BOOST_PP_XOR(1,1) == 0) diff --git a/test/preprocessor_test.cpp b/test/preprocessor_test.cpp index 79d38e0..9395e62 100644 --- a/test/preprocessor_test.cpp +++ b/test/preprocessor_test.cpp @@ -9,165 +9,37 @@ // See http://www.boost.org for most recent version. -#include +#include +#include +#include +#include + +#include // *** struct Container { -#define BOOST_PREPROCESSOR_DEF(CV)\ +#define BOOST_PP_DEF(CV)\ CV int& operator[](int i) CV; - BOOST_PREPROCESSOR_DEF(BOOST_PREPROCESSOR_EMPTY()) - BOOST_PREPROCESSOR_DEF(const) - BOOST_PREPROCESSOR_DEF(volatile) - BOOST_PREPROCESSOR_DEF(const volatile) + BOOST_PP_DEF(BOOST_PP_EMPTY()) + BOOST_PP_DEF(const) + BOOST_PP_DEF(volatile) + BOOST_PP_DEF(const volatile) -#undef BOOST_PREPROCESSOR_DEF +#undef BOOST_PP_DEF }; // *** -int test_logic_1[0+(BOOST_PREPROCESSOR_NOT(0) == 1)]; -int test_logic_2[0+(BOOST_PREPROCESSOR_NOT(1) == 0)]; - -int test_logic_3[0+(BOOST_PREPROCESSOR_AND(0,0) == 0)]; -int test_logic_4[0+(BOOST_PREPROCESSOR_AND(0,1) == 0)]; -int test_logic_5[0+(BOOST_PREPROCESSOR_AND(1,0) == 0)]; -int test_logic_6[0+(BOOST_PREPROCESSOR_AND(1,1) == 1)]; - -int test_logic_7[0+(BOOST_PREPROCESSOR_OR(0,0) == 0)]; -int test_logic_8[0+(BOOST_PREPROCESSOR_OR(0,1) == 1)]; -int test_logic_9[0+(BOOST_PREPROCESSOR_OR(1,0) == 1)]; -int test_logic_a[0+(BOOST_PREPROCESSOR_OR(1,1) == 1)]; - -int test_logic_b[0+(BOOST_PREPROCESSOR_XOR(0,0) == 0)]; -int test_logic_c[0+(BOOST_PREPROCESSOR_XOR(0,1) == 1)]; -int test_logic_d[0+(BOOST_PREPROCESSOR_XOR(1,0) == 1)]; -int test_logic_e[0+(BOOST_PREPROCESSOR_XOR(1,1) == 0)]; +TEST(BOOST_PP_IF(BOOST_PP_IF(1,1,1),true,false) && + BOOST_PP_IF(BOOST_PP_IF(0,0,0),false,true)) // *** -int if_test[ - 0+(BOOST_PREPROCESSOR_IF(BOOST_PREPROCESSOR_INC(0),true,false) && - BOOST_PREPROCESSOR_IF(BOOST_PREPROCESSOR_DEC(1),false,true))]; +TEST(BOOST_PP_CAT(BOOST_PP_IF(1,tru,fals), e)) // *** -int cat_test[ - 0+(BOOST_PREPROCESSOR_CAT(BOOST_PREPROCESSOR_IF(1,tru,fals), e))]; - -// *** - -char stringize_test[4] = BOOST_PREPROCESSOR_STRINGIZE(__LINE__); - -// *** - -// RATIONALE: -// - All forms of ENUM_PARAMS must be tested with 0 and n, where n is -// sufficiently large to exceed imaginable usage like. 50 should be -// suffient in this case. - -#ifndef ENUM_PARAMS_TEST_MAX -#define ENUM_PARAMS_TEST_MAX 50 -#endif - -#define CONSTANT(I,A) const A##I = I; -BOOST_PREPROCESSOR_REPEAT(ENUM_PARAMS_TEST_MAX, CONSTANT, int default_param_) -#undef CONSTANT - -#define TEST_ENUM_PARAMS(N)\ - void BOOST_PREPROCESSOR_CAT(test_enum_params,N)(\ - BOOST_PREPROCESSOR_ENUM_PARAMS(N, double x));\ - void BOOST_PREPROCESSOR_CAT(test_enum_params_with_a_default,N)(\ - BOOST_PREPROCESSOR_ENUM_PARAMS_WITH_A_DEFAULT(N, double x, 0));\ - void BOOST_PREPROCESSOR_CAT(test_enum_params_with_defaults,N)(\ - BOOST_PREPROCESSOR_ENUM_PARAMS_WITH_DEFAULTS(N, double x, default_param_)); - -TEST_ENUM_PARAMS(0) -TEST_ENUM_PARAMS(ENUM_PARAMS_TEST_MAX) - -#undef TEST_ENUM_PARAMS - -// *** - -// RATIONALE: -// - BOOST_PREPROCESSOR_REPEAT, BOOST_PREPROCESSOR_REPEAT_2ND, ... must work -// together. -// - BOOST_PREPROCESSOR_REPEAT is already tested with -// BOOST_PREPROCESSOR_ENUM_PARAMS. -// - The tested repeat count should exceed imaginable usage. -// - Testing the generation of is_function_helper()s upto 40 arguments should -// be sufficient in this case. Many compilers may fail the repetition tests -// (at least with higher counts). However, the primary purpose of the -// repetition primitives is to enable configurability with reasonable -// defaults, and not necessarily "the most impressive repetition". -// - ENUM_SHIFTED_PARAMS must be tested so that the shifted range is shown to -// be correct. - -#ifndef IS_FUNCTION_HELPER_TEST_MAX -#define IS_FUNCTION_HELPER_TEST_MAX 40 -#endif - -typedef char yes_type; - -#define IS_FUNCTION_HELPER(I,A)\ - template\ - \ - yes_type is_function_helper(\ - P0 (*)(BOOST_PREPROCESSOR_ENUM_SHIFTED_PARAMS(BOOST_PREPROCESSOR_INC(I),P))); - -BOOST_PREPROCESSOR_REPEAT_2ND(BOOST_PREPROCESSOR_INC(IS_FUNCTION_HELPER_TEST_MAX),IS_FUNCTION_HELPER,A) - -#undef IS_FUNCTION_HELPER - -// *** - -int test_arithmetic_1[0+(BOOST_PREPROCESSOR_ADD(2,3)==5)]; -int test_arithmetic_2[0+(BOOST_PREPROCESSOR_ADD(11,BOOST_PREPROCESSOR_SUB(BOOST_PREPROCESSOR_LIMIT_MAG,10))==BOOST_PREPROCESSOR_LIMIT_MAG)]; - -int test_arithmetic_4[0+(BOOST_PREPROCESSOR_SUB(11,0)==11)]; -int test_arithmetic_5[0+(BOOST_PREPROCESSOR_SUB(12,1)==11)]; -int test_arithmetic_6[0+(BOOST_PREPROCESSOR_SUB(3,4)==0)]; - -int test_arithmetic_7[0+(BOOST_PREPROCESSOR_MUL(0,1)==0)]; -int test_arithmetic_8[0+(BOOST_PREPROCESSOR_MUL(1,0)==0)]; -int test_arithmetic_9[0+(BOOST_PREPROCESSOR_MUL(1,1)==1)]; -int test_arithmetic_10[0+(BOOST_PREPROCESSOR_MUL(4,3)==12)]; - -int test_arithmetic_11[0+(BOOST_PREPROCESSOR_DIV(2,1)==2)]; -int test_arithmetic_12[0+(BOOST_PREPROCESSOR_DIV(0,5)==0)]; -int test_arithmetic_13[0+(BOOST_PREPROCESSOR_DIV(7,3)==2)]; - -int test_arithmetic_15[0+(BOOST_PREPROCESSOR_EQUAL(1,0)==0)]; -int test_arithmetic_16[0+(BOOST_PREPROCESSOR_EQUAL(10,10)==1)]; -int test_arithmetic_17[0+(BOOST_PREPROCESSOR_NOT_EQUAL(3,4)==1)]; -int test_arithmetic_18[0+(BOOST_PREPROCESSOR_NOT_EQUAL(7,7)==0)]; -int test_arithmetic_19[0+(BOOST_PREPROCESSOR_LESS_EQUAL(6,7)==1)]; -int test_arithmetic_20[0+(BOOST_PREPROCESSOR_LESS_EQUAL(8,1)==0)]; -int test_arithmetic_21[0+(BOOST_PREPROCESSOR_LESS_EQUAL(5,5)==1)]; -int test_arithmetic_22[0+(BOOST_PREPROCESSOR_GREATER_EQUAL(6,7)==0)]; -int test_arithmetic_23[0+(BOOST_PREPROCESSOR_GREATER_EQUAL(10,10)==1)]; -int test_arithmetic_24[0+(BOOST_PREPROCESSOR_GREATER_EQUAL(8,1)==1)]; -int test_arithmetic_25[0+(BOOST_PREPROCESSOR_LESS(2,1)==0)]; -int test_arithmetic_26[0+(BOOST_PREPROCESSOR_LESS(1,1)==0)]; -int test_arithmetic_27[0+(BOOST_PREPROCESSOR_LESS(1,2)==1)]; -int test_arithmetic_28[0+(BOOST_PREPROCESSOR_GREATER(2,1)==1)]; -int test_arithmetic_29[0+(BOOST_PREPROCESSOR_GREATER(1,1)==0)]; -int test_arithmetic_30[0+(BOOST_PREPROCESSOR_GREATER(1,2)==0)]; - -int test_arithmetic_31[0+(BOOST_PREPROCESSOR_MIN(1,0)==0)]; -int test_arithmetic_32[0+(BOOST_PREPROCESSOR_MIN(1,2)==1)]; -int test_arithmetic_33[0+(BOOST_PREPROCESSOR_MAX(3,2)==3)]; -int test_arithmetic_34[0+(BOOST_PREPROCESSOR_MAX(4,5)==5)]; - -int test_arithmetic_35[0+(BOOST_PREPROCESSOR_MOD(5,5)==0)]; -int test_arithmetic_36[0+(BOOST_PREPROCESSOR_MOD(9,5)==4)]; -int test_arithmetic_37[0+(BOOST_PREPROCESSOR_MOD(7,4)==3)]; - -// *** - -int - main() -{ return 0; -} +char stringize_test[4] = BOOST_PP_STRINGIZE(__LINE__); diff --git a/test/repeat_2nd_test.cpp b/test/repeat_2nd_test.cpp new file mode 100644 index 0000000..fe5b9af --- /dev/null +++ b/test/repeat_2nd_test.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include +#include +#include +#include + +// *** + +// RATIONALE: +// - BOOST_PP_REPEAT, BOOST_PP_REPEAT_2ND, ... must work +// together. +// - BOOST_PP_REPEAT is already tested with +// BOOST_PP_ENUM_PARAMS. +// - The tested repeat count should exceed imaginable usage. +// - Testing the generation of is_function_helper()s upto 40 arguments should +// be sufficient in this case. Many compilers may fail the repetition tests +// (at least with higher counts). However, the primary purpose of the +// repetition primitives is to enable configurability with reasonable +// defaults, and not necessarily "the most impressive repetition". +// - ENUM_SHIFTED_PARAMS must be tested so that the shifted range is shown to +// be correct. + +#ifndef IS_FUNCTION_HELPER_TEST_MAX +#define IS_FUNCTION_HELPER_TEST_MAX 40 +#endif + +typedef char yes_type; + +#define IS_FUNCTION_HELPER(I,A)\ + template\ + \ + yes_type is_function_helper(\ + P0 (*)(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_INC(I),P))); + +BOOST_PP_REPEAT_2ND(BOOST_PP_INC(IS_FUNCTION_HELPER_TEST_MAX),IS_FUNCTION_HELPER,A) + +#undef IS_FUNCTION_HELPER diff --git a/test/repeat_test.cpp b/test/repeat_test.cpp new file mode 100644 index 0000000..08c7db4 --- /dev/null +++ b/test/repeat_test.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include +#include +#include +#include + +// *** + +// RATIONALE: +// - All forms of ENUM_PARAMS must be tested with 0 and n, where n is +// sufficiently large to exceed imaginable usage like. 50 should be +// suffient in this case. + +#ifndef ENUM_PARAMS_TEST_MAX +#define ENUM_PARAMS_TEST_MAX 50 +#endif + +#define CONSTANT(I,A) const A##I = I; +BOOST_PP_REPEAT(ENUM_PARAMS_TEST_MAX, CONSTANT, int default_param_) +#undef CONSTANT + +#define TEST_ENUM_PARAMS(N)\ + void BOOST_PP_CAT(test_enum_params,N)(\ + BOOST_PP_ENUM_PARAMS(N, double x));\ + void BOOST_PP_CAT(test_enum_params_with_a_default,N)(\ + BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(N, double x, 0));\ + void BOOST_PP_CAT(test_enum_params_with_defaults,N)(\ + BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(N, double x, default_param_)); + +TEST_ENUM_PARAMS(0) +TEST_ENUM_PARAMS(ENUM_PARAMS_TEST_MAX) + +#undef TEST_ENUM_PARAMS diff --git a/test/test.hpp b/test/test.hpp new file mode 100644 index 0000000..2694b5b --- /dev/null +++ b/test/test.hpp @@ -0,0 +1,18 @@ +#ifndef BOOST_LIBS_PREPROCESSOR_TEST_TEST_HPP +#define BOOST_LIBS_PREPROCESSOR_TEST_TEST_HPP + +// Copyright (C) 2001 +// Housemarque Oy +// http://www.housemarque.com +// +// Permission to copy, use, modify, sell and distribute this software is +// granted provided this copyright notice appears in all copies. This +// software is provided "as is" without express or implied warranty, and +// with no claim as to its suitability for any purpose. + +// See http://www.boost.org for most recent version. + +#include + +#define TEST(C) typedef BOOST_PP_CAT(test_,__LINE__)[((C)==1) ? 1 : -1]; +#endif