2
0
mirror of https://github.com/boostorg/any.git synced 2026-02-01 08:02:07 +00:00

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]
This commit is contained in:
Vladimir Prus
2005-04-22 06:37:25 +00:00
parent 1e578233c5
commit 9f1c19dc3d
3 changed files with 81 additions and 56 deletions

View File

@@ -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<int>(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<int& >(a);
int const& ra2 = any_cast<int const& >(a);
int const volatile& ra3 = any_cast<int const volatile&>(a);
check_true(
&ra1 == &ra2 && &ra2 == &ra3,
"references refer to a same object");
int& rb1 = any_cast<int& >(b);
int const& rb2 = any_cast<int const& >(b);
int const volatile& rb3 = any_cast<int const volatile&>(b);
check_true(
&rb1 == &rb2 && &rb2 == &rb3,
"references refer to a same object");
int const& rc1 = any_cast<int const& >(c);
int const volatile& rc2 = any_cast<int const volatile&>(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<int>(b);
check_true((v2 == i - 1), "modified through reference");
TEST_CHECK_THROW(
any_cast<char&>(a),
bad_any_cast,
"any_cast to incorrect reference type");
#endif
}
}
// Copyright Kevlin Henney, 2000, 2001. All rights reserved.

23
test/Jamfile Normal file
View File

@@ -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) : : : <include>$(BOOST_ROOT) ] ;
}
test-suite any :
[ any-test ../any_test.cpp ]
[ any-test any_to_ref_test.cpp <lib>../../test/build/boost_test_exec_monitor ]
;

57
test/any_to_ref_test.cpp Normal file
View File

@@ -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 <boost/any.hpp>
#include <boost/test/test_tools.hpp>
using namespace boost;
void test_cast_to_reference()
{
int i = 7;
any a(i), b(a);
const any c(i);
int& ra1 = any_cast<int& >(a);
int const& ra2 = any_cast<int const& >(a);
int const volatile& ra3 = any_cast<int const volatile&>(a);
BOOST_CHECK(&ra1 == &ra2 && &ra2 == &ra3);
int& rb1 = any_cast<int& >(b);
int const& rb2 = any_cast<int const& >(b);
int const volatile& rb3 = any_cast<int const volatile&>(b);
BOOST_CHECK(&rb1 == &rb2 && &rb2 == &rb3);
int const& rc1 = any_cast<int const& >(c);
int const volatile& rc2 = any_cast<int const volatile&>(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<int>(a);
BOOST_CHECK(v == i + 1);
--rb1;
int v2 = any_cast<int>(b);
BOOST_CHECK(v2 == i - 1);
BOOST_CHECK_THROW(
any_cast<char&>(a),
bad_any_cast);
}
int test_main(int, char**)
{
test_cast_to_reference();
return 0;
}