| 1 | package XAO::testcases::FS::base; | ||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use XAO::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use XAO::Objects; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use XAO::testcases::base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use base qw(XAO::testcases::base); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | sub new ($) { | ||||||||||||||||||||||||||||
| 10 | 13 | ▶ | my $proto=shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 13 | my $self=$proto->SUPER::new(@_); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Reading configuration | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | 13 | my %d; | |||||||||||||||||||||||||||
| 16 | 13 | ▶ | if(open(F,'.config')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 13 | local($/); | |||||||||||||||||||||||||||
| 18 | 13 | my $t=<F>; | |||||||||||||||||||||||||||
| 19 | 13 | close(F); | |||||||||||||||||||||||||||
| 20 | 13 | eval $t; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 13 | ▶ | (!$@ && $d{'test_dsn'}) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $@ and $d{"test_dsn"}
MC/DC0%0/2
not $@ and $d{"test_dsn"}
not $@
$d{"test_dsn"}
Truth table33%1/3
not(A) and B
A= not $@B= $d{"test_dsn"}
| |||||||||||||||||||||||||||||
| 24 | die "Invalid config, re-run 'perl Makefile.PL'\n"; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 13 | $self->{'dbconfig'}=\%d; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 13 | ▶ | if($d{'test_dsn'} eq 'none') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 13 | dprint "No DSN configured, skipping all tests"; | |||||||||||||||||||||||||||
| 30 | 13 | $self->{'skip_db_tests'}=1; | |||||||||||||||||||||||||||
| 31 | 13 | return; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub list_tests ($) { | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
list_tests: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if($self->{'skip_db_tests'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return wantarray ? () : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 0 | return $self->SUPER::list_tests(@_); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub reconnect ($) { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
reconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | my $dbconfig=$self->{'dbconfig'}; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | $self->assert($dbconfig->{'test_dsn'}, | |||||||||||||||||||||||||||
| 54 | "No test configuration available (no .config)"); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | $self->{'odb'}=XAO::Objects->new( | ||||||||||||||||||||||||||||
| 57 | objname => 'FS::Glue', | ||||||||||||||||||||||||||||
| 58 | dsn => $dbconfig->{'test_dsn'}, | ||||||||||||||||||||||||||||
| 59 | user => $dbconfig->{'test_user'}, | ||||||||||||||||||||||||||||
| 60 | 0 | password => $dbconfig->{'test_password'}, | |||||||||||||||||||||||||||
| 61 | check_consistency => 1, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $self->get_odb; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub set_up ($) { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
set_up: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | ### $self->SUPER::set_up(@_); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $dbconfig=$self->{'dbconfig'}; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $self->assert($dbconfig->{'test_dsn'}, | |||||||||||||||||||||||||||
| 75 | "No test configuration available (no .config)"); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | $self->{'odb'}=XAO::Objects->new( | ||||||||||||||||||||||||||||
| 78 | objname => 'FS::Glue', | ||||||||||||||||||||||||||||
| 79 | dsn => $dbconfig->{'test_dsn'}, | ||||||||||||||||||||||||||||
| 80 | user => $dbconfig->{'test_user'}, | ||||||||||||||||||||||||||||
| 81 | 0 | password => $dbconfig->{'test_password'}, | |||||||||||||||||||||||||||
| 82 | empty_database => 'confirm', | ||||||||||||||||||||||||||||
| 83 | check_consistency => 1, | ||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $self->assert($self->{odb}, "Can't connect to the FS database"); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | $self->{'odb_args'}={ | ||||||||||||||||||||||||||||
| 89 | dsn => $dbconfig->{'test_dsn'}, | ||||||||||||||||||||||||||||
| 90 | user => $dbconfig->{'test_user'}, | ||||||||||||||||||||||||||||
| 91 | 0 | password => $dbconfig->{'test_password'}, | |||||||||||||||||||||||||||
| 92 | }; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $global=$self->{'odb'}->fetch('/'); | |||||||||||||||||||||||||||
| 95 | 0 | $self->assert($global, "Can't fetch Global from FS database"); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | $global->build_structure( | |||||||||||||||||||||||||||
| 98 | Customers => { | ||||||||||||||||||||||||||||
| 99 | type => 'list', | ||||||||||||||||||||||||||||
| 100 | class => 'Data::Customer', | ||||||||||||||||||||||||||||
| 101 | key => 'customer_id', | ||||||||||||||||||||||||||||
| 102 | structure => { | ||||||||||||||||||||||||||||
| 103 | name => { | ||||||||||||||||||||||||||||
| 104 | type => 'text', | ||||||||||||||||||||||||||||
| 105 | maxlength => 40, | ||||||||||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $clist=$self->{odb}->fetch('/Customers'); | |||||||||||||||||||||||||||
| 112 | 0 | $self->assert($clist, "Can't fetch /Customers from FS database"); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | my $customer=$clist->get_new(); | |||||||||||||||||||||||||||
| 115 | 0 | $self->assert(ref($customer), "Can't create new Data::Customer"); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | $customer->put(name => 'Test Customer #1'); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | $clist->put(c1 => $customer); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $customer->put(name => 'Test Customer #2'); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | $clist->put(c2 => $customer); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | sub tear_down { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
tear_down: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | ### $self->SUPER::tear_down(@_); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | $self->{odb}=undef; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub get_odb { | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self=shift; | ||||||||||||||||||||||||||
|
Subroutine
get_odb: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $odb=$self->{'odb'}; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | $self->assert(defined($odb) && ref($odb), 'No object database handler'); | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $odb && ref $odb
MC/DC0%0/2
defined $odb && ref $odb
defined $odb
ref $odb
Truth table0%0/3
A && B
A= defined $odbB= ref $odb
| |||||||||||||||||||||||||||||
| 138 | 0 | $odb; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 13 | ▶ | use vars qw(*SE); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | sub stderr_stop { | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | open(SE,">&STDERR"); | ||||||||||||||||||||||||||
|
Subroutine
stderr_stop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 0 | open(STDERR,">/dev/null"); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub stderr_restore { | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | open(STDERR,">&SE"); | ||||||||||||||||||||||||||
|
Subroutine
stderr_restore: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 0 | close(SE); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 13 | 1; | |||||||||||||||||||||||||||