0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added a few more type tests.

This commit is contained in:
Roland Bock 2013-11-10 18:03:39 +01:00
parent 9d09127e71
commit a0af42e57e
5 changed files with 123 additions and 67 deletions

View File

@ -23,17 +23,11 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <iostream>
#include <sqlpp11/insert.h>
#include <sqlpp11/select.h>
#include "TabSample.h"
#include "MockDb.h"
#include "is_regular.h"
#include <sqlpp11/insert.h>
#include <iostream>
class DbMock
{
public:
const std::string& escape(const std::string& text) { return text; }
};
DbMock db;
@ -47,14 +41,26 @@ int main()
auto a = t.alpha;
a = t.alpha;
{
using T = decltype(insert_into(t));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(insert_into(t).set(t.beta = "kirschauflauf"));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(dynamic_insert_into(db, t).dynamic_set());
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
insert_into(t).serialize(std::cerr, db); std::cerr << "\n";
insert_into(t).set(t.beta = "kirschauflauf").serialize(std::cerr, db); std::cerr << "\n";
auto i = dynamic_insert_into(db, t).dynamic_set();
i = i.add_set(t.beta = "kirschauflauf");
i.serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).values(25, "drei").serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).select(select(t.alpha, t.beta).from(t)).serialize(std::cerr, db);
return 0;
}

View File

@ -27,13 +27,9 @@
#include <sqlpp11/remove.h>
#include <sqlpp11/select.h>
#include "TabSample.h"
#include "MockDb.h"
#include "is_regular.h"
#include <iostream>
class DbMock
{
public:
const std::string& escape(const std::string& text) { return text; }
};
DbMock db;
@ -45,6 +41,21 @@ int main()
auto y = t.beta = "kaesekuchen";
auto z = t.gamma = true;
{
using T = decltype(remove_from(t));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(remove_from(t).where(t.beta != "transparent"));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(dynamic_remove_from(db, t).dynamic_using_().dynamic_where());
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
remove_from(t).serialize(std::cerr, db); std::cerr << "\n";
remove_from(t).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n";
remove_from(t).using_(t).serialize(std::cerr, db); std::cerr << "\n";
@ -52,8 +63,6 @@ int main()
r = r.add_using_(t);
r = r.add_where(t.beta != "transparent");
r.serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).values(25, "drei").serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).select(select(t.alpha, t.beta).from(t)).serialize(std::cerr, db);
return 0;
}

View File

@ -24,47 +24,15 @@
*/
#include "TabSample.h"
#include "MockDb.h"
#include "is_regular.h"
#include <sqlpp11/select.h>
#include <sqlpp11/functions.h>
#include <sqlpp11/connection.h>
#include <iostream>
class DbMock: public sqlpp::connection
{
public:
// join types
static constexpr bool _supports_inner_join = true;
static constexpr bool _supports_outer_join = true;
static constexpr bool _supports_left_outer_join = true;
static constexpr bool _supports_right_outer_join = true;
// functions
static constexpr bool _supports_avg = true;
static constexpr bool _supports_count = true;
static constexpr bool _supports_exists = true;
static constexpr bool _supports_like = true;
static constexpr bool _supports_in = true;
static constexpr bool _supports_max = true;
static constexpr bool _supports_min = true;
static constexpr bool _supports_not_in = true;
static constexpr bool _supports_sum = true;
// select
static constexpr bool _supports_group_by = true;
static constexpr bool _supports_having = true;
static constexpr bool _supports_limit = true;
static constexpr bool _supports_order_by = true;
static constexpr bool _supports_select_as_table = true;
static constexpr bool _supports_some = true;
static constexpr bool _supports_any = true;
static constexpr bool _use_concat_operator = true;
static constexpr bool _use_concat_function = true;
const std::string& escape(const std::string& text) { return text; }
};
DbMock db;
DbMock db = {};
int main()
{
@ -86,6 +54,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test an alias of table
@ -103,6 +72,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test an integral column of an alias of table
@ -120,6 +90,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
@ -138,6 +109,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test a floating point table column
@ -155,6 +127,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test a an alias of a numeric table column
@ -170,6 +143,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test a select of a single column without a from
@ -185,6 +159,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test a select of a single numeric table column
@ -200,6 +175,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test a select of an alias of a single numeric table column
@ -215,6 +191,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test an alias of a select of a single numeric table column
@ -230,6 +207,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test the column of an alias of a select of an alias of a single numeric table column
@ -245,6 +223,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test the column of an alias of a select of a single numeric table column
@ -260,6 +239,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test an alias of a select of an alias of a single numeric table column
@ -275,6 +255,7 @@ int main()
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test that select(all_of(tab)) is expanded in select
@ -317,6 +298,8 @@ int main()
decltype(t.alpha)::_value_type::_base_value_type,
decltype(f.epsilon)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type");
static_assert(std::is_same<A, B>::value, "select with identical columns(name/value_type) need to have identical result_types");
static_assert(sqlpp::is_regular<A>::value, "type requirement");
static_assert(sqlpp::is_regular<B>::value, "type requirement");
}
{
@ -328,6 +311,8 @@ int main()
std::cerr << "------------------------\n";
s.serialize(std::cerr, db);
std::cerr << "------------------------\n";
using T = decltype(s);
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
// Test that select can be called with zero columns if it is used with dynamic columns.
@ -339,6 +324,7 @@ int main()
static_assert(sqlpp::is_select_flag_t<decltype(sqlpp::all)>::value, "sqlpp::all has to be a select_flag");
using T = sqlpp::detail::wrap_operand<int>::type;
static_assert(sqlpp::is_regular<T>::value, "type requirement");
static_assert(T::_is_expression, "T has to be an expression");
static_assert(std::is_same<typename T::_value_type::_is_numeric, std::true_type>::value, "T has to be a numeric");
static_assert(sqlpp::is_numeric_t<T>::value, "T has to be a numeric");

View File

@ -25,15 +25,9 @@
#include <iostream>
#include <sqlpp11/update.h>
#include <sqlpp11/select.h>
#include "TabSample.h"
#include <iostream>
class DbMock
{
public:
const std::string& escape(const std::string& text) { return text; }
};
#include "MockDb.h"
#include "is_regular.h"
DbMock db;
@ -45,6 +39,21 @@ int main()
auto y = t.beta = "kaesekuchen";
auto z = t.gamma = true;
{
using T = decltype(update(t));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(update(t).set(t.gamma = false).where(t.beta != "transparent"));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
{
using T = decltype(dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where());
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
update(t).serialize(std::cerr, db); std::cerr << "\n";
update(t).set(t.gamma = false).serialize(std::cerr, db); std::cerr << "\n";
update(t).set(t.gamma = false).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n";
@ -52,8 +61,5 @@ int main()
u = u.add_set(t.gamma = false);
u.serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).values(7, "wurstwaren", true).serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).values(25, "drei").serialize(std::cerr, db); std::cerr << "\n";
//insert_into(t).columns(t.alpha, t.beta).select(select(t.alpha, t.beta).from(t)).serialize(std::cerr, db);
return 0;
}

49
tests/is_regular.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2013, 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.
*/
#ifndef SQLPP_IS_REGULAR_H
#define SQLPP_IS_REGULAR_H
#include <type_traits>
namespace sqlpp
{
template<typename T>
struct is_regular
{
static constexpr bool value = true
and std::is_nothrow_move_constructible<T>::value
and std::is_move_assignable<T>::value // containers and strings are not noexcept_assignable
and std::is_copy_constructible<T>::value
and std::is_copy_assignable<T>::value
// default constructor makes no sense
// (not) equals would be possible
// not sure about less
;
};
}
#endif