Skip to content

Commit 5da7b4f

Browse files
committed
Add tests for setting and getting environment attributes
1 parent 24961c4 commit 5da7b4f

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
#include "arrow/flight/sql/odbc/tests/odbc_test_suite.h"
18+
19+
#ifdef _WIN32
20+
# include <windows.h>
21+
#endif
22+
23+
#include <sql.h>
24+
#include <sqltypes.h>
25+
#include <sqlucode.h>
26+
27+
#include "gmock/gmock.h"
28+
#include "gtest/gtest.h"
29+
30+
namespace arrow::flight::sql::odbc {
31+
32+
TEST(SQLGetEnvAttr, TestSQLGetEnvAttrODBCVersion) {
33+
// ODBC Environment
34+
SQLHENV env;
35+
36+
SQLINTEGER version;
37+
38+
// Allocate an environment handle
39+
SQLRETURN return_env = SQLAllocEnv(&env);
40+
41+
EXPECT_EQ(SQL_SUCCESS, return_env);
42+
43+
SQLRETURN return_get = SQLGetEnvAttr(env, SQL_ATTR_ODBC_VERSION, &version, 0, 0);
44+
45+
EXPECT_EQ(SQL_SUCCESS, return_get);
46+
47+
EXPECT_EQ(SQL_OV_ODBC2, version);
48+
}
49+
50+
TEST(SQLSetEnvAttr, TestSQLSetEnvAttrODBCVersionValid) {
51+
// ODBC Environment
52+
SQLHENV env;
53+
54+
// Allocate an environment handle
55+
SQLRETURN return_env = SQLAllocEnv(&env);
56+
57+
EXPECT_EQ(SQL_SUCCESS, return_env);
58+
59+
// Attempt to set to unsupported version
60+
SQLRETURN return_set =
61+
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC2), 0);
62+
63+
EXPECT_EQ(SQL_SUCCESS, return_set);
64+
}
65+
66+
TEST(SQLSetEnvAttr, TestSQLSetEnvAttrODBCVersionInvalid) {
67+
// ODBC Environment
68+
SQLHENV env;
69+
70+
// Allocate an environment handle
71+
SQLRETURN return_env = SQLAllocEnv(&env);
72+
73+
EXPECT_EQ(SQL_SUCCESS, return_env);
74+
75+
// Attempt to set to unsupported version
76+
SQLRETURN return_set =
77+
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(1), 0);
78+
79+
EXPECT_EQ(SQL_ERROR, return_set);
80+
}
81+
82+
} // namespace arrow::flight::sql::odbc

0 commit comments

Comments
 (0)