From 6684ac9ea830cc592f595795b763f806478806fb Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 29 Oct 2014 07:34:42 +0100 Subject: [PATCH] Added first test --- include/sqlpp11/custom_query.h | 20 +++++++------- include/sqlpp11/interpret_tuple.h | 23 ++++++++++------ tests/CMakeLists.txt | 23 ++++++++-------- tests/CustomQueryTest.cpp | 44 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 tests/CustomQueryTest.cpp diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h index 4af3cf71..4acf12d1 100644 --- a/include/sqlpp11/custom_query.h +++ b/include/sqlpp11/custom_query.h @@ -31,12 +31,12 @@ namespace sqlpp { - template - struct custom_query_t: - public FirstPart::_result_type_provider::template _result_methods_t + template + struct custom_query_t/*: + public FirstPart::_result_type_provider::template _result_methods_t*/ { - custom_query_t(Expressions... expressions): - _expressions(expressions...) + custom_query_t(Parts... parts): + _parts(parts...) {} custom_query_t(const custom_query_t&) = default; @@ -45,7 +45,7 @@ namespace sqlpp custom_query_t& operator=(custom_query_t&&) = default; ~custom_query_t() = default; - std::tuple _parts; + std::tuple _parts; }; template @@ -55,21 +55,21 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - interpret_tuple(t._parts, " ", context); + interpret_tuple_without_braces(t._parts, " ", context); return context; } }; template auto custom_query(Parts... parts) - -> statement_t + -> custom_query_t { - return statement_t(parts...); + return custom_query_t(parts...); } template auto dynamic_custom_query(const Database&, Parts...) - -> statement_t + -> custom_query_t { static_assert(std::is_base_of::value, "Invalid database parameter"); return { }; diff --git a/include/sqlpp11/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h index 4edb2631..518c607c 100644 --- a/include/sqlpp11/interpret_tuple.h +++ b/include/sqlpp11/interpret_tuple.h @@ -34,20 +34,20 @@ namespace sqlpp { - template - static void interpret_tuple_element(const Element& element, const Separator& separator, Context& context, size_t index) + template + static void interpret_tuple_element(const Element& element, const Separator& separator, Context& context, const UseBraces&, size_t index) { if (index) context << separator; - if (requires_braces_t::value) + if (UseBraces::value and requires_braces_t::value) context << "("; serialize(element, context); - if (requires_braces_t::value) + if (UseBraces::value and requires_braces_t::value) context << ")"; } - template - auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const detail::index_sequence&) + template + auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const UseBraces& useBraces, const detail::index_sequence&) -> Context& { // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. @@ -55,7 +55,7 @@ namespace sqlpp // See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777" // Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could be used using swallow = int[]; - (void) swallow{(interpret_tuple_element(std::get(t), separator, context, Is), 0)...}; + (void) swallow{(interpret_tuple_element(std::get(t), separator, context, useBraces, Is), 0)...}; return context; } @@ -63,7 +63,14 @@ namespace sqlpp auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context& { - return interpret_tuple_impl(t, separator, context, detail::make_index_sequence::value>{}); + return interpret_tuple_impl(t, separator, context, std::true_type{}, detail::make_index_sequence::value>{}); + } + + template + auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) + -> Context& + { + return interpret_tuple_impl(t, separator, context, std::false_type{}, detail::make_index_sequence::value>{}); } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 86462e61..b521ce6b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,17 +6,18 @@ macro (build_and_run arg) add_test("${arg}" "${arg}") endmacro () -build_and_run(BooleanExpressionTest) -build_and_run(InterpretTest) -build_and_run(InsertTest) -build_and_run(RemoveTest) -build_and_run(UpdateTest) -build_and_run(SelectTest) -build_and_run(SelectTypeTest) -build_and_run(FunctionTest) -build_and_run(PreparedTest) -build_and_run(Minimalistic) -build_and_run(ResultTest) +#build_and_run(BooleanExpressionTest) +build_and_run(CustomQueryTest) +#build_and_run(InterpretTest) +#build_and_run(InsertTest) +#build_and_run(RemoveTest) +#build_and_run(UpdateTest) +#build_and_run(SelectTest) +#build_and_run(SelectTypeTest) +#build_and_run(FunctionTest) +#build_and_run(PreparedTest) +#build_and_run(Minimalistic) +#build_and_run(ResultTest) # if you want to use the generator, you can do something like this: #find_package(PythonInterp REQUIRED) diff --git a/tests/CustomQueryTest.cpp b/tests/CustomQueryTest.cpp new file mode 100644 index 00000000..64654367 --- /dev/null +++ b/tests/CustomQueryTest.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013-2014, 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 +#include "Sample.h" +#include "MockDb.h" +#include +#include + +MockDb db = {}; +MockDb::_serializer_context_t printer; + +int main() +{ + test::TabFoo f; + test::TabBar t; + + auto c = custom_query(select(all_of(t)).from(t), insert_into(t)); + std::cerr << serialize(c, printer).str() << std::endl; + + return 0; +}