From 9f1c19dc3d62fb2147ae3aaeab85d9252ceee324 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Fri, 22 Apr 2005 06:37:25 +0000 Subject: [PATCH] Split test for any-to-reference cast into a separate file. In fails on vc6 for unknown reason, and I don't want to investigate this. [SVN r28401] --- any_test.cpp | 57 +--------------------------------------- test/Jamfile | 23 ++++++++++++++++ test/any_to_ref_test.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 56 deletions(-) create mode 100644 test/Jamfile create mode 100644 test/any_to_ref_test.cpp diff --git a/any_test.cpp b/any_test.cpp index 380378c..45ee080 100644 --- a/any_test.cpp +++ b/any_test.cpp @@ -46,8 +46,7 @@ namespace any_tests // test suite { "converting assignment operator", test_converting_assign }, { "failed custom keyword cast", test_bad_cast }, { "swap member function", test_swap }, - { "copying operations on a null", test_null_copying }, - { "casting to reference", test_cast_to_reference } + { "copying operations on a null", test_null_copying } }; const test_case_iterator begin = test_cases; @@ -187,60 +186,6 @@ namespace any_tests // test definitions check_true(copied.empty(), "empty on copied"); check_true(assigned.empty(), "empty on copied"); } - - void test_cast_to_reference() - { - int i = 7; - any a(i), b(a); - int v = any_cast(a); - //VP, 2005/03/17: commented out while I try to figure out why - // vc6 crashes on this code. -#if 0 - const any c(i); - - int& ra1 = any_cast(a); - int const& ra2 = any_cast(a); - int const volatile& ra3 = any_cast(a); - - check_true( - &ra1 == &ra2 && &ra2 == &ra3, - "references refer to a same object"); - - int& rb1 = any_cast(b); - int const& rb2 = any_cast(b); - int const volatile& rb3 = any_cast(b); - - check_true( - &rb1 == &rb2 && &rb2 == &rb3, - "references refer to a same object"); - - int const& rc1 = any_cast(c); - int const volatile& rc2 = any_cast(c); - - check_true(&rc1 == &rc2, "references refer to a same object"); - - check_true( - &ra1 != &rb1 && &rb1 != &rc1 && &rc1 != &ra1, - "references refer to different objects"); - - check_true( - &ra1 != &i && &rb1 != &i && &rc1 != &i, - "references don't refer to original"); - - ++ra1; - - check_true((v == i + 1), "modified through reference"); - - --rb1; - int v2 = any_cast(b); - check_true((v2 == i - 1), "modified through reference"); - - TEST_CHECK_THROW( - any_cast(a), - bad_any_cast, - "any_cast to incorrect reference type"); -#endif - } } // Copyright Kevlin Henney, 2000, 2001. All rights reserved. diff --git a/test/Jamfile b/test/Jamfile new file mode 100644 index 0000000..1c81169 --- /dev/null +++ b/test/Jamfile @@ -0,0 +1,23 @@ +# Copyright Vladimur Prus 2005. Use, modification and +# distribution is subject to 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) +# +# For more information, see http://www.boost.org/libs/any +# + +subproject libs/any/test ; + +import testing ; + +rule any-test ( sources + ) +{ + return [ run $(sources) : : : $(BOOST_ROOT) ] ; +} + +test-suite any : + [ any-test ../any_test.cpp ] + [ any-test any_to_ref_test.cpp ../../test/build/boost_test_exec_monitor ] + ; + + diff --git a/test/any_to_ref_test.cpp b/test/any_to_ref_test.cpp new file mode 100644 index 0000000..440c768 --- /dev/null +++ b/test/any_to_ref_test.cpp @@ -0,0 +1,57 @@ +// Copyright 2005 Alexander Nasonov. +// +// 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) + +#include +#include + +using namespace boost; + +void test_cast_to_reference() +{ + int i = 7; + any a(i), b(a); + const any c(i); + + int& ra1 = any_cast(a); + int const& ra2 = any_cast(a); + int const volatile& ra3 = any_cast(a); + + BOOST_CHECK(&ra1 == &ra2 && &ra2 == &ra3); + + int& rb1 = any_cast(b); + int const& rb2 = any_cast(b); + int const volatile& rb3 = any_cast(b); + + BOOST_CHECK(&rb1 == &rb2 && &rb2 == &rb3); + + int const& rc1 = any_cast(c); + int const volatile& rc2 = any_cast(c); + + BOOST_CHECK(&rc1 == &rc2); + + BOOST_CHECK(&ra1 != &rb1 && &rb1 != &rc1 && &rc1 != &ra1); + + BOOST_CHECK(&ra1 != &i && &rb1 != &i && &rc1 != &i); + + ++ra1; + int v = any_cast(a); + BOOST_CHECK(v == i + 1); + + --rb1; + int v2 = any_cast(b); + BOOST_CHECK(v2 == i - 1); + + BOOST_CHECK_THROW( + any_cast(a), + bad_any_cast); +} + +int test_main(int, char**) +{ + test_cast_to_reference(); + return 0; +} +