Release 1.6-rc2.
[wine/testsucceed.git] / dlls / odbccp32 / tests / misc.c
blob40846e5c9ef9dea74a5432daf500519907e66a5a
1 /*
2 * Copyright 2007 Bill Medland
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <wine/test.h>
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "odbcinst.h"
26 static void test_SQLConfigMode(void)
28 BOOL bool_ret;
29 DWORD error_code;
30 RETCODE sql_ret;
31 UWORD config_mode;
32 int i;
34 ok(SQLGetConfigMode(NULL), "SQLGetConfigMode(NULL) should succeed\n");
36 bool_ret = SQLGetConfigMode(&config_mode);
37 ok(bool_ret && config_mode == ODBC_BOTH_DSN, "Failed to get the initial SQLGetConfigMode or it was not both\n");
39 bool_ret = SQLSetConfigMode(3);
40 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
41 ok(!bool_ret && sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_PARAM_SEQUENCE, "SQLSetConfigMode with invalid argument did not fail correctly\n");
43 ok (ODBC_SYSTEM_DSN == 2 && ODBC_USER_DSN == 1 && ODBC_BOTH_DSN == 0, "SQLSetConfigMode modes not as expected\n");
44 for (i = ODBC_SYSTEM_DSN; i >= ODBC_BOTH_DSN; --i)
46 ok(SQLSetConfigMode((UWORD)i), "SQLSetConfigMode Failed to set config mode\n");
47 bool_ret = SQLGetConfigMode(&config_mode);
48 ok(bool_ret && config_mode == i, "Failed to confirm SQLSetConfigMode.\n");
50 /* And that leaves it correctly on BOTH */
53 static void test_SQLInstallerError(void)
55 RETCODE sql_ret;
57 /* MSDN states that the error number should be between 1 and 8. Passing 0 is an error */
58 sql_ret = SQLInstallerError(0, NULL, NULL, 0, NULL);
59 ok(sql_ret == SQL_ERROR, "SQLInstallerError(0...) failed with %d instead of SQL_ERROR\n", sql_ret);
60 /* However numbers greater than 8 do not return SQL_ERROR.
61 * I am currently unsure as to whether it should return SQL_NO_DATA or "the same as for error 8";
62 * I have never been able to generate 8 errors to test it
64 sql_ret = SQLInstallerError(65535, NULL, NULL, 0, NULL);
65 ok(sql_ret == SQL_NO_DATA, "SQLInstallerError(>8...) failed with %d instead of SQL_NO_DATA\n", sql_ret);
67 /* Force an error to work with. This should generate ODBC_ERROR_INVALID_BUFF_LEN */
68 ok(!SQLGetInstalledDrivers(0, 0, 0), "Failed to force an error for testing\n");
69 sql_ret = SQLInstallerError(2, NULL, NULL, 0, NULL);
70 ok(sql_ret == SQL_NO_DATA, "Too many errors when forcing an error for testing\n");
72 /* Null pointers are acceptable in all obvious places */
73 sql_ret = SQLInstallerError(1, NULL, NULL, 0, NULL);
74 ok(sql_ret == SQL_SUCCESS_WITH_INFO, "SQLInstallerError(null addresses) failed with %d instead of SQL_SUCCESS_WITH_INFO\n", sql_ret);
77 static void test_SQLInstallDriverManager(void)
79 BOOL bool_ret;
80 RETCODE sql_ret;
81 DWORD error_code;
82 CHAR target_path[MAX_PATH];
83 WORD path_out;
85 /* NULL check */
86 bool_ret = SQLInstallDriverManager(NULL, 0, NULL);
87 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
88 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
89 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
90 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
92 /* Length smaller than MAX_PATH */
93 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, NULL);
94 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
95 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
96 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
97 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
99 path_out = 0xcafe;
100 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH / 2, &path_out);
101 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
102 ok(!bool_ret, "SQLInstallDriverManager unexpectedly succeeded\n");
103 ok(sql_ret == SQL_SUCCESS_WITH_INFO && error_code == ODBC_ERROR_INVALID_BUFF_LEN,
104 "Expected SQLInstallDriverManager to fail with ODBC_ERROR_INVALID_BUFF_LEN\n");
105 ok(path_out == 0xcafe, "Expected path_out to not have changed\n");
107 /* Length OK */
108 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, NULL);
109 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
110 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n",
111 error_code);
112 if (bool_ret)
113 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
114 else
115 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
116 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
118 path_out = 0xcafe;
119 bool_ret = SQLInstallDriverManager(target_path, MAX_PATH, &path_out);
120 sql_ret = SQLInstallerErrorW(1, &error_code, NULL, 0, NULL);
121 ok(bool_ret, "SQLInstallDriverManager unexpectedly failed: %d\n",
122 error_code);
123 if (bool_ret)
124 ok(sql_ret == SQL_NO_DATA, "Expected SQL_NO_DATA, got %d\n", sql_ret);
125 else
126 ok(sql_ret == SQL_SUCCESS_WITH_INFO,
127 "Expected SQL_SUCCESS_WITH_INFO, got %d\n", sql_ret);
128 /* path_out should in practice be less than 0xcafe */
129 ok(path_out != 0xcafe, "Expected path_out to show the correct amount of bytes\n");
132 START_TEST(misc)
134 test_SQLConfigMode();
135 test_SQLInstallerError();
136 test_SQLInstallDriverManager();