1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#define BOOST_TEST_MODULE BitSet
#include <boost/test/unit_test.hpp>
#include <cstddef>
#include <cstdint>
#include <dbTypes.h>
#include <helpers.h>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <variant>
namespace MyGrate {
class BitSet;
}
namespace boost::numeric {
class bad_numeric_cast;
}
struct timespec;
BOOST_AUTO_TEST_CASE(verify)
{
BOOST_CHECK_NO_THROW(MyGrate::verify<std::runtime_error>(true, "no throw"));
BOOST_CHECK_THROW(MyGrate::verify<std::runtime_error>(false, "throw re"), std::runtime_error);
BOOST_CHECK_THROW(MyGrate::verify<std::logic_error>(false, "throw le"), std::logic_error);
}
using Ints = std::tuple<int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t>;
using Floats = std::tuple<float, double>;
using Times = std::tuple<timespec, MyGrate::Date, MyGrate::Time, MyGrate::DateTime>;
using Str = std::tuple<std::string_view>;
using Others = std::tuple<std::nullptr_t, MyGrate::BitSet, MyGrate::Blob>;
using TinyInts = std::tuple<int8_t, uint8_t>;
using SmallInts = std::tuple<int8_t, uint8_t, int16_t, uint16_t>;
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToInts, I, Ints)
{
MyGrate::DbValue v {123};
I out {v};
BOOST_CHECK_EQUAL(123, out);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToTinyInts, I, TinyInts)
{
MyGrate::DbValue v {1234};
BOOST_CHECK_THROW([[maybe_unused]] I out {v}, boost::bad_numeric_cast);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToSmallInts, I, SmallInts)
{
MyGrate::DbValue v {123400};
BOOST_CHECK_THROW([[maybe_unused]] I out {v}, boost::bad_numeric_cast);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToFloats, F, Floats)
{
MyGrate::DbValue v {123400};
BOOST_CHECK_THROW([[maybe_unused]] F out {v}, std::logic_error);
}
BOOST_AUTO_TEST_CASE(DbValueConvIntToStringView)
{
MyGrate::DbValue v {123};
BOOST_CHECK_THROW([[maybe_unused]] std::string_view out {v}, std::bad_variant_access);
}
BOOST_AUTO_TEST_CASE(DbValueConvStrViewToStringView)
{
using namespace std::literals;
MyGrate::DbValue v {"str"};
BOOST_CHECK_EQUAL((std::string_view)v, "str"sv);
BOOST_CHECK_EQUAL((std::string)v, "str"s);
}
static_assert(MyGrate::detail::HasToString<int>);
static_assert(!MyGrate::detail::HasToString<MyGrate::Date>);
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToString, I, Ints)
{
using namespace std::literals;
MyGrate::DbValue v {I {123}};
BOOST_CHECK_EQUAL((std::string)v, "123"s);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvFloatToString, F, Floats)
{
using namespace std::literals;
MyGrate::DbValue v {F {123}};
BOOST_CHECK_EQUAL((std::string)v, "123.000000"s);
}
|