Re-animated all tests

This commit is contained in:
rbock
2014-01-18 20:58:51 +01:00
parent 87302fa27f
commit 24b44fae65
22 changed files with 105 additions and 156 deletions

View File

@@ -4,10 +4,10 @@ macro (build_and_run arg)
endmacro ()
build_and_run(InterpretTest)
#build_and_run(InsertTest)
#build_and_run(RemoveTest)
#build_and_run(UpdateTest)
#build_and_run(SelectTest)
#build_and_run(FunctionTest)
#build_and_run(PreparedTest)
build_and_run(InsertTest)
build_and_run(RemoveTest)
build_and_run(UpdateTest)
build_and_run(SelectTest)
build_and_run(FunctionTest)
build_and_run(PreparedTest)

View File

@@ -25,6 +25,7 @@
#include "TabSample.h"
#include "MockDb.h"
#include <sqlpp11/alias_provider.h>
#include <sqlpp11/select.h>
#include <sqlpp11/functions.h>
#include <sqlpp11/connection.h>
@@ -32,7 +33,7 @@
#include <iostream>
DbMock db = {};
SQLPP_ALIAS_PROVIDER_GENERATOR(kaesekuchen);
SQLPP_ALIAS_PROVIDER(kaesekuchen);
int main()
{

View File

@@ -30,6 +30,7 @@
#include <iostream>
DbMock db;
DbMock::_context_t printer(std::cerr);
int main()
{
@@ -56,11 +57,11 @@ int main()
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";
interpret(insert_into(t), printer).flush();
interpret(insert_into(t).set(t.beta = "kirschauflauf"), printer).flush();
auto i = dynamic_insert_into(db, t).dynamic_set();
i = i.add_set(t.beta = "kirschauflauf");
i.serialize(std::cerr, db); std::cerr << "\n";
interpret(i, printer).flush();
return 0;
}

View File

@@ -35,7 +35,7 @@
#include <iostream>
DbMock db = {};
DbMock::context printer(std::cerr);
DbMock::_context_t printer(std::cerr);
SQLPP_ALIAS_PROVIDER(kaesekuchen);
int main()

View File

@@ -27,66 +27,14 @@
#define SQLPP_MOCK_DB_H
#include <sqlpp11/connection.h>
#include <sqlpp11/serializer.h>
class DbMock: public sqlpp::connection
struct DbMock: public sqlpp::connection
{
public:
struct context
struct _context_t : public sqlpp::serializer_t
{
using _database_t = DbMock;
context(std::ostream& os):
_os(os)
{}
template<typename T>
std::ostream& operator<<(T t)
{
return _os << t;
}
void flush()
{
_os << std::endl;
}
std::string escape(std::string arg)
{
return arg;
}
std::ostream& _os;
_context_t(std::ostream& os): sqlpp::serializer_t(os) {}
};
// 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; }
};
#endif

View File

@@ -87,7 +87,7 @@ int main()
// Wonderful, now take a look at the parameter list of a select
{
auto s = select(all_of(t)).from(t).where(t.beta.like(where_parameter(t.beta)) and t.alpha == where_parameter(t.alpha) or t.gamma != parameter(t.gamma));
auto s = select(all_of(t)).from(t).where(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma));
using S = decltype(s);
using T = sqlpp::make_parameter_list_t<S>::type;
T npl;

View File

@@ -32,6 +32,7 @@
DbMock db;
DbMock::_context_t printer(std::cerr);
int main()
{
@@ -56,13 +57,13 @@ int main()
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";
interpret(remove_from(t), printer).flush();
interpret(remove_from(t).where(t.beta != "transparent"), printer).flush();
interpret(remove_from(t).using_(t), printer).flush();
auto r = dynamic_remove_from(db, t).dynamic_using_().dynamic_where();
r = r.add_using_(t);
r = r.add_where(t.beta != "transparent");
r.serialize(std::cerr, db); std::cerr << "\n";
interpret(r, printer).flush();
return 0;
}

View File

@@ -26,6 +26,7 @@
#include "TabSample.h"
#include "MockDb.h"
#include "is_regular.h"
#include <sqlpp11/alias_provider.h>
#include <sqlpp11/select.h>
#include <sqlpp11/functions.h>
#include <sqlpp11/connection.h>
@@ -33,6 +34,15 @@
#include <iostream>
DbMock db = {};
DbMock::_context_t printer(std::cerr);
namespace alias
{
SQLPP_ALIAS_PROVIDER(a);
SQLPP_ALIAS_PROVIDER(b);
SQLPP_ALIAS_PROVIDER(left);
SQLPP_ALIAS_PROVIDER(right);
}
int main()
{
@@ -59,7 +69,7 @@ int main()
// Test an alias of table
{
using T = decltype(t.as(sqlpp::alias::a));
using T = decltype(t.as(alias::a));
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
@@ -77,7 +87,7 @@ int main()
// Test an integral column of an alias of table
{
using T = decltype(t.as(sqlpp::alias::a).alpha);
using T = decltype(t.as(alias::a).alpha);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
@@ -132,7 +142,7 @@ int main()
// Test a an alias of a numeric table column
{
using T = decltype(t.alpha.as(sqlpp::alias::a));
using T = decltype(t.alpha.as(alias::a));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -180,7 +190,7 @@ int main()
// Test a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t));
using T = decltype(select(t.alpha.as(alias::a)).from(t));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -196,7 +206,7 @@ int main()
// Test an alias of a select of a single numeric table column
{
using T = decltype(select(t.alpha).from(t).as(sqlpp::alias::b));
using T = decltype(select(t.alpha).from(t).as(alias::b));
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -212,7 +222,7 @@ int main()
// Test the column of an alias of a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t).as(sqlpp::alias::b));
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b));
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -228,7 +238,7 @@ int main()
// Test the column of an alias of a select of a single numeric table column
{
using T = decltype(select(t.alpha).from(t).as(sqlpp::alias::b).alpha);
using T = decltype(select(t.alpha).from(t).as(alias::b).alpha);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -244,7 +254,7 @@ int main()
// Test an alias of a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t).as(sqlpp::alias::b).a);
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b).a);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<T>::value, "type requirement");
@@ -269,22 +279,22 @@ int main()
// Test that select(all_of(tab)) is expanded in multi_column
{
auto a = multi_column(sqlpp::alias::a, all_of(t));
auto b = multi_column(sqlpp::alias::a, t.alpha, t.beta, t.gamma);
auto a = multi_column(alias::a, all_of(t));
auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma);
static_assert(std::is_same<decltype(a), decltype(b)>::value, "all_of(t) has to be expanded by multi_column");
}
// Test that select(tab) is expanded in multi_column
{
auto a = multi_column(sqlpp::alias::a, all_of(t));
auto b = multi_column(sqlpp::alias::a, t.alpha, t.beta, t.gamma);
auto a = multi_column(alias::a, all_of(t));
auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma);
static_assert(std::is_same<decltype(a), decltype(b)>::value, "t has to be expanded by multi_column");
}
// Test that a multicolumn is not a value
{
auto m = multi_column(sqlpp::alias::a, t.alpha, t.beta);
auto a = select(m).from(t).as(sqlpp::alias::b).a;
auto m = multi_column(alias::a, t.alpha, t.beta);
auto a = select(m).from(t).as(alias::b).a;
static_assert(not sqlpp::is_value_t<decltype(a)>::value, "a multi_column is not a value");
}
@@ -307,7 +317,7 @@ int main()
s = s.set_limit(30);
s = s.set_limit(3);
std::cerr << "------------------------\n";
s.serialize(std::cerr, db);
interpret(s, printer).flush();
std::cerr << "------------------------\n";
using T = decltype(s);
static_assert(sqlpp::is_regular<T>::value, "type requirement");
@@ -316,18 +326,18 @@ int main()
// Test that select can be called with zero columns if it is used with dynamic columns.
{
auto s = dynamic_select(db).dynamic_columns().add_column(t.alpha);
s.serialize(std::cerr, db); std::cerr << "\n";
interpret(s, printer).flush();
}
// Test that verbatim_table compiles
{
auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table"));
s.serialize(std::cerr, db); std::cerr << "\n";
interpret(s, printer).flush();
}
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;
using T = sqlpp::vendor::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");
@@ -339,29 +349,28 @@ int main()
auto y = t.gamma and true and t.gamma;
!t.gamma;
t.beta < "kaesekuchen";
(t.beta + "hallenhalma").serialize(std::cerr, db);
concat(t.beta, "hallenhalma").serialize(std::cerr, db);
interpret(t.beta + "hallenhalma", printer).flush();
static_assert(sqlpp::must_not_insert_t<decltype(t.alpha)>::value, "alpha must not be inserted");
t.alpha.serialize(std::cerr, db);
interpret(t.alpha, printer).flush();
std::cerr << "\n" << sizeof(TabSample) << std::endl;
static_assert(std::is_same<typename decltype(t.alpha)::_value_type::_is_named_expression, std::true_type>::value, "alpha should be a named expression");
static_assert(sqlpp::is_named_expression_t<decltype(t.alpha)>::value, "alpha should be a named expression");
static_assert(sqlpp::is_named_expression_t<decltype(t.alpha.as(sqlpp::alias::a))>::value, "an alias of alpha should be a named expression");
static_assert(sqlpp::is_alias_t<decltype(t.alpha.as(sqlpp::alias::a))>::value, "an alias of alpha should be an alias");
static_assert(sqlpp::is_named_expression_t<decltype(t.alpha.as(alias::a))>::value, "an alias of alpha should be a named expression");
static_assert(sqlpp::is_alias_t<decltype(t.alpha.as(alias::a))>::value, "an alias of alpha should be an alias");
auto z = select(t.alpha) == 7;
auto l = t.as(sqlpp::alias::left);
auto r = select(t.gamma.as(sqlpp::alias::a)).from(t).where(t.gamma == true).as(sqlpp::alias::right);
auto l = t.as(alias::left);
auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right);
static_assert(sqlpp::is_boolean_t<decltype(select(t.gamma).from(t))>::value, "select(bool) has to be a bool");
select(sqlpp::distinct, sqlpp::straight_join, l.alpha, l.beta, select(r.a).from(r))
interpret(select(sqlpp::distinct, sqlpp::straight_join, l.alpha, l.beta, select(r.a).from(r))
.from(l, r)
.where(t.beta == "hello world" and select(t.gamma).from(t))// .as(sqlpp::alias::right))
.where(t.beta == "hello world" and select(t.gamma).from(t))// .as(alias::right))
.group_by(l.gamma, r.a)
.having(r.a != true)
.order_by(l.beta.asc())
.limit(17)
.offset(3)
.as(sqlpp::alias::a)
.serialize(std::cerr, db);
.as(alias::a)
, printer).flush();
return 0;
}

View File

@@ -30,6 +30,7 @@
#include "is_regular.h"
DbMock db;
DbMock::_context_t printer(std::cerr);
int main()
{
@@ -54,12 +55,12 @@ int main()
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";
interpret(update(t), printer).flush();
interpret(update(t).set(t.gamma = false), printer).flush();
interpret(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).flush();
auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where();
u = u.add_set(t.gamma = false);
u.serialize(std::cerr, db); std::cerr << "\n";
interpret(u, printer).flush();
return 0;
}