IGNITE-2442: ODBC projects moved to main cpp solution.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e8287063 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e8287063 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e8287063 Branch: refs/heads/ignite-1786 Commit: e8287063908ec918f5afa72032854e7bf5a54f20 Parents: 57822b6 Author: isapego <[email protected]> Authored: Tue Jan 26 16:43:39 2016 +0300 Committer: isapego <[email protected]> Committed: Tue Jan 26 16:43:39 2016 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/odbc-test/Makefile.am | 55 + modules/platforms/cpp/odbc-test/README.TXT | 1 + modules/platforms/cpp/odbc-test/configure.ac | 62 + .../cpp/odbc-test/include/teamcity_messages.h | 55 + .../cpp/odbc-test/project/vs/odbc-test.vcxproj | 189 ++ .../project/vs/odbc-test.vcxproj.filters | 79 + .../src/application_data_buffer_test.cpp | 630 +++++++ .../platforms/cpp/odbc-test/src/column_test.cpp | 290 +++ .../cpp/odbc-test/src/configuration_test.cpp | 206 +++ .../cpp/odbc-test/src/connection_info_test.cpp | 219 +++ .../platforms/cpp/odbc-test/src/cursor_test.cpp | 166 ++ .../platforms/cpp/odbc-test/src/parser_test.cpp | 94 + .../platforms/cpp/odbc-test/src/row_test.cpp | 167 ++ .../cpp/odbc-test/src/teamcity_boost.cpp | 159 ++ .../cpp/odbc-test/src/teamcity_messages.cpp | 150 ++ .../cpp/odbc-test/src/utility_test.cpp | 81 + modules/platforms/cpp/odbc/Makefile.am | 67 + modules/platforms/cpp/odbc/configure.ac | 62 + modules/platforms/cpp/odbc/ignite-odbc.pc.in | 9 + .../ignite/odbc/app/application_data_buffer.h | 342 ++++ .../odbc/include/ignite/odbc/app/parameter.h | 113 ++ .../cpp/odbc/include/ignite/odbc/column.h | 149 ++ .../cpp/odbc/include/ignite/odbc/common_types.h | 225 +++ .../include/ignite/odbc/config/configuration.h | 164 ++ .../ignite/odbc/config/connection_info.h | 98 + .../cpp/odbc/include/ignite/odbc/connection.h | 258 +++ .../cpp/odbc/include/ignite/odbc/cursor.h | 108 ++ .../cpp/odbc/include/ignite/odbc/decimal.h | 126 ++ .../ignite/odbc/diagnostic/diagnosable.h | 82 + .../odbc/diagnostic/diagnosable_adapter.h | 107 ++ .../ignite/odbc/diagnostic/diagnostic_record.h | 165 ++ .../odbc/diagnostic/diagnostic_record_storage.h | 198 ++ .../cpp/odbc/include/ignite/odbc/environment.h | 137 ++ .../cpp/odbc/include/ignite/odbc/message.h | 630 +++++++ .../odbc/include/ignite/odbc/meta/column_meta.h | 210 +++ .../include/ignite/odbc/meta/primary_key_meta.h | 188 ++ .../odbc/include/ignite/odbc/meta/table_meta.h | 166 ++ .../cpp/odbc/include/ignite/odbc/parser.h | 141 ++ .../ignite/odbc/query/column_metadata_query.h | 146 ++ .../odbc/include/ignite/odbc/query/data_query.h | 152 ++ .../ignite/odbc/query/foreign_keys_query.h | 143 ++ .../ignite/odbc/query/primary_keys_query.h | 137 ++ .../cpp/odbc/include/ignite/odbc/query/query.h | 119 ++ .../ignite/odbc/query/special_columns_query.h | 142 ++ .../ignite/odbc/query/table_metadata_query.h | 150 ++ .../include/ignite/odbc/query/type_info_query.h | 118 ++ .../cpp/odbc/include/ignite/odbc/result_page.h | 101 ++ .../cpp/odbc/include/ignite/odbc/row.h | 132 ++ .../cpp/odbc/include/ignite/odbc/statement.h | 525 ++++++ .../include/ignite/odbc/system/odbc_constants.h | 45 + .../include/ignite/odbc/system/socket_client.h | 92 + .../cpp/odbc/include/ignite/odbc/type_traits.h | 313 ++++ .../cpp/odbc/include/ignite/odbc/utility.h | 171 ++ .../platforms/cpp/odbc/odbc-driver/Makefile.am | 67 - .../platforms/cpp/odbc/odbc-driver/configure.ac | 62 - .../cpp/odbc/odbc-driver/ignite-odbc.pc.in | 9 - .../ignite/odbc/app/application_data_buffer.h | 342 ---- .../include/ignite/odbc/app/parameter.h | 113 -- .../odbc-driver/include/ignite/odbc/column.h | 149 -- .../include/ignite/odbc/common_types.h | 225 --- .../include/ignite/odbc/config/configuration.h | 164 -- .../ignite/odbc/config/connection_info.h | 98 - .../include/ignite/odbc/connection.h | 258 --- .../odbc-driver/include/ignite/odbc/cursor.h | 108 -- .../odbc-driver/include/ignite/odbc/decimal.h | 126 -- .../ignite/odbc/diagnostic/diagnosable.h | 82 - .../odbc/diagnostic/diagnosable_adapter.h | 107 -- .../ignite/odbc/diagnostic/diagnostic_record.h | 165 -- .../odbc/diagnostic/diagnostic_record_storage.h | 198 -- .../include/ignite/odbc/environment.h | 137 -- .../odbc-driver/include/ignite/odbc/message.h | 630 ------- .../include/ignite/odbc/meta/column_meta.h | 210 --- .../include/ignite/odbc/meta/primary_key_meta.h | 188 -- .../include/ignite/odbc/meta/table_meta.h | 166 -- .../odbc-driver/include/ignite/odbc/parser.h | 141 -- .../ignite/odbc/query/column_metadata_query.h | 146 -- .../include/ignite/odbc/query/data_query.h | 152 -- .../ignite/odbc/query/foreign_keys_query.h | 143 -- .../ignite/odbc/query/primary_keys_query.h | 137 -- .../include/ignite/odbc/query/query.h | 119 -- .../ignite/odbc/query/special_columns_query.h | 142 -- .../ignite/odbc/query/table_metadata_query.h | 150 -- .../include/ignite/odbc/query/type_info_query.h | 118 -- .../include/ignite/odbc/result_page.h | 101 -- .../odbc/odbc-driver/include/ignite/odbc/row.h | 132 -- .../odbc-driver/include/ignite/odbc/statement.h | 525 ------ .../include/ignite/odbc/system/odbc_constants.h | 45 - .../include/ignite/odbc/system/socket_client.h | 92 - .../include/ignite/odbc/type_traits.h | 313 ---- .../odbc-driver/include/ignite/odbc/utility.h | 171 -- .../os/linux/src/system/socket_client.cpp | 120 -- .../os/win/src/system/socket_client.cpp | 133 -- .../cpp/odbc/odbc-driver/project/README.TXT | 1 - .../cpp/odbc/odbc-driver/project/vs/README.TXT | 1 - .../cpp/odbc/odbc-driver/project/vs/module.def | 69 - .../odbc-driver/project/vs/odbc-driver.vcxproj | 233 --- .../project/vs/odbc-driver.vcxproj.filters | 229 --- .../src/app/application_data_buffer.cpp | 834 --------- .../cpp/odbc/odbc-driver/src/app/parameter.cpp | 147 -- .../cpp/odbc/odbc-driver/src/column.cpp | 454 ----- .../cpp/odbc/odbc-driver/src/common_types.cpp | 120 -- .../odbc-driver/src/config/configuration.cpp | 245 --- .../odbc-driver/src/config/connection_info.cpp | 419 ----- .../cpp/odbc/odbc-driver/src/connection.cpp | 269 --- .../cpp/odbc/odbc-driver/src/cursor.cpp | 78 - .../cpp/odbc/odbc-driver/src/decimal.cpp | 117 -- .../src/diagnostic/diagnosable_adapter.cpp | 49 - .../src/diagnostic/diagnostic_record.cpp | 241 --- .../diagnostic/diagnostic_record_storage.cpp | 242 --- .../cpp/odbc/odbc-driver/src/environment.cpp | 172 -- .../odbc/odbc-driver/src/meta/column_meta.cpp | 275 --- .../odbc/odbc-driver/src/meta/table_meta.cpp | 50 - .../platforms/cpp/odbc/odbc-driver/src/odbc.cpp | 1687 ------------------ .../src/query/column_metadata_query.cpp | 317 ---- .../odbc/odbc-driver/src/query/data_query.cpp | 277 --- .../src/query/foreign_keys_query.cpp | 131 -- .../src/query/primary_keys_query.cpp | 210 --- .../src/query/special_columns_query.cpp | 121 -- .../src/query/table_metadata_query.cpp | 242 --- .../odbc-driver/src/query/type_info_query.cpp | 394 ---- .../cpp/odbc/odbc-driver/src/result_page.cpp | 58 - .../platforms/cpp/odbc/odbc-driver/src/row.cpp | 120 -- .../cpp/odbc/odbc-driver/src/statement.cpp | 529 ------ .../cpp/odbc/odbc-driver/src/type_traits.cpp | 657 ------- .../cpp/odbc/odbc-driver/src/utility.cpp | 105 -- .../platforms/cpp/odbc/odbc-test/Makefile.am | 55 - modules/platforms/cpp/odbc/odbc-test/README.TXT | 1 - .../platforms/cpp/odbc/odbc-test/configure.ac | 62 - .../odbc/odbc-test/include/teamcity_messages.h | 55 - .../odbc/odbc-test/project/vs/odbc-test.vcxproj | 189 -- .../project/vs/odbc-test.vcxproj.filters | 79 - .../src/application_data_buffer_test.cpp | 630 ------- .../cpp/odbc/odbc-test/src/column_test.cpp | 290 --- .../odbc/odbc-test/src/configuration_test.cpp | 206 --- .../odbc/odbc-test/src/connection_info_test.cpp | 219 --- .../cpp/odbc/odbc-test/src/cursor_test.cpp | 166 -- .../cpp/odbc/odbc-test/src/parser_test.cpp | 94 - .../cpp/odbc/odbc-test/src/row_test.cpp | 167 -- .../cpp/odbc/odbc-test/src/teamcity_boost.cpp | 159 -- .../odbc/odbc-test/src/teamcity_messages.cpp | 150 -- .../cpp/odbc/odbc-test/src/utility_test.cpp | 81 - .../odbc/os/linux/src/system/socket_client.cpp | 120 ++ .../odbc/os/win/src/system/socket_client.cpp | 133 ++ modules/platforms/cpp/odbc/project/README.TXT | 1 + .../platforms/cpp/odbc/project/vs/README.TXT | 1 + .../platforms/cpp/odbc/project/vs/module.def | 69 + modules/platforms/cpp/odbc/project/vs/odbc.sln | 56 - .../platforms/cpp/odbc/project/vs/odbc.vcxproj | 233 +++ .../cpp/odbc/project/vs/odbc.vcxproj.filters | 229 +++ .../odbc/src/app/application_data_buffer.cpp | 834 +++++++++ .../platforms/cpp/odbc/src/app/parameter.cpp | 147 ++ modules/platforms/cpp/odbc/src/column.cpp | 454 +++++ modules/platforms/cpp/odbc/src/common_types.cpp | 120 ++ .../cpp/odbc/src/config/configuration.cpp | 245 +++ .../cpp/odbc/src/config/connection_info.cpp | 419 +++++ modules/platforms/cpp/odbc/src/connection.cpp | 269 +++ modules/platforms/cpp/odbc/src/cursor.cpp | 78 + modules/platforms/cpp/odbc/src/decimal.cpp | 117 ++ .../odbc/src/diagnostic/diagnosable_adapter.cpp | 49 + .../odbc/src/diagnostic/diagnostic_record.cpp | 241 +++ .../diagnostic/diagnostic_record_storage.cpp | 242 +++ modules/platforms/cpp/odbc/src/environment.cpp | 172 ++ .../platforms/cpp/odbc/src/meta/column_meta.cpp | 275 +++ .../platforms/cpp/odbc/src/meta/table_meta.cpp | 50 + modules/platforms/cpp/odbc/src/odbc.cpp | 1687 ++++++++++++++++++ .../odbc/src/query/column_metadata_query.cpp | 317 ++++ .../platforms/cpp/odbc/src/query/data_query.cpp | 277 +++ .../cpp/odbc/src/query/foreign_keys_query.cpp | 131 ++ .../cpp/odbc/src/query/primary_keys_query.cpp | 210 +++ .../odbc/src/query/special_columns_query.cpp | 121 ++ .../cpp/odbc/src/query/table_metadata_query.cpp | 242 +++ .../cpp/odbc/src/query/type_info_query.cpp | 394 ++++ modules/platforms/cpp/odbc/src/result_page.cpp | 58 + modules/platforms/cpp/odbc/src/row.cpp | 120 ++ modules/platforms/cpp/odbc/src/statement.cpp | 529 ++++++ modules/platforms/cpp/odbc/src/type_traits.cpp | 657 +++++++ modules/platforms/cpp/odbc/src/utility.cpp | 105 ++ modules/platforms/cpp/project/vs/ignite.sln | 20 + 178 files changed, 18200 insertions(+), 18236 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/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 new file mode 100644 index 0000000..32ca6b2 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/Makefile.am @@ -0,0 +1,55 @@ +## +## 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. +## + +ACLOCAL_AMFLAGS = "-Im4" + +SUBDIRS = . +DIST_SUBDIRS = . + +AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/../odbc-driver/include -DIGNITE_IMPL +AM_CXXFLAGS = -Wall -std=c++0x + +noinst_PROGRAMS = ignite-odbc-tests + +ignite_odbc_tests_SOURCES = src/teamcity_boost.cpp \ + src/teamcity_messages.cpp \ + src/parser_test.cpp \ + src/cursor_test.cpp \ + src/connection_info_test.cpp \ + src/application_data_buffer_test.cpp \ + src/configuration_test.cpp \ + src/row_test.cpp \ + src/utility_test.cpp \ + ../odbc-driver/src/cursor.cpp \ + ../odbc-driver/src/config/connection_info.cpp \ + ../odbc-driver/src/app/application_data_buffer.cpp \ + ../odbc-driver/src/config/configuration.cpp \ + ../odbc-driver/src/row.cpp \ + ../odbc-driver/src/decimal.cpp \ + ../odbc-driver/src/utility.cpp \ + ../odbc-driver/src/result_page.cpp + +ignite_odbc_tests_LDFLAGS = -static-libtool-libs -L/usr/local/lib -lignite-binary -ldl + +run-check: check + ./ignite-odbc-tests -p + +clean-local: clean-check + $(RM) *.gcno *.gcda + +clean-docs: + $(RM) $(ignite_odbc_tests_OBJECTS) http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/README.TXT ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/README.TXT b/modules/platforms/cpp/odbc-test/README.TXT new file mode 100644 index 0000000..97f4c64 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/README.TXT @@ -0,0 +1 @@ +Contains IDE projects artifacts. http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/configure.ac ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/configure.ac b/modules/platforms/cpp/odbc-test/configure.ac new file mode 100644 index 0000000..abb7adc --- /dev/null +++ b/modules/platforms/cpp/odbc-test/configure.ac @@ -0,0 +1,62 @@ +# +# 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. +# + +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.69]) +AC_INIT([Apache Ignite ODBC Test], [1.5.1.7927], [[email protected]], [ignite], [ignite.apache.org]) +AC_CONFIG_SRCDIR(src) + +AC_CANONICAL_SYSTEM +AC_CONFIG_MACRO_DIR([m4]) +AC_LANG([C++]) + +# Initialize automake +AM_INIT_AUTOMAKE([-Wall foreign subdir-objects]) +AC_CONFIG_HEADER(config.h) + +AM_PROG_AR + +# Checks for programs. +GXX="-g -O2" + +AC_PROG_CXX + +# Initialize Libtool +LT_INIT + +# Checks for libraries. +AC_CHECK_LIB([pthread], [pthread_mutex_lock]) + +# Checks for header files. + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_INLINE +AC_TYPE_INT16_T +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_INT8_T +AC_TYPE_PID_T +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE + +AC_CONFIG_FILES(Makefile) + +AC_OUTPUT http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/include/teamcity_messages.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/teamcity_messages.h b/modules/platforms/cpp/odbc-test/include/teamcity_messages.h new file mode 100644 index 0000000..8cf23d0 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/include/teamcity_messages.h @@ -0,0 +1,55 @@ +/* Copyright 2011 JetBrains s.r.o. + * + * Licensed 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. + * + * $Revision: 88625 $ +*/ + +#ifndef H_TEAMCITY_MESSAGES +#define H_TEAMCITY_MESSAGES + +#include <string> +#include <iostream> + +namespace JetBrains { + +std::string getFlowIdFromEnvironment(); +bool underTeamcity(); + +class TeamcityMessages { + std::ostream *m_out; + +protected: + std::string escape(std::string s); + + void openMsg(const std::string &name); + void writeProperty(std::string name, std::string value); + void closeMsg(); + +public: + TeamcityMessages(); + + void setOutput(std::ostream &); + + void suiteStarted(std::string name, std::string flowid = ""); + void suiteFinished(std::string name, std::string flowid = ""); + + void testStarted(std::string name, std::string flowid = ""); + void testFailed(std::string name, std::string message, std::string details, std::string flowid = ""); + void testIgnored(std::string name, std::string message, std::string flowid = ""); + void testFinished(std::string name, int durationMs = -1, std::string flowid = ""); +}; + +} + +#endif /* H_TEAMCITY_MESSAGES */ http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/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 new file mode 100644 index 0000000..f39e071 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj @@ -0,0 +1,189 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{309BEA40-495D-463F-98D5-4657F03F6D8F}</ProjectGuid> + <RootNamespace>odbctest</RootNamespace> + <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v100</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v100</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v100</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v100</PlatformToolset> + <CharacterSet>MultiByte</CharacterSet> + <WholeProgramOptimization>true</WholeProgramOptimization> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> + <IntDir>$(Platform)\$(Configuration)\</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>Async</ExceptionHandling> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>Async</ExceptionHandling> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-gd-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Console</SubSystem> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>Async</ExceptionHandling> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <AdditionalIncludeDirectories>$(ProjectDir)\..\..\..\common\include;$(ProjectDir)\..\..\..\common\os\win\include;$(ProjectDir)\..\..\src;$(ProjectDir)\..\..\os\win;$(ProjectDir)\..\..\..\binary\include;$(ProjectDir)\..\..\..\binary\os\win\include;$(ProjectDir)\..\..\..\odbc\include;$(ProjectDir)\..\..\include;$(BOOST_HOME)</AdditionalIncludeDirectories> + <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;BOOST_DATE_TIME_NO_LIB;BOOST_REGEX_NO_LIB;IGNITE_IMPL;IGNITE_FRIEND;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ExceptionHandling>Async</ExceptionHandling> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>$(BOOST_HOME)\lib64-msvc-10.0\libboost_unit_test_framework-vc100-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="..\..\..\odbc\src\app\application_data_buffer.cpp" /> + <ClCompile Include="..\..\..\odbc\src\column.cpp" /> + <ClCompile Include="..\..\..\odbc\src\config\configuration.cpp" /> + <ClCompile Include="..\..\..\odbc\src\config\connection_info.cpp" /> + <ClCompile Include="..\..\..\odbc\src\cursor.cpp" /> + <ClCompile Include="..\..\..\odbc\src\decimal.cpp" /> + <ClCompile Include="..\..\..\odbc\src\result_page.cpp" /> + <ClCompile Include="..\..\..\odbc\src\row.cpp" /> + <ClCompile Include="..\..\..\odbc\src\utility.cpp" /> + <ClCompile Include="..\..\src\application_data_buffer_test.cpp" /> + <ClCompile Include="..\..\src\column_test.cpp" /> + <ClCompile Include="..\..\src\configuration_test.cpp" /> + <ClCompile Include="..\..\src\connection_info_test.cpp" /> + <ClCompile Include="..\..\src\cursor_test.cpp" /> + <ClCompile Include="..\..\src\parser_test.cpp" /> + <ClCompile Include="..\..\src\row_test.cpp" /> + <ClCompile Include="..\..\src\teamcity_boost.cpp" /> + <ClCompile Include="..\..\src\teamcity_messages.cpp" /> + <ClCompile Include="..\..\src\utility_test.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\include\teamcity_messages.h" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\binary\project\vs\binary.vcxproj"> + <Project>{4f15669b-92eb-49f0-b774-8f19bae0b960}</Project> + </ProjectReference> + <ProjectReference Include="..\..\..\common\project\vs\common.vcxproj"> + <Project>{4f7e4917-4612-4b96-9838-025711ade391}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/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 new file mode 100644 index 0000000..cf44ba9 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/project/vs/odbc-test.vcxproj.filters @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Code"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Externals"> + <UniqueIdentifier>{cc75fc86-c08d-428a-8ae3-f9979e4588ab}</UniqueIdentifier> + </Filter> + <Filter Include="Code\teamcity"> + <UniqueIdentifier>{5438a56d-1009-412a-86e3-ceb1112af275}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\src\configuration_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\utility.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\src\connection_info_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\src\parser_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\src\teamcity_boost.cpp"> + <Filter>Code\teamcity</Filter> + </ClCompile> + <ClCompile Include="..\..\src\teamcity_messages.cpp"> + <Filter>Code\teamcity</Filter> + </ClCompile> + <ClCompile Include="..\..\src\application_data_buffer_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\src\row_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\row.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\result_page.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\src\cursor_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\cursor.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\src\utility_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\config\configuration.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\config\connection_info.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\app\application_data_buffer.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\decimal.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\..\odbc-driver\src\column.cpp"> + <Filter>Externals</Filter> + </ClCompile> + <ClCompile Include="..\..\src\column_test.cpp"> + <Filter>Code</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="..\..\include\teamcity_messages.h"> + <Filter>Code\teamcity</Filter> + </ClInclude> + </ItemGroup> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/application_data_buffer_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/application_data_buffer_test.cpp b/modules/platforms/cpp/odbc-test/src/application_data_buffer_test.cpp new file mode 100644 index 0000000..632f05f --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/application_data_buffer_test.cpp @@ -0,0 +1,630 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include <ignite/guid.h> +#include <ignite/odbc/decimal.h> +#include <ignite/odbc/app/application_data_buffer.h> + +#define FLOAT_PRECISION 0.0000001f + +using namespace ignite; +using namespace ignite::odbc; +using namespace ignite::odbc::app; +using namespace ignite::odbc::type_traits; + +BOOST_AUTO_TEST_SUITE(ApplicationDataBufferTestSuite) + +BOOST_AUTO_TEST_CASE(TestPutIntToString) +{ + char buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, buffer, sizeof(buffer), &reslen, &offset); + + appBuf.PutInt8(12); + BOOST_REQUIRE(!strcmp(buffer, "12")); + BOOST_REQUIRE(reslen == strlen("12")); + + appBuf.PutInt8(-12); + BOOST_REQUIRE(!strcmp(buffer, "-12")); + BOOST_REQUIRE(reslen == strlen("-12")); + + appBuf.PutInt16(9876); + BOOST_REQUIRE(!strcmp(buffer, "9876")); + BOOST_REQUIRE(reslen == strlen("9876")); + + appBuf.PutInt16(-9876); + BOOST_REQUIRE(!strcmp(buffer, "-9876")); + BOOST_REQUIRE(reslen == strlen("-9876")); + + appBuf.PutInt32(1234567); + BOOST_REQUIRE(!strcmp(buffer, "1234567")); + BOOST_REQUIRE(reslen == strlen("1234567")); + + appBuf.PutInt32(-1234567); + BOOST_REQUIRE(!strcmp(buffer, "-1234567")); + BOOST_REQUIRE(reslen == strlen("-1234567")); +} + +BOOST_AUTO_TEST_CASE(TestPutFloatToString) +{ + char buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, buffer, sizeof(buffer), &reslen, &offset); + + appBuf.PutFloat(12.42f); + BOOST_REQUIRE(!strcmp(buffer, "12.42")); + BOOST_REQUIRE(reslen == strlen("12.42")); + + appBuf.PutFloat(-12.42f); + BOOST_REQUIRE(!strcmp(buffer, "-12.42")); + BOOST_REQUIRE(reslen == strlen("-12.42")); + + appBuf.PutDouble(1000.21); + BOOST_REQUIRE(!strcmp(buffer, "1000.21")); + BOOST_REQUIRE(reslen == strlen("1000.21")); + + appBuf.PutDouble(-1000.21); + BOOST_REQUIRE(!strcmp(buffer, "-1000.21")); + BOOST_REQUIRE(reslen == strlen("-1000.21")); +} + +BOOST_AUTO_TEST_CASE(TestPutGuidToString) +{ + char buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, buffer, sizeof(buffer), &reslen, &offset); + + ignite::Guid guid(0x1da1ef8f39ff4d62ULL, 0x8b72e8e9f3371801ULL); + + appBuf.PutGuid(guid); + + BOOST_REQUIRE(!strcmp(buffer, "1da1ef8f-39ff-4d62-8b72-e8e9f3371801")); + BOOST_REQUIRE(reslen == strlen("1da1ef8f-39ff-4d62-8b72-e8e9f3371801")); +} + +BOOST_AUTO_TEST_CASE(TestPutBinaryToString) +{ + char buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, buffer, sizeof(buffer), &reslen, &offset); + + uint8_t binary[] = { 0x21, 0x84, 0xF4, 0xDC, 0x01, 0x00, 0xFF, 0xF0 }; + + appBuf.PutBinaryData(binary, sizeof(binary)); + + BOOST_REQUIRE(!strcmp(buffer, "2184f4dc0100fff0")); + BOOST_REQUIRE(reslen == strlen("2184f4dc0100fff0")); +} + +BOOST_AUTO_TEST_CASE(TestPutStringToString) +{ + char buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, buffer, sizeof(buffer), &reslen, &offset); + + std::string testString("Test string"); + + appBuf.PutString(testString); + + BOOST_REQUIRE(!strcmp(buffer, testString.c_str())); + BOOST_REQUIRE(reslen == testString.size()); +} + +BOOST_AUTO_TEST_CASE(TestPutStringToWstring) +{ + wchar_t buffer[1024]; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_WCHAR, buffer, sizeof(buffer), &reslen, &offset); + + std::string testString("Test string"); + + appBuf.PutString(testString); + BOOST_REQUIRE(!wcscmp(buffer, L"Test string")); +} + +BOOST_AUTO_TEST_CASE(TestPutStringToLong) +{ + long numBuf; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_LONG, &numBuf, sizeof(numBuf), &reslen, &offset); + + appBuf.PutString("424242424"); + BOOST_REQUIRE(numBuf == 424242424L); + + appBuf.PutString("-424242424"); + BOOST_REQUIRE(numBuf == -424242424L); +} + +BOOST_AUTO_TEST_CASE(TestPutStringToTiny) +{ + int8_t numBuf; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_TINYINT, &numBuf, sizeof(numBuf), &reslen, &offset); + + appBuf.PutString("12"); + BOOST_REQUIRE(numBuf == 12); + + appBuf.PutString("-12"); + BOOST_REQUIRE(numBuf == -12); +} + +BOOST_AUTO_TEST_CASE(TestPutStringToFloat) +{ + float numBuf; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_FLOAT, &numBuf, sizeof(numBuf), &reslen, &offset); + + appBuf.PutString("12.21"); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 12.21, FLOAT_PRECISION); + + appBuf.PutString("-12.21"); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -12.21, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestPutIntToFloat) +{ + float numBuf; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_FLOAT, &numBuf, sizeof(numBuf), &reslen, &offset); + + appBuf.PutInt8(5); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 5.0, FLOAT_PRECISION); + + appBuf.PutInt8(-5); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -5.0, FLOAT_PRECISION); + + appBuf.PutInt16(4242); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 4242.0, FLOAT_PRECISION); + + appBuf.PutInt16(-4242); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -4242.0, FLOAT_PRECISION); + + appBuf.PutInt32(1234567); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 1234567.0, FLOAT_PRECISION); + + appBuf.PutInt32(-1234567); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -1234567.0, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestPutFloatToShort) +{ + short numBuf; + SqlLen reslen; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_SHORT, &numBuf, sizeof(numBuf), &reslen, &offset); + + appBuf.PutDouble(5.42); + BOOST_REQUIRE(numBuf == 5); + + appBuf.PutDouble(-5.42); + BOOST_REQUIRE(numBuf == -5.0); + + appBuf.PutFloat(42.99f); + BOOST_REQUIRE(numBuf == 42); + + appBuf.PutFloat(-42.99f); + BOOST_REQUIRE(numBuf == -42); +} + +BOOST_AUTO_TEST_CASE(TestPutDecimalToDouble) +{ + double numBuf; + SqlLen reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_DOUBLE, &numBuf, sizeof(numBuf), &reslen, 0); + + Decimal decimal; + + BOOST_REQUIRE_CLOSE_FRACTION(static_cast<double>(decimal), 0.0, FLOAT_PRECISION); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 0.0, FLOAT_PRECISION); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, 256.0, FLOAT_PRECISION); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE_CLOSE_FRACTION(numBuf, -53.5, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestPutDecimalToLong) +{ + long numBuf; + SqlLen reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_LONG, &numBuf, sizeof(numBuf), &reslen, 0); + + Decimal decimal; + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == 0); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == 256); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(numBuf == -53); +} + +BOOST_AUTO_TEST_CASE(TestPutDecimalToString) +{ + char strBuf[64]; + SqlLen reslen; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &strBuf, sizeof(strBuf), &reslen, 0); + + Decimal decimal; + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "0"); + + int8_t mag1[] = { 1, 0 }; + + decimal = Decimal(0, mag1, sizeof(mag1)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "256"); + + int8_t mag2[] = { 2, 23 }; + + decimal = Decimal(1 | 0x80000000, mag2, sizeof(mag2)); + + appBuf.PutDecimal(decimal); + BOOST_REQUIRE(std::string(strBuf, reslen) == "-53.5"); +} + +BOOST_AUTO_TEST_CASE(TestGetStringFromLong) +{ + long numBuf = 42; + SqlLen reslen = sizeof(numBuf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_SIGNED_LONG, &numBuf, reslen, &reslen, &offset); + + std::string res = appBuf.GetString(32); + + BOOST_REQUIRE(res == "42"); + + numBuf = -77; + + res = appBuf.GetString(32); + + BOOST_REQUIRE(res == "-77"); +} + +BOOST_AUTO_TEST_CASE(TestGetStringFromDouble) +{ + double numBuf = 43.36; + SqlLen reslen = sizeof(numBuf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_DOUBLE, &numBuf, reslen, &reslen, &offset); + + std::string res = appBuf.GetString(32); + + BOOST_REQUIRE(res == "43.36"); + + numBuf = -58.91; + + res = appBuf.GetString(32); + + BOOST_REQUIRE(res == "-58.91"); +} + +BOOST_AUTO_TEST_CASE(TestGetStringFromString) +{ + char buf[] = "Some data 32d2d5hs"; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &buf, reslen, &reslen, &offset); + + std::string res = appBuf.GetString(reslen); + + BOOST_REQUIRE(res.compare(buf)); +} + +BOOST_AUTO_TEST_CASE(TestGetFloatFromUshort) +{ + unsigned short numBuf = 7162; + SqlLen reslen = sizeof(numBuf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_UNSIGNED_SHORT, &numBuf, reslen, &reslen, &offset); + + float resFloat = appBuf.GetFloat(); + + BOOST_REQUIRE_CLOSE_FRACTION(resFloat, 7162.0f, FLOAT_PRECISION); + + double resDouble = appBuf.GetDouble(); + + BOOST_REQUIRE_CLOSE_FRACTION(resDouble, 7162.0, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestGetFloatFromString) +{ + char buf[] = "28.562"; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &buf, reslen, &reslen, &offset); + + float resFloat = appBuf.GetFloat(); + + BOOST_REQUIRE_CLOSE_FRACTION(resFloat, 28.562f, FLOAT_PRECISION); + + double resDouble = appBuf.GetDouble(); + + BOOST_REQUIRE_CLOSE_FRACTION(resDouble, 28.562, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestGetFloatFromFloat) +{ + float buf = 207.49f; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_FLOAT, &buf, reslen, &reslen, &offset); + + float resFloat = appBuf.GetFloat(); + + BOOST_REQUIRE_CLOSE_FRACTION(resFloat, 207.49f, FLOAT_PRECISION); + + double resDouble = appBuf.GetDouble(); + + BOOST_REQUIRE_CLOSE_FRACTION(resDouble, 207.49, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestGetFloatFromDouble) +{ + double buf = 893.162; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_DOUBLE, &buf, reslen, &reslen, &offset); + + float resFloat = appBuf.GetFloat(); + + BOOST_REQUIRE_CLOSE_FRACTION(resFloat, 893.162f, FLOAT_PRECISION); + + double resDouble = appBuf.GetDouble(); + + BOOST_REQUIRE_CLOSE_FRACTION(resDouble, 893.162, FLOAT_PRECISION); +} + +BOOST_AUTO_TEST_CASE(TestGetIntFromString) +{ + char buf[] = "39"; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &buf, reslen, &reslen, &offset); + + int64_t resInt64 = appBuf.GetInt64(); + + BOOST_REQUIRE(resInt64 == 39); + + int32_t resInt32 = appBuf.GetInt32(); + + BOOST_REQUIRE(resInt32 == 39); + + int16_t resInt16 = appBuf.GetInt16(); + + BOOST_REQUIRE(resInt16 == 39); + + int8_t resInt8 = appBuf.GetInt8(); + + BOOST_REQUIRE(resInt8 == 39); +} + +BOOST_AUTO_TEST_CASE(TestGetIntFromFloat) +{ + float buf = -107.49f; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_FLOAT, &buf, reslen, &reslen, &offset); + + int64_t resInt64 = appBuf.GetInt64(); + + BOOST_REQUIRE(resInt64 == -107); + + int32_t resInt32 = appBuf.GetInt32(); + + BOOST_REQUIRE(resInt32 == -107); + + int16_t resInt16 = appBuf.GetInt16(); + + BOOST_REQUIRE(resInt16 == -107); + + int8_t resInt8 = appBuf.GetInt8(); + + BOOST_REQUIRE(resInt8 == -107); +} + +BOOST_AUTO_TEST_CASE(TestGetIntFromDouble) +{ + double buf = 42.97f; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_DOUBLE, &buf, reslen, &reslen, &offset); + + int64_t resInt64 = appBuf.GetInt64(); + + BOOST_REQUIRE(resInt64 == 42); + + int32_t resInt32 = appBuf.GetInt32(); + + BOOST_REQUIRE(resInt32 == 42); + + int16_t resInt16 = appBuf.GetInt16(); + + BOOST_REQUIRE(resInt16 == 42); + + int8_t resInt8 = appBuf.GetInt8(); + + BOOST_REQUIRE(resInt8 == 42); +} + +BOOST_AUTO_TEST_CASE(TestGetIntFromBigint) +{ + uint64_t buf = 19; + SqlLen reslen = sizeof(buf); + size_t* offset = 0; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_UNSIGNED_BIGINT, &buf, reslen, &reslen, &offset); + + int64_t resInt64 = appBuf.GetInt64(); + + BOOST_REQUIRE(resInt64 == 19); + + int32_t resInt32 = appBuf.GetInt32(); + + BOOST_REQUIRE(resInt32 == 19); + + int16_t resInt16 = appBuf.GetInt16(); + + BOOST_REQUIRE(resInt16 == 19); + + int8_t resInt8 = appBuf.GetInt8(); + + BOOST_REQUIRE(resInt8 == 19); +} + +BOOST_AUTO_TEST_CASE(TestGetIntWithOffset) +{ + struct TestStruct + { + uint64_t val; + SqlLen reslen; + }; + + TestStruct buf[2] = { + { 12, sizeof(uint64_t) }, + { 42, sizeof(uint64_t) } + }; + + size_t offset = 0; + size_t* offsetPtr = &offset; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_UNSIGNED_BIGINT, &buf[0].val, sizeof(buf[0].val), &buf[0].reslen, &offsetPtr); + + int64_t val = appBuf.GetInt64(); + + BOOST_REQUIRE(val == 12); + + offset += sizeof(TestStruct); + + val = appBuf.GetInt64(); + + BOOST_REQUIRE(val == 42); + + offsetPtr = 0; + + val = appBuf.GetInt64(); + + BOOST_REQUIRE(val == 12); +} + +BOOST_AUTO_TEST_CASE(TestSetStringWithOffset) +{ + struct TestStruct + { + char val[64]; + SqlLen reslen; + }; + + TestStruct buf[2] = { + { "", 0 }, + { "", 0 } + }; + + size_t offset = 0; + size_t* offsetPtr = &offset; + + ApplicationDataBuffer appBuf(IGNITE_ODBC_C_TYPE_CHAR, &buf[0].val, sizeof(buf[0].val), &buf[0].reslen, &offsetPtr); + + appBuf.PutString("Hello Ignite!"); + + std::string res(buf[0].val, buf[0].reslen); + + BOOST_REQUIRE(buf[0].reslen == strlen("Hello Ignite!")); + BOOST_REQUIRE(res == "Hello Ignite!"); + BOOST_REQUIRE(res.size() == strlen("Hello Ignite!")); + + offset += sizeof(TestStruct); + + appBuf.PutString("Hello with offset!"); + + res.assign(buf[0].val, buf[0].reslen); + + BOOST_REQUIRE(res == "Hello Ignite!"); + BOOST_REQUIRE(res.size() == strlen("Hello Ignite!")); + BOOST_REQUIRE(buf[0].reslen == strlen("Hello Ignite!")); + + res.assign(buf[1].val, buf[1].reslen); + + BOOST_REQUIRE(res == "Hello with offset!"); + BOOST_REQUIRE(res.size() == strlen("Hello with offset!")); + BOOST_REQUIRE(buf[1].reslen == strlen("Hello with offset!")); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/column_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/column_test.cpp b/modules/platforms/cpp/odbc-test/src/column_test.cpp new file mode 100644 index 0000000..4864a6a --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/column_test.cpp @@ -0,0 +1,290 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include <ignite/impl/binary/binary_common.h> +#include <ignite/impl/binary/binary_writer_impl.h> + +#include "ignite/odbc/system/odbc_constants.h" +#include "ignite/odbc/column.h" + +using namespace ignite::impl::binary; +using namespace ignite::odbc::app; +using namespace ignite::odbc; + +BOOST_AUTO_TEST_SUITE(ColumnTestSuite) + +BOOST_AUTO_TEST_CASE(TestColumnDefaultConstruction) +{ + Column column; + + BOOST_REQUIRE(!column.IsValid()); +} + +BOOST_AUTO_TEST_CASE(TestColumnShort) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + ignite::impl::interop::InteropOutputStream outStream(&mem); + ignite::impl::binary::BinaryWriterImpl writer(&outStream, 0); + + int16_t data = 42; + + writer.WriteInt8(IGNITE_TYPE_SHORT); + writer.WriteInt16(data); + + outStream.Synchronize(); + + ignite::impl::interop::InteropInputStream inStream(&mem); + ignite::impl::binary::BinaryReaderImpl reader(&inStream); + + Column column(reader); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == 2); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 2); + + short shortBuf = 0; + SqlLen reslen = 0; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(type_traits::IGNITE_ODBC_C_TYPE_SIGNED_SHORT, &shortBuf, sizeof(shortBuf), &reslen, &offset); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == 2); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(shortBuf == data); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_NO_DATA); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == 2); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); +} + +BOOST_AUTO_TEST_CASE(TestColumnString) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + ignite::impl::interop::InteropOutputStream outStream(&mem); + ignite::impl::binary::BinaryWriterImpl writer(&outStream, 0); + + std::string data("Some test data."); + + writer.WriteString(data.data(), static_cast<int32_t>(data.size())); + + outStream.Synchronize(); + + ignite::impl::interop::InteropInputStream inStream(&mem); + ignite::impl::binary::BinaryReaderImpl reader(&inStream); + + Column column(reader); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == data.size()); + + char strBuf[1024] = {}; + SqlLen reslen = 0; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(type_traits::IGNITE_ODBC_C_TYPE_CHAR, &strBuf, sizeof(strBuf), &reslen, &offset); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(std::string(strBuf) == data); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_NO_DATA); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); +} + +BOOST_AUTO_TEST_CASE(TestColumnStringSeveral) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + ignite::impl::interop::InteropOutputStream outStream(&mem); + ignite::impl::binary::BinaryWriterImpl writer(&outStream, 0); + + std::string data("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + + writer.WriteString(data.data(), static_cast<int32_t>(data.size())); + + outStream.Synchronize(); + + ignite::impl::interop::InteropInputStream inStream(&mem); + ignite::impl::binary::BinaryReaderImpl reader(&inStream); + + Column column(reader); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == data.size()); + + std::string res; + + std::string strBuf(data.size() / 3 + 2, 0); + SqlLen reslen = 0; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(type_traits::IGNITE_ODBC_C_TYPE_CHAR, &strBuf[0], strBuf.size(), &reslen, &offset); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == data.size() - (strBuf.size() - 1)); + + res.append(strBuf.c_str()); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == data.size() - 2 * (strBuf.size() - 1)); + + res.append(strBuf.c_str()); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); + + res.append(strBuf.c_str()); + + BOOST_REQUIRE(column.ReadToBuffer(reader, appBuf) == SQL_RESULT_NO_DATA); + + BOOST_REQUIRE(column.IsValid()); + + BOOST_REQUIRE(column.GetSize() == data.size()); + + BOOST_REQUIRE(column.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(res == data); +} + +BOOST_AUTO_TEST_CASE(TestColumnMultiString) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + ignite::impl::interop::InteropOutputStream outStream(&mem); + ignite::impl::binary::BinaryWriterImpl writer(&outStream, 0); + + std::string data1("Some test data."); + std::string data2("Other TEST DATA."); + + writer.WriteString(data1.data(), static_cast<int32_t>(data1.size())); + writer.WriteString(data2.data(), static_cast<int32_t>(data2.size())); + + outStream.Synchronize(); + + ignite::impl::interop::InteropInputStream inStream(&mem); + ignite::impl::binary::BinaryReaderImpl reader(&inStream); + + Column column1(reader); + + inStream.Position(column1.GetEndPosition()); + + Column column2(reader); + + BOOST_REQUIRE(column1.IsValid()); + + BOOST_REQUIRE(column1.GetSize() == data1.size()); + + BOOST_REQUIRE(column1.GetUnreadDataLength() == data1.size()); + + BOOST_REQUIRE(column2.IsValid()); + + BOOST_REQUIRE(column2.GetSize() == data2.size()); + + BOOST_REQUIRE(column2.GetUnreadDataLength() == data2.size()); + + char strBuf[1024] = {}; + SqlLen reslen = 0; + size_t* offset = 0; + + ApplicationDataBuffer appBuf(type_traits::IGNITE_ODBC_C_TYPE_CHAR, &strBuf, sizeof(strBuf), &reslen, &offset); + + BOOST_REQUIRE(column1.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column1.IsValid()); + + BOOST_REQUIRE(column1.GetSize() == data1.size()); + + BOOST_REQUIRE(column1.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(std::string(strBuf) == data1); + + BOOST_REQUIRE(column1.ReadToBuffer(reader, appBuf) == SQL_RESULT_NO_DATA); + + BOOST_REQUIRE(column1.IsValid()); + + BOOST_REQUIRE(column1.GetSize() == data1.size()); + + BOOST_REQUIRE(column1.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(column2.ReadToBuffer(reader, appBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(column2.IsValid()); + + BOOST_REQUIRE(column2.GetSize() == data2.size()); + + BOOST_REQUIRE(column2.GetUnreadDataLength() == 0); + + BOOST_REQUIRE(std::string(strBuf) == data2); + + BOOST_REQUIRE(column2.ReadToBuffer(reader, appBuf) == SQL_RESULT_NO_DATA); + + BOOST_REQUIRE(column2.IsValid()); + + BOOST_REQUIRE(column2.GetSize() == data2.size()); + + BOOST_REQUIRE(column2.GetUnreadDataLength() == 0); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/configuration_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/configuration_test.cpp b/modules/platforms/cpp/odbc-test/src/configuration_test.cpp new file mode 100644 index 0000000..fba46cc --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/configuration_test.cpp @@ -0,0 +1,206 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <iostream> + +#include <boost/test/unit_test.hpp> + +#include <ignite/odbc/config/configuration.h> + +using namespace ignite::odbc::config; + +namespace +{ + const char* testDriverName = "Ignite"; + const char* testServerHost = "testhost.com"; + const uint16_t testServerPort = 4242; + const char* testCacheName = "TestCache"; + const char* testDsn = "Ignite DSN"; +} + +BOOST_AUTO_TEST_SUITE(ConfigurationTestSuite) + +void CheckConnectionConfig(const Configuration& cfg) +{ + BOOST_REQUIRE(cfg.GetDriver() == testDriverName); + BOOST_REQUIRE(cfg.GetHost() == testServerHost); + BOOST_REQUIRE(cfg.GetPort() == testServerPort); + BOOST_REQUIRE(cfg.GetCache() == testCacheName); + BOOST_REQUIRE(cfg.GetDsn().empty()); + + std::stringstream constructor; + + constructor << "driver={" << testDriverName << "};" + << "server=" << testServerHost << ";" + << "port=" << testServerPort << ";" + << "cache=" << testCacheName << ";"; + + const std::string& expectedStr = constructor.str(); + + BOOST_REQUIRE(cfg.ToConnectString() == expectedStr); +} + +void CheckDsnConfig(const Configuration& cfg) +{ + BOOST_REQUIRE(cfg.GetDriver() == testDriverName); + BOOST_REQUIRE(cfg.GetDsn() == testDsn); + BOOST_REQUIRE(cfg.GetHost().empty()); + BOOST_REQUIRE(cfg.GetCache().empty()); + BOOST_REQUIRE(cfg.GetPort() == 0); +} + +BOOST_AUTO_TEST_CASE(TestConnectStringUppercase) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "DRIVER={" << testDriverName << "};" + << "SERVER=" << testServerHost <<";" + << "PORT=" << testServerPort << ";" + << "CACHE=" << testCacheName; + + const std::string& connectStr = constructor.str(); + + cfg.FillFromConnectString(connectStr.c_str(), connectStr.size()); + + CheckConnectionConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestConnectStringLowercase) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "driver={" << testDriverName << "};" + << "server=" << testServerHost << ";" + << "port=" << testServerPort << ";" + << "cache=" << testCacheName; + + const std::string& connectStr = constructor.str(); + + cfg.FillFromConnectString(connectStr.c_str(), connectStr.size()); + + CheckConnectionConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestConnectStringMixed) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "Driver={" << testDriverName << "};" + << "Server=" << testServerHost << ";" + << "Port=" << testServerPort << ";" + << "Cache=" << testCacheName; + + const std::string& connectStr = constructor.str(); + + cfg.FillFromConnectString(connectStr.c_str(), connectStr.size()); + + CheckConnectionConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestConnectStringWhitepaces) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "DRIVER = {" << testDriverName << "} ;\n" + << " SERVER =" << testServerHost << " ; \n" + << "PORT= " << testServerPort << "; " + << "CACHE = \n\r" << testCacheName; + + const std::string& connectStr = constructor.str(); + + cfg.FillFromConnectString(connectStr.c_str(), connectStr.size()); + + CheckConnectionConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestDsnStringUppercase) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "DRIVER=" << testDriverName << '\0' + << "DSN={" << testDsn << "}" << '\0' << '\0'; + + const std::string& configStr = constructor.str(); + + cfg.FillFromConfigAttributes(configStr.data()); + + CheckDsnConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestDsnStrinLowercase) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "driver=" << testDriverName << '\0' + << "dsn={" << testDsn << "}" << '\0' << '\0'; + + const std::string& configStr = constructor.str(); + + cfg.FillFromConfigAttributes(configStr.data()); + + CheckDsnConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestDsnStrinMixed) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << "Driver=" << testDriverName << '\0' + << "Dsn={" << testDsn << "}" << '\0' << '\0'; + + const std::string& configStr = constructor.str(); + + cfg.FillFromConfigAttributes(configStr.data()); + + CheckDsnConfig(cfg); +} + +BOOST_AUTO_TEST_CASE(TestDsnStrinWhitespaces) +{ + Configuration cfg; + + std::stringstream constructor; + + constructor << " DRIVER = " << testDriverName << "\r\n" << '\0' + << "DSN= {" << testDsn << "} \n" << '\0' << '\0'; + + const std::string& configStr = constructor.str(); + + cfg.FillFromConfigAttributes(configStr.data()); + + CheckDsnConfig(cfg); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/connection_info_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/connection_info_test.cpp b/modules/platforms/cpp/odbc-test/src/connection_info_test.cpp new file mode 100644 index 0000000..dd8d1f6 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/connection_info_test.cpp @@ -0,0 +1,219 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <iostream> + +#include <boost/test/unit_test.hpp> + +#include "ignite/odbc/system/odbc_constants.h" +#include "ignite/odbc/config/connection_info.h" + +using namespace ignite::odbc; +using namespace ignite::odbc::config; + +BOOST_AUTO_TEST_SUITE(ConnectionInfoTestSuite) + +BOOST_AUTO_TEST_CASE(TestConnectionInfoSupportedInfo) +{ + char buffer[4096]; + short reslen = 0; + + ConnectionInfo info; + + SqlResult result; + +#ifdef SQL_DRIVER_NAME + result = info.GetInfo(SQL_DRIVER_NAME, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DRIVER_NAME + +#ifdef SQL_DBMS_NAME + result = info.GetInfo(SQL_DBMS_NAME, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DBMS_NAME + +#ifdef SQL_DRIVER_ODBC_VER + result = info.GetInfo(SQL_DRIVER_ODBC_VER, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DRIVER_ODBC_VER + +#ifdef SQL_DBMS_VER + result = info.GetInfo(SQL_DBMS_VER, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DBMS_VER + +#ifdef SQL_DRIVER_VER + result = info.GetInfo(SQL_DRIVER_VER, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DRIVER_VER + +#ifdef SQL_COLUMN_ALIAS + result = info.GetInfo(SQL_COLUMN_ALIAS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_COLUMN_ALIAS + +#ifdef SQL_IDENTIFIER_QUOTE_CHAR + result = info.GetInfo(SQL_IDENTIFIER_QUOTE_CHAR, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_IDENTIFIER_QUOTE_CHAR + +#ifdef SQL_CATALOG_NAME_SEPARATOR + result = info.GetInfo(SQL_CATALOG_NAME_SEPARATOR, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CATALOG_NAME_SEPARATOR + +#ifdef SQL_SPECIAL_CHARACTERS + result = info.GetInfo(SQL_SPECIAL_CHARACTERS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_SPECIAL_CHARACTERS + +#ifdef SQL_CATALOG_TERM + result = info.GetInfo(SQL_CATALOG_TERM, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CATALOG_TERM + +#ifdef SQL_TABLE_TERM + result = info.GetInfo(SQL_TABLE_TERM, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_TABLE_TERM + +#ifdef SQL_SCHEMA_TERM + result = info.GetInfo(SQL_SCHEMA_TERM, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_SCHEMA_TERM + +#ifdef SQL_ASYNC_DBC_FUNCTIONS + result = info.GetInfo(SQL_ASYNC_DBC_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_ASYNC_DBC_FUNCTIONS + +#ifdef SQL_GETDATA_EXTENSIONS + result = info.GetInfo(SQL_GETDATA_EXTENSIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_GETDATA_EXTENSIONS + +#ifdef SQL_ODBC_INTERFACE_CONFORMANCE + result = info.GetInfo(SQL_ODBC_INTERFACE_CONFORMANCE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_ODBC_INTERFACE_CONFORMANCE + +#ifdef SQL_SQL_CONFORMANCE + result = info.GetInfo(SQL_SQL_CONFORMANCE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_SQL_CONFORMANCE + +#ifdef SQL_CATALOG_USAGE + result = info.GetInfo(SQL_CATALOG_USAGE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CATALOG_USAGE + +#ifdef SQL_SCHEMA_USAGE + result = info.GetInfo(SQL_SCHEMA_USAGE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_SCHEMA_USAGE + +#ifdef SQL_MAX_IDENTIFIER_LEN + result = info.GetInfo(SQL_MAX_IDENTIFIER_LEN, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_MAX_IDENTIFIER_LEN + +#ifdef SQL_AGGREGATE_FUNCTIONS + result = info.GetInfo(SQL_AGGREGATE_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_AGGREGATE_FUNCTIONS + +#ifdef SQL_AGGREGATE_FUNCTIONS + result = info.GetInfo(SQL_NUMERIC_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_AGGREGATE_FUNCTIONS + +#ifdef SQL_STRING_FUNCTIONS + result = info.GetInfo(SQL_STRING_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_STRING_FUNCTIONS + +#ifdef SQL_TIMEDATE_FUNCTIONS + result = info.GetInfo(SQL_TIMEDATE_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_TIMEDATE_FUNCTIONS + +#ifdef SQL_TIMEDATE_ADD_INTERVALS + result = info.GetInfo(SQL_TIMEDATE_ADD_INTERVALS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_TIMEDATE_ADD_INTERVALS + +#ifdef SQL_TIMEDATE_DIFF_INTERVALS + result = info.GetInfo(SQL_TIMEDATE_DIFF_INTERVALS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_TIMEDATE_DIFF_INTERVALS + +#ifdef SQL_DATETIME_LITERALS + result = info.GetInfo(SQL_DATETIME_LITERALS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_DATETIME_LITERALS + +#ifdef SQL_SYSTEM_FUNCTIONS + result = info.GetInfo(SQL_SYSTEM_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_SYSTEM_FUNCTIONS + +#ifdef SQL_CONVERT_FUNCTIONS + result = info.GetInfo(SQL_CONVERT_FUNCTIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CONVERT_FUNCTIONS + +#ifdef SQL_OJ_CAPABILITIES + result = info.GetInfo(SQL_OJ_CAPABILITIES, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_OJ_CAPABILITIES + +#ifdef SQL_POS_OPERATIONS + result = info.GetInfo(SQL_POS_OPERATIONS, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_POS_OPERATIONS + +#ifdef SQL_MAX_CONCURRENT_ACTIVITIES + result = info.GetInfo(SQL_MAX_CONCURRENT_ACTIVITIES, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_MAX_CONCURRENT_ACTIVITIES + +#ifdef SQL_CURSOR_COMMIT_BEHAVIOR + result = info.GetInfo(SQL_CURSOR_COMMIT_BEHAVIOR, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CURSOR_COMMIT_BEHAVIOR + +#ifdef SQL_CURSOR_ROLLBACK_BEHAVIOR + result = info.GetInfo(SQL_CURSOR_ROLLBACK_BEHAVIOR, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_CURSOR_ROLLBACK_BEHAVIOR + +#ifdef SQL_TXN_CAPABLE + result = info.GetInfo(SQL_TXN_CAPABLE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_TXN_CAPABLE + +#ifdef SQL_QUOTED_IDENTIFIER_CASE + result = info.GetInfo(SQL_QUOTED_IDENTIFIER_CASE, buffer, sizeof(buffer), &reslen); + BOOST_REQUIRE(result == SQL_RESULT_SUCCESS); +#endif //SQL_QUOTED_IDENTIFIER_CASE +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/cursor_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/cursor_test.cpp b/modules/platforms/cpp/odbc-test/src/cursor_test.cpp new file mode 100644 index 0000000..af841e7 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/cursor_test.cpp @@ -0,0 +1,166 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include <ignite/impl/binary/binary_writer_impl.h> + +#include "ignite/odbc/system/odbc_constants.h" +#include "ignite/odbc/cursor.h" + +using namespace ignite::odbc; + +const int64_t testQueryId = 42; + +std::auto_ptr<ResultPage> CreateTestPage(bool last, int32_t size) +{ + using namespace ignite::impl::binary; + using namespace ignite::impl::interop; + + ignite::impl::interop::InteropUnpooledMemory mem(1024); + InteropOutputStream outStream(&mem); + BinaryWriterImpl writer(&outStream, 0); + + // Last page flag. + writer.WriteBool(last); + + //Page size. + writer.WriteInt32(size); + + for (int32_t i = 0; i < size; ++i) + { + // Writing row size = 1 column. + writer.WriteInt32(1); + + // Writing column type. + writer.WriteInt8(IGNITE_TYPE_INT); + + // Column value. + writer.WriteInt32(i); + } + + outStream.Synchronize(); + + std::auto_ptr<ResultPage> res(new ResultPage()); + + InteropInputStream inStream(&mem); + BinaryReaderImpl reader(&inStream); + + res->Read(reader); + + BOOST_REQUIRE(res->GetSize() == size); + BOOST_REQUIRE(res->IsLast() == last); + + return res; +} + +void CheckCursorNeedUpdate(Cursor& cursor) +{ + BOOST_REQUIRE(cursor.NeedDataUpdate()); + + BOOST_REQUIRE(cursor.HasNext()); + + BOOST_REQUIRE(!cursor.Increment()); +} + +void CheckCursorReady(Cursor& cursor) +{ + BOOST_REQUIRE(!cursor.NeedDataUpdate()); + + BOOST_REQUIRE(cursor.HasNext()); + + BOOST_REQUIRE(cursor.GetRow()); +} + +void CheckCursorEnd(Cursor& cursor) +{ + BOOST_REQUIRE(!cursor.NeedDataUpdate()); + + BOOST_REQUIRE(!cursor.HasNext()); + + BOOST_REQUIRE(!cursor.Increment()); + + BOOST_REQUIRE(cursor.GetRow()); +} + +BOOST_AUTO_TEST_SUITE(CursorTestSuite) + +BOOST_AUTO_TEST_CASE(TestCursorEmpty) +{ + Cursor cursor(testQueryId); + + BOOST_REQUIRE(cursor.GetQueryId() == testQueryId); + + CheckCursorNeedUpdate(cursor); +} + +BOOST_AUTO_TEST_CASE(TestCursorLast) +{ + const int32_t pageSize = 16; + + Cursor cursor(testQueryId); + + std::auto_ptr<ResultPage> resultPage = CreateTestPage(true, pageSize); + + cursor.UpdateData(resultPage); + + BOOST_REQUIRE(cursor.GetQueryId() == testQueryId); + + CheckCursorReady(cursor); + + for (int32_t i = 0; i < pageSize - 1; ++i) + BOOST_REQUIRE(cursor.Increment()); + + CheckCursorEnd(cursor); +} + +BOOST_AUTO_TEST_CASE(TestCursorUpdate) +{ + const int32_t pageSize = 16; + + Cursor cursor(testQueryId); + + std::auto_ptr<ResultPage> resultPage = CreateTestPage(false, pageSize); + + cursor.UpdateData(resultPage); + + BOOST_REQUIRE(cursor.GetQueryId() == testQueryId); + + CheckCursorReady(cursor); + + for (int32_t i = 0; i < pageSize - 1; ++i) + BOOST_REQUIRE(cursor.Increment()); + + CheckCursorNeedUpdate(cursor); + + resultPage = CreateTestPage(true, pageSize); + + cursor.UpdateData(resultPage); + + CheckCursorReady(cursor); + + for (int32_t i = 0; i < pageSize - 1; ++i) + BOOST_REQUIRE(cursor.Increment()); + + CheckCursorEnd(cursor); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/parser_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/parser_test.cpp b/modules/platforms/cpp/odbc-test/src/parser_test.cpp new file mode 100644 index 0000000..ad8a5b4 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/parser_test.cpp @@ -0,0 +1,94 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include <ignite/odbc/parser.h> + +using namespace ignite::odbc; + +struct TestMessage +{ + TestMessage() + { + // No-op. + } + + TestMessage(int32_t a, const std::string& b) : a(a), b(b) + { + // No-op. + } + + ~TestMessage() + { + // No-op. + } + + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt32(a); + writer.WriteString(b.data(), static_cast<int32_t>(b.size())); + } + + void Read(ignite::impl::binary::BinaryReaderImpl& reader) + { + a = reader.ReadInt32(); + + b.resize(reader.ReadString(0, 0)); + reader.ReadString(&b[0], static_cast<int32_t>(b.size())); + } + + int32_t a; + std::string b; +}; + +bool operator==(const TestMessage& lhs, const TestMessage& rhs) +{ + return lhs.a == rhs.a && + lhs.b == rhs.b; +} + +BOOST_AUTO_TEST_SUITE(ParserTestSuite) + +BOOST_AUTO_TEST_CASE(TestParserEncodeDecode) +{ + Parser parser; + + std::vector<int8_t> outBuffer; + std::vector<int8_t> inBuffer; + + TestMessage outMsg(42, "Test message"); + TestMessage inMsg; + + parser.Encode(outMsg, outBuffer); + + inBuffer.reserve(outBuffer.size()); + + // First 4 bytes contain message size after encoding but are not expected + // during decoding. + std::copy(outBuffer.begin() + 4, outBuffer.end(), std::back_inserter(inBuffer)); + + parser.Decode(inMsg, inBuffer); + + BOOST_REQUIRE(outMsg == inMsg); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/e8287063/modules/platforms/cpp/odbc-test/src/row_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/src/row_test.cpp b/modules/platforms/cpp/odbc-test/src/row_test.cpp new file mode 100644 index 0000000..e655cf7 --- /dev/null +++ b/modules/platforms/cpp/odbc-test/src/row_test.cpp @@ -0,0 +1,167 @@ +/* + * 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. + */ + +#ifndef _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include <ignite/impl/binary/binary_writer_impl.h> + +#include "ignite/odbc/system/odbc_constants.h" +#include "ignite/odbc/row.h" + +using namespace ignite::odbc::app; +using namespace ignite::odbc; + + +std::string GetStrColumnValue(size_t rowIdx) +{ + std::stringstream generator("Column 2 test string, row num: "); + generator << rowIdx << ". Some trailing bytes"; + + return generator.str(); +} + +void FillMemWithData(ignite::impl::interop::InteropUnpooledMemory& mem, size_t rowNum) +{ + using namespace ignite::impl::binary; + using namespace ignite::impl::interop; + + InteropOutputStream stream(&mem); + BinaryWriterImpl writer(&stream, 0); + + for (size_t i = 0; i < rowNum; ++i) + { + // Number of columns in page. + writer.WriteInt32(4); + + // First column is int. + writer.WriteInt8(IGNITE_TYPE_LONG); + writer.WriteInt64(static_cast<int64_t>(i * 10)); + + // Second column is string. + const std::string& str(GetStrColumnValue(i)); + + writer.WriteString(str.data(), static_cast<int32_t>(str.size())); + + // Third column is GUID. + ignite::Guid guid(0x2b218f63642a4a64ULL, 0x9674098f388ac298ULL + i); + + writer.WriteGuid(guid); + + // The last column is bool. + writer.WriteInt8(IGNITE_TYPE_BOOL); + writer.WriteBool(i % 2 == 1); + } + + stream.Synchronize(); +} + +void CheckRowData(Row& row, size_t rowIdx) +{ + SqlLen reslen; + + long longBuf; + char strBuf[1024]; + SQLGUID guidBuf; + char bitBuf; + size_t* offset = 0; + + ApplicationDataBuffer appLongBuf(type_traits::IGNITE_ODBC_C_TYPE_SIGNED_LONG, &longBuf, sizeof(longBuf), &reslen, &offset); + ApplicationDataBuffer appStrBuf(type_traits::IGNITE_ODBC_C_TYPE_CHAR, &strBuf, sizeof(strBuf), &reslen, &offset); + ApplicationDataBuffer appGuidBuf(type_traits::IGNITE_ODBC_C_TYPE_GUID, &guidBuf, sizeof(guidBuf), &reslen, &offset); + ApplicationDataBuffer appBitBuf(type_traits::IGNITE_ODBC_C_TYPE_BIT, &bitBuf, sizeof(bitBuf), &reslen, &offset); + + // Checking size. + BOOST_REQUIRE(row.GetSize() == 4); + + // Checking 1st column. + BOOST_REQUIRE(row.ReadColumnToBuffer(1, appLongBuf) == SQL_RESULT_SUCCESS); + BOOST_REQUIRE(longBuf == rowIdx * 10); + + // Checking 2nd column. + BOOST_REQUIRE(row.ReadColumnToBuffer(2, appStrBuf) == SQL_RESULT_SUCCESS); + + std::string strReal(strBuf, static_cast<size_t>(reslen)); + std::string strExpected(GetStrColumnValue(rowIdx)); + + BOOST_REQUIRE(strReal == strExpected); + + // Checking 3rd column. + BOOST_REQUIRE(row.ReadColumnToBuffer(3, appGuidBuf) == SQL_RESULT_SUCCESS); + + BOOST_REQUIRE(guidBuf.Data1 == 0x2b218f63UL); + BOOST_REQUIRE(guidBuf.Data2 == 0x642aU); + BOOST_REQUIRE(guidBuf.Data3 == 0x4a64U); + + BOOST_REQUIRE(guidBuf.Data4[0] == 0x96); + BOOST_REQUIRE(guidBuf.Data4[1] == 0x74); + BOOST_REQUIRE(guidBuf.Data4[2] == 0x09); + BOOST_REQUIRE(guidBuf.Data4[3] == 0x8f); + BOOST_REQUIRE(guidBuf.Data4[4] == 0x38); + BOOST_REQUIRE(guidBuf.Data4[5] == 0x8a); + BOOST_REQUIRE(guidBuf.Data4[6] == 0xc2); + BOOST_REQUIRE(guidBuf.Data4[7] == 0x98 + rowIdx); + + // Checking 4th column. + BOOST_REQUIRE(row.ReadColumnToBuffer(4, appBitBuf) == SQL_RESULT_SUCCESS); + BOOST_REQUIRE(bitBuf == rowIdx % 2); +} + + +BOOST_AUTO_TEST_SUITE(RowTestSuite) + +BOOST_AUTO_TEST_CASE(TestRowMoveToNext) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + + const size_t rowNum = 32; + + FillMemWithData(mem, rowNum); + + Row row(mem); + + for (size_t i = 0; i < rowNum - 1; ++i) + { + BOOST_REQUIRE(row.GetSize() == 4); + BOOST_REQUIRE(row.MoveToNext()); + } +} + +BOOST_AUTO_TEST_CASE(TestRowRead) +{ + ignite::impl::interop::InteropUnpooledMemory mem(4096); + + const size_t rowNum = 8; + + FillMemWithData(mem, rowNum); + + Row row(mem); + + BOOST_REQUIRE(row.GetSize() == 4); + + for (size_t i = 0; i < rowNum - 1; ++i) + { + CheckRowData(row, i); + + BOOST_REQUIRE(row.MoveToNext()); + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file
