Jeremy White : twain_32: Add an initial test framework for twain_32.dll.
Alexandre Julliard
julliard at winehq.org
Tue Jan 27 09:08:00 CST 2009
Module: wine
Branch: master
Commit: 499603c360941ff60778f575ef76a3da9c32f5c1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=499603c360941ff60778f575ef76a3da9c32f5c1
Author: Jeremy White <jwhite at winehq.org>
Date: Mon Jan 26 11:40:49 2009 -0600
twain_32: Add an initial test framework for twain_32.dll.
---
configure | 9 ++
configure.ac | 1 +
dlls/twain_32/tests/Makefile.in | 13 +++
dlls/twain_32/tests/dsm.c | 166 +++++++++++++++++++++++++++++++++++++++
4 files changed, 189 insertions(+), 0 deletions(-)
diff --git a/configure b/configure
index 19d95a0..5053163 100755
--- a/configure
+++ b/configure
@@ -26542,6 +26542,14 @@ dlls/twain_32/Makefile: dlls/twain_32/Makefile.in dlls/Makedll.rules"
ac_config_files="$ac_config_files dlls/twain_32/Makefile"
ALL_MAKEFILES="$ALL_MAKEFILES \\
+ dlls/twain_32/tests/Makefile"
+test "x$enable_tests" != xno && ALL_TEST_DIRS="$ALL_TEST_DIRS \\
+ twain_32/tests"
+ALL_MAKEFILE_DEPENDS="$ALL_MAKEFILE_DEPENDS
+dlls/twain_32/tests/Makefile: dlls/twain_32/tests/Makefile.in dlls/Maketest.rules"
+ac_config_files="$ac_config_files dlls/twain_32/tests/Makefile"
+
+ALL_MAKEFILES="$ALL_MAKEFILES \\
dlls/unicows/Makefile"
test "x$enable_unicows" != xno && ALL_DLL_DIRS="$ALL_DLL_DIRS \\
unicows"
@@ -28578,6 +28586,7 @@ do
"dlls/sxs/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/sxs/Makefile" ;;
"dlls/tapi32/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/tapi32/Makefile" ;;
"dlls/twain_32/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/twain_32/Makefile" ;;
+ "dlls/twain_32/tests/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/twain_32/tests/Makefile" ;;
"dlls/unicows/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/unicows/Makefile" ;;
"dlls/updspapi/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/updspapi/Makefile" ;;
"dlls/url/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/url/Makefile" ;;
diff --git a/configure.ac b/configure.ac
index 063ea15..12cc8e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2110,6 +2110,7 @@ WINE_CONFIG_MAKEFILE([dlls/svrapi/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL
WINE_CONFIG_MAKEFILE([dlls/sxs/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
WINE_CONFIG_MAKEFILE([dlls/tapi32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
WINE_CONFIG_MAKEFILE([dlls/twain_32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
+WINE_CONFIG_MAKEFILE([dlls/twain_32/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS],[enable_tests])
WINE_CONFIG_MAKEFILE([dlls/unicows/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
WINE_CONFIG_MAKEFILE([dlls/updspapi/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
WINE_CONFIG_MAKEFILE([dlls/url/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
diff --git a/dlls/twain_32/tests/Makefile.in b/dlls/twain_32/tests/Makefile.in
new file mode 100644
index 0000000..708fb6d
--- /dev/null
+++ b/dlls/twain_32/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = twain_32.dll
+IMPORTS = user32 gdi32 kernel32
+
+CTESTS = \
+ dsm.c
+
+ at MAKE_TEST_RULES@
+
+ at DEPENDENCIES@ # everything below this line is overwritten by make depend
diff --git a/dlls/twain_32/tests/dsm.c b/dlls/twain_32/tests/dsm.c
new file mode 100644
index 0000000..a915b53
--- /dev/null
+++ b/dlls/twain_32/tests/dsm.c
@@ -0,0 +1,166 @@
+/* Unit test suite for Twain DSM functions
+ *
+ * Copyright 2009 Jeremy White, CodeWeavers, Inc.
+ *
+ * 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 <stdarg.h>
+#include <assert.h>
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "winerror.h"
+#include "winuser.h"
+#include "twain.h"
+
+#include "wine/test.h"
+
+static DSMENTRYPROC pDSM_Entry;
+
+static BOOL dsm_RegisterWindowClasses(void)
+{
+ WNDCLASSA cls;
+
+ cls.style = 0;
+ cls.lpfnWndProc = DefWindowProc;
+ cls.cbClsExtra = 0;
+ cls.cbWndExtra = 0;
+ cls.hInstance = GetModuleHandleA(0);
+ cls.hIcon = 0;
+ cls.hCursor = LoadCursorA(0, IDC_ARROW);
+ cls.hbrBackground = GetStockObject(WHITE_BRUSH);
+ cls.lpszMenuName = NULL;
+ cls.lpszClassName = "TWAIN_dsm_class";
+ if (!RegisterClassA(&cls)) return FALSE;
+
+ return TRUE;
+}
+
+
+static void get_condition_code(TW_IDENTITY *appid, TW_STATUS *status)
+{
+ TW_UINT16 rc;
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_STATUS, MSG_GET, status);
+ ok(rc == TWRC_SUCCESS, "Condition code not available, rc %d\n", rc);
+}
+
+static void test_sources(TW_IDENTITY *appid)
+{
+ TW_UINT16 rc;
+ TW_IDENTITY source;
+ TW_STATUS status;
+
+ memset(&source, 0, sizeof(source));
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &source);
+ get_condition_code(appid, &status);
+ todo_wine
+ ok(rc == TWRC_SUCCESS || rc == TWRC_FAILURE, "Get first error code, rc %d, cc %d\n", rc, status.ConditionCode);
+ if (rc == TWRC_SUCCESS)
+ ok(status.ConditionCode == TWCC_SUCCESS,"Get first invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
+ if (rc == TWRC_FAILURE)
+ ok(status.ConditionCode == TWCC_NODS,"Get first invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
+
+ while (rc == TWRC_SUCCESS)
+ {
+ trace("Got scanner %s\n", source.ProductName);
+ memset(&source, 0, sizeof(source));
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &source);
+ get_condition_code(appid, &status);
+ ok(rc == TWRC_SUCCESS || rc == TWRC_ENDOFLIST, "Get next source failed, rc %d, cc %d\n", rc, status.ConditionCode);
+ }
+
+ memset(&source, 0, sizeof(source));
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &source);
+ get_condition_code(appid, &status);
+ ok(rc == TWRC_SUCCESS || rc == TWRC_FAILURE, "Get default error code, rc %d, cc %d\n", rc, status.ConditionCode);
+ if (rc == TWRC_SUCCESS)
+ {
+ todo_wine
+ ok(status.ConditionCode == TWCC_SUCCESS,"Get default invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
+ }
+
+ if (rc == TWRC_FAILURE)
+ ok(status.ConditionCode == TWCC_NODS,"Get default invalid condition code, rc %d, cc %d\n", rc, status.ConditionCode);
+
+ if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
+ {
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &source);
+ get_condition_code(appid, &status);
+
+ if (rc == TWRC_SUCCESS && status.ConditionCode == TWCC_SUCCESS)
+ {
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, &source);
+ get_condition_code(appid, &status);
+ ok(rc == TWRC_SUCCESS, "Close DS Failed, rc %d, cc %d\n", rc, status.ConditionCode);
+ }
+ }
+
+ if (winetest_interactive)
+ {
+ trace("Interactive, so trying userselect\n");
+ memset(&source, 0, sizeof(source));
+ rc = pDSM_Entry(appid, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &source);
+ get_condition_code(appid, &status);
+ ok(rc == TWRC_SUCCESS || rc == TWRC_CANCEL, "Userselect failed, rc %d, cc %d\n", rc, status.ConditionCode);
+ }
+
+}
+
+START_TEST(dsm)
+{
+ TW_IDENTITY appid;
+ TW_UINT16 rc;
+ HANDLE hwnd;
+ HMODULE htwain;
+
+ if (!dsm_RegisterWindowClasses()) assert(0);
+
+ htwain = LoadLibraryA("twain_32.dll");
+ if (! htwain)
+ {
+ skip("twain_32.dll not available, skipping tests\n");
+ return;
+ }
+ pDSM_Entry = (void*)GetProcAddress(htwain, "DSM_Entry");
+ ok(pDSM_Entry != NULL, "Unable to GetProcAddress DSM_Entry\n");
+ if (! pDSM_Entry)
+ {
+ skip("DSM_Entry not available, skipping tests\n");
+ return;
+ }
+
+ memset(&appid, 0, sizeof(appid));
+ appid.Version.Language = TWLG_ENGLISH_USA;
+ appid.Version.Country = TWCY_USA;
+ appid.ProtocolMajor = TWON_PROTOCOLMAJOR;
+ appid.ProtocolMinor = TWON_PROTOCOLMINOR;
+ appid.SupportedGroups = DG_CONTROL | DG_IMAGE;
+
+ hwnd = CreateWindow("TWAIN_dsm_class", "Twain Test", 0,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, GetModuleHandleA(0), NULL);
+
+ rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &hwnd);
+ ok(rc == TWRC_SUCCESS, "MSG_OPENDSM returned %d", rc);
+
+ test_sources(&appid);
+
+ rc = pDSM_Entry(&appid, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF) &hwnd);
+ ok(rc == TWRC_SUCCESS, "MSG_CLOSEDSM returned %d", rc);
+
+ DestroyWindow(hwnd);
+ FreeLibrary(htwain);
+}
More information about the wine-cvs
mailing list