r45105 - in /branches/upstream/libspreadsheet-parseexcel-perl/current: ./ lib/Spreadsheet/ lib/Spreadsheet/ParseExcel/ t/ t/excel_files/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Wed Sep 30 15:44:40 UTC 2009


Author: jawnsy-guest
Date: Wed Sep 30 15:44:33 2009
New Revision: 45105

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=45105
Log:
[svn-upgrade] Integrating new upstream version, libspreadsheet-parseexcel-perl (0.5500)

Added:
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/06_regression.t
Modified:
    branches/upstream/libspreadsheet-parseexcel-perl/current/Changes
    branches/upstream/libspreadsheet-parseexcel-perl/current/MANIFEST
    branches/upstream/libspreadsheet-parseexcel-perl/current/META.yml
    branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel.pm
    branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel/Cell.pm
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/04_regression.t
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/05_regression.t
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/41_test95-97j.t
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/42_test95-97j-2.t
    branches/upstream/libspreadsheet-parseexcel-perl/current/t/excel_files/worksheet_01.xls

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/Changes?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/Changes (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/Changes Wed Sep 30 15:44:33 2009
@@ -1,4 +1,13 @@
 Revision history for Perl extension Spreadsheet::ParseExcel.
+
+0.55 August 25 2009
+
+    + Refactored Cell.pm documentation and method names and added
+      regression suite, t/06_regression.t.
+
+    ! Added float comparison test to avoid false failing tests on
+      64bit systems. 
+
 
 0.54 August 25 2009
 

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/MANIFEST?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/MANIFEST (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/MANIFEST Wed Sep 30 15:44:33 2009
@@ -13,6 +13,7 @@
 t/03_regression.t
 t/04_regression.t
 t/05_regression.t
+t/06_regression.t
 t/20_number_format_default.t
 t/21_number_format_user.t
 t/22_number_format_datetime.t

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/META.yml?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/META.yml (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/META.yml Wed Sep 30 15:44:33 2009
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Spreadsheet-ParseExcel
-version:            0.54
+version:            0.55
 abstract:           Read information from an Excel file.
 author:
     - John McNamara (jmcnamara at cpan.org)

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel.pm?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel.pm (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel.pm Wed Sep 30 15:44:33 2009
@@ -18,7 +18,7 @@
 use OLE::Storage_Lite;
 use IO::File;
 use Config;
-our $VERSION = '0.54';
+our $VERSION = '0.55';
 
 use Spreadsheet::ParseExcel::Workbook;
 use Spreadsheet::ParseExcel::Worksheet;
@@ -2023,15 +2023,12 @@
     my $FmtStr = $oBook->{FormatStr}{ $rhKey{Format}{FmtIdx} };
 
     # Set "Date" type if required for numbers in a MulRK BIFF block.
-    if (   defined $FmtStr
-        && $rhKey{Type} eq "Numeric"
-        && $rhKey{Kind} eq "MulRK" )
-    {
+    if ( defined $FmtStr && $rhKey{Type} eq "Numeric" ) {
 
         # Match a range of possible date formats. Note: this isn't important
         # except for reporting. The number will still be converted to a date
         # by ExcelFmt() even if 'Type' isn't set to 'Date'.
-        if ( $FmtStr =~ m{[dmy]+([^dmy]?)[dmy]+\1[dmy]+}i ) {
+        if ( $FmtStr =~ m{^[dmy][-\\/dmy]*$}i ) {
             $rhKey{Type} = "Date";
         }
     }
@@ -2279,63 +2276,37 @@
 
 =head1 Cell
 
-The C<Spreadsheet::ParseExcel::Cell> class has the following methods and properties.
-
-=head1 Cell methods
+The C<Spreadsheet::ParseExcel::Cell> class has the following main methods.
+
+    $cell->value()
+    $cell->unformatted()
 
 =head2 value()
 
-Formatted value of the cell.
+The C<value()> method returns the formatted value of the cell.
+
+    my $value = $cell->value();
+
+Formatted in this sense refers to the numeric format of the cell value. For example a number such as 40177 might be formatted as 40,117, 40117.000 or even as the date 2009/12/30.
+
+If the cell doesn't contain a numeric format then the formatted and unformatted cell values are the same, see the C<unformatted()> method below.
+
+For a defined C<$cell> the C<value()> method will always return a value.
+
+In the case of a cell with formatting but no numeric or string contents the method will return the empty string C<''>.
+
 
 =head2 unformatted()
 
-Unformatted value of the cell.
-
-
-=head1 Cell properties
-
-    $cell->{Val}
-    $cell->{Type}
-    $cell->{Code}
-    $cell->{Format}
-    $cell->{Merged}
-    $cell->{Rich}
-
-=head2 $cell->{Val}
-
-Returns the unformatted value of the cell. This is B<Deprecated>, use C<< $cell->unformatted() >> instead.
-
-=head2 $cell->{Type}
-
-Returns the type of cell such as C<Text>, C<Numeric> or C<Date>.
-
-If the type was detected as C<Numeric>, and the Cell Format matches C<m{^[dmy][-\\/dmy]*$}>, it will be treated as a C<Date> type.
-
-=head2 $cell->{Code}
-
-Returns the character encoding of the cell. It is either  C<undef>, C<ucs2> or C<_native_>.
-
-If C<undef> then the character encoding seems to be C<ascii>.
-
-If C<_native_> it means that cell seems to be 'sjis' or something similar.
-
-=head2 $cell->{Format}
-
-Returns the L<"Format"> object for the cell.
-
-=head2 $cell->{Merged}
-
-Returns true if the cell is merged.
-
-=head2 $cell->{Rich}
-
-Returns an array ref of font information about each string block in a "rich", i.e. multi-format, string. Each entry has the form:
-
-    [ $start_position>, $font_object ]
-
-For more information refer to the example program C<sample/dmpExR.pl>.
-
-
+The C<unformatted()> method returns the unformatted value of the cell.
+
+    my $unformatted = $cell->unformatted();
+
+Returns the cell value without a numeric format. See the C<value()> method above.
+
+=head2 Other Cell Methods
+
+For other, less commonly used, Worksheet methods see L<Spreadsheet::ParseExcel::Cell>.
 
 
 =head1 Format

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel/Cell.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel/Cell.pm?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel/Cell.pm (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/lib/Spreadsheet/ParseExcel/Cell.pm Wed Sep 30 15:44:33 2009
@@ -2,7 +2,7 @@
 
 ###############################################################################
 #
-# Spreadsheet::ParseExcel::Cell - A class for Cells.
+# Spreadsheet::ParseExcel::Cell - A class for Cell data and formatting.
 #
 # Used in conjunction with Spreadsheet::ParseExcel.
 #
@@ -18,27 +18,134 @@
 use strict;
 use warnings;
 
-our $VERSION = '0.44';
-
+our $VERSION = '0.55';
+
+###############################################################################
+#
+# new()
+#
+# Constructor.
+#
 sub new {
-    my ( $sPkg, %rhKey ) = @_;
-    my ( $sWk, $iLen );
-    my $self = \%rhKey;
-
-    bless $self, $sPkg;
-}
-
+    my ( $package, %properties ) = @_;
+    my $self = \%properties;
+
+    bless $self, $package;
+}
+
+###############################################################################
+#
+# value()
+#
+# Returns the formatted value of the cell.
+#
 sub value {
-    my ($self) = @_;
+
+    my $self = shift;
+
     return $self->{_Value};
 }
 
+###############################################################################
+#
+# unformatted()
+#
+# Returns the unformatted value of the cell.
+#
 sub unformatted {
-    my ($self) = @_;
+
+    my $self = shift;
+
     return $self->{Val};
 }
 
-*Value = *value;
+###############################################################################
+#
+# get_format()
+#
+# Returns the Format object for the cell.
+#
+sub get_format {
+
+    my $self = shift;
+
+    return $self->{Format};
+}
+
+###############################################################################
+#
+# type()
+#
+# Returns the type of cell such as Text, Numeric or Date.
+#
+sub type {
+
+    my $self = shift;
+
+    return $self->{Type};
+}
+
+###############################################################################
+#
+# encoding()
+#
+# Returns the character encoding of the cell.
+#
+sub encoding {
+
+    my $self = shift;
+
+    if ( !defined $self->{Code} ) {
+        return 1;
+    }
+    elsif ( $self->{Code} eq 'ucs2' ) {
+        return 2;
+    }
+    elsif ( $self->{Code} eq '_native_' ) {
+        return 3;
+    }
+    else {
+        return 0;
+    }
+
+    return $self->{Code};
+}
+
+###############################################################################
+#
+# is_merged()
+#
+# Returns true if the cell is merged.
+#
+sub is_merged {
+
+    my $self = shift;
+
+    return $self->{Merged};
+}
+
+###############################################################################
+#
+# get_rich_text()
+#
+# Returns an array ref of font information about each string block in a "rich",
+# i.e. multi-format, string.
+#
+sub get_rich_text {
+
+    my $self = shift;
+
+    return $self->{Rich};
+}
+
+###############################################################################
+#
+# Mapping between legacy method names and new names.
+#
+{
+    no warnings;    # Ignore warnings about variables used only once.
+    *Value = *value;
+}
 
 1;
 
@@ -48,7 +155,7 @@
 
 =head1 NAME
 
-Spreadsheet::ParseExcel::Cell - A class for Cells.
+Spreadsheet::ParseExcel::Cell - A class for Cell data and formatting.
 
 =head1 SYNOPSIS
 
@@ -58,6 +165,132 @@
 
 This module is used in conjunction with Spreadsheet::ParseExcel. See the documentation for Spreadsheet::ParseExcel.
 
+=head1 Methods
+
+The following Cell methods are available:
+
+    $cell->value()
+    $cell->unformatted()
+    $cell->get_format()
+    $cell->type()
+    $cell->encoding()
+    $cell->is_merged()
+    $cell->get_rich_text()
+
+
+=head2 value()
+
+The C<value()> method returns the formatted value of the cell.
+
+    my $value = $cell->value();
+
+Formatted in this sense refers to the numeric format of the cell value. For example a number such as 40177 might be formatted as 40,117, 40117.000 or even as the date 2009/12/30.
+
+If the cell doesn't contain a numeric format then the formatted and unformatted cell values are the same, see the C<unformatted()> method below.
+
+For a defined C<$cell> the C<value()> method will always return a value.
+
+In the case of a cell with formatting but no numeric or string contents the method will return the empty string C<''>.
+
+
+=head2 unformatted()
+
+The C<unformatted()> method returns the unformatted value of the cell.
+
+    my $unformatted = $cell->unformatted();
+
+Returns the cell value without a numeric format. See the C<value()> method above.
+
+
+=head2 get_format()
+
+The C<get_format()> method returns the L<Spreadsheet::ParseExcel::Format> object for the cell.
+
+    my $format = $cell->get_format();
+
+If a user defined format hasn't been applied to the cell then the default cell format is returned.
+
+
+=head2 type()
+
+The C<type()> method returns the type of cell such as Text, Numeric or Date. If the type was detected as Numeric, and the Cell Format matches C<m{^[dmy][-\\/dmy]*$}i>, it will be treated as a Date type.
+
+    my $type = $cell->type();
+
+See also L<Dates and Time in Excel>.
+
+
+=head2 encoding()
+
+The C<encoding()> method returns the character encoding of the cell.
+
+    my $encoding = $cell->encoding();
+
+This method is only of interest to developers. In general Spreadsheet::ParseExcel will return all character strings in UTF-8 regardless of the encoding used by Excel.
+
+The C<encoding()> method returns one of the following values:
+
+=over
+
+=item * 0: Unknown format. This shouldn't happen. In the default case the format should be 1.
+
+=item * 1: 8bit ASCII or single byte UTF-16. This indicates that the characters are encoded in a single byte. In Excel 95 and earlier This usually meant ASCII or an international variant. In Excel 97 it refers to a compressed UTF-16 character string where all of the high order bytes are 0 and are omitted to save space.
+
+=item * 2: UTF-16BE.
+
+=item * 3: Native encoding. In Excel 95 and earlier this encoding was used to represent multi-byte character encodings such as SJIS.
+
+=back
+
+
+=head2 is_merged()
+
+The C<is_merged()> method returns true if the cell is merged.
+
+    my $is_merged = $cell->is_merged();
+
+Returns C<undef> if the property isn't set.
+
+
+=head2 get_rich_text()
+
+The C<get_rich_text()> method returns an array ref of font information about each string block in a "rich", i.e. multi-format, string.
+
+    my $rich_text = $cell->get_rich_text();
+
+The return value is an arrayref of arrayrefs in the form:
+
+    [
+        [ $start_position, $font_object ],
+         ...,
+    ]
+
+Returns undef if the property isn't set.
+
+
+=head1 Dates and Time in Excel
+
+Dates and times in Excel are represented by real numbers, for example "Jan 1 2001 12:30 PM" is represented by the number 36892.521.
+
+The integer part of the number stores the number of days since the epoch and the fractional part stores the percentage of the day.
+
+A date or time in Excel is just like any other number. The way in which it is displayed is controlled by the number format:
+
+    Number format               $cell->value()            $cell->unformatted()
+    =============               ==============            ==============
+    'dd/mm/yy'                  '28/02/08'                39506.5
+    'mm/dd/yy'                  '02/28/08'                39506.5
+    'd-m-yyyy'                  '28-2-2008'               39506.5
+    'dd/mm/yy hh:mm'            '28/02/08 12:00'          39506.5
+    'd mmm yyyy'                '28 Feb 2008'             39506.5
+    'mmm d yyyy hh:mm AM/PM'    'Feb 28 2008 12:00 PM'    39506.5
+
+
+The L<Spreadsheet::ParseExcel::Utility> module contains a function called C<ExcelLocaltime> which will convert between an unformatted Excel date/time number and a C<localtime()> like array.
+
+For date conversions using the CPAN C<DateTime> framework see L<DateTime::Format::Excel> http://search.cpan.org/search?dist=DateTime-Format-Excel
+
+
 =head1 AUTHOR
 
 Maintainer 0.40+: John McNamara jmcnamara at cpan.org

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/t/04_regression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/04_regression.t?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/t/04_regression.t (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/t/04_regression.t Wed Sep 30 15:44:33 2009
@@ -46,7 +46,7 @@
 $caption    = " \tWorksheet regression: " . $caption;
 
 is( $got_1, $expected_1, $caption );
-is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/t/05_regression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/05_regression.t?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/t/05_regression.t (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/t/05_regression.t Wed Sep 30 15:44:33 2009
@@ -46,7 +46,7 @@
 $caption    = " \tWorksheet regression: " . $caption;
 
 is( $got_1, $expected_1, $caption );
-is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -131,8 +131,8 @@
 $got_2      = $worksheet->get_default_col_width;
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -145,8 +145,8 @@
 $got_2      = ( $worksheet->get_row_heights() )[2];
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -289,8 +289,8 @@
 $got_2      = $worksheet->get_margin_left();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -303,8 +303,8 @@
 $got_2      = $worksheet->get_margin_right();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -317,8 +317,8 @@
 $got_2      = $worksheet->get_margin_top();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -331,8 +331,8 @@
 $got_2      = $worksheet->get_margin_bottom();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -345,8 +345,8 @@
 $got_2      = $worksheet->get_margin_header();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -359,8 +359,8 @@
 $got_2      = $worksheet->get_margin_footer();
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
 
 ###############################################################################
 #
@@ -569,9 +569,31 @@
 $got_2      = ( $worksheet->get_col_widths() )[7];
 $caption    = " \tWorksheet regression: " . $caption;
 
-is( $got_1, $expected_1, $caption );
-is( $got_2, $expected_1, $caption );
-
-
+_is_float( $got_1, $expected_1, $caption );
+_is_float( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# _is_float()
+#
+# Helper function for float comparison. This is mainly to prevent failing tests
+# on 64bit systems with extended doubles where the 128bit precision is compared
+# against Excel's 64bit precision.
+#
+sub _is_float {
+
+    my ( $got, $expected, $caption ) = @_;
+
+    my $max = 1;
+    $max = abs($got)      if abs($got) > $max;
+    $max = abs($expected) if abs($expected) > $max;
+
+    if ( abs( $got - $expected ) <= 1e-15 * $max ) {
+        ok( 1, $caption );
+    }
+    else {
+        is( $got, $expected, $caption );
+    }
+}
 
 __END__

Added: branches/upstream/libspreadsheet-parseexcel-perl/current/t/06_regression.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/06_regression.t?rev=45105&op=file
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/t/06_regression.t (added)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/t/06_regression.t Wed Sep 30 15:44:33 2009
@@ -1,0 +1,317 @@
+#!/usr/bin/perl
+
+###############################################################################
+#
+# A test for Spreadsheet::ParseExcel.
+#
+# Regression tests for Cell properties and methods.
+#
+# The tests are mainly in pairs where direct hash access (old methodology)
+# is tested along with the method calls (>= version 0.50 methodology).
+#
+# reverse('©'), January 2009, John McNamara, jmcnamara at cpan.org
+#
+
+use strict;
+use warnings;
+use Spreadsheet::ParseExcel;
+use Test::More tests => 32;
+
+###############################################################################
+#
+# Tests setup.
+#
+my $file      = 't/excel_files/worksheet_01.xls';
+my $parser    = Spreadsheet::ParseExcel->new();
+my $workbook  = $parser->Parse($file);
+my $worksheet = $workbook->worksheet('Sheet3');
+my $cell;
+my $format;
+my $got_1;
+my $got_2;
+my $expected_1;
+my $expected_2;
+my $caption;
+
+###############################################################################
+#
+# Test 1, 2. Unformatted cell value.
+#
+$caption = "Test unformatted cell value";
+$cell = $worksheet->get_cell( 2, 1 );
+
+$expected_1 = 1;
+$got_1      = $cell->value();
+$got_2      = $cell->Value();
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 3, 4. Unformatted cell value from a formatted cell.
+#
+$caption = "Test unformatted cell value from a formatted cell";
+$cell = $worksheet->get_cell( 3, 1 );
+
+$expected_1 = 40177;
+$got_1      = $cell->unformatted();
+$got_2      = $cell->{Val};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 5, 6. Formatted cell value.
+#
+$caption = "Test formatted cell value";
+$cell = $worksheet->get_cell( 3, 1 );
+
+$expected_1 = '2009/12/30';
+$got_1      = $cell->value();
+$got_2      = $cell->Value;
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 7, 8. Cell format.
+#
+$caption = "Test cell format";
+$cell = $worksheet->get_cell( 3, 1 );
+
+$expected_1 = 170;
+$got_1      = $cell->get_format()->{FmtIdx};
+$got_2      = $cell->{Format}->{FmtIdx};;
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 9. Cell format.
+#
+$caption = "Test cell format string";
+$cell = $worksheet->get_cell( 2, 1 );
+
+$expected_1 = '@'; # TODO. Probably should be '' or 'general'.
+$got_1      = $workbook->{FmtClass}->FmtString( $cell, $workbook );
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 10. Cell format.
+#
+$caption = "Test cell format string";
+$cell = $worksheet->get_cell( 3, 1 );
+
+$expected_1 = 'yyyy/mm/dd';
+$got_1      = $workbook->{FmtClass}->FmtString( $cell, $workbook );
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 11, 12. Cell type.
+#
+$caption = "Test cell type = Text";
+$cell = $worksheet->get_cell( 2, 0 );
+
+$expected_1 = 'Text';
+$got_1      = $cell->type();
+$got_2      = $cell->{Type};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 13, 14. Cell type.
+#
+$caption = "Test cell type = Numeric";
+$cell = $worksheet->get_cell( 2, 1 );
+
+$expected_1 = 'Numeric';
+$got_1      = $cell->type();
+$got_2      = $cell->{Type};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+###############################################################################
+#
+# Test 15, 16. Cell type.
+#
+$caption = "Test cell type = Date";
+$cell = $worksheet->get_cell( 3, 1 );
+
+$expected_1 = 'Date';
+$got_1      = $cell->type();
+$got_2      = $cell->{Type};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 17, 18. Cell string encoding.
+#
+$caption = "Test cell encoding = Ascii";
+$cell = $worksheet->get_cell( 5, 0 );
+
+$expected_1 = 1;
+$expected_2 = undef;
+$got_1      = $cell->encoding();
+$got_2      = $cell->{Code};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_2, $caption );
+
+
+###############################################################################
+#
+# Test 19, 20. Cell string encoding.
+#
+$caption = "Test cell encoding = Unicode";
+$cell = $worksheet->get_cell( 5, 1 );
+
+$expected_1 = 2;
+$expected_2 = 'ucs2';
+$got_1      = $cell->encoding();
+$got_2      = $cell->{Code};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_2, $caption );
+
+
+###############################################################################
+#
+# Test 21, 22. Cell string encoding.
+#
+
+# Switch file to get native encoding from Excel 5 file.
+$file      = 't/excel_files/Test95J.xls';
+$parser    = Spreadsheet::ParseExcel->new();
+$workbook  = $parser->Parse($file);
+$worksheet = $workbook->worksheet(0);
+
+$caption = "Test cell encoding = Native";
+$cell = $worksheet->get_cell( 1, 0 );
+
+$expected_1 = 3;
+$expected_2 = '_native_';
+$got_1      = $cell->encoding();
+$got_2      = $cell->{Code};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_2, $caption );
+
+# Switch back to main test worksheet.
+$file      = 't/excel_files/worksheet_01.xls';
+$parser    = Spreadsheet::ParseExcel->new();
+$workbook  = $parser->Parse($file);
+$worksheet = $workbook->worksheet('Sheet3');
+
+
+###############################################################################
+#
+# Test 23, 24. Cell is un-merged.
+#
+$caption = "Test cell is un-merged";
+$cell = $worksheet->get_cell( 6, 0 );
+
+$expected_1 = undef;
+$got_1      = $cell->is_merged();
+$got_2      = $cell->{Merged};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 25, 26. Cell is merged.
+#
+$caption = "Test cell is merged";
+$cell = $worksheet->get_cell( 7, 0 );
+
+$expected_1 = 1;
+$got_1      = $cell->is_merged();
+$got_2      = $cell->{Merged};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 27, 28. Cell is merged.
+#
+$caption = "Test cell is merged";
+$cell = $worksheet->get_cell( 7, 1 );
+
+$expected_1 = 1;
+$got_1      = $cell->is_merged();
+$got_2      = $cell->{Merged};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 29, 30. Cell is merged.
+#
+$caption = "Test cell is merged";
+$cell = $worksheet->get_cell( 7, 1 );
+
+$expected_1 = 1;
+$got_1      = $cell->is_merged();
+$got_2      = $cell->{Merged};
+$caption    = " \tCell regression: " . $caption;
+
+is( $got_1, $expected_1, $caption );
+is( $got_2, $expected_1, $caption );
+
+
+###############################################################################
+#
+# Test 31, 32. Cell contains Rich Text.
+#
+$caption = "Test cell containing rich text";
+$cell = $worksheet->get_cell( 8, 0 );
+
+$expected_1 = [ 10, 14, 19 ];
+$got_1      = $cell->get_rich_text();
+$got_2      = $cell->{Rich};
+$caption    = " \tCell regression: " . $caption;
+
+# Just test the indices and not the font objects.
+$got_1 = [ map { $_->[0] } @$got_1 ];
+$got_2 = [ map { $_->[0] } @$got_2 ];
+
+is_deeply( $got_1, $expected_1, $caption );
+is_deeply( $got_2, $expected_1, $caption );
+
+
+__END__

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/t/41_test95-97j.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/41_test95-97j.t?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/t/41_test95-97j.t (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/t/41_test95-97j.t Wed Sep 30 15:44:33 2009
@@ -40,7 +40,17 @@
 	for my $i($rmin .. $rmax){
 		for my $j($cmin .. $cmax){
 			#print $sheet->get_cell($i, $j)->value, "\n";
-			is $sheet->get_cell($i, $j)->value, $expected[$i][$j], "[$i, $j]";
+			my $cell     = $sheet->get_cell($i, $j);
+			my $got		 = $cell->value;
+			my $expected = $expected[$i][$j];
+			my $caption	 = "[$i, $j]";
+
+			if ($expected =~ /\d\.\d+/) {
+				_is_float($got, $expected, $caption);
+			}
+			else {
+				is $got, $expected, $caption;
+			}
 		}
 	}
 
@@ -65,8 +75,43 @@
 	for my $i($rmin .. $rmax){
 		for my $j($cmin .. $cmax){
 			#print $sheet->get_cell($i, $j)->value, "\n";
-			my $cell = $sheet->get_cell($i, $j);
-			is ref($cell) ? $cell->value : $cell, $expected[$i][$j], "[$i, $j]";
+			my $cell     = $sheet->get_cell($i, $j);
+			my $got		 = ref($cell) ? $cell->value : $cell;
+			my $expected = $expected[$i][$j];
+			my $caption	 = "[$i, $j]";
+
+			if (defined $expected && $expected =~ /\d\.\d+/) {
+				_is_float($got, $expected, $caption);
+			}
+			else {
+				is $got, $expected, $caption;
+			}
 		}
 	}
 }
+
+
+###############################################################################
+#
+# _is_float()
+#
+# Helper function for float comparison. This is mainly to prevent failing tests
+# on 64bit systems with extended doubles where the 128bit precision is compared
+# against Excel's 64bit precision.
+#
+sub _is_float {
+
+	my ( $got, $expected, $caption ) = @_;
+
+	my $max = 1;
+	$max = abs($got)	  if abs($got) > $max;
+	$max = abs($expected) if abs($expected) > $max;
+
+	if ( abs( $got - $expected ) <= 1e-15 * $max ) {
+		ok( 1, $caption );
+	}
+	else {
+		is( $got, $expected, $caption );
+	}
+}
+

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/t/42_test95-97j-2.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/42_test95-97j-2.t?rev=45105&op=diff
==============================================================================
--- branches/upstream/libspreadsheet-parseexcel-perl/current/t/42_test95-97j-2.t (original)
+++ branches/upstream/libspreadsheet-parseexcel-perl/current/t/42_test95-97j-2.t Wed Sep 30 15:44:33 2009
@@ -41,7 +41,17 @@
 	for my $i($rmin .. $rmax){
 		for my $j($cmin .. $cmax){
 			#print $sheet->get_cell($i, $j)->value, "\n";
-			is $sheet->get_cell($i, $j)->value, $expected[$i][$j], "[$i, $j]";
+			my $cell     = $sheet->get_cell($i, $j);
+			my $got		 = $cell->value;
+			my $expected = $expected[$i][$j];
+			my $caption	 = "[$i, $j]";
+
+			if ($expected =~ /\d\.\d+/) {
+				_is_float($got, $expected, $caption);
+			}
+			else {
+				is $got, $expected, $caption;
+			}
 		}
 	}
 
@@ -66,8 +76,43 @@
 	for my $i($rmin .. $rmax){
 		for my $j($cmin .. $cmax){
 			#print $sheet->get_cell($i, $j)->value, "\n";
-			my $cell = $sheet->get_cell($i, $j);
-			is ref($cell) ? $cell->value : $cell, $expected[$i][$j], "[$i, $j]";
+			my $cell     = $sheet->get_cell($i, $j);
+			my $got		 = ref($cell) ? $cell->value : $cell;
+			my $expected = $expected[$i][$j];
+			my $caption	 = "[$i, $j]";
+
+			if (defined $expected && $expected =~ /\d\.\d+/) {
+				_is_float($got, $expected, $caption);
+			}
+			else {
+				is $got, $expected, $caption;
+			}
 		}
 	}
 }
+
+
+###############################################################################
+#
+# _is_float()
+#
+# Helper function for float comparison. This is mainly to prevent failing tests
+# on 64bit systems with extended doubles where the 128bit precision is compared
+# against Excel's 64bit precision.
+#
+sub _is_float {
+
+	my ( $got, $expected, $caption ) = @_;
+
+	my $max = 1;
+	$max = abs($got)	  if abs($got) > $max;
+	$max = abs($expected) if abs($expected) > $max;
+
+	if ( abs( $got - $expected ) <= 1e-15 * $max ) {
+		ok( 1, $caption );
+	}
+	else {
+		is( $got, $expected, $caption );
+	}
+}
+

Modified: branches/upstream/libspreadsheet-parseexcel-perl/current/t/excel_files/worksheet_01.xls
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libspreadsheet-parseexcel-perl/current/t/excel_files/worksheet_01.xls?rev=45105&op=diff
==============================================================================
Binary files - no diff available.




More information about the Pkg-perl-cvs-commits mailing list