mirror of
https://github.com/boostorg/core.git
synced 2025-05-09 23:03:54 +00:00
Update empty_value test cases
This commit is contained in:
parent
8ea2ac50fe
commit
266076f83b
@ -128,6 +128,7 @@ run exchange_move_test.cpp ;
|
||||
|
||||
run empty_value_test.cpp ;
|
||||
run empty_value_size_test.cpp ;
|
||||
run empty_value_final_test.cpp ;
|
||||
|
||||
run quick_exit_test.cpp ;
|
||||
run-fail quick_exit_fail.cpp ;
|
||||
|
62
test/empty_value_final_test.cpp
Normal file
62
test/empty_value_final_test.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/core/empty_value.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_FINAL)
|
||||
class type final {
|
||||
public:
|
||||
explicit type(int count)
|
||||
: value_(count) { }
|
||||
int value() const {
|
||||
return value_ + 1;
|
||||
}
|
||||
int value() {
|
||||
return value_ + 2;
|
||||
}
|
||||
private:
|
||||
int value_;
|
||||
};
|
||||
|
||||
struct empty final {
|
||||
int value() const {
|
||||
return 1;
|
||||
}
|
||||
int value() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
void test_type()
|
||||
{
|
||||
const boost::empty_value<type> v1(boost::empty_init_t(), 3);
|
||||
BOOST_TEST(v1.get().value() == 4);
|
||||
boost::empty_value<type> v2(boost::empty_init_t(), 3);
|
||||
BOOST_TEST(v2.get().value() == 5);
|
||||
}
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
const boost::empty_value<empty> v1 = boost::empty_init_t();
|
||||
BOOST_TEST(v1.get().value() == 1);
|
||||
boost::empty_value<empty> v2;
|
||||
BOOST_TEST(v2.get().value() == 2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_type();
|
||||
test_empty();
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -9,67 +9,63 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct empty {
|
||||
operator bool() const {
|
||||
return false;
|
||||
int value() const {
|
||||
return 1;
|
||||
}
|
||||
operator bool() {
|
||||
return true;
|
||||
int value() {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
|
||||
class type {
|
||||
public:
|
||||
type()
|
||||
: value_(false) { }
|
||||
explicit type(bool value)
|
||||
: value_(value) { }
|
||||
operator bool() const {
|
||||
return value_;
|
||||
explicit type(int count)
|
||||
: value_(count) { }
|
||||
int value() const {
|
||||
return value_ + 1;
|
||||
}
|
||||
int value() {
|
||||
return value_ + 2;
|
||||
}
|
||||
private:
|
||||
bool value_;
|
||||
int value_;
|
||||
};
|
||||
|
||||
void test_bool()
|
||||
void test_int()
|
||||
{
|
||||
const boost::empty_value<bool> v1(boost::empty_init_t(), true);
|
||||
BOOST_TEST(v1.get());
|
||||
boost::empty_value<bool> v2 = boost::empty_init_t();
|
||||
BOOST_TEST(!v2.get());
|
||||
const boost::empty_value<int> v1(boost::empty_init_t(), 7);
|
||||
BOOST_TEST(v1.get() == 7);
|
||||
boost::empty_value<int> v2 = boost::empty_init_t();
|
||||
BOOST_TEST(v2.get() == 0);
|
||||
v2 = v1;
|
||||
BOOST_TEST(v2.get());
|
||||
v2.get() = false;
|
||||
BOOST_TEST(!v2.get());
|
||||
BOOST_TEST(v2.get() == 7);
|
||||
v2.get() = 8;
|
||||
BOOST_TEST(v2.get() == 8);
|
||||
}
|
||||
|
||||
void test_empty()
|
||||
{
|
||||
empty e;
|
||||
const boost::empty_value<empty> v1(boost::empty_init_t(), e);
|
||||
BOOST_TEST(!v1.get());
|
||||
const boost::empty_value<empty> v1 = boost::empty_init_t();
|
||||
BOOST_TEST(v1.get().value() == 1);
|
||||
boost::empty_value<empty> v2;
|
||||
BOOST_TEST(v2.get());
|
||||
v2 = v1;
|
||||
BOOST_TEST(v2.get());
|
||||
v2.get() = empty();
|
||||
BOOST_TEST(v2.get());
|
||||
BOOST_TEST(v2.get().value() == 2);
|
||||
}
|
||||
|
||||
void test_type()
|
||||
{
|
||||
const boost::empty_value<type> v1(boost::empty_init_t(), true);
|
||||
BOOST_TEST(v1.get());
|
||||
boost::empty_value<type> v2;
|
||||
BOOST_TEST(!v2.get());
|
||||
const boost::empty_value<type> v1(boost::empty_init_t(), 2);
|
||||
BOOST_TEST(v1.get().value() == 3);
|
||||
boost::empty_value<type> v2(boost::empty_init_t(), 3);
|
||||
BOOST_TEST(v2.get().value() == 5);
|
||||
v2 = v1;
|
||||
BOOST_TEST(v2.get());
|
||||
v2.get() = type();
|
||||
BOOST_TEST(!v2.get());
|
||||
BOOST_TEST(v2.get().value() == 4);
|
||||
v2.get() = type(4);
|
||||
BOOST_TEST(v2.get().value() == 6);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_bool();
|
||||
test_int();
|
||||
test_empty();
|
||||
test_type();
|
||||
return boost::report_errors();
|
||||
|
Loading…
x
Reference in New Issue
Block a user