File: 10_error_codes.t

package info (click to toggle)
libspreadsheet-parseexcel-perl 0.6500-1.1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,852 kB
  • sloc: perl: 9,442; makefile: 12
file content (100 lines) | stat: -rwxr-xr-x 2,746 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl -w

###############################################################################
#
# A test for Spreadsheet::ParseExcel.
#
# Tests for parse() error handling.
#
# reverse(''), August 2009, John McNamara, jmcnamara@cpan.org
#

use strict;

use Spreadsheet::ParseExcel;
use Test::More tests => 8;


###############################################################################
#
# Tests setup.
#
my $file;
my $parser;
my $workbook;
my $got;
my $caption;
my $error_code;
my $error_string;
my $expected_code;
my $expected_string;


###############################################################################
#
# Tests 1, 2. Normal file, no errors.
#
$caption         = " \tError codes: Normal file";
$file            = 't/excel_files/chart1.xls';
$parser          = Spreadsheet::ParseExcel->new();
$workbook        = $parser->Parse($file);
$error_string    = $parser->error();
$error_code      = $parser->error_code();
$expected_code   = 0;
$expected_string = '';

is( $error_code,   $expected_code,   $caption );
is( $error_string, $expected_string, $caption );


###############################################################################
#
# Tests 3, 4. Non existent file.
#
$caption         = " \tError codes: Non existent file";
$file            = 'file_doesnt_exist.xls';
$parser          = Spreadsheet::ParseExcel->new();
$workbook        = $parser->Parse($file);
$error_string    = $parser->error();
$error_code      = $parser->error_code();
$expected_code   = 1;
$expected_string = 'File not found';

is( $error_code,   $expected_code,   $caption );
is( $error_string, $expected_string, $caption );


###############################################################################
#
# Tests 5, 6. File with no Excel data.
#
$caption         = " \tError codes:File with no Excel data";
$file            = 't/00_basic.t';
$parser          = Spreadsheet::ParseExcel->new();
$workbook        = $parser->Parse($file);
$error_string    = $parser->error();
$error_code      = $parser->error_code();
$expected_code   = 2;
$expected_string = 'No Excel data found in file';

is( $error_code,   $expected_code,   $caption );
is( $error_string, $expected_string, $caption );


###############################################################################
#
# Tests 7, 8. Encrypted file.
#
$caption         = " \tEncrypted file";
$file            = 't/excel_files/encrypted.xls';
$parser          = Spreadsheet::ParseExcel->new();
$workbook        = $parser->Parse($file);
$error_string    = $parser->error();
$error_code      = $parser->error_code();
$expected_code   = 3;
$expected_string = 'File is encrypted';

is( $error_code,   $expected_code,   $caption );
is( $error_string, $expected_string, $caption );

__END__