Skip to content

Commit

Permalink
removed test.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Jan 7, 2024
1 parent 1ce3b4d commit da5b664
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 449 deletions.
5 changes: 1 addition & 4 deletions test/any_test_cv_to_rv_failed.cpp
Expand Up @@ -13,13 +13,10 @@
#include <utility>

#include <boost/any.hpp>
#include "test.hpp"

int main()
{
int main() {
boost::any const cvalue(10);
int i = boost::any_cast<int&&>(cvalue);
(void)i;
return EXIT_SUCCESS;
}

5 changes: 1 addition & 4 deletions test/any_test_temporary_to_ref_failed.cpp
Expand Up @@ -13,13 +13,10 @@
#include <utility>

#include <boost/any.hpp>
#include "test.hpp"


int main()
{
int main() {
int i = boost::any_cast<int&>(10);
(void)i;
return EXIT_SUCCESS;
}

5 changes: 1 addition & 4 deletions test/basic_any_test_cv_to_rv_failed.cpp
Expand Up @@ -14,14 +14,11 @@
#include <utility>

#include <boost/any/basic_any.hpp>
#include "test.hpp"


int main()
{
int main() {
boost::anys::basic_any<> const cvalue(10);
int i = boost::any_cast<int&&>(cvalue);
(void)i;
return EXIT_SUCCESS;
}

5 changes: 1 addition & 4 deletions test/basic_any_test_temporary_to_ref_failed.cpp
Expand Up @@ -14,12 +14,9 @@
#include <utility>

#include <boost/any/basic_any.hpp>
#include "test.hpp"

int main()
{
int main() {
int i = boost::any_cast<int&>(boost::anys::basic_any<>(10));
(void)i;
return EXIT_SUCCESS;
}

4 changes: 2 additions & 2 deletions test/basic_test.hpp
Expand Up @@ -18,9 +18,9 @@
#include <string>
#include <vector>
#include <utility>
#include <type_traits>

#include <boost/core/lightweight_test.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>

namespace any_tests {

Expand Down Expand Up @@ -225,7 +225,7 @@ struct basic_tests // test definitions
static void test_bad_any_cast()
{
BOOST_TEST((
boost::is_base_and_derived<std::exception, boost::bad_any_cast>::value
std::is_base_of<std::exception, boost::bad_any_cast>::value
));

BOOST_TEST(
Expand Down
173 changes: 63 additions & 110 deletions test/move_test.hpp
Expand Up @@ -14,7 +14,7 @@
#include <string>
#include <utility>

#include "test.hpp"
#include <boost/core/lightweight_test.hpp>
#include <boost/type_index.hpp>

namespace any_tests {
Expand All @@ -29,16 +29,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
Any value(std::move(value0));

check(value0.empty(), "moved away value is empty");
check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
check_equal(
move_copy_conting_class::copy_count, 0u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST(value0.empty());
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 0u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static void test_move_assignment()
Expand All @@ -49,16 +45,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
value = std::move(value0);

check(value0.empty(), "moved away is empty");
check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
check_equal(
move_copy_conting_class::copy_count, 0u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST(value0.empty());
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 0u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static void test_copy_construction()
Expand All @@ -68,16 +60,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
Any value(value0);

check_false(value0.empty(), "copied value is not empty");
check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
check_equal(
move_copy_conting_class::copy_count, 1u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST(!value0.empty());
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 1u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static void test_copy_assignment()
Expand All @@ -88,16 +76,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
value = value0;

check_false(value0.empty(), "copied value is not empty");
check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
check_equal(
move_copy_conting_class::copy_count, 1u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST(!value0.empty());
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 1u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static void test_move_construction_from_value()
Expand All @@ -108,16 +92,12 @@ struct move_tests // test definitions

Any value(std::move(value0));

check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));

check_equal(
move_copy_conting_class::copy_count, 0u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 1u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 0u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 1u);
}

static void test_move_assignment_from_value()
Expand All @@ -128,16 +108,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
value = std::move(value0);

check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));

check_equal(
move_copy_conting_class::copy_count, 0u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 1u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 0u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 1u);
}

static void test_copy_construction_from_value()
Expand All @@ -147,16 +123,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
Any value(value0);

check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));

check_equal(
move_copy_conting_class::copy_count, 1u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 1u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static void test_copy_assignment_from_value()
Expand All @@ -167,16 +139,12 @@ struct move_tests // test definitions
move_copy_conting_class::moves_count = 0;
value = value0;

check_false(value.empty(), "empty");
check_equal(value.type(), boost::typeindex::type_id<move_copy_conting_class>(), "type");
check_non_null(boost::any_cast<move_copy_conting_class>(&value), "any_cast<move_copy_conting_class>");
BOOST_TEST(!value.empty());
BOOST_TEST(value.type() == boost::typeindex::type_id<move_copy_conting_class>());
BOOST_TEST(boost::any_cast<move_copy_conting_class>(&value));

check_equal(
move_copy_conting_class::copy_count, 1u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 1u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
}

static const Any helper_method() {
Expand All @@ -203,28 +171,19 @@ struct move_tests // test definitions

move_copy_conting_class value1 = boost::any_cast<move_copy_conting_class&&>(value);

check_equal(
move_copy_conting_class::copy_count, 0u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 1u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 0u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 1u);
(void)value1;
// Following code shall fail to compile

const Any cvalue = value0;
move_copy_conting_class::copy_count = 0;
move_copy_conting_class::moves_count = 0;

move_copy_conting_class value2 = boost::any_cast<const move_copy_conting_class&>(cvalue);

check_equal(
move_copy_conting_class::copy_count, 1u,
"checking copy counts");
check_equal(
move_copy_conting_class::moves_count, 0u,
"checking move counts");
BOOST_TEST_EQ(move_copy_conting_class::copy_count, 1u);
BOOST_TEST_EQ(move_copy_conting_class::moves_count, 0u);
(void)value2;
//
}

class move_copy_conting_class {
Expand Down Expand Up @@ -252,25 +211,19 @@ struct move_tests // test definitions
};

static int run_tests() {
typedef test<const char *, void (*)()> test_case;
const test_case test_cases[] =
{
{ "move construction of any", test_move_construction },
{ "move assignment of any", test_move_assignment },
{ "copy construction of any", test_copy_construction },
{ "copy assignment of any", test_copy_assignment },

{ "move construction from value", test_move_construction_from_value },
{ "move assignment from value", test_move_assignment_from_value },
{ "copy construction from value", test_copy_construction_from_value },
{ "copy assignment from value", test_copy_assignment_from_value },
{ "constructing from const any&&", test_construction_from_const_any_rv },
{ "casting to rvalue reference", test_cast_to_rv }
};
typedef const test_case * test_case_iterator;

tester<test_case_iterator> test_suite(test_cases, test_cases + sizeof(test_cases) / sizeof(test_cases[0]));
return test_suite() ? EXIT_SUCCESS : EXIT_FAILURE;
test_move_construction();
test_move_assignment();
test_copy_construction();
test_copy_assignment();

test_move_construction_from_value();
test_move_assignment_from_value();
test_copy_construction_from_value();
test_copy_assignment_from_value();
test_construction_from_const_any_rv();
test_cast_to_rv();

return boost::report_errors();
}
}; // struct move_tests

Expand Down

0 comments on commit da5b664

Please sign in to comment.