2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-14 12:52:17 +00:00

Field view

This commit is contained in:
Ruben Perez
2022-08-08 17:04:50 +02:00
parent 780b0d19e4
commit 50cd20bb7d
73 changed files with 1087 additions and 1219 deletions

View File

@@ -5,18 +5,18 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mysql/value.hpp>
#include <boost/mysql/field_view.hpp>
#include "test_common.hpp"
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_suite.hpp>
#include <cstdint>
using boost::mysql::value;
using boost::mysql::field_view;
using boost::mysql::null_t;
using boost::mysql::datetime;
using boost::mysql::date;
using boost::mysql::days;
using vt = boost::mysql::value::variant_type;
using vt = boost::mysql::field_view::variant_type;
#ifndef BOOST_NO_CXX14_CONSTEXPR
@@ -26,16 +26,16 @@ BOOST_AUTO_TEST_SUITE(test_value_constexpr)
BOOST_AUTO_TEST_CASE(null_type)
{
constexpr value v {};
constexpr value v2 (nullptr);
constexpr field_view v {};
constexpr field_view v2 (nullptr);
static_assert(v.is_null(), "");
static_assert(v.is<null_t>(), "");
static_assert(v.is_convertible_to<null_t>(), "");
static_assert(v.to_variant() == vt(null_t()), "");
static_assert(v == v2, "");
static_assert(v != value(10), "");
static_assert(v < value(10), "");
static_assert(v <= value(10), "");
static_assert(v != field_view(10), "");
static_assert(v < field_view(10), "");
static_assert(v <= field_view(10), "");
static_assert(v >= v2, "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
@@ -47,8 +47,8 @@ BOOST_AUTO_TEST_CASE(null_type)
BOOST_AUTO_TEST_CASE(int64_t_type)
{
constexpr value v (std::int64_t(60));
constexpr value v2 (-4); // from other int type
constexpr field_view v (std::int64_t(60));
constexpr field_view v2 (-4); // from other int type
static_assert(!v.is_null(), "");
static_assert(v.is<std::int64_t>(), "");
static_assert(v.is_convertible_to<std::int64_t>(), "");
@@ -56,10 +56,10 @@ BOOST_AUTO_TEST_CASE(int64_t_type)
static_assert(v.to_variant() == vt(std::int64_t(60)), "");
static_assert(v == v, "");
static_assert(v != v2, "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<std::int64_t>(), "");
@@ -68,18 +68,18 @@ BOOST_AUTO_TEST_CASE(int64_t_type)
BOOST_AUTO_TEST_CASE(uint64_t_type)
{
constexpr value v (std::uint64_t(60));
constexpr field_view v (std::uint64_t(60));
static_assert(!v.is_null(), "");
static_assert(v.is<std::uint64_t>(), "");
static_assert(v.is_convertible_to<std::int64_t>(), "");
static_assert(v.is_convertible_to<std::uint64_t>(), "");
static_assert(v.to_variant() == vt(std::uint64_t(60)), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<std::uint64_t>(), "");
@@ -88,16 +88,16 @@ BOOST_AUTO_TEST_CASE(uint64_t_type)
BOOST_AUTO_TEST_CASE(string_view_type)
{
constexpr value v (boost::string_view("test", 4));
constexpr field_view v (boost::string_view("test", 4));
static_assert(!v.is_null(), "");
static_assert(v.is<boost::string_view>(), "");
static_assert(v.is_convertible_to<boost::string_view>(), "");
// Equality is not constexpr for strings
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<boost::string_view>(), "");
@@ -106,18 +106,18 @@ BOOST_AUTO_TEST_CASE(string_view_type)
BOOST_AUTO_TEST_CASE(float_type)
{
constexpr value v (3.14f);
constexpr field_view v (3.14f);
static_assert(!v.is_null(), "");
static_assert(v.is<float>(), "");
static_assert(v.is_convertible_to<float>(), "");
static_assert(v.is_convertible_to<double>(), "");
static_assert(v.to_variant() == vt(3.14f), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<float>(), "");
@@ -126,17 +126,17 @@ BOOST_AUTO_TEST_CASE(float_type)
BOOST_AUTO_TEST_CASE(double_type)
{
constexpr value v (3.14);
constexpr field_view v (3.14);
static_assert(!v.is_null(), "");
static_assert(v.is<double>(), "");
static_assert(v.is_convertible_to<double>(), "");
static_assert(v.to_variant() == vt(3.14), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<double>(), "");
@@ -146,17 +146,17 @@ BOOST_AUTO_TEST_CASE(double_type)
BOOST_AUTO_TEST_CASE(date_type)
{
constexpr date d (days(1));
constexpr value v (d);
constexpr field_view v (d);
static_assert(!v.is_null(), "");
static_assert(v.is<date>(), "");
static_assert(v.is_convertible_to<date>(), "");
static_assert(v.to_variant() == vt(d), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<date>(), "");
@@ -166,17 +166,17 @@ BOOST_AUTO_TEST_CASE(date_type)
BOOST_AUTO_TEST_CASE(datetime_type)
{
constexpr datetime d (days(1));
constexpr value v (d);
constexpr field_view v (d);
static_assert(!v.is_null(), "");
static_assert(v.is<datetime>(), "");
static_assert(v.is_convertible_to<datetime>(), "");
static_assert(v.to_variant() == vt(d), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<datetime>(), "");
@@ -186,17 +186,17 @@ BOOST_AUTO_TEST_CASE(datetime_type)
BOOST_AUTO_TEST_CASE(time_type)
{
constexpr boost::mysql::time t (1);
constexpr value v (t);
constexpr field_view v (t);
static_assert(!v.is_null(), "");
static_assert(v.is<boost::mysql::time>(), "");
static_assert(v.is_convertible_to<boost::mysql::time>(), "");
static_assert(v.to_variant() == vt(t), "");
static_assert(v == v, "");
static_assert(v != value(std::int64_t(0)), "");
static_assert(v < value(boost::mysql::time(9999)), "");
static_assert(v <= value(boost::mysql::time(9999)), "");
static_assert(v > value(std::int64_t(0)), "");
static_assert(v >= value(std::int64_t(0)), "");
static_assert(v != field_view(std::int64_t(0)), "");
static_assert(v < field_view(boost::mysql::time(9999)), "");
static_assert(v <= field_view(boost::mysql::time(9999)), "");
static_assert(v > field_view(std::int64_t(0)), "");
static_assert(v >= field_view(std::int64_t(0)), "");
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
static_assert(v.get_std_optional<boost::mysql::time>(), "");