diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-15 05:28:25 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-15 05:28:25 +0000 |
commit | d88305e4a06c58854ec43dd906f285426ed2de60 (patch) | |
tree | e98e0efc99bb74d5bfe8022dc90a2373e332f600 /t | |
parent | a05883f2b96d88671322911276167a0bb0c42ab2 (diff) |
More tests, including some version consistency ones
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1196 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 't')
-rw-r--r-- | t/02-number-handling.t | 67 | ||||
-rw-r--r-- | t/11-ledgersmb.t | 41 | ||||
-rw-r--r-- | t/99-versioning.t | 45 |
3 files changed, 153 insertions, 0 deletions
diff --git a/t/02-number-handling.t b/t/02-number-handling.t index 95502666..6d38de27 100644 --- a/t/02-number-handling.t +++ b/t/02-number-handling.t @@ -82,6 +82,22 @@ foreach my $format (0 .. $#formats) { } } +foreach my $format (0 .. $#formats) { + %myconfig = (numberformat => $formats[$format][0]); + my $thou = $formats[$format][1]; + my $dec = $formats[$format][2]; + my $rawValue = '6d00'; + $expected = $rawValue; + $expected =~ s/d/$dec/gx; + my $value = $form->parse_amount(\%myfooconfig, '6'); + is($form->format_amount(\%myconfig, $value, 2, '0'), $expected, + "form: $value formatted as $formats[$format][0] - $expected"); + is($lsmb->format_amount('user' => \%myconfig, + 'amount' => $value, 'precision' => 2, + 'neg_format' => '0'), $expected, + "lsmb: $value formatted as $formats[$format][0] - $expected"); +} + $expected = $form->parse_amount({'numberformat' => '1000.00'}, '0.00'); is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2, 'x'), 'x', "form: 0.00 with dash x"); @@ -89,6 +105,57 @@ is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 'amount' => $expected, 'precision' => 2, 'neg_format' => 'x'), 'x', "lsmb: 0.00 with dash x"); +is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2, ''), '', + "form: 0.00 with dash ''"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => $expected, 'precision' => 2, + 'neg_format' => ''), '', + "lsmb: 0.00 with dash ''"); +is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2), '', + "form: 0.00 with undef dash"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => $expected, 'precision' => 2), '', + "lsmb: 0.00 with undef dash"); +is($form->format_amount({'apples' => '1000.00'} , 'foo', 2), 'NaN', + "form: No numberformat set, invalid amount"); +is($lsmb->format_amount('user' => {'apples' => '1000.00'}, + 'amount' => 'foo', 'precision' => 2), 'NaN', + "lsmb: No numberformat set, invalid amount"); +cmp_ok($form->format_amount({'apples' => '1000.00'} , '1.00', 2), '==', 1, + "form: No numberformat set, valid amount"); +cmp_ok($lsmb->format_amount('user' => {'apples' => '1000.00'}, + 'amount' => '1.00', 'precision' => 2), '==', 1, + "lsmb: No numberformat set, valid amount"); +is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, '-'), '(1.00)', + "form: -1.00 with dash '-'"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '-1.00', 'precision' => 2, 'neg_format' => '-'), '(1.00)', + "lsmb: -1.00 with dash '-'"); +is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, '-'), '1.00', + "form: 1.00 with dash '-'"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '1.00', 'precision' => 2, 'neg_format' => '-'), '1.00', + "lsmb: 1.00 with dash '-'"); +is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, 'DRCR'), + '1.00 DR', "form: -1.00 with dash DRCR"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '-1.00', 'precision' => 2, 'neg_format' => 'DRCR'), + '1.00 DR', "lsmb: -1.00 with dash DRCR"); +is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, 'DRCR'), + '1.00 CR', "form: 1.00 with dash DRCR"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '1.00', 'precision' => 2, 'neg_format' => 'DRCR'), + '1.00 CR', "lsmb: 1.00 with dash DRCR"); +is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, 'x'), '-1.00', + "form: -1.00 with dash 'x'"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '-1.00', 'precision' => 2, 'neg_format' => 'x'), '-1.00', + "lsmb: -1.00 with dash 'x'"); +is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, 'x'), '1.00', + "form: 1.00 with dash 'x'"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '1.00', 'precision' => 2, 'neg_format' => 'x'), '1.00', + "lsmb: 1.00 with dash 'x'"); foreach my $format (0 .. $#formats) { %myconfig = (numberformat => $formats[$format][0]); diff --git a/t/11-ledgersmb.t b/t/11-ledgersmb.t index ad8ba58d..ff388742 100644 --- a/t/11-ledgersmb.t +++ b/t/11-ledgersmb.t @@ -2,6 +2,9 @@ use strict; use warnings; + +$ENV{TMPDIR} = 't/var'; + use Test::More 'no_plan'; use Test::Exception; use Test::Trap qw(trap $trap); @@ -129,3 +132,41 @@ SKIP: { is(unlink("t/var/lsmb-11.$$"), 1, "debug: removing t/var/lsmb-11.$$"); ok(!-e "t/var/lsmb-11.$$", "debug: t/var/lsmb-11.$$ removed"); }; + +# $lsmb->new checks +$lsmb = new LedgerSMB; +ok(defined $lsmb, 'new: blank, defined'); +isa_ok($lsmb, 'LedgerSMB', 'new: blank, correct type'); +ok(defined $lsmb->{action}, 'new: blank, action defined'); +ok(defined $lsmb->{dbversion}, 'new: blank, dbversion defined'); +ok(defined $lsmb->{path}, 'new: blank, path defined'); +ok(defined $lsmb->{version}, 'new: blank, version defined'); + +$lsmb = new LedgerSMB('action=Apple%20sauce'); +ok(defined $lsmb, 'new: action set, defined'); +isa_ok($lsmb, 'LedgerSMB', 'new: action set, correct type'); +ok(defined $lsmb->{action}, 'new: action set, action defined'); +is($lsmb->{action}, 'apple_sauce', 'new: action set, action processed'); +ok(defined $lsmb->{dbversion}, 'new: action set, dbversion defined'); +ok(defined $lsmb->{path}, 'new: action set, path defined'); +ok(defined $lsmb->{version}, 'new: action set, version defined'); + +$lsmb = new LedgerSMB('path=bin/lynx'); +ok(defined $lsmb, 'new: lynx, defined'); +isa_ok($lsmb, 'LedgerSMB', 'new: lynx, correct type'); +ok(defined $lsmb->{action}, 'new: lynx, action defined'); +ok(defined $lsmb->{dbversion}, 'new: lynx, dbversion defined'); +ok(defined $lsmb->{path}, 'new: lynx, path defined'); +is($lsmb->{path}, 'bin/lynx', 'new: lynx, path carried through'); +ok(defined $lsmb->{lynx}, 'new: lynx, lynx defined'); +is($lsmb->{lynx}, 1, 'new: lynx, lynx enabled'); +ok(defined $lsmb->{menubar}, 'new: lynx, menubar defined (deprecated)'); +is($lsmb->{menubar}, 1, 'new: lynx, menubar enabled (deprecated)'); +ok(defined $lsmb->{version}, 'new: lynx, version defined'); + +TODO: { + local $TODO = 'Error handling for LedgerSMB'; + @r = trap{new LedgerSMB('script=foo/bar.pl')}; + is($trap->die, "Error: Access Denied\n", + 'new: directory traversal caught'); +} diff --git a/t/99-versioning.t b/t/99-versioning.t new file mode 100644 index 00000000..e8e18469 --- /dev/null +++ b/t/99-versioning.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 17; + +use LedgerSMB; +use LedgerSMB::Form; + +my $lsmb = new LedgerSMB; +ok(defined $lsmb, 'lsmb: defined'); +isa_ok($lsmb, 'LedgerSMB', 'lsmb: correct type'); +ok(defined $lsmb->{version}, 'lsmb: version set'); +ok(defined $lsmb->{dbversion}, 'lsmb: dbversion set'); + +my $form = new Form; +ok(defined $form, 'form: defined'); +isa_ok($form, 'Form', 'form: correct type'); +ok(defined $form->{version}, 'form: version set'); +ok(defined $form->{dbversion}, 'form: dbversion set'); + +is($lsmb->{version}, $form->{version}, 'LedgerSMB and Form versions match'); +is($lsmb->{dbversion}, $form->{dbversion}, 'LedgerSMB and Form dbversions match'); + +ok(-e 'VERSION', 'VERSION exists'); +ok(-s 'VERSION', 'VERSION non-empty'); +ok(-r 'VERSION', 'VERSION readable'); +open(my $FH, '<', 'VERSION'); +my $ver = readline $FH; +close $FH; +chomp $ver; +is($lsmb->{version}, $ver, 'LedgerSMB version matches VERSION'); +is($form->{version}, $ver, 'Form version matches VERSION'); + +SKIP: { + skip 'LedgerSMB is trunk', 1 if $lsmb->{version} =~ /trunk$/i; + cmp_ok($lsmb->{version}, '>=', $lsmb->{dbversion}, + 'lsmb: version >= dbversion'); +} +SKIP: { + skip 'Form is trunk', 1 if $form->{version} =~ /trunk$/i; + cmp_ok($form->{version}, '>=', $form->{dbversion}, + 'form: version >= dbversion'); +} |