0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

Need tests for type_traits

This commit is contained in:
Roland Bock 2024-08-11 20:26:34 +02:00
parent a6843f4518
commit bd54159446
12 changed files with 216 additions and 31 deletions

View File

@ -48,7 +48,6 @@ namespace sqlpp
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
using _can_be_null = std::false_type;
using _is_aggregate_expression = std::true_type;
constexpr avg_t(Expr expr) : _expr(std::move(expr))
{
@ -64,7 +63,7 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct is_aggregate<avg_t<Flag, Expr>> : public std::true_type
struct contains_aggregate<avg_t<Flag, Expr>> : public std::true_type
{
};

View File

@ -48,7 +48,6 @@ namespace sqlpp
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
using _can_be_null = std::false_type;
using _is_aggregate_expression = std::true_type;
constexpr count_t(Expr expr) : _expr(std::move(expr))
{
@ -64,7 +63,7 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct is_aggregate<count_t<Flag, Expr>> : public std::true_type
struct contains_aggregate<count_t<Flag, Expr>> : public std::true_type
{
};

View File

@ -47,7 +47,6 @@ namespace sqlpp
{
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
constexpr max_t(Expr expr) : _expr(std::move(expr))
{
@ -63,7 +62,7 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct is_aggregate<max_t<Flag, Expr>> : public std::true_type
struct contains_aggregate<max_t<Flag, Expr>> : public std::true_type
{
};

View File

@ -47,7 +47,6 @@ namespace sqlpp
{
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
constexpr min_t(Expr expr) : _expr(std::move(expr))
{
@ -63,7 +62,7 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct is_aggregate<min_t<Flag, Expr>> : public std::true_type
struct contains_aggregate<min_t<Flag, Expr>> : public std::true_type
{
};

View File

@ -50,11 +50,6 @@ namespace sqlpp
Expr _expr;
};
template <typename Expr>
struct is_aggregate<over_t<Expr>> : public is_aggregate<Expr>
{
};
template<typename Expr>
struct name_tag_of<over_t<Expr>> : public name_tag_of<Expr> {};
@ -67,7 +62,7 @@ namespace sqlpp
struct value_type_of<over_t<Expr>>: public value_type_of<Expr> {};
template<typename Expr>
using check_over_args = ::sqlpp::enable_if_t<is_aggregate<Expr>::value>;
using check_over_args = ::sqlpp::enable_if_t<contains_aggregate<Expr>::value>;
template <typename Context, typename Expr>
auto to_sql_string(Context& context, const over_t<Expr>& t) -> std::string

View File

@ -47,7 +47,6 @@ namespace sqlpp
{
using _traits = make_traits<value_type_of_t<Expr>, tag::is_expression, tag::is_selectable>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
constexpr sum_t(Expr expr) : _expr(std::move(expr))
{
@ -63,7 +62,7 @@ namespace sqlpp
};
template <typename Flag, typename Expr>
struct is_aggregate<sum_t<Flag, Expr>> : public std::true_type
struct contains_aggregate<sum_t<Flag, Expr>> : public std::true_type
{
};

View File

@ -43,6 +43,8 @@
#include <sqlpp11/core/detail/type_vector.h>
#include <sqlpp11/core/detail/type_set.h>
#include <sqlpp11/core/detail/get_first.h>
#include <sqlpp11/core/type_traits/aggregates.h>
#include <sqlpp11/core/type_traits/nodes_of.h>
namespace sqlpp
{
@ -126,7 +128,6 @@ namespace sqlpp
template <typename T>
using value_type_of_t = typename value_type_of<T>::type;
#warning: Add partial specialization to handle const?
template<typename T>
struct value_type_of<::sqlpp::optional<T>>
{
@ -505,13 +506,6 @@ namespace sqlpp
using is_database =
typename std::conditional<std::is_same<Database, void>::value, std::false_type, std::true_type>::type;
template <typename T>
struct nodes_of {
using type = detail::type_vector<>;
};
template <typename T>
using nodes_of_t = typename nodes_of<T>::type;
#define SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(trait) \
namespace detail \
{ \
@ -585,13 +579,6 @@ namespace sqlpp
;
};
template<typename T>
struct is_aggregate : public std::false_type{};
#warning: Need to make this recursive! and then add tests!
template<typename T>
struct contains_aggregate : public std::false_type{};
namespace detail
{
template <typename KnownAggregates, typename T, typename Leaf = void>

View File

@ -0,0 +1,47 @@
#pragma once
/*
* Copyright (c) 2024, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sqlpp11/core/detail/type_vector.h>
#include <sqlpp11/core/type_traits/nodes_of.h>
#include <sqlpp11/core/logic.h>
namespace sqlpp
{
template <typename T>
struct contains_aggregate : public std::integral_constant<bool, contains_aggregate<nodes_of_t<T>>::value>
{
};
template <typename... T>
struct contains_aggregate<detail::type_vector<T...>>
: public std::integral_constant<bool, logic::any_t<contains_aggregate<T>::value...>::value>
{
};
} // namespace sqlpp11

View File

@ -0,0 +1,43 @@
#pragma once
/*
* Copyright (c) 2024, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sqlpp11/core/detail/type_vector.h>
namespace sqlpp
{
template <typename T>
struct nodes_of
{
using type = detail::type_vector<>;
};
template <typename T>
using nodes_of_t = typename nodes_of<T>::type;
} // namespace sqlpp11

View File

@ -37,3 +37,4 @@ test_compile(value)
add_subdirectory(aggregate_function)
add_subdirectory(operator)
add_subdirectory(type_traits)

View File

@ -0,0 +1,32 @@
# Copyright (c) 2024, Roland Bock
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function(test_compile name)
set(target sqlpp11_core_types_operator_${name})
add_executable(${target} ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
endfunction()
test_compile(aggregates)

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2024, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "MockDb.h"
#include "Sample.h"
#include <sqlpp11/sqlpp11.h>
namespace
{
auto db = MockDb{};
template <typename T, typename V>
using is_same_type = std::is_same<sqlpp::value_type_of_t<T>, V>;
}
template <typename Value>
void test_aggregates(Value v)
{
auto v_not_null = sqlpp::value(v);
auto v_maybe_null = sqlpp::value(::sqlpp::make_optional(v));
using OptFloat = sqlpp::value_type_of_t<::sqlpp::optional<float>>;
#warning: Need to test contains_aggregate
}
int main()
{
// boolean
test_avg(bool{true});
// integral
test_avg(int8_t{7});
test_avg(int16_t{7});
test_avg(int32_t{7});
test_avg(int64_t{7});
// unsigned integral
test_avg(uint8_t{7});
test_avg(uint16_t{7});
test_avg(uint32_t{7});
test_avg(uint64_t{7});
// floating point
test_avg(float{7.7});
test_avg(double{7.7});
#warning: Should there be avg date time duration?
#if 0
// date
test_avg(::sqlpp::chrono::day_point{});
// timestamp
test_avg(::sqlpp::chrono::microsecond_point{});
using minute_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>;
test_avg(minute_point{});
// time_of_day
test_avg(std::chrono::microseconds{});
#endif
}