#include using namespace chaiscript; template void use(T){} template bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass) { try { To ret = chaiscript::boxed_cast(bv); use(ret); } catch (const chaiscript::bad_boxed_cast &/*e*/) { if (expectedpass) { // std::cerr << "Failure in run_test_type_conversion: " << e.what() << std::endl; return false; } else { return true; } } catch (const std::exception &e) { std::cerr << "Unexpected standard exception when attempting cast_conversion: " << e.what() << std::endl; return false; } catch (...) { std::cerr << "Unexpected unknown exception when attempting cast_conversion." << std::endl; return false; } if (expectedpass) { return true; } else { return false; } } template bool test_type_conversion(const Boxed_Value &bv, bool expectedpass) { bool ret = run_test_type_conversion(bv, expectedpass); if (!ret) { std::cerr << "Error with type conversion test. From: " << (bv.is_const()?(std::string("const ")):(std::string())) << bv.get_type_info().name() << " To: " << (boost::is_const::value?(std::string("const ")):(std::string())) << typeid(To).name() << " test was expected to " << ((expectedpass)?(std::string("succeed")):(std::string("fail"))) << " but did not" << std::endl; } return ret; } template bool do_test(const Boxed_Value &bv, bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool PODValue, bool ConstPODValue, bool ConstPODValueRef, bool TPtrConstRef, bool ConstTPtrConstRef) { bool passed = true; passed &= test_type_conversion(bv, T); passed &= test_type_conversion(bv, ConstT); passed &= test_type_conversion(bv, TRef); passed &= test_type_conversion(bv, ConstTRef); passed &= test_type_conversion(bv, TPtr); passed &= test_type_conversion(bv, ConstTPtr); passed &= test_type_conversion(bv, TPtrConst); passed &= test_type_conversion(bv, ConstTPtrConst); passed &= test_type_conversion >(bv, SharedPtrT); passed &= test_type_conversion >(bv, SharedConstPtrT); passed &= test_type_conversion &>(bv, false); passed &= test_type_conversion &>(bv, false); passed &= test_type_conversion >(bv, ConstSharedPtrT); passed &= test_type_conversion >(bv, ConstSharedConstPtrT); passed &= test_type_conversion &>(bv, ConstSharedPtrTRef); passed &= test_type_conversion &>(bv, ConstSharedPtrTConstRef); passed &= test_type_conversion >(bv, BoostRef); passed &= test_type_conversion >(bv, BoostConstRef); passed &= test_type_conversion &>(bv, false); passed &= test_type_conversion &>(bv, false); passed &= test_type_conversion >(bv, ConstBoostRef); passed &= test_type_conversion >(bv, ConstBoostConstRef); passed &= test_type_conversion &>(bv, ConstBoostRefRef); passed &= test_type_conversion &>(bv, ConstBoostConstRefRef); passed &= test_type_conversion(bv, PODValue); passed &= test_type_conversion(bv, ConstPODValue); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, ConstPODValueRef); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, false); passed &= test_type_conversion(bv, TPtrConstRef); passed &= test_type_conversion(bv, ConstTPtrConstRef); passed &= test_type_conversion(bv, true); passed &= test_type_conversion(bv, true); passed &= test_type_conversion(bv, true); return passed; } int main() { bool passed = true; /* bool T, bool ConstT, bool TRef, bool ConstTRef, bool TPtr, bool ConstTPtr, bool TPtrConst, bool ConstTPtrConst, bool SharedPtrT, bool SharedConstPtrT, bool ConstSharedPtrT, bool ConstSharedConstPtrT, bool ConstSharedPtrTRef, bool ConstSharedPtrTConstRef, bool BoostRef, bool BoostConstRef, bool ConstBoostRef, bool ConstBoostConstRef, bool ConstBoostRefRef, bool ConstBoostConstRefRef, bool PODValue, bool ConstPODValue, bool ConstPODValueRef */ int i = 5; passed &= do_test(var(i), true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true); passed &= do_test(const_var(i), true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, false, true); passed &= do_test(var(&i), true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true); passed &= do_test(const_var(&i), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, true, true, true, false, true); passed &= do_test(var(boost::ref(i)), true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true); passed &= do_test(var(boost::cref(i)), true, true, false, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, false, true, true, true, true, false, true); if (passed) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } }