| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package XAO::testcases::FS::basic; | 
| 2 | 2 |  |  | 2 |  | 651 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 61 |  | 
| 3 | 2 |  |  | 2 |  | 494 | use XAO::Utils; | 
|  | 2 |  |  |  |  | 18681 |  | 
|  | 2 |  |  |  |  | 116 |  | 
| 4 | 2 |  |  | 2 |  | 519 | use XAO::Objects; | 
|  | 2 |  |  |  |  | 5344 |  | 
|  | 2 |  |  |  |  | 80 |  | 
| 5 | 2 |  |  | 2 |  | 10 | use Error qw(:try); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 2 |  |  | 2 |  | 259 | use base qw(XAO::testcases::FS::base); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 898 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub test_reset { | 
| 10 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 0 |  |  |  |  |  | my $odb=$self->{'odb'}; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 0 |  |  |  |  |  | $self->assert($odb->objname eq 'FS::Glue', | 
| 15 |  |  |  |  |  |  | "Expected odb objname to be FS::Glue, got ".$odb->objname); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 0 |  |  |  |  |  | my $g=$odb->fetch('/'); | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 0 |  |  |  |  |  | $g->put(project => 'test'); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 0 |  |  |  |  |  | $self->assert($g->_driver->connector->sql_connected, | 
| 22 |  |  |  |  |  |  | "Database is NOT connected before reset"); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | # This is not normally used! | 
| 25 | 0 |  |  |  |  |  | $g->_driver->disconnect; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 |  |  |  |  |  | $self->stderr_stop(); | 
| 28 | 0 |  |  |  |  |  | my $rc=$g->_driver->connector->sql_connected; | 
| 29 | 0 |  |  |  |  |  | $self->stderr_restore(); | 
| 30 | 0 |  |  |  |  |  | $self->assert(!$rc, | 
| 31 |  |  |  |  |  |  | "Database is still connected after the disconnect"); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | $self->stderr_stop(); | 
| 34 | 0 |  |  |  |  |  | $g->reset; | 
| 35 | 0 |  |  |  |  |  | $self->stderr_restore(); | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 0 |  |  |  |  |  | $self->assert($g->_driver->connector->sql_connected, | 
| 38 |  |  |  |  |  |  | "Database is NOT connected after reset()"); | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | $self->assert($g->get('project') eq 'test', | 
| 41 |  |  |  |  |  |  | "Value is not the same as stored"); | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # Checking the reset from a non-disconnected state | 
| 44 |  |  |  |  |  |  | # | 
| 45 | 0 |  |  |  |  |  | $g->reset; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 |  |  |  |  |  | $self->assert($g->_driver->connector->sql_connected, | 
| 48 |  |  |  |  |  |  | "Database is NOT connected after reset() (connected)"); | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 0 |  |  |  |  |  | $self->assert($g->get('project') eq 'test', | 
| 51 |  |  |  |  |  |  | "Value is not the same as stored after reset() (connected)"); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub test_xaofs { | 
| 55 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 0 |  |  |  |  |  | my $odb=$self->{odb}; | 
| 58 | 0 |  | 0 |  |  |  | $self->assert(defined($odb) && ref($odb), | 
| 59 |  |  |  |  |  |  | 'Object database creating failure'); | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 0 |  |  |  |  |  | my %matrix=( | 
| 62 |  |  |  |  |  |  | t1 => { | 
| 63 |  |  |  |  |  |  | path    => '/Customers/c2/name', | 
| 64 |  |  |  |  |  |  | result  => 'Test Customer #2', | 
| 65 |  |  |  |  |  |  | }, | 
| 66 |  |  |  |  |  |  | t2 => { | 
| 67 |  |  |  |  |  |  | path    => 'xaofs://uri/Customers/c2/name', | 
| 68 |  |  |  |  |  |  | result  => 'Test Customer #2', | 
| 69 |  |  |  |  |  |  | }, | 
| 70 |  |  |  |  |  |  | t3 => { | 
| 71 |  |  |  |  |  |  | path    => 'xaofs://collection/class/Data::Customer/2/name', | 
| 72 |  |  |  |  |  |  | result  => 'Test Customer #2', | 
| 73 |  |  |  |  |  |  | }, | 
| 74 |  |  |  |  |  |  | t4 => { | 
| 75 |  |  |  |  |  |  | path    => 'xaofs://collection/class/Data::Customer', | 
| 76 |  |  |  |  |  |  | result  => 'XAO::DO::FS::Collection', | 
| 77 |  |  |  |  |  |  | objname => 'FS::Collection', | 
| 78 |  |  |  |  |  |  | }, | 
| 79 |  |  |  |  |  |  | t5 => { | 
| 80 |  |  |  |  |  |  | path    => 'xaofs://collection/class/Data::Customer/', | 
| 81 |  |  |  |  |  |  | result  => 'XAO::DO::FS::Collection', | 
| 82 |  |  |  |  |  |  | objname => 'FS::Collection', | 
| 83 |  |  |  |  |  |  | }, | 
| 84 |  |  |  |  |  |  | t6 => { | 
| 85 |  |  |  |  |  |  | path    => 'xaofs://uri/Customers', | 
| 86 |  |  |  |  |  |  | result  => 'XAO::DO::FS::List', | 
| 87 |  |  |  |  |  |  | objname => 'FS::List', | 
| 88 |  |  |  |  |  |  | }, | 
| 89 |  |  |  |  |  |  | ); | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 0 |  |  |  |  |  | foreach my $test (values %matrix) { | 
| 92 | 0 |  |  |  |  |  | my $path=$test->{path}; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 0 |  |  |  |  |  | my $got=$odb->fetch($path); | 
| 95 | 0 |  |  |  |  |  | my $expect=$test->{result}; | 
| 96 | 0 |  | 0 |  |  |  | $self->assert((ref($got) || $got) eq $expect, | 
| 97 |  |  |  |  |  |  | "Expected '$expect', got '$got'"); | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 0 | 0 |  |  |  |  | if($test->{'objname'}) { | 
| 100 | 0 |  |  |  |  |  | my $objname=$got->objname; | 
| 101 | 0 |  |  |  |  |  | $self->assert($objname eq $test->{'objname'}, | 
| 102 |  |  |  |  |  |  | "Expected objname() to return '$test->{'objname'}', got '$objname'"); | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub test_objtype { | 
| 108 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 109 | 0 |  |  |  |  |  | my $odb=$self->{odb}; | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 0 |  |  |  |  |  | my $ot=$odb->objtype; | 
| 112 | 0 |  |  |  |  |  | $self->assert($ot eq 'Glue', | 
| 113 |  |  |  |  |  |  | "Glue object returned wrong 'objtype' ($ot)"); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 0 |  |  |  |  |  | my $list=$odb->fetch('/Customers'); | 
| 116 | 0 |  |  |  |  |  | $ot=$list->objtype; | 
| 117 | 0 |  |  |  |  |  | $self->assert($ot eq 'List', | 
| 118 |  |  |  |  |  |  | "List object returned wrong 'objtype' ($ot)"); | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | my $hash=$list->get('c1'); | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 0 |  |  |  |  |  | $ot=$hash->objtype; | 
| 123 | 0 |  |  |  |  |  | $self->assert($ot eq 'Hash', | 
| 124 |  |  |  |  |  |  | "Hash object returned wrong 'objtype' ($ot)"); | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 0 |  |  |  |  |  | $self->assert($hash->upper_class eq 'FS::Global', | 
| 127 |  |  |  |  |  |  | "Wrong upper_class() for the customer Hash"); | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | sub test_uri { | 
| 131 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 132 | 0 |  |  |  |  |  | my $odb=$self->{odb}; | 
| 133 |  |  |  |  |  |  |  | 
| 134 | 0 |  |  |  |  |  | my $global=$odb->fetch('/'); | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 0 |  |  |  |  |  | my $uri=$global->uri; | 
| 137 | 0 |  |  |  |  |  | $self->assert($uri eq '/', | 
| 138 |  |  |  |  |  |  | "Global returned bad URI ('$uri' != '/')"); | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 0 |  |  |  |  |  | $uri=$global->uri('Customers'); | 
| 141 | 0 |  |  |  |  |  | $self->assert($uri eq '/Customers', | 
| 142 |  |  |  |  |  |  | "Global returned bad URI ('$uri' != '/Customers')"); | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 0 |  |  |  |  |  | my $list=$global->get('Customers'); | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 0 |  |  |  |  |  | $uri=$list->uri; | 
| 147 | 0 |  |  |  |  |  | $self->assert($uri eq '/Customers', | 
| 148 |  |  |  |  |  |  | "Customers returned bad URI ('$uri' != '/Customers')"); | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 0 |  |  |  |  |  | $uri=$list->uri('c2'); | 
| 151 | 0 |  |  |  |  |  | $self->assert($uri eq '/Customers/c2', | 
| 152 |  |  |  |  |  |  | "Customers returned bad URI ('$uri' != '/Customers/c2')"); | 
| 153 |  |  |  |  |  |  |  | 
| 154 | 0 |  |  |  |  |  | my $hash=$odb->fetch('/Customers/c1'); | 
| 155 |  |  |  |  |  |  |  | 
| 156 | 0 |  |  |  |  |  | $uri=$hash->uri; | 
| 157 | 0 |  |  |  |  |  | $self->assert($uri eq '/Customers/c1', | 
| 158 |  |  |  |  |  |  | "Hash returned bad URI ('$uri' != '/Customers/c1')"); | 
| 159 |  |  |  |  |  |  |  | 
| 160 | 0 |  |  |  |  |  | $uri=$hash->uri('name'); | 
| 161 | 0 |  |  |  |  |  | $self->assert($uri eq '/Customers/c1/name', | 
| 162 |  |  |  |  |  |  | "Hash returned bad URI ('$uri' != '/Customers/c1/name')"); | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | sub test_upper_class { | 
| 166 | 0 |  |  | 0 | 0 |  | my $self=shift; | 
| 167 | 0 |  |  |  |  |  | my $odb=$self->{odb}; | 
| 168 |  |  |  |  |  |  |  | 
| 169 | 0 |  |  |  |  |  | my $got=$odb->upper_class('FS::Global'); | 
| 170 | 0 |  | 0 |  |  |  | $self->assert(!defined($got), | 
| 171 |  |  |  |  |  |  | "Got wrong upper class for Global (" . ($got || '') . ")"); | 
| 172 |  |  |  |  |  |  |  | 
| 173 | 0 |  |  |  |  |  | $got=$odb->upper_class('Data::Customer'); | 
| 174 | 0 |  |  |  |  |  | $self->assert($got eq 'FS::Global', | 
| 175 |  |  |  |  |  |  | "Got wrong upper class for Data::Customer ($got)"); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | 1; |