From: Bruno Jesus <00cpxxx@gmail.com> Subject: winscard/tests: Add the tests file (try 3) Message-Id: Date: Mon, 31 Oct 2011 23:27:41 -0200 try 3 - avoid magic constants by using winscard.h defines try 2 - split the patches and fix win2000 error This is the starting point for the winscard implementation. I'll add dozens of tests and I would like all of them to pass in windows before we start using pcsclite. Testbot will probably be useless since it does not have a smartcard reader connected so I'll ensure all tests succeed in my local machine before submitting them to wine (i'll append the test results on the patch email) In the next days I'll be updating the test file constantly by adding a new tested function per patch. From 0f3b4180a4720d4c5e9f6d405aeeeca4447fe46e Mon Sep 17 00:00:00 2001 --- configure.ac | 1 + dlls/winscard/tests/Makefile.in | 7 +++ dlls/winscard/tests/winscard.c | 85 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 0 deletions(-) create mode 100644 dlls/winscard/tests/Makefile.in create mode 100644 dlls/winscard/tests/winscard.c diff --git a/configure.ac b/configure.ac index ad4f36f..6f73cb2 100644 --- a/configure.ac +++ b/configure.ac @@ -2869,6 +2869,7 @@ WINE_CONFIG_TEST(dlls/winmm/tests) WINE_CONFIG_DLL(winnls.dll16,enable_win16) WINE_CONFIG_DLL(winnls32,,[implib]) WINE_CONFIG_DLL(winscard,,[implib]) +WINE_CONFIG_TEST(dlls/winscard/tests) WINE_CONFIG_DLL(winsock.dll16,enable_win16) WINE_CONFIG_DLL(winspool.drv,,[implib,po],[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..f582a24 --- /dev/null +++ b/dlls/winscard/tests/Makefile.in @@ -0,0 +1,7 @@ +TESTDLL = winscard.dll +IMPORTS = winscard + +C_SRCS = \ + winscard.c + +@MAKE_TEST_RULES@ diff --git a/dlls/winscard/tests/winscard.c b/dlls/winscard/tests/winscard.c new file mode 100644 index 0000000..162a9f5 --- /dev/null +++ b/dlls/winscard/tests/winscard.c @@ -0,0 +1,85 @@ +/* + * Unit test suite for winscard functions + * + * Copyright 2011 Bruno Jesus + * + * 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 + * + * + * Remarks + * - Windows 2000 returns ERROR_INVALID_HANDLE instead of SCARD_INVALID_HANDLE + */ + +#include +#include +#include "wine/test.h" + +SCARDCONTEXT phContext; + +/**************** Test function ***************/ + +static BOOL test_SCardEstablishContext(void) +{ + LONG ret; + + ret = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &phContext); + if(ret == SCARD_E_NO_SERVICE) + { + skip("Smartcard service is not running.\n"); + return FALSE; + } + + todo_wine ok(ret == SCARD_S_SUCCESS, "SCardEstablishContext expected SCARD_S_SUCCESS, received %08X\n", ret); + + return ret == SCARD_S_SUCCESS; +} + +static void test_SCardIsValidContext(void) +{ + LONG ret; + ret = SCardIsValidContext(phContext); + todo_wine ok(ret == SCARD_S_SUCCESS, "SCardIsValidContext expected SCARD_S_SUCCESS, received %08X\n", ret); + + ret = SCardIsValidContext(0); + todo_wine ok(ret == SCARD_E_INVALID_HANDLE || broken(ret == ERROR_INVALID_HANDLE), + "SCardReleaseContext expected SCARD_E_INVALID_HANDLE, received %08X\n", ret); +} + +static void test_SCardReleaseContext(void) +{ + LONG ret; + ret = SCardReleaseContext(phContext); + todo_wine ok(ret == SCARD_S_SUCCESS, "SCardReleaseContext expected SCARD_S_SUCCESS, received %08X\n", ret); + + /* double free the context */ + ret = SCardIsValidContext(phContext); + todo_wine ok(ret == SCARD_E_INVALID_HANDLE || broken(ret == ERROR_INVALID_HANDLE), + "SCardReleaseContext expected SCARD_E_INVALID_HANDLE, received %08X\n", ret); +} + +/**************** Main program ***************/ + +START_TEST( winscard ) +{ + if(test_SCardEstablishContext()) + { + test_SCardIsValidContext(); + + /* add other tests here */ + + test_SCardReleaseContext(); + } +} + -- 1.7.7