From 648d4f13e26a076feca219b76111c03262504d95 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Fri, 3 Feb 2023 14:16:21 +1100 Subject: [PATCH 04/42] odbc32: Add initial tests --- configure | 1 + configure.ac | 1 + dlls/odbc32/tests/Makefile.in | 4 + dlls/odbc32/tests/connection.c | 165 +++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 dlls/odbc32/tests/Makefile.in create mode 100644 dlls/odbc32/tests/connection.c diff --git a/configure b/configure index 66e607337db..40b93ce0490 100755 --- a/configure +++ b/configure @@ -21634,6 +21634,7 @@ wine_fn_config_makefile dlls/ntprint enable_ntprint wine_fn_config_makefile dlls/ntprint/tests enable_tests wine_fn_config_makefile dlls/objsel enable_objsel wine_fn_config_makefile dlls/odbc32 enable_odbc32 +wine_fn_config_makefile dlls/odbc32/tests enable_tests wine_fn_config_makefile dlls/odbcbcp enable_odbcbcp wine_fn_config_makefile dlls/odbccp32 enable_odbccp32 wine_fn_config_makefile dlls/odbccp32/tests enable_tests diff --git a/configure.ac b/configure.ac index 1033af2e613..249ea8b3f05 100644 --- a/configure.ac +++ b/configure.ac @@ -2898,6 +2898,7 @@ WINE_CONFIG_MAKEFILE(dlls/ntprint) WINE_CONFIG_MAKEFILE(dlls/ntprint/tests) WINE_CONFIG_MAKEFILE(dlls/objsel) WINE_CONFIG_MAKEFILE(dlls/odbc32) +WINE_CONFIG_MAKEFILE(dlls/odbc32/tests) WINE_CONFIG_MAKEFILE(dlls/odbcbcp) WINE_CONFIG_MAKEFILE(dlls/odbccp32) WINE_CONFIG_MAKEFILE(dlls/odbccp32/tests) diff --git a/dlls/odbc32/tests/Makefile.in b/dlls/odbc32/tests/Makefile.in new file mode 100644 index 00000000000..4d8716ed2ed --- /dev/null +++ b/dlls/odbc32/tests/Makefile.in @@ -0,0 +1,4 @@ +TESTDLL = odbc32.dll +IMPORTS = odbc32 + +C_SRCS = connection.c diff --git a/dlls/odbc32/tests/connection.c b/dlls/odbc32/tests/connection.c new file mode 100644 index 00000000000..b04d93c42c5 --- /dev/null +++ b/dlls/odbc32/tests/connection.c @@ -0,0 +1,165 @@ +/* + * Copyright 2018 Alistair Leslie-Hughes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + +#include "windef.h" +#include "winbase.h" +#include "sqlext.h" +#include "sqlucode.h" +#include "odbcinst.h" + +static void test_SQLAllocEnv(void) +{ + SQLRETURN ret; + SQLHENV sqlenv, sqlenv2; + + ret = SQLAllocEnv(NULL); + ok(ret == SQL_ERROR, "got %d\n", ret); + + ret = SQLAllocEnv(&sqlenv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + ret = SQLAllocEnv(&sqlenv2); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(sqlenv != sqlenv2, "got %d\n", ret); + + ret = SQLFreeEnv(sqlenv2); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + ret = SQLFreeEnv(sqlenv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + ret = SQLFreeEnv(sqlenv); + todo_wine ok(ret == SQL_INVALID_HANDLE, "got %d\n", ret); + + ret = SQLFreeEnv(SQL_NULL_HENV); + todo_wine ok(ret == SQL_INVALID_HANDLE, "got %d\n", ret); +} + +void test_SQLGetEnvAttr(void) +{ + SQLRETURN ret; + SQLHENV sqlenv; + SQLINTEGER value, length; + + ret = SQLAllocEnv(&sqlenv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + value = 5; + length = 12; + ret = SQLGetEnvAttr(SQL_NULL_HENV, SQL_ATTR_CONNECTION_POOLING, &value, sizeof(SQLINTEGER), &length); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(value == 0, "got %d\n", value); + todo_wine ok(length == 12, "got %d\n", length); + + value = 5; + length = 13; + ret = SQLGetEnvAttr(SQL_NULL_HENV, SQL_ATTR_CONNECTION_POOLING, &value, 0, &length); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(value == 0, "got %d\n", value); + todo_wine ok(length == 13, "got %d\n", length); + + value = 5; + length = 12; + ret = SQLGetEnvAttr(sqlenv, SQL_ATTR_CONNECTION_POOLING, &value, sizeof(SQLINTEGER), &length); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(value == 0, "got %d\n", value); + ok(length == 12, "got %d\n", length); + + value = 5; + length = 12; + ret = SQLGetEnvAttr(sqlenv, SQL_ATTR_CONNECTION_POOLING, &value, 2, &length); + todo_wine ok(ret == SQL_SUCCESS, "got %d\n", ret); + todo_wine ok(value == 0, "got %d\n", value); + ok(length == 12, "got %d\n", length); + + ret = SQLFreeEnv(sqlenv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); +} + +static void test_SQLDriver(void) +{ + SQLHENV henv = SQL_NULL_HENV; + SQLRETURN ret; + SQLCHAR driver[256]; + SQLCHAR attr[256]; + SQLSMALLINT driver_ret; + SQLSMALLINT attr_ret; + SQLUSMALLINT direction; + + ret = SQLAllocEnv(&henv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(henv != SQL_NULL_HENV, "NULL handle\n"); + + direction = SQL_FETCH_FIRST; + + while(SQL_SUCCEEDED(ret = SQLDrivers(henv, direction, driver, sizeof(driver), + &driver_ret, attr, sizeof(attr), &attr_ret))) + { + direction = SQL_FETCH_NEXT; + + trace("%s - %s\n", driver, attr); + } + todo_wine ok(ret == SQL_NO_DATA, "got %d\n", ret); + + ret = SQLFreeEnv(henv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); +} + +static void test_SQLGetDiagRec(void) +{ + SQLHENV henv = SQL_NULL_HENV; + SQLHDBC connection; + SQLRETURN ret; + WCHAR version[11]; + WCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH]; + SQLINTEGER NativeError; + SQLSMALLINT MsgLen; + + ret = SQLAllocEnv(&henv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + ok(henv != SQL_NULL_HENV, "NULL handle\n"); + + ret = SQLAllocConnect(henv, &connection); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + ret = SQLGetInfoW(connection, SQL_ODBC_VER, version, 22, NULL); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + trace("ODBC_VER=%s\n", wine_dbgstr_w(version)); + + ret = SQLFreeConnect(connection); + ok(ret == SQL_SUCCESS, "got %d\n", ret); + + NativeError = 88; + ret = SQLGetDiagRecW( SQL_HANDLE_ENV, henv, 1, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen); + todo_wine ok(ret == SQL_NO_DATA, "got %d\n", ret); + ok(NativeError == 88, "got %d\n", NativeError); + + ret = SQLFreeEnv(henv); + ok(ret == SQL_SUCCESS, "got %d\n", ret); +} + +START_TEST(connection) +{ + test_SQLAllocEnv(); + test_SQLGetEnvAttr(); + test_SQLDriver(); + test_SQLGetDiagRec(); +} -- 2.39.1