IGNITE-3764: ODBC Added tests for SQL operators. This closes #986.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/99e3e8a2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/99e3e8a2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/99e3e8a2 Branch: refs/heads/master Commit: 99e3e8a2d997aa681264460c2845984712ded90e Parents: 6fd53ea Author: Igor Sapego <[email protected]> Authored: Fri Aug 26 11:23:49 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Fri Aug 26 11:23:49 2016 +0300 ---------------------------------------------------------------------- .../cpp/common/src/common/big_integer.cpp | 1 - modules/platforms/cpp/odbc-test/Makefile.am | 1 + .../include/sql_function_test_suite_fixture.h | 3 + .../cpp/odbc-test/project/vs/odbc-test.vcxproj | 1 + .../project/vs/odbc-test.vcxproj.filters | 3 + .../src/sql_function_test_suite_fixture.cpp | 10 + .../cpp/odbc-test/src/sql_operators_test.cpp | 214 +++++++++++++++++++ 7 files changed, 232 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/common/src/common/big_integer.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/common/src/common/big_integer.cpp b/modules/platforms/cpp/common/src/common/big_integer.cpp index 475ddc6..6aa6614 100644 --- a/modules/platforms/cpp/common/src/common/big_integer.cpp +++ b/modules/platforms/cpp/common/src/common/big_integer.cpp @@ -58,7 +58,6 @@ namespace ignite assert(val != 0); assert(len > 0); assert(sign == 1 || sign == 0 || sign == -1); - assert(val[0] != 0); if (bigEndian) { http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/Makefile.am b/modules/platforms/cpp/odbc-test/Makefile.am index 1f641be..a3f954e 100644 --- a/modules/platforms/cpp/odbc-test/Makefile.am +++ b/modules/platforms/cpp/odbc-test/Makefile.am @@ -67,6 +67,7 @@ ignite_odbc_tests_SOURCES = \ src/sql_numeric_functions_test.cpp \ src/sql_aggregate_functions_test.cpp \ src/sql_system_functions_test.cpp \ + src/sql_operators_test.cpp \ src/sql_value_expressions.cpp \ ../odbc/src/cursor.cpp \ ../odbc/src/config/connection_info.cpp \ http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h b/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h index eef0a9b..57c3f0f 100644 --- a/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h +++ b/modules/platforms/cpp/odbc-test/include/sql_function_test_suite_fixture.h @@ -161,6 +161,9 @@ namespace ignite void SqlFunctionTestSuiteFixture::CheckSingleResult<double>(const char* request, const double& expected); template<> + void SqlFunctionTestSuiteFixture::CheckSingleResult<bool>(const char* request, const bool& expected); + + template<> void SqlFunctionTestSuiteFixture::CheckSingleResult<std::string>(const char* request); template<> http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj index 4d3a9cc..8b4bee6 100644 --- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj @@ -171,6 +171,7 @@ <ClCompile Include="..\..\src\sql_aggregate_functions_test.cpp" /> <ClCompile Include="..\..\src\sql_function_test_suite_fixture.cpp" /> <ClCompile Include="..\..\src\sql_numeric_functions_test.cpp" /> + <ClCompile Include="..\..\src\sql_operators_test.cpp" /> <ClCompile Include="..\..\src\sql_string_functions_test.cpp" /> <ClCompile Include="..\..\src\sql_system_functions_test.cpp" /> <ClCompile Include="..\..\src\sql_value_expressions.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters index c4d70b7..4756f83 100644 --- a/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters @@ -94,6 +94,9 @@ <ClCompile Include="..\..\src\sql_system_functions_test.cpp"> <Filter>Code</Filter> </ClCompile> + <ClCompile Include="..\..\src\sql_operators_test.cpp"> + <Filter>Code</Filter> + </ClCompile> <ClCompile Include="..\..\src\sql_value_expressions.cpp"> <Filter>Code</Filter> </ClCompile> http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp b/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp index 4d8b919..d6b175f 100644 --- a/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp +++ b/modules/platforms/cpp/odbc-test/src/sql_function_test_suite_fixture.cpp @@ -192,6 +192,16 @@ namespace ignite } template<> + void SqlFunctionTestSuiteFixture::CheckSingleResult<bool>(const char* request, const bool& expected) + { + SQLCHAR res = 0; + + CheckSingleResult0(request, SQL_C_BIT, &res, 0, 0); + + BOOST_CHECK_EQUAL((res != 0), expected); + } + + template<> void SqlFunctionTestSuiteFixture::CheckSingleResult<std::string>(const char* request) { SQLCHAR res[ODBC_BUFFER_SIZE] = { 0 }; http://git-wip-us.apache.org/repos/asf/ignite/blob/99e3e8a2/modules/platforms/cpp/odbc-test/src/sql_operators_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/sql_operators_test.cpp b/modules/platforms/cpp/odbc-test/src/sql_operators_test.cpp new file mode 100644 index 0000000..db3d3f7 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/sql_operators_test.cpp @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef _WIN32 +# include <windows.h> +#endif + +#include <vector> +#include <string> + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include "test_type.h" +#include "sql_function_test_suite_fixture.h" +#include <ignite/common/decimal.h> + +using namespace ignite; + +BOOST_FIXTURE_TEST_SUITE(SqlOperatorTestSuite, ignite::SqlFunctionTestSuiteFixture) + +BOOST_AUTO_TEST_CASE(TestOperatorAddInt) +{ + CheckSingleResult<int32_t>("SELECT 123 + 51", 123 + 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorSubInt) +{ + CheckSingleResult<int32_t>("SELECT 123 - 51", 123 - 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorDivInt) +{ + CheckSingleResult<int32_t>("SELECT 123 / 51", 123 / 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorModInt) +{ + CheckSingleResult<int32_t>("SELECT 123 % 51", 123 % 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorMultInt) +{ + CheckSingleResult<int32_t>("SELECT 123 * 51", 123 * 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorAddDouble) +{ + CheckSingleResult<double>("SELECT 123.0 + 51.0", 123.0 + 51.0); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorSubDouble) +{ + CheckSingleResult<double>("SELECT 123.0 - 51.0", 123.0 - 51.0); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorDivDouble) +{ + CheckSingleResult<double>("SELECT 123.0 / 51.0", 123.0 / 51.0); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorModDouble) +{ + CheckSingleResult<double>("SELECT 123.0 % 51.0", 123 % 51); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorMultDouble) +{ + CheckSingleResult<double>("SELECT 123.0 * 51.0", 123.0 * 51.0); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorConcatString) +{ + CheckSingleResult<std::string>("SELECT 'Hello' || ' ' || 'World' || '!'", "Hello World!"); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterInt) +{ + CheckSingleResult<bool>("SELECT 2 > 3", false); + CheckSingleResult<bool>("SELECT 3 > 3", false); + CheckSingleResult<bool>("SELECT 34 > 3", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessInt) +{ + CheckSingleResult<bool>("SELECT 4 < 4", false); + CheckSingleResult<bool>("SELECT 4 < 4", false); + CheckSingleResult<bool>("SELECT 8 < 42", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterEquealInt) +{ + CheckSingleResult<bool>("SELECT 2 >= 3", false); + CheckSingleResult<bool>("SELECT 3 >= 3", true); + CheckSingleResult<bool>("SELECT 34 >= 3", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessEquealInt) +{ + CheckSingleResult<bool>("SELECT 4 <= 3", false); + CheckSingleResult<bool>("SELECT 4 <= 4", true); + CheckSingleResult<bool>("SELECT 8 <= 42", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorEquealInt) +{ + CheckSingleResult<bool>("SELECT 4 = 3", false); + CheckSingleResult<bool>("SELECT 4 = 4", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorNotEquealInt) +{ + CheckSingleResult<bool>("SELECT 4 != 3", true); + CheckSingleResult<bool>("SELECT 4 != 4", false); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterDouble) +{ + CheckSingleResult<bool>("SELECT 2 > 3", false); + CheckSingleResult<bool>("SELECT 3 > 3", false); + CheckSingleResult<bool>("SELECT 34 > 3", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessDouble) +{ + CheckSingleResult<bool>("SELECT 4.0 < 4.0", false); + CheckSingleResult<bool>("SELECT 4.0 < 4.0", false); + CheckSingleResult<bool>("SELECT 8.0 < 42.0", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterEquealDouble) +{ + CheckSingleResult<bool>("SELECT 2.0 >= 3.0", false); + CheckSingleResult<bool>("SELECT 3.0 >= 3.0", true); + CheckSingleResult<bool>("SELECT 34.0 >= 3.0", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessEquealDouble) +{ + CheckSingleResult<bool>("SELECT 4.0 <= 3.0", false); + CheckSingleResult<bool>("SELECT 4.0 <= 4.0", true); + CheckSingleResult<bool>("SELECT 8.0 <= 42.0", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorEquealDouble) +{ + CheckSingleResult<bool>("SELECT 4.0 = 3.0", false); + CheckSingleResult<bool>("SELECT 4.0 = 4.0", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorNotEquealDouble) +{ + CheckSingleResult<bool>("SELECT 4.0 != 3.0", true); + CheckSingleResult<bool>("SELECT 4.0 != 4.0", false); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterString) +{ + CheckSingleResult<bool>("SELECT 'abc' > 'bcd'", false); + CheckSingleResult<bool>("SELECT 'abc' > 'abc'", false); + CheckSingleResult<bool>("SELECT 'bcd' > 'abc'", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessString) +{ + CheckSingleResult<bool>("SELECT 'bcd' < 'abc'", false); + CheckSingleResult<bool>("SELECT 'abc' < 'abc'", false); + CheckSingleResult<bool>("SELECT 'abc' < 'bcd'", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorGreaterEquealString) +{ + CheckSingleResult<bool>("SELECT 'abc' >= 'bcd'", false); + CheckSingleResult<bool>("SELECT 'abc' >= 'abc'", true); + CheckSingleResult<bool>("SELECT 'bcd' >= 'abc'", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorLessEquealString) +{ + CheckSingleResult<bool>("SELECT 'bcd' <= 'abc'", false); + CheckSingleResult<bool>("SELECT 'abc' <= 'bcd'", true); + CheckSingleResult<bool>("SELECT 'abc' <= 'abc'", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorEquealString) +{ + CheckSingleResult<bool>("SELECT 'bcd' = 'abc'", false); + CheckSingleResult<bool>("SELECT 'abc' = 'abc'", true); +}; + +BOOST_AUTO_TEST_CASE(TestOperatorNotEquealString) +{ + CheckSingleResult<bool>("SELECT 'abc' != 'abc'", false); + CheckSingleResult<bool>("SELECT 'bcd' != 'abc'", true); +}; + +BOOST_AUTO_TEST_SUITE_END()
