| 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::Morescip-perl cpan Chipcard-PCSC v1.4.16 Test/More/; |
| 22 | use Chipcard::PCSCscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/; |
| 23 | use Chipcard::PCSC::Cardscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/Card/; |
| 24 | |
| 25 | planscip-perl cpan Chipcard-PCSC v1.4.16 main/plan(). tests => 9; |
| 26 | |
| 27 | use strictscip-perl cpan Chipcard-PCSC v1.4.16 strict/; |
| 28 | use warningsscip-perl cpan Chipcard-PCSC v1.4.16 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 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().(definedscip-perl cpan Chipcard-PCSC v1.4.16 main/defined(). $hContext, "new Chipcard::PCSC()"); |
| 43 | |
| 44 | #------------------------------------------------------------------------------- |
| 45 | @ReadersList = $hContext->ListReadersscip-perl cpan Chipcard-PCSC v1.4.16 main/ListReaders(). (); |
| 46 | #die ("not ok : Can't get readers' list: $Chipcard::PCSC::errno\n") unless (defined($ReadersList[0])); |
| 47 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().(definedscip-perl cpan Chipcard-PCSC v1.4.16 main/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 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().(definedscip-perl cpan Chipcard-PCSC v1.4.16 main/defined().($hCard), "new Chipcard::PCSC::Card (\$hContext)"); |
| 53 | |
| 54 | $tmpVal = $hCard->Connectscip-perl cpan Chipcard-PCSC v1.4.16 main/Connect().($ReadersList[0], $Chipcard::PCSC::SCARD_SHARE_SHAREDscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_SHARE_SHARED.); |
| 55 | unless ($tmpVal) { |
| 56 | # Try to reconnect and reset if connect fails |
| 57 | printscip-perl cpan Chipcard-PCSC v1.4.16 main/print(). "not ok : Connect failed: trying to reset the card:\n"; |
| 58 | $tmpVal = $hCard->Reconnectscip-perl cpan Chipcard-PCSC v1.4.16 main/Reconnect(). ($Chipcard::PCSC::SCARD_SHARE_SHAREDscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_SHARE_SHARED., |
| 59 | $Chipcard::PCSC::SCARD_PROTOCOL_T0scip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_PROTOCOL_T0., $Chipcard::PCSC::SCARD_RESET_CARDscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_RESET_CARD.); |
| 60 | diescip-perl cpan Chipcard-PCSC v1.4.16 main/die(). ("not ok : Can't reconnect to the reader '$ReadersList[0]': |
| 61 | $Chipcard::PCSC::errno\n") unless ($tmpVal); |
| 62 | } |
| 63 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok(). ($hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_T0scip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_PROTOCOL_T0. || |
| 64 | $hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_T1scip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_PROTOCOL_T1. || |
| 65 | $hCard->{dwProtocol}==$Chipcard::PCSC::SCARD_PROTOCOL_RAWscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_PROTOCOL_RAW., |
| 66 | "Can understand the current protocol: $hCard->{dwProtocol}"); |
| 67 | |
| 68 | #------------------------------------------------------------------------------- |
| 69 | @StatusResult = $hCard->Statusscip-perl cpan Chipcard-PCSC v1.4.16 main/Status().(); |
| 70 | #die ("not ok : Can't get status: $Chipcard::PCSC::errno\n") unless ($StatusResult[0]); |
| 71 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().($StatusResult[0], "\$hCard->Status()"); |
| 72 | |
| 73 | #------------------------------------------------------------------------------- |
| 74 | #die ("not ok : Can't initiate transaction: $Chipcard::PCSC::errno\n") unless ($hCard->BeginTransaction()); |
| 75 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().($hCard->BeginTransactionscip-perl cpan Chipcard-PCSC v1.4.16 main/BeginTransaction().(), "\$hCard->BeginTransaction()"); |
| 76 | |
| 77 | #------------------------------------------------------------------------------- |
| 78 | $SendData = Chipcard::PCSC::ascii_to_arrayscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/ascii_to_array(). ("00 A4 01 00 02 01 00"); |
| 79 | $RecvData = $hCard->Transmitscip-perl cpan Chipcard-PCSC v1.4.16 main/Transmit().($SendData); |
| 80 | #die ("not ok : Can't transmit data: $Chipcard::PCSC::errno") unless (defined ($RecvData)); |
| 81 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().(definedscip-perl cpan Chipcard-PCSC v1.4.16 main/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 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().($hCard->EndTransactionscip-perl cpan Chipcard-PCSC v1.4.16 main/EndTransaction().($Chipcard::PCSC::SCARD_LEAVE_CARDscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_LEAVE_CARD.), |
| 87 | "\$hCard->EndTransaction()"); |
| 88 | |
| 89 | #------------------------------------------------------------------------------- |
| 90 | $tmpVal = $hCard->Disconnectscip-perl cpan Chipcard-PCSC v1.4.16 main/Disconnect().($Chipcard::PCSC::SCARD_LEAVE_CARDscip-perl cpan Chipcard-PCSC v1.4.16 Chipcard/PCSC/$SCARD_LEAVE_CARD.); |
| 91 | #die ("not ok : Can't disconnect the PCSC object: $Chipcard::PCSC::errno\n") unless $tmpVal; |
| 92 | okscip-perl cpan Chipcard-PCSC v1.4.16 main/ok().($tmpVal, "\$hCard->Disconnect"); |
| 93 | |
| 94 | #------------------------------------------------------------------------------- |
| 95 | $hCard = undef; |
| 96 | $hContext = undef; |
| 97 | |
| 98 | # End of File # |
| 99 |