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 9BEGIN { $| = 1; print "1..12\n"; } 10END {print "not ok 1\n" unless $loaded;} 11use Convert::TNEF; 12$loaded = 1; 13print "ok 1\n"; 14 15######################### End of black magic. 16 17use strict; 18use Convert::TNEF; 19 20my $n = 2; 21my $tnef = Convert::TNEF->read_in("t/tnef.doc",{ignore_checksum=>1}); 22if (ref($tnef) eq 'Convert::TNEF') { 23 print "ok $n\n"; 24} else { 25 print "not ok $n\n"; 26 exit; 27} 28 29my $att_cnt=0; 30my $att_name_exists; 31my $att_name_ok; 32my $att_lname_exists; 33my $att_lname_ok; 34my $att_data_exists; 35my $att_data_ok; 36 37for my $attachment ($tnef->attachments) { 38 last if $att_cnt > 1; 39 if (my $att_name = $attachment->name) { 40 $att_name_exists++; 41 if ($att_name eq "tmp.out") { 42 $att_name_ok++; 43 } 44 } 45 46 if (my $att_lname = $attachment->longname) { 47 $att_lname_exists++; 48 if ($att_lname eq "tmp.out") { 49 $att_lname_ok++; 50 } 51 } 52 53 if (my $att_data = $attachment->data) { 54 $att_data_exists++; 55 if ($att_data =~ /^This is an attachment/) { 56 $att_data_ok++; 57 } 58 } 59 $att_cnt++; 60} 61 62# Check here for errors from above 63$n++; 64if ($att_cnt == 1) { 65 print "ok $n\n"; 66} else { 67 print "not ok $n\n"; 68} 69 70$n++; 71if ($att_name_exists) { 72 print "ok $n\n"; 73} else { 74 print "not ok $n\n"; 75} 76 77$n++; 78if ($att_name_ok) { 79 print "ok $n\n"; 80} else { 81 print "not ok $n\n"; 82} 83 84$n++; 85if ($att_lname_ok) { 86 print "ok $n\n"; 87} else { 88 print "not ok $n\n"; 89} 90 91$n++; 92if ($att_data_exists) { 93 print "ok $n\n"; 94} else { 95 print "not ok $n\n"; 96} 97 98$n++; 99if ($att_data_ok) { 100 print "ok $n\n"; 101} else { 102 print "not ok $n\n"; 103} 104 105# Test messages 106my $msg_exists; 107my $msg_class_exists; 108my $msg_class_ok; 109if (my $message = $tnef->message) { 110 $msg_exists++; 111 if (my $msg_class = $message->data('MessageClass')) { 112 $msg_class_exists++; 113 if ($msg_class eq "IPM.Microsoft Mail.Note\x00") { 114 $msg_class_ok++; 115 } 116 } 117} 118 119$n++; 120if ($msg_exists) { 121 print "ok $n\n"; 122} else { 123 print "not ok $n\n"; 124} 125 126$n++; 127if ($msg_class_exists) { 128 print "ok $n\n"; 129} else { 130 print "not ok $n\n"; 131} 132 133$n++; 134if ($msg_class_ok) { 135 print "ok $n\n"; 136} else { 137 print "not ok $n\n"; 138} 139 140# Check that errors work 141$n++; 142$tnef = Convert::TNEF->read_in("t/tnef.doc"); 143if ($Convert::TNEF::errstr eq 'Bad Checksum') { 144 print "ok $n\n"; 145} else { 146 print "not ok $n\n"; 147} 148