Sergey,

>+ * Unit test suite for AVI Functions
>+ * Copyright 2008 Detlef Riekenberg
+#include "wingdi.h"
>+#include "vfw.h"
Please try and hide better the copy&paste origin of the code :-)

>rezult
result

+    ok(winscard_rezult != SCARD_F_INTERNAL_ERROR
I recommend tests to be stricter, e.g.
ok(result == SCARD_S_SUCCESS || result == SCARD_E_XYZ || broken(result == 
SCARD_E_...)

Here's work done last year by Yauheni Baltouski and Aliaksei Hud.
They are not working on winscard any more.

I'd be pleased to eventually see winscard tests in Wine.
Maybe you could merge this work?

I *hope* I attached the latest version of the patch.  If yes, it was verified
last year to pass on:
- native machines with and without card readers;
- testbot, incl. w9x machines;
- 64 bit? can't remember;
- stock Linux (Ubuntu Lucid);
- Linux with Mounir Idrassi's winscard dll (in which case the todo_wine succeed)
  and a card reader.
It contains a good mixture of win_skip(), broken() and todo_wine to that effect.

I had not submitted these tests in the past because IIRC there's
still a resource leak (FreeLibrary following LoadLibrary;
 SCardFreeMemory following SCardListReaders AUTOALLOCATE)
and some style issues (casts inside ok("%ld") formats)
as well as IMHO too many redundant trace("testing X\n"), see 
$WINETEST_REPORT_SUCCESS.

In their patch,
LoadLibrary was necessary instead of a statically linked .exe because
not all native systems provide winscard.dll
Nowadays, successful tests on w9x are not considered important anymore,
so this might be superfluous (but I don't know whether one can expect
winscard on all machines since NT).

+#ifndef SCARD_AUTOALLOCATE
+#define SCARD_AUTOALLOCATE (DWORD)(-1)
+#ifndef SCARD_SCOPE_USER
+#define SCARD_SCOPE_USER 0x0000
was necessary because Wine's winscard.h does not yet provide enough definitions.
-- Completing winscard.h would be a useful patch on its own.

This test was considered the first of a series: small enough yet still doing
something useful (ListReaders), but not yet depending on the presence of a chip 
card.


Final comments on your initial patch:
+           mszReaders = malloc(cchReaders);
HeapAlloc() is recommended in Wine, i.e. programming against the MS API.

+START_TEST(winscard_api)
Just name it winscard.  Keep the name short because you use it on the command 
line.

You don't initialize SCARD_READERSTATE as MSDN requires it for 
SCardGetStatusChange:
"Important  Each member of each structure in this array must be initialized to 
zero"
and you don't check whether SCardListReaders returned at least one string in 
mszReaders
for you to feed into SCardGetStatusChange.

Regards,
 Jörg Höhle

>From 3a936d8e0c100aee0da324d4d32e92368eefde88 Mon Sep 17 00:00:00 2001
From: Yauheni Baltouski <ybaltou...@gmail.com>
Date: Tue, 29 Jun 2010 11:25:24 +0300
Subject: winscard/test: add initial test cases

---
 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 = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = winscard.dll
+IMPORTS   = kernel32 ntdll
+
+C_SRCS = \
+       scard.c
+
+@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
+ * 
+ *
+ * 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 <stdio.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "winver.h" 
+
+#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[] = "winscard.dll";
+
+static LONG (WINAPI *pSCardEstablishContext)(DWORD ,LPCVOID, LPCVOID, 
LPSCARDCONTEXT);
+static LONG (WINAPI *pSCardReleaseContext)(SCARDCONTEXT);
+static LONG (WINAPI *pSCardListReadersA)(SCARDCONTEXT,LPCSTR,LPSTR,LPDWORD);
+static LONG (WINAPI *pSCardListReadersW)(SCARDCONTEXT,LPCSTR,LPSTR,LPDWORD);
+
+static SCARDCONTEXT    hSC; 
+static LPTSTR          szReaders;
+static DWORD           cchReaders = SCARD_AUTOALLOCATE;
+
+static void test_SCardEstablishContext(void) {
+        LONG lReturn;
+
+        trace("testing SCardEstablishContext\n");
+
+        lReturn = pSCardEstablishContext(SCARD_SCOPE_USER,
+                                         NULL,
+                                         NULL,
+                                         &hSC);
+        todo_wine
+        {
+               ok((SCARD_S_SUCCESS==lReturn || 
broken(SCARD_E_NO_SERVICE==lReturn /*service disabled */)),
+                   "can't execute SCardEstablishContext, SCardEstablishContext 
ptr = %p, return = %ld\n",
+                   pSCardEstablishContext,
+                   (long)lReturn);
+        }
+}
+
+static void test_SCardReleaseContext(void) {
+    LONG lReturn;
+
+    trace("testing SCardReleaseContext\n");
+    if (hSC) {
+
+             lReturn = pSCardReleaseContext(hSC); }
+
+    todo_wine 
+    {
+        ok(SCARD_S_SUCCESS==lReturn && hSC,
+        "can't execute SCardReleaseContext, SCardReleaseContext ptr = %p, 
SCARDCONTEXT=%lx, return=%ld\n",
+        pSCardReleaseContext,
+        (long int)hSC,
+        (long)lReturn);
+    }
+}
+
+static void test_SCardListReadersA(void) {
+    LONG lReturn;
+
+    trace("testing SCardListReadersA\n");
+    if (hSC) {
+
+        lReturn = pSCardListReadersA(hSC,
+                           NULL,
+                           (LPTSTR)&szReaders,
+                           &cchReaders);    }
+
+    todo_wine
+    {
+        ok((lReturn == SCARD_S_SUCCESS || lReturn == 
SCARD_E_NO_READERS_AVAILABLE) && hSC,
+        "can't execute SCardListReadersA, SCardListReadersA ptr = %p, 
SCARDCONTEXT=%lx, return=%ld\n",
+        pSCardListReadersA,
+        (long int)hSC,
+        (long)lReturn); 
+    }
+}
+
+static void test_SCardListReadersW(void) {
+    LONG    lReturn;
+
+    trace("testing SCardListReadersW\n");
+    if (hSC) {
+
+        lReturn = pSCardListReadersW(hSC,
+                           NULL,
+                           (LPTSTR)&szReaders,
+                           &cchReaders);}
+
+    todo_wine
+    {
+        ok((lReturn == SCARD_S_SUCCESS || lReturn == 
SCARD_E_NO_READERS_AVAILABLE) && hSC,
+        "can't execute SCardListReadersW, SCardListReadersW ptr = %p, 
SCARDCONTEXT=%lx, return=%ld\n",
+        pSCardListReadersW,
+        (long int)hSC,
+        (long)lReturn);
+    }
+}
+
+static BOOL init_winscard(void){
+#define GET_PROC(func) \
+    (p ## func = (void *)GetProcAddress(module, #func))
+    HMODULE module=NULL;
+    trace("testing winscard initialization\n");
+    module = LoadLibraryA(winscardDll);
+    if (!module) 
+    {
+        win_skip("No winscard.dll found - aborting");
+        return FALSE;
+    }
+    else {
+
+        trace("loading winscard SCardEstablishContext\n");
+        GET_PROC(SCardEstablishContext);
+        todo_wine ok(pSCardEstablishContext!=NULL, "can't initialize winscard 
SCardEstablishContext, error=%lx\n", (long int)GetLastError());
+        if (pSCardEstablishContext==NULL) return FALSE;
+
+        trace("loading winscard SCardReleaseContext\n");
+        GET_PROC(SCardReleaseContext);
+        todo_wine ok(pSCardReleaseContext!=NULL, "can't initialize winscard 
SCardReleaseContext, error=%lx\n", (long int)GetLastError());
+        if (pSCardReleaseContext==NULL) return FALSE;
+
+        trace("loading winscard SCardListReadersA\n");
+        GET_PROC(SCardListReadersA);
+        todo_wine ok(pSCardListReadersA!=NULL, "can't initialize winscard 
SCardListReadersA, error=%lx\n", (long int)GetLastError());
+        if (pSCardListReadersA==NULL) return FALSE;
+
+        trace("loading winscard SCardListReadersW\n");
+        GET_PROC(SCardListReadersW);
+        todo_wine ok(pSCardListReadersW!=NULL, "can't initialize winscard 
SCardListReadersW, error=%lx\n", (long int)GetLastError());
+        if (pSCardListReadersW==NULL) return FALSE;
+
+        return TRUE;
+    }
+#undef GET_PROC
+}
+
+
+START_TEST(scard)
+{
+    if (init_winscard()) {
+        test_SCardEstablishContext();
+        if (hSC) 
+        {
+            test_SCardListReadersW();
+            test_SCardListReadersA();
+            test_SCardReleaseContext();/*must be at end of tests*/
+        }
+    }
+}
-- 
1.7.0.4



Reply via email to