Debian Codegraph @

Card/t/test.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 # test.pl: simple sample program based on test.pl to test the pcsc
4 # Perl wrapper under Test::Harness
5 # Copyright (C) 2001 Lionel Victor, 2003 Ludovic Rousseau
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 use Test::More;
22 use Chipcard::PCSC;
23 use Chipcard::PCSC::Card;
24
25 plan tests => 9;
26
27 use strict;
28 use warnings;
29
30 my $hContext;
31 my @ReadersList;
32
33 my $hCard;
34 my @StatusResult;
35 my $tmpVal;
36 my $SendData;
37 my $RecvData;
38
39 #-------------------------------------------------------------------------------
40 $hContext = new Chipcard::PCSC();
41 #die ("not ok : Can't create the pcsc object: $Chipcard::PCSC::errno\n") unless (defined $hContext);
42 ok(defined $hContext, "new Chipcard::PCSC()");
43
44 #-------------------------------------------------------------------------------
45 @ReadersList = $hContext->ListReaders ();
46 #die ("not ok : Can't get readers' list: $Chipcard::PCSC::errno\n") unless (defined($ReadersList[0]));
47 ok(defined($ReadersList[0]), "\$hContext->ListReaders ()");
48
49 #-------------------------------------------------------------------------------
50 $hCard = new Chipcard::PCSC::Card ($hContext);
51 #die ("not ok : Can't create the reader object: $Chipcard::PCSC::errno\n") unless (defined($hCard));
52 ok(defined($hCard), "new Chipcard::PCSC::Card (\$hContext)");
53
54 $tmpVal = $hCard->Connect($ReadersList[0], $Chipcard::PCSC::SCARD_SHARE_SHARED);
55 unless ($tmpVal) {
56 # Try to reconnect and reset if connect fails
57 print "not ok : Connect failed: trying to reset the card:\n";
58 $tmpVal = $hCard->Reconnect ($Chipcard::PCSC::SCARD_SHARE_SHARED,
59 $Chipcard::PCSC::SCARD_PROTOCOL_T0, $Chipcard::PCSC::SCARD_RESET_CARD);
60 die ("not ok : Can't reconnect to the reader '$ReadersList[0]':
61 $Chipcard::PCSC::errno\n") unless ($tmpVal);
62 }
63 ok ($hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_T0 ||
64 $hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_T1 ||
65 $hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_RAW,
66 "Can understand the current protocol: $hCard->{dwProtocol}");
67
68 #-------------------------------------------------------------------------------
69 @StatusResult = $hCard->Status();
70 #die ("not ok : Can't get status: $Chipcard::PCSC::errno\n") unless ($StatusResult[0]);
71 ok($StatusResult[0], "\$hCard->Status()");
72
73 #-------------------------------------------------------------------------------
74 #die ("not ok : Can't initiate transaction: $Chipcard::PCSC::errno\n") unless ($hCard->BeginTransaction());
75 ok($hCard->BeginTransaction(), "\$hCard->BeginTransaction()");
76
77 #-------------------------------------------------------------------------------
78 $SendData = Chipcard::PCSC::ascii_to_array ("00 A4 01 00 02 01 00");
79 $RecvData = $hCard->Transmit($SendData);
80 #die ("not ok : Can't transmit data: $Chipcard::PCSC::errno") unless (defined ($RecvData));
81 ok(defined ($RecvData), "\$hCard->Transmit()");
82
83 #-------------------------------------------------------------------------------
84 #die ("not ok : Can't terminate transaction: $Chipcard::PCSC::errno\n")
85 #unless ($hCard->EndTransaction($Chipcard::PCSC::SCARD_LEAVE_CARD));
86 ok($hCard->EndTransaction($Chipcard::PCSC::SCARD_LEAVE_CARD),
87 "\$hCard->EndTransaction()");
88
89 #-------------------------------------------------------------------------------
90 $tmpVal = $hCard->Disconnect($Chipcard::PCSC::SCARD_LEAVE_CARD);
91 #die ("not ok : Can't disconnect the PCSC object: $Chipcard::PCSC::errno\n") unless $tmpVal;
92 ok($tmpVal, "\$hCard->Disconnect");
93
94 #-------------------------------------------------------------------------------
95 $hCard = undef;
96 $hContext = undef;
97
98 # End of File #
99