winscard/test: add initial test cases

Yauheni Baltouski ybaltouski at gmail.com
Tue Jun 29 03:25:24 CDT 2010


---
 configure.ac                    |    1 +
 dlls/winscard/tests/Makefile.in |   11 +++
 dlls/winscard/tests/scard.c     |  180 +++++++++++++++++++++++++++++++++++=
++++
 3 files changed, 192 insertions(+), 0 deletions(-)
 create mode 100644 dlls/winscard/tests/Makefile.in
 create mode 100644 dlls/winscard/tests/scard.c

diff --git a/configure.ac b/configure.ac
index 61f376e..0309abc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2661,6 +2661,7 @@ WINE_CONFIG_TEST(dlls/winmm/tests)
 WINE_CONFIG_DLL(winnls.dll16,enable_win16)
 WINE_CONFIG_DLL(winnls32,,[winnls32])
 WINE_CONFIG_DLL(winscard,,[winscard])
+WINE_CONFIG_TEST(dlls/winscard/tests)
 WINE_CONFIG_DLL(winsock.dll16,enable_win16)
 WINE_CONFIG_DLL(winspool.drv,,[winspool])
 WINE_CONFIG_TEST(dlls/winspool.drv/tests)
diff --git a/dlls/winscard/tests/Makefile.in b/dlls/winscard/tests/Makefile=
.in
new file mode 100644
index 0000000..879481b
--- /dev/null
+++ b/dlls/winscard/tests/Makefile.in
@@ -0,0 +1,11 @@
+TOPSRCDIR =3D @top_srcdir@
+TOPOBJDIR =3D ../../..
+SRCDIR    =3D @srcdir@
+VPATH     =3D @srcdir@
+TESTDLL   =3D winscard.dll
+IMPORTS   =3D kernel32 ntdll
+
+C_SRCS =3D \
+	scard.c
+
+ at MAKE_TEST_RULES@
diff --git a/dlls/winscard/tests/scard.c b/dlls/winscard/tests/scard.c
new file mode 100644
index 0000000..fd751c8
--- /dev/null
+++ b/dlls/winscard/tests/scard.c
@@ -0,0 +1,180 @@
+/*
+ * Unit tests for winscard.dll functions
+ *
+ * Copyright 2010 Yauheni S Baltouski
+ *=20
+ *
+ * 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, U=
SA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winver.h"=20
+
+#include <winscard.h>
+#include "wine/test.h"
+
+#ifndef SCARD_AUTOALLOCATE
+#define SCARD_AUTOALLOCATE (DWORD)(-1)
+#endif
+
+#ifndef SCARD_SCOPE_USER
+#define SCARD_SCOPE_USER 0x0000
+#endif
+
+static const CHAR winscardDll[] =3D "winscard.dll";
+
+static LONG (WINAPI *pSCardEstablishContext)(DWORD ,LPCVOID, LPCVOID, LPSC=
ARDCONTEXT);
+static LONG (WINAPI *pSCardReleaseContext)(SCARDCONTEXT);
+static LONG (WINAPI *pSCardListReadersA)(SCARDCONTEXT,LPCSTR,LPSTR,LPDWORD=
);
+static LONG (WINAPI *pSCardListReadersW)(SCARDCONTEXT,LPCSTR,LPSTR,LPDWORD=
);
+
+static SCARDCONTEXT    hSC;=20
+static LPTSTR          szReaders;
+static DWORD           cchReaders =3D SCARD_AUTOALLOCATE;
+
+static void test_SCardEstablishContext(void) {
+        LONG lReturn;
+
+        trace("testing SCardEstablishContext\n");
+
+        lReturn =3D pSCardEstablishContext(SCARD_SCOPE_USER,
+                                         NULL,
+                                         NULL,
+                                         &hSC);
+        todo_wine
+        {
+               ok((SCARD_S_SUCCESS=3D=3DlReturn || broken(SCARD_E_NO_SERVI=
CE=3D=3DlReturn /*service disabled */)),
+                   "can't execute SCardEstablishContext, SCardEstablishCon=
text ptr =3D %p, return =3D %ld\n",
+                   pSCardEstablishContext,
+                   (long)lReturn);
+        }
+}
+
+static void test_SCardReleaseContext(void) {
+    LONG lReturn;
+
+    trace("testing SCardReleaseContext\n");
+    if (hSC) {
+
+             lReturn =3D pSCardReleaseContext(hSC); }
+
+    todo_wine=20
+    {
+        ok(SCARD_S_SUCCESS=3D=3DlReturn && hSC,
+        "can't execute SCardReleaseContext, SCardReleaseContext ptr =3D %p=
, SCARDCONTEXT=3D%lx, return=3D%ld\n",
+        pSCardReleaseContext,
+        (long int)hSC,
+        (long)lReturn);
+    }
+}
+
+static void test_SCardListReadersA(void) {
+    LONG lReturn;
+
+    trace("testing SCardListReadersA\n");
+    if (hSC) {
+
+        lReturn =3D pSCardListReadersA(hSC,
+                           NULL,
+                           (LPTSTR)&szReaders,
+                           &cchReaders);    }
+
+    todo_wine
+    {
+        ok((lReturn =3D=3D SCARD_S_SUCCESS || lReturn =3D=3D SCARD_E_NO_RE=
ADERS_AVAILABLE) && hSC,
+        "can't execute SCardListReadersA, SCardListReadersA ptr =3D %p, SC=
ARDCONTEXT=3D%lx, return=3D%ld\n",
+        pSCardListReadersA,
+        (long int)hSC,
+        (long)lReturn);=20
+    }
+}
+
+static void test_SCardListReadersW(void) {
+    LONG    lReturn;
+
+    trace("testing SCardListReadersW\n");
+    if (hSC) {
+
+        lReturn =3D pSCardListReadersW(hSC,
+                           NULL,
+                           (LPTSTR)&szReaders,
+                           &cchReaders);}
+
+    todo_wine
+    {
+        ok((lReturn =3D=3D SCARD_S_SUCCESS || lReturn =3D=3D SCARD_E_NO_RE=
ADERS_AVAILABLE) && hSC,
+        "can't execute SCardListReadersW, SCardListReadersW ptr =3D %p, SC=
ARDCONTEXT=3D%lx, return=3D%ld\n",
+        pSCardListReadersW,
+        (long int)hSC,
+        (long)lReturn);
+    }
+}
+
+static BOOL init_winscard(void){
+#define GET_PROC(func) \
+    (p ## func =3D (void *)GetProcAddress(module, #func))
+    HMODULE module=3DNULL;
+    trace("testing winscard initialization\n");
+    module =3D LoadLibraryA(winscardDll);
+    if (!module)=20
+    {
+        win_skip("No winscard.dll found - aborting");
+        return FALSE;
+    }
+    else {
+
+        trace("loading winscard SCardEstablishContext\n");
+        GET_PROC(SCardEstablishContext);
+        todo_wine ok(pSCardEstablishContext!=3DNULL, "can't initialize win=
scard SCardEstablishContext, error=3D%lx\n", (long int)GetLastError());
+        if (pSCardEstablishContext=3D=3DNULL) return FALSE;
+
+        trace("loading winscard SCardReleaseContext\n");
+        GET_PROC(SCardReleaseContext);
+        todo_wine ok(pSCardReleaseContext!=3DNULL, "can't initialize winsc=
ard SCardReleaseContext, error=3D%lx\n", (long int)GetLastError());
+        if (pSCardReleaseContext=3D=3DNULL) return FALSE;
+
+        trace("loading winscard SCardListReadersA\n");
+        GET_PROC(SCardListReadersA);
+        todo_wine ok(pSCardListReadersA!=3DNULL, "can't initialize winscar=
d SCardListReadersA, error=3D%lx\n", (long int)GetLastError());
+        if (pSCardListReadersA=3D=3DNULL) return FALSE;
+
+        trace("loading winscard SCardListReadersW\n");
+        GET_PROC(SCardListReadersW);
+        todo_wine ok(pSCardListReadersW!=3DNULL, "can't initialize winscar=
d SCardListReadersW, error=3D%lx\n", (long int)GetLastError());
+        if (pSCardListReadersW=3D=3DNULL) return FALSE;
+
+        return TRUE;
+    }
+#undef GET_PROC
+}
+
+
+START_TEST(scard)
+{
+    if (init_winscard()) {
+        test_SCardEstablishContext();
+        if (hSC)=20
+        {
+            test_SCardListReadersW();
+            test_SCardListReadersA();
+            test_SCardReleaseContext();/*must be at end of tests*/
+        }
+    }
+}
--=20
1.7.0.4




More information about the wine-devel mailing list