From 4c1ea3a821872735fa1b630715655030ff6ea6f6 Mon Sep 17 00:00:00 2001 From: Bruce Irschick Date: Wed, 23 Feb 2022 13:28:51 -0800 Subject: [PATCH 01/32] [AD-616] [ODBC] Reformat code to adhere to Google style (#31) ### Summary [AD-616] [ODBC] Reformat code to adhere to Google style ### Description Reformat source code for projects `odbc` and `odbc-test` ### Related Issue https://bitquill.atlassian.net/browse/AD-616 * [ODBC] Update CLang format settings file. - Change the .clang-format to use tab/indentation to 2. - Provide a Visual Studio option setting for importing by developers - Update README.md * [ODBC] Update CLang format settings file. - Change VS setting to version "16" for compatibility with VS 2019. * [AD-616] [ODBC] Reformat code to adhere to Google style * [AD-616] [ODBC] * Correct spelling. --- .clang-format | 4 +- README.md | 7 + VS-C++-Settings-Export.vssettings | 244 + src/odbc-test/include/complex_type.h | 198 +- src/odbc-test/include/odbc_test_suite.h | 674 +-- .../include/sql_test_suite_fixture.h | 338 +- .../include/teamcity/teamcity_messages.h | 54 +- src/odbc-test/include/test_server.h | 315 +- src/odbc-test/include/test_type.h | 276 +- src/odbc-test/include/test_utils.h | 236 +- src/odbc-test/src/api_robustness_test.cpp | 1524 +++--- .../src/application_data_buffer_test.cpp | 1300 +++-- src/odbc-test/src/attributes_test.cpp | 303 +- src/odbc-test/src/authentication_test.cpp | 324 +- src/odbc-test/src/column_test.cpp | 523 +- src/odbc-test/src/configuration_test.cpp | 1154 ++--- src/odbc-test/src/connection_info_test.cpp | 242 +- src/odbc-test/src/connection_test.cpp | 189 +- src/odbc-test/src/cursor_binding_test.cpp | 380 +- src/odbc-test/src/cursor_test.cpp | 194 +- src/odbc-test/src/dummy_test.cpp | 30 +- src/odbc-test/src/errors_test.cpp | 198 +- src/odbc-test/src/java_test.cpp | 752 +-- src/odbc-test/src/jni_test.cpp | 330 +- src/odbc-test/src/meta_queries_test.cpp | 1260 ++--- src/odbc-test/src/odbc_test_suite.cpp | 1320 +++-- src/odbc-test/src/parser_test.cpp | 89 +- src/odbc-test/src/queries_ssl_test.cpp | 350 +- src/odbc-test/src/queries_test.cpp | 3017 ++++++------ src/odbc-test/src/row_test.cpp | 248 +- .../src/sql_aggregate_functions_test.cpp | 252 +- .../src/sql_date_time_functions_test.cpp | 232 +- .../src/sql_esc_convert_function_test.cpp | 180 +- src/odbc-test/src/sql_get_info_test.cpp | 837 ++-- .../src/sql_numeric_functions_test.cpp | 292 +- src/odbc-test/src/sql_operators_test.cpp | 216 +- src/odbc-test/src/sql_outer_join_test.cpp | 582 +-- src/odbc-test/src/sql_parsing_test.cpp | 531 +- .../src/sql_string_functions_test.cpp | 383 +- .../src/sql_system_functions_test.cpp | 18 +- src/odbc-test/src/sql_test_suite_fixture.cpp | 509 +- src/odbc-test/src/sql_types_test.cpp | 588 +-- .../src/sql_value_expressions_test.cpp | 102 +- src/odbc-test/src/streaming_test.cpp | 673 ++- src/odbc-test/src/teamcity/teamcity_boost.cpp | 346 +- .../src/teamcity/teamcity_messages.cpp | 292 +- src/odbc-test/src/test_server.cpp | 193 +- src/odbc-test/src/test_utils.cpp | 137 +- src/odbc-test/src/transaction_test.cpp | 1001 ++-- src/odbc-test/src/types_test.cpp | 176 +- src/odbc-test/src/utility_test.cpp | 174 +- src/odbc/include/ignite/odbc.h | 417 +- .../ignite/odbc/app/application_data_buffer.h | 973 ++-- src/odbc/include/ignite/odbc/app/parameter.h | 228 +- .../include/ignite/odbc/app/parameter_set.h | 528 +- src/odbc/include/ignite/odbc/column.h | 257 +- .../include/ignite/odbc/common/big_integer.h | 985 ++-- src/odbc/include/ignite/odbc/common/bits.h | 384 +- .../include/ignite/odbc/common/concurrent.h | 1102 ++--- src/odbc/include/ignite/odbc/common/decimal.h | 979 ++-- .../ignite/odbc/common/default_allocator.h | 114 +- .../ignite/odbc/common/dynamic_size_array.h | 739 ++- .../include/ignite/odbc/common/expected.h | 524 +- .../ignite/odbc/common/fixed_size_array.h | 476 +- .../ignite/odbc/common/platform_utils.h | 207 +- src/odbc/include/ignite/odbc/common/utils.h | 1226 +++-- src/odbc/include/ignite/odbc/common_types.h | 634 ++- .../include/ignite/odbc/config/config_tools.h | 117 +- .../ignite/odbc/config/configuration.h | 1633 ++++--- .../ignite/odbc/config/connection_info.h | 152 +- .../odbc/config/connection_string_parser.h | 378 +- .../ignite/odbc/config/settable_value.h | 137 +- src/odbc/include/ignite/odbc/connection.h | 898 ++-- src/odbc/include/ignite/odbc/cursor.h | 183 +- .../ignite/odbc/diagnostic/diagnosable.h | 144 +- .../odbc/diagnostic/diagnosable_adapter.h | 228 +- .../odbc/diagnostic/diagnostic_record.h | 313 +- .../diagnostic/diagnostic_record_storage.h | 388 +- src/odbc/include/ignite/odbc/driverInstance.h | 12 +- src/odbc/include/ignite/odbc/dsn_config.h | 71 +- src/odbc/include/ignite/odbc/end_point.h | 80 +- src/odbc/include/ignite/odbc/environment.h | 254 +- src/odbc/include/ignite/odbc/ignite_error.h | 552 +-- .../ignite/odbc/jni/database_metadata.h | 79 +- .../ignite/odbc/jni/documentdb_connection.h | 151 +- src/odbc/include/ignite/odbc/jni/java.h | 1380 +++--- src/odbc/include/ignite/odbc/jni/result_set.h | 203 +- src/odbc/include/ignite/odbc/jni/utils.h | 329 +- src/odbc/include/ignite/odbc/log.h | 192 +- src/odbc/include/ignite/odbc/message.h | 1991 ++++---- .../include/ignite/odbc/meta/column_meta.h | 464 +- .../ignite/odbc/meta/primary_key_meta.h | 309 +- .../include/ignite/odbc/meta/table_meta.h | 299 +- src/odbc/include/ignite/odbc/nested_tx_mode.h | 96 +- src/odbc/include/ignite/odbc/odbc_error.h | 173 +- src/odbc/include/ignite/odbc/parser.h | 244 +- .../include/ignite/odbc/protocol_version.h | 369 +- .../include/ignite/odbc/query/batch_query.h | 288 +- .../ignite/odbc/query/column_metadata_query.h | 265 +- .../include/ignite/odbc/query/data_query.h | 436 +- .../ignite/odbc/query/foreign_keys_query.h | 254 +- .../ignite/odbc/query/internal_query.h | 300 +- .../ignite/odbc/query/primary_keys_query.h | 239 +- src/odbc/include/ignite/odbc/query/query.h | 290 +- .../ignite/odbc/query/special_columns_query.h | 251 +- .../ignite/odbc/query/streaming_query.h | 251 +- .../ignite/odbc/query/table_metadata_query.h | 274 +- .../ignite/odbc/query/type_info_query.h | 209 +- .../include/ignite/odbc/read_preference.h | 90 +- src/odbc/include/ignite/odbc/result_page.h | 119 +- src/odbc/include/ignite/odbc/row.h | 216 +- src/odbc/include/ignite/odbc/scan_method.h | 74 +- .../include/ignite/odbc/sql/sql_command.h | 109 +- src/odbc/include/ignite/odbc/sql/sql_lexer.h | 184 +- src/odbc/include/ignite/odbc/sql/sql_parser.h | 79 +- .../odbc/sql/sql_set_streaming_command.h | 340 +- src/odbc/include/ignite/odbc/sql/sql_token.h | 259 +- src/odbc/include/ignite/odbc/sql/sql_utils.h | 71 +- src/odbc/include/ignite/odbc/ssl_mode.h | 75 +- src/odbc/include/ignite/odbc/statement.h | 1401 +++--- .../ignite/odbc/streaming/streaming_batch.h | 173 +- .../ignite/odbc/streaming/streaming_context.h | 220 +- .../ignite/odbc/system/odbc_constants.h | 12 +- .../include/ignite/odbc/system/system_dsn.h | 20 +- .../odbc/system/ui/dsn_configuration_window.h | 696 ++- src/odbc/include/ignite/odbc/type_traits.h | 560 ++- src/odbc/include/ignite/odbc/utility.h | 168 +- .../linux/include/ignite/odbc/common/common.h | 30 +- .../ignite/odbc/common/concurrent_os.h | 1306 +++-- .../os/linux/src/common/concurrent_os.cpp | 327 +- .../os/linux/src/common/platform_utils.cpp | 167 +- .../win/include/ignite/odbc/common/common.h | 17 +- .../ignite/odbc/common/concurrent_os.h | 1129 +++-- .../ignite/odbc/system/ui/custom_window.h | 331 +- .../include/ignite/odbc/system/ui/window.h | 366 +- src/odbc/os/win/src/common/concurrent_os.cpp | 341 +- src/odbc/os/win/src/common/platform_utils.cpp | 165 +- .../os/win/src/system/ui/custom_window.cpp | 249 +- .../system/ui/dsn_configuration_window.cpp | 1466 +++--- src/odbc/os/win/src/system/ui/window.cpp | 324 +- src/odbc/os/win/src/system_dsn.cpp | 229 +- src/odbc/src/app/application_data_buffer.cpp | 2639 +++++----- src/odbc/src/app/parameter.cpp | 456 +- src/odbc/src/app/parameter_set.cpp | 414 +- src/odbc/src/column.cpp | 720 ++- src/odbc/src/common/big_integer.cpp | 1395 +++--- src/odbc/src/common/bits.cpp | 372 +- src/odbc/src/common/concurrent.cpp | 159 +- src/odbc/src/common/decimal.cpp | 441 +- src/odbc/src/common/utils.cpp | 340 +- src/odbc/src/common_types.cpp | 230 +- src/odbc/src/config/config_tools.cpp | 318 +- src/odbc/src/config/configuration.cpp | 1170 +++-- src/odbc/src/config/connection_info.cpp | 4352 +++++++++-------- .../src/config/connection_string_parser.cpp | 1066 ++-- src/odbc/src/connection.cpp | 1320 +++-- src/odbc/src/cursor.cpp | 103 +- .../src/diagnostic/diagnosable_adapter.cpp | 78 +- src/odbc/src/diagnostic/diagnostic_record.cpp | 643 ++- .../diagnostic/diagnostic_record_storage.cpp | 385 +- src/odbc/src/driverInstance.cpp | 11 +- src/odbc/src/dsn_config.cpp | 308 +- src/odbc/src/entry_points.cpp | 1224 ++--- src/odbc/src/environment.cpp | 270 +- src/odbc/src/ignite_error.cpp | 412 +- src/odbc/src/jni/database_metadata.cpp | 43 +- src/odbc/src/jni/documentdb_connection.cpp | 149 +- src/odbc/src/jni/java.cpp | 2773 ++++++----- src/odbc/src/jni/os/linux/utils.cpp | 635 ++- src/odbc/src/jni/os/win/utils.cpp | 670 ++- src/odbc/src/jni/result_set.cpp | 110 +- src/odbc/src/log.cpp | 92 +- src/odbc/src/message.cpp | 954 ++-- src/odbc/src/meta/column_meta.cpp | 614 ++- src/odbc/src/meta/table_meta.cpp | 91 +- src/odbc/src/nested_tx_mode.cpp | 85 +- src/odbc/src/odbc.cpp | 1856 ++++--- src/odbc/src/protocol_version.cpp | 281 +- src/odbc/src/query/batch_query.cpp | 329 +- src/odbc/src/query/column_metadata_query.cpp | 580 ++- src/odbc/src/query/data_query.cpp | 776 ++- src/odbc/src/query/foreign_keys_query.cpp | 222 +- src/odbc/src/query/primary_keys_query.cpp | 350 +- src/odbc/src/query/special_columns_query.cpp | 203 +- src/odbc/src/query/streaming_query.cpp | 105 +- src/odbc/src/query/table_metadata_query.cpp | 463 +- src/odbc/src/query/type_info_query.cpp | 671 ++- src/odbc/src/read_preference.cpp | 110 +- src/odbc/src/result_page.cpp | 52 +- src/odbc/src/row.cpp | 133 +- src/odbc/src/scan_method.cpp | 97 +- src/odbc/src/sql/sql_lexer.cpp | 292 +- src/odbc/src/sql/sql_parser.cpp | 114 +- .../src/sql/sql_set_streaming_command.cpp | 233 +- src/odbc/src/sql/sql_utils.cpp | 57 +- src/odbc/src/ssl_mode.cpp | 72 +- src/odbc/src/statement.cpp | 1956 ++++---- src/odbc/src/streaming/streaming_batch.cpp | 77 +- src/odbc/src/streaming/streaming_context.cpp | 181 +- src/odbc/src/type_traits.cpp | 1230 +++-- src/odbc/src/utility.cpp | 218 +- 201 files changed, 46836 insertions(+), 48613 deletions(-) create mode 100644 VS-C++-Settings-Export.vssettings diff --git a/.clang-format b/.clang-format index b8fd6433b..836a6507e 100644 --- a/.clang-format +++ b/.clang-format @@ -4,13 +4,13 @@ AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: 'false' AllowShortLoopsOnASingleLine: 'false' BreakBeforeBinaryOperators: NonAssignment -IndentWidth: '4' +IndentWidth: '2' SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: 'false' SpacesInAngles: 'true' SpacesInParentheses: 'false' SpacesInSquareBrackets: 'false' -TabWidth: '4' +TabWidth: '2' UseTab: 'false' # See https://zed0.co.uk/clang-format-configurator/ for generating this file. \ No newline at end of file diff --git a/README.md b/README.md index a823fbfcb..eed8fce05 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ ## Development Environment +### C/C++ Formatting + +- This project uses [Google's C++ Style Guide](https://google.github.io/styleguide/cppguide.htm) as a basis for +C/C++ usage and formatting. +- Some formatting is set using the .clang-format file at the base of repository. Other options for Visual Studio can be imported from the +`VS-C++-Settings-Export.vssettings` file also found at root of repository. + ### Environment Variables for Testing Accounts/Secrets To enable the test environment to run the tests against a live DocumentDB system, set the following environment variables on your development machine. diff --git a/VS-C++-Settings-Export.vssettings b/VS-C++-Settings-Export.vssettings new file mode 100644 index 000000000..d24422217 --- /dev/null +++ b/VS-C++-Settings-Export.vssettings @@ -0,0 +1,244 @@ + + + + + + 2 + true + true + true + true + 2 + true + true + true + false + false + true + true + false + true + true + true + 58 + true + false + 2 + true + true + true + true + + + false + true + false + 15 + 2 + true + true + 1 + 1 + false + true + true + false + 2 + false + 11 + true + false + true + false + false + 0 + true + true + 50 + true + false + true + 2 + 1 + true + false + false + false + 2 + 1 + true + 0 + false + true + false + false + false + false + true + false + {}[]().,:;+-*/%&|^!=<>?@#\ + 1 + true + true + false + 1 + true + false + false + false + false + true + true + false + false + true + false + 1 + true + true + 2 + false + true + 0 + true + false + 1 + true + true + false + false + false + true + false + 5120 + false + 0 + false + false + false + + true + false + false + false + false + false + false + false + false + 2 + 0 + false + 1 + false + false + false + true + true + false + true + true + true + false + true + false + false + true + 1 + true + 5 + false + false + 1 + false + false + false + false + true + true + 3 + true + true + true + false + false + 1 + 2 + 1 + true + false + 60 + false + false + true + false + false + false + false + false + false + false + false + true + 55 + 1 + false + false + false + false + 2 + false + false + true + true + 1 + true + true + false + true + false + true + true + false + 1 + 2 + 2 + true + false + false + true + false + true + false + false + true + false + false + 1 + 1 + false + false + false + false + false + false + false + false + 0 + true + false + 1 + true + 1 + https://www.bing.com/search?q={0} + false + false + false + false + false + false + 2 + + + + \ No newline at end of file diff --git a/src/odbc-test/include/complex_type.h b/src/odbc-test/include/complex_type.h index 341fd9aa6..bb0735331 100644 --- a/src/odbc-test/include/complex_type.h +++ b/src/odbc-test/include/complex_type.h @@ -22,115 +22,97 @@ #include "ignite/ignite.h" -namespace ignite -{ - struct TestObject - { - TestObject() : - f1(412), - f2("Lorem ipsum") - { - // No-op. - } - - friend bool operator==(TestObject const& lhs, TestObject const& rhs) - { - return lhs.f1 == rhs.f1 && lhs.f2 == rhs.f2; - } - - friend std::ostream& operator<<(std::ostream& str, TestObject const& obj) - { - str << "TestObject::f1: " << obj.f1 - << "TestObject::f2: " << obj.f2; - return str; - } - - int32_t f1; - std::string f2; - }; - - struct ComplexType - { - ComplexType() : - i32Field(0) - { - // No-op. - } - - friend bool operator==(ComplexType const& lhs, ComplexType const& rhs) - { - return lhs.i32Field == rhs.i32Field && lhs.objField == rhs.objField && lhs.strField == rhs.strField; - } - - friend std::ostream& operator<<(std::ostream& str, ComplexType const& obj) - { - str << "ComplexType::i32Field: " << obj.i32Field - << "ComplexType::objField: " << obj.objField - << "ComplexType::strField: " << obj.strField; - return str; - } - - int32_t i32Field; - TestObject objField; - std::string strField; - }; +namespace ignite { +struct TestObject { + TestObject() : f1(412), f2("Lorem ipsum") { + // No-op. + } + + friend bool operator==(TestObject const& lhs, TestObject const& rhs) { + return lhs.f1 == rhs.f1 && lhs.f2 == rhs.f2; + } + + friend std::ostream& operator<<(std::ostream& str, TestObject const& obj) { + str << "TestObject::f1: " << obj.f1 << "TestObject::f2: " << obj.f2; + return str; + } + + int32_t f1; + std::string f2; +}; + +struct ComplexType { + ComplexType() : i32Field(0) { + // No-op. + } + + friend bool operator==(ComplexType const& lhs, ComplexType const& rhs) { + return lhs.i32Field == rhs.i32Field && lhs.objField == rhs.objField + && lhs.strField == rhs.strField; + } + + friend std::ostream& operator<<(std::ostream& str, ComplexType const& obj) { + str << "ComplexType::i32Field: " << obj.i32Field + << "ComplexType::objField: " << obj.objField + << "ComplexType::strField: " << obj.strField; + return str; + } + + int32_t i32Field; + TestObject objField; + std::string strField; +}; +} // namespace ignite + +namespace ignite { +namespace binary { + +IGNITE_BINARY_TYPE_START(ignite::TestObject) + +typedef ignite::TestObject TestObject; + +IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestObject) +IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestObject) +IGNITE_BINARY_GET_FIELD_ID_AS_HASH +IGNITE_BINARY_IS_NULL_FALSE(TestObject) +IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject) + +static void Write(BinaryWriter& writer, const TestObject& obj) { + writer.WriteInt32("f1", obj.f1); + writer.WriteString("f2", obj.f2); } -namespace ignite -{ - namespace binary - { - - IGNITE_BINARY_TYPE_START(ignite::TestObject) - - typedef ignite::TestObject TestObject; - - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestObject) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestObject) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(TestObject) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject) - - static void Write(BinaryWriter& writer, const TestObject& obj) - { - writer.WriteInt32("f1", obj.f1); - writer.WriteString("f2", obj.f2); - } - - static void Read(BinaryReader& reader, TestObject& dst) - { - dst.f1 = reader.ReadInt32("f1"); - dst.f2 = reader.ReadString("f2"); - } - - IGNITE_BINARY_TYPE_END - - IGNITE_BINARY_TYPE_START(ignite::ComplexType) - - typedef ignite::ComplexType ComplexType; - - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_IS_NULL_FALSE(ComplexType) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) - - static void Write(BinaryWriter& writer, const ComplexType& obj) - { - writer.WriteInt32("i32Field", obj.i32Field); - writer.WriteObject("objField", obj.objField); - writer.WriteString("strField", obj.strField); - } - - static void Read(BinaryReader& reader, ComplexType& dst) - { - dst.i32Field = reader.ReadInt32("i32Field"); - dst.objField = reader.ReadObject("objField"); - dst.strField = reader.ReadString("strField"); - } - - IGNITE_BINARY_TYPE_END - } +static void Read(BinaryReader& reader, TestObject& dst) { + dst.f1 = reader.ReadInt32("f1"); + dst.f2 = reader.ReadString("f2"); } -#endif // _IGNITE_ODBC_TEST_COMPLEX_TYPE +IGNITE_BINARY_TYPE_END + +IGNITE_BINARY_TYPE_START(ignite::ComplexType) + +typedef ignite::ComplexType ComplexType; + +IGNITE_BINARY_GET_TYPE_ID_AS_HASH(ComplexType) +IGNITE_BINARY_GET_TYPE_NAME_AS_IS(ComplexType) +IGNITE_BINARY_GET_FIELD_ID_AS_HASH +IGNITE_BINARY_IS_NULL_FALSE(ComplexType) +IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) + +static void Write(BinaryWriter& writer, const ComplexType& obj) { + writer.WriteInt32("i32Field", obj.i32Field); + writer.WriteObject("objField", obj.objField); + writer.WriteString("strField", obj.strField); +} + +static void Read(BinaryReader& reader, ComplexType& dst) { + dst.i32Field = reader.ReadInt32("i32Field"); + dst.objField = reader.ReadObject< TestObject >("objField"); + dst.strField = reader.ReadString("strField"); +} + +IGNITE_BINARY_TYPE_END +} // namespace binary +} // namespace ignite + +#endif // _IGNITE_ODBC_TEST_COMPLEX_TYPE diff --git a/src/odbc-test/include/odbc_test_suite.h b/src/odbc-test/include/odbc_test_suite.h index 7b21d99a2..5dbdb56dd 100644 --- a/src/odbc-test/include/odbc_test_suite.h +++ b/src/odbc-test/include/odbc_test_suite.h @@ -19,7 +19,7 @@ #define ODBC_TEST_ODBC_TEST_SUITE #ifdef _WIN32 -# include +#include #endif #include @@ -28,345 +28,347 @@ #include #ifndef BOOST_TEST_CONTEXT -# define BOOST_TEST_CONTEXT(...) +#define BOOST_TEST_CONTEXT(...) #endif #ifndef BOOST_TEST_INFO -# define BOOST_TEST_INFO(...) +#define BOOST_TEST_INFO(...) #endif #include -namespace ignite -{ - namespace odbc - { - /** - * Test setup fixture. - */ - struct OdbcTestSuite - { - /** - * Prepare environment. - */ - void Prepare(); - - /** - * Establish connection to node using provided handles. - * - * @param conn Connection. - * @param statement Statement to allocate. - * @param connectStr Connection string. - */ - void Connect(SQLHDBC& conn, SQLHSTMT& statement, const std::string& connectStr); - - /** - * Establish connection to node using default handles. - * - * @param connectStr Connection string. - */ - void Connect(const std::string& connectStr); - - /** - * Expect connection to be rejected by the node. - * - * @param connectStr Connection string. - * @return SQL State. - */ - std::string ExpectConnectionReject( - const std::string& connectStr, - const std::string& expectedError = "08001: Failed to establish connection with the host."); - - /** - * Disconnect. - */ - void Disconnect(); - - /** - * Clean up. - */ - void CleanUp(); - - /** - * Constructor. - */ - OdbcTestSuite(); - - /** - * Destructor. - */ - virtual ~OdbcTestSuite(); - - /** - * Insert requested number of TestType values with all defaults except - * for the strFields, which are generated using GetTestString(). - * - * @param recordsNum Number of records to insert. - * @param merge Set to true to use merge instead. - */ - void InsertTestStrings(int recordsNum, bool merge = false); - - /** - * Insert requested number of TestType values in a batch. - * - * @param from Index to start from. - * @param to Index to stop. - * @param expectedToAffect Expected number of affected records. - * @param merge Set to true to use merge instead of insert. - * @return Records inserted. - */ - int InsertTestBatch(int from, int to, int expectedToAffect, bool merge = false); - - /** - * Insert requested number of TestType values in a batch, - * select them and check all the values. - * - * @param recordsNum Number of records. - */ - void InsertBatchSelect(int recordsNum); - - /** - * Insert values in two batches, select them and check all the values. - * @param recordsNum Number of records. - * @param splitAt Point where two batches are separated. - */ - void InsertNonFullBatchSelect(int recordsNum, int splitAt); - - /** - * Get test i8Field. - * - * @param idx Index. - * @return Corresponding i8Field value. - */ - static int8_t GetTestI8Field(int64_t idx); - - /** - * Check i8Field test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestI8Value(int idx, int8_t value); - - /** - * Get test i16Field. - * - * @param idx Index. - * @return Corresponding i16Field value. - */ - static int16_t GetTestI16Field(int64_t idx); - - /** - * Check i16Field test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestI16Value(int idx, int16_t value); - - /** - * Get test i32Field. - * - * @param idx Index. - * @return Corresponding i32Field value. - */ - static int32_t GetTestI32Field(int64_t idx); - - /** - * Check i32Field test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestI32Value(int idx, int32_t value); - - /** - * Get test string. - * - * @param idx Index. - * @return Corresponding test string. - */ - static std::string GetTestString(int64_t idx); - - /** - * Check strField test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestStringValue(int idx, const std::string& value); - - /** - * Get test floatField. - * - * @param idx Index. - * @return Corresponding floatField value. - */ - static float GetTestFloatField(int64_t idx); - - /** - * Check floatField test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestFloatValue(int idx, float value); - - /** - * Get test doubleField. - * - * @param idx Index. - * @return Corresponding doubleField value. - */ - static double GetTestDoubleField(int64_t idx); - - /** - * Check doubleField test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestDoubleValue(int idx, double value); - - /** - * Get test boolField. - * - * @param idx Index. - * @return Corresponding boolField value. - */ - static bool GetTestBoolField(int64_t idx); - - /** - * Check boolField test value. - * @param idx Index. - * @param value Value to test. - */ - static void CheckTestBoolValue(int idx, bool value); - - /** - * Get test dateField. - * - * @param idx Index. - * @param val Output value. - */ - static void GetTestDateField(int64_t idx, SQL_DATE_STRUCT& val); - - /** - * Check dateField test value. - * - * @param idx Index. - * @param val Value to test. - */ - static void CheckTestDateValue(int idx, const SQL_DATE_STRUCT& val); - - /** - * Get test timeField. - * - * @param idx Index. - * @param val Output value. - */ - static void GetTestTimeField(int64_t idx, SQL_TIME_STRUCT& val); - - /** - * Check timeField test value. - * - * @param idx Index. - * @param val Value to test. - */ - static void CheckTestTimeValue(int idx, const SQL_TIME_STRUCT& val); - - /** - * Get test timestampField. - * - * @param idx Index. - * @param val Output value. - */ - static void GetTestTimestampField(int64_t idx, SQL_TIMESTAMP_STRUCT& val); - - /** - * Check timestampField test value. - * - * @param idx Index. - * @param val Value to test. - */ - static void CheckTestTimestampValue(int idx, const SQL_TIMESTAMP_STRUCT& val); - - /** - * Get test i8ArrayField. - * - * @param idx Index. - * @param val Output value. - * @param valLen Value length. - */ - static void GetTestI8ArrayField(int64_t idx, int8_t* val, size_t valLen); - - /** - * Check i8ArrayField test value. - * - * @param idx Index. - * @param val Value to test. - * @param valLen Value length. - */ - static void CheckTestI8ArrayValue(int idx, const int8_t* val, size_t valLen); - - /** - * Check that SQL error has expected SQL state. - * - * @param handleType Handle type. - * @param handle Handle. - * @param expectSqlState Expected state. - */ - void CheckSQLDiagnosticError(int16_t handleType, SQLHANDLE handle, const std::string& expectSqlState); - - /** - * Check that statement SQL error has expected SQL state. - * - * @param expectSqlState Expected state. - */ - void CheckSQLStatementDiagnosticError(const std::string& expectSqlState); - - /** - * Check that connection SQL error has expected SQL state. - * - * @param expectSqlState Expected state. - */ - void CheckSQLConnectionDiagnosticError(const std::string& expectSqlState); - - /** - * Convert string to vector of SQLCHARs. - * - * @param qry Query. - * @return Corresponding vector. - */ - static std::vector MakeQuery(const std::string& qry); - - /** - * Performs SQL query. - * - * @param qry Query. - * @return Result. - */ - SQLRETURN ExecQuery(const std::string& qry); - - /** - * Prepares SQL query. - * - * @param qry Query. - * @return Result. - */ - SQLRETURN PrepareQuery(const std::string& qry); - - /** - * Creates the standard DSN connection string. - */ - void CreateDsnConnectionString(std::string& connectionString, - const std::string& username = std::string(), bool sshTunnel = true, - const std::string& miscOptions = std::string()) const; - - /** ODBC Environment. */ - SQLHENV env; - - /** ODBC Connect. */ - SQLHDBC dbc; - - /** ODBC Statement. */ - SQLHSTMT stmt; - }; - } -} - -#endif //ODBC_TEST_ODBC_TEST_SUITE +namespace ignite { +namespace odbc { +/** + * Test setup fixture. + */ +struct OdbcTestSuite { + /** + * Prepare environment. + */ + void Prepare(); + + /** + * Establish connection to node using provided handles. + * + * @param conn Connection. + * @param statement Statement to allocate. + * @param connectStr Connection string. + */ + void Connect(SQLHDBC& conn, SQLHSTMT& statement, + const std::string& connectStr); + + /** + * Establish connection to node using default handles. + * + * @param connectStr Connection string. + */ + void Connect(const std::string& connectStr); + + /** + * Expect connection to be rejected by the node. + * + * @param connectStr Connection string. + * @return SQL State. + */ + std::string ExpectConnectionReject( + const std::string& connectStr, + const std::string& expectedError = + "08001: Failed to establish connection with the host."); + + /** + * Disconnect. + */ + void Disconnect(); + + /** + * Clean up. + */ + void CleanUp(); + + /** + * Constructor. + */ + OdbcTestSuite(); + + /** + * Destructor. + */ + virtual ~OdbcTestSuite(); + + /** + * Insert requested number of TestType values with all defaults except + * for the strFields, which are generated using GetTestString(). + * + * @param recordsNum Number of records to insert. + * @param merge Set to true to use merge instead. + */ + void InsertTestStrings(int recordsNum, bool merge = false); + + /** + * Insert requested number of TestType values in a batch. + * + * @param from Index to start from. + * @param to Index to stop. + * @param expectedToAffect Expected number of affected records. + * @param merge Set to true to use merge instead of insert. + * @return Records inserted. + */ + int InsertTestBatch(int from, int to, int expectedToAffect, + bool merge = false); + + /** + * Insert requested number of TestType values in a batch, + * select them and check all the values. + * + * @param recordsNum Number of records. + */ + void InsertBatchSelect(int recordsNum); + + /** + * Insert values in two batches, select them and check all the values. + * @param recordsNum Number of records. + * @param splitAt Point where two batches are separated. + */ + void InsertNonFullBatchSelect(int recordsNum, int splitAt); + + /** + * Get test i8Field. + * + * @param idx Index. + * @return Corresponding i8Field value. + */ + static int8_t GetTestI8Field(int64_t idx); + + /** + * Check i8Field test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestI8Value(int idx, int8_t value); + + /** + * Get test i16Field. + * + * @param idx Index. + * @return Corresponding i16Field value. + */ + static int16_t GetTestI16Field(int64_t idx); + + /** + * Check i16Field test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestI16Value(int idx, int16_t value); + + /** + * Get test i32Field. + * + * @param idx Index. + * @return Corresponding i32Field value. + */ + static int32_t GetTestI32Field(int64_t idx); + + /** + * Check i32Field test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestI32Value(int idx, int32_t value); + + /** + * Get test string. + * + * @param idx Index. + * @return Corresponding test string. + */ + static std::string GetTestString(int64_t idx); + + /** + * Check strField test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestStringValue(int idx, const std::string& value); + + /** + * Get test floatField. + * + * @param idx Index. + * @return Corresponding floatField value. + */ + static float GetTestFloatField(int64_t idx); + + /** + * Check floatField test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestFloatValue(int idx, float value); + + /** + * Get test doubleField. + * + * @param idx Index. + * @return Corresponding doubleField value. + */ + static double GetTestDoubleField(int64_t idx); + + /** + * Check doubleField test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestDoubleValue(int idx, double value); + + /** + * Get test boolField. + * + * @param idx Index. + * @return Corresponding boolField value. + */ + static bool GetTestBoolField(int64_t idx); + + /** + * Check boolField test value. + * @param idx Index. + * @param value Value to test. + */ + static void CheckTestBoolValue(int idx, bool value); + + /** + * Get test dateField. + * + * @param idx Index. + * @param val Output value. + */ + static void GetTestDateField(int64_t idx, SQL_DATE_STRUCT& val); + + /** + * Check dateField test value. + * + * @param idx Index. + * @param val Value to test. + */ + static void CheckTestDateValue(int idx, const SQL_DATE_STRUCT& val); + + /** + * Get test timeField. + * + * @param idx Index. + * @param val Output value. + */ + static void GetTestTimeField(int64_t idx, SQL_TIME_STRUCT& val); + + /** + * Check timeField test value. + * + * @param idx Index. + * @param val Value to test. + */ + static void CheckTestTimeValue(int idx, const SQL_TIME_STRUCT& val); + + /** + * Get test timestampField. + * + * @param idx Index. + * @param val Output value. + */ + static void GetTestTimestampField(int64_t idx, SQL_TIMESTAMP_STRUCT& val); + + /** + * Check timestampField test value. + * + * @param idx Index. + * @param val Value to test. + */ + static void CheckTestTimestampValue(int idx, const SQL_TIMESTAMP_STRUCT& val); + + /** + * Get test i8ArrayField. + * + * @param idx Index. + * @param val Output value. + * @param valLen Value length. + */ + static void GetTestI8ArrayField(int64_t idx, int8_t* val, size_t valLen); + + /** + * Check i8ArrayField test value. + * + * @param idx Index. + * @param val Value to test. + * @param valLen Value length. + */ + static void CheckTestI8ArrayValue(int idx, const int8_t* val, size_t valLen); + + /** + * Check that SQL error has expected SQL state. + * + * @param handleType Handle type. + * @param handle Handle. + * @param expectSqlState Expected state. + */ + void CheckSQLDiagnosticError(int16_t handleType, SQLHANDLE handle, + const std::string& expectSqlState); + + /** + * Check that statement SQL error has expected SQL state. + * + * @param expectSqlState Expected state. + */ + void CheckSQLStatementDiagnosticError(const std::string& expectSqlState); + + /** + * Check that connection SQL error has expected SQL state. + * + * @param expectSqlState Expected state. + */ + void CheckSQLConnectionDiagnosticError(const std::string& expectSqlState); + + /** + * Convert string to vector of SQLCHARs. + * + * @param qry Query. + * @return Corresponding vector. + */ + static std::vector< SQLCHAR > MakeQuery(const std::string& qry); + + /** + * Performs SQL query. + * + * @param qry Query. + * @return Result. + */ + SQLRETURN ExecQuery(const std::string& qry); + + /** + * Prepares SQL query. + * + * @param qry Query. + * @return Result. + */ + SQLRETURN PrepareQuery(const std::string& qry); + + /** + * Creates the standard DSN connection string. + */ + void CreateDsnConnectionString( + std::string& connectionString, + const std::string& username = std::string(), bool sshTunnel = true, + const std::string& miscOptions = std::string()) const; + + /** ODBC Environment. */ + SQLHENV env; + + /** ODBC Connect. */ + SQLHDBC dbc; + + /** ODBC Statement. */ + SQLHSTMT stmt; +}; +} // namespace odbc +} // namespace ignite + +#endif // ODBC_TEST_ODBC_TEST_SUITE diff --git a/src/odbc-test/include/sql_test_suite_fixture.h b/src/odbc-test/include/sql_test_suite_fixture.h index b9c35c018..32600ca58 100644 --- a/src/odbc-test/include/sql_test_suite_fixture.h +++ b/src/odbc-test/include/sql_test_suite_fixture.h @@ -19,193 +19,199 @@ #define _IGNITE_ODBC_TEST_SQL_TEST_SUIT_FIXTURE #ifdef _WIN32 -# include +#include #endif #include #include -#include - #include +#include +#include "ignite/common/decimal.h" #include "ignite/ignite.h" #include "ignite/ignition.h" -#include "ignite/common/decimal.h" - #include "test_type.h" -namespace ignite -{ - /** - * Test setup fixture. - */ - struct SqlTestSuiteFixture - { - /** - * Constructor. - */ - SqlTestSuiteFixture(); - - /** - * Destructor. - */ - ~SqlTestSuiteFixture(); - - /** - * Run query returning single result and stores it to buffer. - * - * @param request SQL request. - * @param type Result type. - * @param column Result buffer. - * @param bufSize Result buffer size. - * @param resSize Size of received value. - */ - void CheckSingleResult0(const char* request, SQLSMALLINT type, - void* column, SQLLEN bufSize, SQLLEN* resSize) const; - - /** - * Run query returning single result and check it to be equal to expected. - * - * @param request SQL request. - * @param expected Expected result. - */ - template - void CheckSingleResult(const char*, const T&) - { - BOOST_FAIL("Function is not defined for the type."); - } - - /** - * Run query returning single result and check it to be successful. - * - * @param request SQL request. - */ - template - void CheckSingleResult(const char*) - { - BOOST_FAIL("Function is not defined for the type."); - } - - /** - * Run query returning single result and check it to be equal to expected. - * - * @param request SQL request. - * @param expected Expected result. - * @param type Result type. - */ - template - void CheckSingleResultNum0(const char* request, const T& expected, SQLSMALLINT type) - { - T res = 0; - - CheckSingleResult0(request, type, &res, 0, 0); - - BOOST_CHECK_EQUAL(res, expected); - } - - /** - * Run query returning single result. - * - * @param request SQL request. - * @param type Result type. - */ - template - void CheckSingleResultNum0(const char* request, SQLSMALLINT type) - { - T res = 0; - - CheckSingleResult0(request, type, &res, 0, 0); - } - - - /** Node started during the test. */ - Ignite grid; - - /** Test cache instance. */ - cache::Cache testCache; - - /** ODBC Environment. */ - SQLHENV env; - - /** ODBC Connect. */ - SQLHDBC dbc; - - /** ODBC Statement. */ - SQLHSTMT stmt; - }; - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const std::string& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const SQLBIGINT& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const SQLINTEGER& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const SQLSMALLINT& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const int8_t& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const float& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const double& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const bool& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request, const ignite::Guid& expected); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); - - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +namespace ignite { +/** + * Test setup fixture. + */ +struct SqlTestSuiteFixture { + /** + * Constructor. + */ + SqlTestSuiteFixture(); + + /** + * Destructor. + */ + ~SqlTestSuiteFixture(); + + /** + * Run query returning single result and stores it to buffer. + * + * @param request SQL request. + * @param type Result type. + * @param column Result buffer. + * @param bufSize Result buffer size. + * @param resSize Size of received value. + */ + void CheckSingleResult0(const char* request, SQLSMALLINT type, void* column, + SQLLEN bufSize, SQLLEN* resSize) const; + + /** + * Run query returning single result and check it to be equal to expected. + * + * @param request SQL request. + * @param expected Expected result. + */ + template < typename T > + void CheckSingleResult(const char*, const T&) { + BOOST_FAIL("Function is not defined for the type."); + } + + /** + * Run query returning single result and check it to be successful. + * + * @param request SQL request. + */ + template < typename T > + void CheckSingleResult(const char*) { + BOOST_FAIL("Function is not defined for the type."); + } + + /** + * Run query returning single result and check it to be equal to expected. + * + * @param request SQL request. + * @param expected Expected result. + * @param type Result type. + */ + template < typename T > + void CheckSingleResultNum0(const char* request, const T& expected, + SQLSMALLINT type) { + T res = 0; + + CheckSingleResult0(request, type, &res, 0, 0); + + BOOST_CHECK_EQUAL(res, expected); + } + + /** + * Run query returning single result. + * + * @param request SQL request. + * @param type Result type. + */ + template < typename T > + void CheckSingleResultNum0(const char* request, SQLSMALLINT type) { + T res = 0; + + CheckSingleResult0(request, type, &res, 0, 0); + } + + /** Node started during the test. */ + Ignite grid; + + /** Test cache instance. */ + cache::Cache< int64_t, TestType > testCache; + + /** ODBC Environment. */ + SQLHENV env; + + /** ODBC Connect. */ + SQLHDBC dbc; + + /** ODBC Statement. */ + SQLHSTMT stmt; +}; + +template <> +void SqlTestSuiteFixture::CheckSingleResult< std::string >( + const char* request, const std::string& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLBIGINT >( + const char* request, const SQLBIGINT& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLINTEGER >( + const char* request, const SQLINTEGER& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLSMALLINT >( + const char* request, const SQLSMALLINT& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< int8_t >(const char* request, + const int8_t& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< float >(const char* request, + const float& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< double >(const char* request, + const double& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< bool >(const char* request, + const bool& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< ignite::Guid >( + const char* request, const ignite::Guid& expected); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< std::string >(const char* request); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLBIGINT >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLINTEGER >(const char* request); + +template <> +void SqlTestSuiteFixture::CheckSingleResult< SQLSMALLINT >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< int8_t >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< float >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< double >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< Date >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult(const char* request); +template <> +void SqlTestSuiteFixture::CheckSingleResult< Timestamp >(const char* request); - template<> - void SqlTestSuiteFixture::CheckSingleResult