[BACK]Return to keyring.t CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / t

Annotation of palm/Palm-Keyring/t/keyring.t, Revision 1.4

1.1       andrew      1: # Before `make install' is performed this script should be runnable with
                      2: # `make test'. After `make install' it should work as `perl test.pl'
                      3:
                      4: ######################### We start with some black magic to print on failure.
                      5:
                      6: # Change 1..1 below to 1..last_test_to_print .
                      7: # (It may become useful if the test is moved to ./t subdirectory.)
                      8:
1.3       andrew      9: my $test = 1;
1.4     ! andrew     10: BEGIN { $| = 1; print "1..17\n"; }
1.3       andrew     11: END {print "not ok $test\n" unless $loaded;}
                     12: use Palm::PDB;
1.1       andrew     13: use Palm::Keyring;
                     14: $loaded = 1;
1.3       andrew     15: print "ok $test\n";
                     16: $test++;
1.1       andrew     17:
                     18: ######################### End of black magic.
                     19:
                     20: # Insert your test code below (better if it prints "ok 13"
                     21: # (correspondingly "not ok 13") depending on the success of chunk 13
                     22: # of the test code):
                     23:
1.3       andrew     24: my $file = 'Keys-GTKR-test.pdb';
1.1       andrew     25: my $password = '12345';
1.3       andrew     26: my $new_password = '54321';
                     27: my $acct = {
                     28:     name        => 'test3',
                     29:        account     => 'atestaccount',
                     30:        password    => $password,
                     31:        notes       => 'now that really roxorZ!',
1.4     ! andrew     32:     lastchange  => {
        !            33:         day   =>  2,
        !            34:         month =>  2,
        !            35:         year  => 99,
        !            36:     },
1.3       andrew     37: };
                     38:
1.1       andrew     39: my $pdb;
1.3       andrew     40: my $record;
1.1       andrew     41:
                     42: eval { $pdb = new Palm::Keyring($password) };
                     43: unless( $@ ) {
1.3       andrew     44:        print "ok $test\n";
                     45: } else {
                     46:        print "not ok $test\n";
                     47: }
                     48: $test++;
                     49:
                     50: eval { $record = $pdb->append_Record() };
                     51: unless( $@ ) {
                     52:        print "ok $test\n";
                     53: } else {
                     54:        print "not ok $test\n";
                     55: }
                     56: $test++;
                     57:
                     58: eval { $pdb->Encrypt($record, $acct, $password) || die };
                     59: unless( $@ ) {
                     60:        print "ok $test\n";
                     61: } else {
                     62:        print "not ok $test\n";
                     63: }
                     64: $test++;
                     65:
                     66: eval { $pdb->Write($file) };
                     67: unless( $@ ) {
                     68:        print "ok $test\n";
1.1       andrew     69: } else {
1.3       andrew     70:        print "not ok $test\n";
1.1       andrew     71: }
1.3       andrew     72: $test++;
1.1       andrew     73:
1.3       andrew     74: $pdb = new Palm::PDB;
                     75: $acct = {};
1.1       andrew     76:
1.3       andrew     77: eval { $pdb->Load($file) };
1.1       andrew     78: unless( $@ ) {
1.3       andrew     79:        print "ok $test\n";
1.1       andrew     80: } else {
1.3       andrew     81:        print "not ok $test\n";
1.1       andrew     82: }
1.3       andrew     83: $test++;
1.1       andrew     84:
1.3       andrew     85: eval { $pdb->Password($password) || die };
                     86: unless( $@ ) {
                     87:        print "ok $test\n";
                     88: } else {
                     89:        print "not ok $test\n";
                     90: }
                     91: $test++;
1.1       andrew     92:
1.3       andrew     93: eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die };
                     94: unless( $@ ) {
                     95:        print "ok $test\n";
                     96: } else {
                     97:        print "not ok $test\n";
                     98: }
                     99: $test++;
1.1       andrew    100:
1.3       andrew    101: if ($acct->{'password'} eq $password) {
                    102:        print "ok $test\n";
1.1       andrew    103: } else {
1.3       andrew    104:        print "not ok $test\n";
1.1       andrew    105: }
1.3       andrew    106: $test++;
1.1       andrew    107:
1.4     ! andrew    108: my $old_date = $acct->{'lastchange'};
        !           109:
1.3       andrew    110: eval { $pdb->Password($password, $new_password) || die };
                    111: unless( $@ ) {
                    112:        print "ok $test\n";
1.1       andrew    113: } else {
1.3       andrew    114:        print "not ok $test\n";
1.1       andrew    115: }
1.3       andrew    116: $test++;
1.1       andrew    117:
1.3       andrew    118: $acct = {};
                    119: eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die };
                    120: unless( $@ ) {
                    121:        print "ok $test\n";
1.1       andrew    122: } else {
1.3       andrew    123:        print "not ok $test\n";
1.1       andrew    124: }
1.3       andrew    125: $test++;
1.1       andrew    126:
1.3       andrew    127: if ($acct->{'password'} eq $password) {
                    128:        print "ok $test\n";
                    129: } else {
                    130:        print "not ok $test\n";
                    131: }
                    132: $test++;
1.4     ! andrew    133:
        !           134: my $new_date = $acct->{'lastchange'};
        !           135:
        !           136: if (
        !           137:     $old_date->{'day'}   == $new_date->{'day'}   &&
        !           138:     $old_date->{'month'} == $new_date->{'month'} &&
        !           139:     $old_date->{'year'}  == $new_date->{'year'}
        !           140: ) {
        !           141:     print "ok $test\n";
        !           142: } else {
        !           143:     print "not ok $test\n";
        !           144: }
        !           145: $test++;
        !           146:
        !           147: $acct->{'password'} = $new_password;
        !           148:
        !           149: eval { $acct = $pdb->Encrypt($pdb->{'records'}->[1], $acct) || die };
        !           150: unless( $@ ) {
        !           151:        print "ok $test\n";
        !           152: } else {
        !           153:        print "not ok $test\n";
        !           154: }
        !           155: $test++;
        !           156:
        !           157: $old_date = $new_date;
        !           158: $new_date = $acct->{'lastchange'};
        !           159:
        !           160: eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die };
        !           161: unless( $@ ) {
        !           162:        print "ok $test\n";
        !           163: } else {
        !           164:        print "not ok $test\n";
        !           165: }
        !           166: $test++;
        !           167:
        !           168: if (
        !           169:     $old_date->{'day'}   != $new_date->{'day'}   ||
        !           170:     $old_date->{'month'} != $new_date->{'month'} ||
        !           171:     $old_date->{'year'}  != $new_date->{'year'}
        !           172: ) {
        !           173:     print "ok $test\n";
        !           174: } else {
        !           175:     print "not ok $test\n";
        !           176: }
        !           177: $test++;
        !           178:
        !           179: if ($acct->{'password'} eq $new_password) {
        !           180:        print "ok $test\n";
        !           181: } else {
        !           182:        print "not ok $test\n";
        !           183: }
        !           184: $test++;
        !           185:
        !           186:
1.1       andrew    187: unlink($file);
                    188:
                    189: 1;
                    190:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>