|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85238 - trunk/libs/any
From: antoshkka_at_[hidden]
Date: 2013-08-07 10:03:28
Author: apolukhin
Date: 2013-08-07 10:03:27 EDT (Wed, 07 Aug 2013)
New Revision: 85238
URL: http://svn.boost.org/trac/boost/changeset/85238
Log:
Add tests for any.clear() and workaround Intel issue in tests (refs #6999)
Text files modified:
trunk/libs/any/any_test.cpp | 42 ++++++++++++++++++++++++++++++---------
1 files changed, 32 insertions(+), 10 deletions(-)
Modified: trunk/libs/any/any_test.cpp
==============================================================================
--- trunk/libs/any/any_test.cpp Wed Aug 7 08:52:10 2013 (r85237)
+++ trunk/libs/any/any_test.cpp 2013-08-07 10:03:27 EDT (Wed, 07 Aug 2013) (r85238)
@@ -1,6 +1,6 @@
// what: unit tests for variant type boost::any
// who: contributed by Kevlin Henney
-// when: July 2001
+// when: July 2001, 2013
// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95
#include <cstdlib>
@@ -38,6 +38,7 @@
void test_cast_to_reference();
void test_with_array();
void test_with_func();
+ void test_clear();
const test_case test_cases[] =
{
@@ -51,7 +52,8 @@
{ "copying operations on a null", test_null_copying },
{ "cast to reference types", test_cast_to_reference },
{ "storing an array inside", test_with_array },
- { "implicit cast of returned value",test_with_func }
+ { "implicit cast of returned value",test_with_func },
+ { "clear() methods", test_clear }
};
const test_case_iterator begin = test_cases;
@@ -286,26 +288,46 @@
std::string s;
s = any_cast<std::string>(returning_string1());
s = any_cast<const std::string&>(returning_string1());
- //s = any_cast<std::string&>(returning_string1());
s = any_cast<std::string>(returning_string2());
s = any_cast<const std::string&>(returning_string2());
- //s = any_cast<std::string&>(returning_string2());
-#if !defined(_MSC_VER) || _MSC_VER != 1600
-#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- //s = static_cast<std::string&&>(any_cast<std::string&>(returning_string1()));
+#if (!defined(_MSC_VER) || _MSC_VER != 1600) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+#if !defined(__INTEL_COMPILER) && !defined(__ICL)
+ // Intel compiler thinks that it must choose the `any_cast(const any&)` function
+ // instead of the `any_cast(const any&&)`.
+ // Bug was not reported because of missing premier support account + annoying
+ // registrations requirements.
s = any_cast<std::string&&>(returning_string1());
-
- //s = static_cast<std::string&&>(any_cast<std::string&>(returning_string2()));
- s = any_cast<std::string&&>(returning_string2());
#endif
+ s = any_cast<std::string&&>(returning_string2());
#endif
}
+
+ void test_clear()
+ {
+ std::string text = "test message";
+ any value = text;
+
+ check_false(value.empty(), "empty");
+
+ value.clear();
+ check_true(value.empty(), "non-empty after clear");
+
+ value.clear();
+ check_true(value.empty(), "non-empty after second clear");
+
+ value = text;
+ check_false(value.empty(), "empty");
+
+ value.clear();
+ check_true(value.empty(), "non-empty after clear");
+ }
}
// Copyright Kevlin Henney, 2000, 2001. All rights reserved.
+// Copyright Antony Polukhin, 2013.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk