lidavidm commented on code in PR #47762: URL: https://github.com/apache/arrow/pull/47762#discussion_r2448055356
########## cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc: ########## @@ -0,0 +1,861 @@ +// 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. +#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h" + +#include "arrow/flight/sql/odbc/odbc_impl/platform.h" + +#include <sql.h> +#include <sqltypes.h> +#include <sqlucode.h> + +#include <gtest/gtest.h> + +namespace arrow::flight::sql::odbc { + +template <typename T> +class ConnectionInfoTest : public T { + public: + using List = std::list<T>; +}; + +class ConnectionInfoMockTest : public FlightSQLODBCMockTestBase {}; +using TestTypes = ::testing::Types<ConnectionInfoMockTest, FlightSQLODBCRemoteTestBase>; +TYPED_TEST_SUITE(ConnectionInfoTest, TestTypes); + +// Helper Functions + +// Validate unsigned short SQLUSMALLINT return value +void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUSMALLINT expected_value) { Review Comment: you may want to put these in an anonymous namespace so you don't accidentally collide with the same name/overload in other translation units ########## cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc: ########## @@ -0,0 +1,861 @@ +// 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. +#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h" + +#include "arrow/flight/sql/odbc/odbc_impl/platform.h" + +#include <sql.h> +#include <sqltypes.h> +#include <sqlucode.h> + +#include <gtest/gtest.h> + +namespace arrow::flight::sql::odbc { + +template <typename T> +class ConnectionInfoTest : public T { + public: + using List = std::list<T>; +}; + +class ConnectionInfoMockTest : public FlightSQLODBCMockTestBase {}; +using TestTypes = ::testing::Types<ConnectionInfoMockTest, FlightSQLODBCRemoteTestBase>; +TYPED_TEST_SUITE(ConnectionInfoTest, TestTypes); + +// Helper Functions + +// Validate unsigned short SQLUSMALLINT return value +void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUSMALLINT expected_value) { + SQLUSMALLINT info_value; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, + SQLGetInfo(connection, info_type, &info_value, 0, &message_length)); + + EXPECT_EQ(expected_value, info_value); +} + +// Validate unsigned long SQLUINTEGER return value +void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLUINTEGER expected_value) { + SQLUINTEGER info_value; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, + SQLGetInfo(connection, info_type, &info_value, 0, &message_length)); + + EXPECT_EQ(expected_value, info_value); +} + +// Validate unsigned length SQLULEN return value +void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLULEN expected_value) { + SQLULEN info_value; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, + SQLGetInfo(connection, info_type, &info_value, 0, &message_length)); + + EXPECT_EQ(expected_value, info_value); +} + +// Validate wchar string SQLWCHAR return value +void Validate(SQLHDBC connection, SQLUSMALLINT info_type, SQLWCHAR* expected_value) { + SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L""; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, + &message_length)); + + EXPECT_EQ(*expected_value, *info_value); +} + +// Validate unsigned long SQLUINTEGER return value is greater than +void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type, + SQLUINTEGER compared_value) { + SQLUINTEGER info_value; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, + SQLGetInfo(connection, info_type, &info_value, 0, &message_length)); + + EXPECT_GT(info_value, compared_value); +} + +// Validate unsigned length SQLULEN return value is greater than +void ValidateGreaterThan(SQLHDBC connection, SQLUSMALLINT info_type, + SQLULEN compared_value) { + SQLULEN info_value; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, + SQLGetInfo(connection, info_type, &info_value, 0, &message_length)); + + EXPECT_GT(info_value, compared_value); +} + +// Validate wchar string SQLWCHAR return value is not empty +void ValidateNotEmptySQLWCHAR(SQLHDBC connection, SQLUSMALLINT info_type, + bool allow_truncation) { + SQLWCHAR info_value[ODBC_BUFFER_SIZE] = L""; + SQLSMALLINT message_length; + + SQLRETURN ret = + SQLGetInfo(connection, info_type, info_value, ODBC_BUFFER_SIZE, &message_length); + if (allow_truncation && ret == SQL_SUCCESS_WITH_INFO) { + ASSERT_EQ(SQL_SUCCESS_WITH_INFO, ret); + } else { + ASSERT_EQ(SQL_SUCCESS, ret); + } + + EXPECT_GT(wcslen(info_value), 0); +} + +// Driver Information + +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoActiveEnvironments) { + Validate(this->conn, SQL_ACTIVE_ENVIRONMENTS, static_cast<SQLUSMALLINT>(0)); +} + +#ifdef SQL_ASYNC_DBC_FUNCTIONS +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoAsyncDbcFunctions) { + Validate(this->conn, SQL_ASYNC_DBC_FUNCTIONS, + static_cast<SQLUINTEGER>(SQL_ASYNC_DBC_NOT_CAPABLE)); +} +#endif + +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoAsyncMode) { + Validate(this->conn, SQL_ASYNC_MODE, static_cast<SQLUINTEGER>(SQL_AM_NONE)); +} + +#ifdef SQL_ASYNC_NOTIFICATION +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoAsyncNotification) { + Validate(this->conn, SQL_ASYNC_NOTIFICATION, + static_cast<SQLUINTEGER>(SQL_ASYNC_NOTIFICATION_NOT_CAPABLE)); +} +#endif + +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoBatchRowCount) { + Validate(this->conn, SQL_BATCH_ROW_COUNT, static_cast<SQLUINTEGER>(0)); +} + +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoBatchSupport) { + Validate(this->conn, SQL_BATCH_SUPPORT, static_cast<SQLUINTEGER>(0)); +} + +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDataSourceName) { + Validate(this->conn, SQL_DATA_SOURCE_NAME, static_cast<SQLWCHAR*>(L"")); +} + +#ifdef SQL_DRIVER_AWARE_POOLING_SUPPORTED +TYPED_TEST(ConnectionInfoTest, TestSQLGetInfoDriverAwarePoolingSupported) { + // A driver does not need to implement SQL_DRIVER_AWARE_POOLING_SUPPORTED and the + // Driver Manager will not honor to the driver's return value. Review Comment: I'm not quite understanding what this comment is trying to say -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
