[Pcsclite-git-commit] [PCSC] 02/02: UnitaryTests/SCardCancel.c: test for SCardCancel
Ludovic Rousseau
rousseau at moszumanska.debian.org
Thu Jun 15 15:44:26 UTC 2017
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository PCSC.
commit 7307cc4a80f887ef59487d7b8edf104fb56f13ca
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date: Thu Jun 15 14:50:28 2017 +0200
UnitaryTests/SCardCancel.c: test for SCardCancel
Check that the fix in 81d52b98d84be900c6a6532d10d1fe88eac092cf works as
expected.
---
UnitaryTests/Makefile | 1 +
UnitaryTests/SCardCancel.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/UnitaryTests/Makefile b/UnitaryTests/Makefile
index 02d344b..d50a006 100644
--- a/UnitaryTests/Makefile
+++ b/UnitaryTests/Makefile
@@ -10,6 +10,7 @@ CFLAGS := -Wall -O2 -g -DVERSION=\"$(VERSION)\" $(PCSC_CFLAGS)
LDLIBS := $(PCSC_LDLIBS)
PROGRAMS := SCardBeginTransaction \
+ SCardCancel \
BufferOverflow_SCardGetAttrib \
BufferOverflow_SCardTransmit \
BufferOverflow_SCardControl \
diff --git a/UnitaryTests/SCardCancel.c b/UnitaryTests/SCardCancel.c
new file mode 100644
index 0000000..e97cfa6
--- /dev/null
+++ b/UnitaryTests/SCardCancel.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+
+#ifdef __APPLE__
+#include <PCSC/winscard.h>
+#include <PCSC/wintypes.h>
+#else
+#include <winscard.h>
+#endif
+
+#define CHECK(f, rv) printf(f ":[0x%08lX] %s\n", rv, pcsc_stringify_error(rv))
+
+#define GREEN "\33[32m"
+#define BRIGHT_RED "\33[01;31m"
+#define NORMAL "\33[0m"
+
+static SCARDCONTEXT context;
+
+static void *canceler_thread(void *arg) {
+ LONG ret;
+
+ getchar();
+
+ printf("Calling SCardCancel...\n");
+ ret = SCardCancel(context);
+ CHECK("SCardCancel", ret);
+
+ return NULL;
+}
+
+int main(void) {
+ LONG ret;
+ int delay = 3;
+
+ ret = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &context);
+ CHECK("SCardEstablishContext", ret);
+
+ // Spawn a thread which waits for a key-press then cancels the operation.
+ pthread_t thread;
+ ret = pthread_create(&thread, NULL, canceler_thread, NULL);
+
+ printf(GREEN "Press Enter to cancel within %d seconds\n" NORMAL, delay);
+
+ // Set up the blocking call, and wait for cancel or timeout.
+ printf("Entering blocking call\n");
+ SCARD_READERSTATE reader_states[] = {
+ {
+ .szReader = "\\\\?PnP?\\Notification",
+ .pvUserData = NULL,
+ .dwCurrentState = SCARD_STATE_UNAWARE,
+ .dwEventState = SCARD_STATE_UNAWARE,
+ },
+ };
+
+ ret = SCardGetStatusChange(context, delay * 1000, reader_states, 1);
+ CHECK("SCardGetStatusChange", ret);
+ switch (ret) {
+ case SCARD_S_SUCCESS:
+ printf("Blocking call exited normally\n");
+ break;
+
+ case SCARD_E_CANCELLED:
+ /* this should be the correct returned value */
+ printf("Blocking call canceled\n");
+ break;
+
+ case SCARD_E_TIMEOUT:
+ printf("Blocking call timed out\n");
+ break;
+
+ default:
+ fprintf(stderr, "Failed to get status changes: %ld", ret);
+ break;
+ }
+ if (SCARD_E_CANCELLED != ret)
+ printf(BRIGHT_RED "ERROR: Something wrong happened!\n" NORMAL);
+ else
+ printf(GREEN "Good\n" NORMAL);
+
+ ret = SCardReleaseContext(context);
+ CHECK("SCardReleaseContext", ret);
+
+ printf("Waiting thread...\n");
+ pthread_join(thread, NULL);
+
+ return 0;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git
More information about the Pcsclite-cvs-commit
mailing list