lidavidm commented on code in PR #47762: URL: https://github.com/apache/arrow/pull/47762#discussion_r2479926917
########## cpp/src/arrow/flight/sql/odbc/tests/connection_info_test.cc: ########## @@ -0,0 +1,865 @@ +// 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 {}; + +class ConnectionInfoMockTest : public FlightSQLODBCMockTestBase {}; +using TestTypes = ::testing::Types<ConnectionInfoMockTest, FlightSQLODBCRemoteTestBase>; +TYPED_TEST_SUITE(ConnectionInfoTest, TestTypes); + +namespace { +// 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, + const SQLWCHAR* expected_value) { + SQLWCHAR info_value[kOdbcBufferSize] = L""; + SQLSMALLINT message_length; + + ASSERT_EQ(SQL_SUCCESS, SQLGetInfo(connection, info_type, info_value, kOdbcBufferSize, + &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) { Review Comment: I do have the same general comment: I think you would be better off creating utility getters (that throw if they fail) and then using standard GTest assertions, instead of making a function for every combination of data type and comparator. (Also, can they be shared across test files?) -- 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]
