Changeset 2155
- Timestamp:
- 04/29/08 23:17:00 (7 months ago)
- Files:
-
- branches/release-36/t/driver-tests.pl (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/release-36/t/driver-tests.pl
r2154 r2155 30 30 } 31 31 32 use constant TESTS => 261;32 use constant TESTS => 187; 33 33 34 34 use Test::More; … … 91 91 my ($got, $expected, $name) = @_; 92 92 93 isa_ok($got, ref $expected, $name); 94 isnt($got, $expected, "$name is not the same instance as the expected object"); 93 if (!defined $got) { 94 fail($name); 95 diag(' got undef, not an object'); 96 return; 97 } 98 99 if (!$got->isa(ref $expected)) { 100 fail($name); 101 diag(' got a ', ref($got), ' but expected a ', ref $expected); 102 return; 103 } 104 105 if ($got == $expected) { 106 fail($name); 107 diag(' got the exact same instance as expected, when really expected a different but equivalent object'); 108 return; 109 } 95 110 96 111 # Ignore object columns that have undefined values. … … 103 118 } 104 119 105 is_deeply(\%got_values, \%expected_values, "$name is equivalent to the expected object");106 } 107 108 is_object(scalar Foo->load(1), $foo[0], 'Foo #1 by id ');109 is_object(scalar Foo->load({ id => 1 }), $foo[0], 'Foo #1 by id hash ');110 is_object(scalar Foo->load({ id => 1, name => 'foo' }), $foo[0], 'Foo #1 by id-name hash ');111 is_object(scalar Foo->load({ name => 'foo' }), $foo[0], 'Foo #1 by name hash ');112 is_object(scalar Foo->load({ created_on => $foo[0]->created_on }), $foo[0], 'Foo #1 by created_on hash ');113 is_object(scalar Foo->load({ status => 2 }), $foo[0], 'Foo #1 by status hash ');120 is_deeply(\%got_values, \%expected_values, $name); 121 } 122 123 is_object(scalar Foo->load(1), $foo[0], 'Foo #1 by id is Foo #1'); 124 is_object(scalar Foo->load({ id => 1 }), $foo[0], 'Foo #1 by id hash is Foo #1'); 125 is_object(scalar Foo->load({ id => 1, name => 'foo' }), $foo[0], 'Foo #1 by id-name hash is Foo #1'); 126 is_object(scalar Foo->load({ name => 'foo' }), $foo[0], 'Foo #1 by name hash is Foo #1'); 127 is_object(scalar Foo->load({ created_on => $foo[0]->created_on }), $foo[0], 'Foo #1 by created_on hash is Foo #1'); 128 is_object(scalar Foo->load({ status => 2 }), $foo[0], 'Foo #1 by status hash is Foo #1'); 114 129 115 130 ## Change column value, save, try to load using old value (fail?), … … 120 135 ok(!$tmp, 'Foo #1 no longer loads with old status (2)'); 121 136 $tmp = Foo->load({ status => 0 }); 122 is_object($tmp, $foo[0], 'Foo #1 by new status (0) ');137 is_object($tmp, $foo[0], 'Foo #1 by new status (0) is Foo #1'); 123 138 124 139 ## Create a new object so we can do range and last/first lookups. … … 139 154 isa_ok($iter, 'CODE', "Iterator for all Foos"); 140 155 ok($tmp = $iter->(), 'Iterator for our two Foos had one object'); 141 is_object($tmp, $foo[0], "All Foo iterator's first Foo ");156 is_object($tmp, $foo[0], "All Foo iterator's first Foo is Foo #1"); 142 157 ok($tmp = $iter->(), 'Iterator for our two Foos had two objects'); 143 is_object($tmp, $foo[1], "All Foo iterator's second Foo ");158 is_object($tmp, $foo[1], "All Foo iterator's second Foo is Foo #2"); 144 159 ok(!$iter->(), 'Iterator for our two Foos did not have a third object'); 145 160 … … 148 163 isa_ok($iter, 'CODE', "Iterator for status=1 Foos"); 149 164 ok($tmp = $iter->(), 'Iterator for our status=1 Foos had one object'); 150 is_object($tmp, $foo[1], "Status=1 Foo iterator's first Foo ");165 is_object($tmp, $foo[1], "Status=1 Foo iterator's first Foo is Foo #2"); 151 166 ok(!$iter->(), "Iterator for our status=1 Foos did not have a second object"); 152 167 … … 160 175 direction => 'descend', 161 176 limit => 1 }); 162 is_object($tmp, $foo[1], 'Newest Foo ');177 is_object($tmp, $foo[1], 'Newest Foo is Foo #2'); 163 178 164 179 ## Load using ascending sort (oldest) … … 167 182 direction => 'ascend', 168 183 limit => 1 }); 169 is_object($tmp, $foo[0], 'Oldest Foo ');184 is_object($tmp, $foo[0], 'Oldest Foo is Foo #1'); 170 185 171 186 sub are_objects { … … 173 188 174 189 my $count = scalar @$expected; 175 is(scalar @$got, $count, "$name got $count objects"); 176 is_object($$got[$_], $$expected[$_], "$name #$_") for (0..$count-1); 190 if ($count != scalar @$got) { 191 fail($name); 192 diag(' got ', scalar(@$got), ' objects but expected ', $count); 193 return; 194 } 195 196 is_object($$got[$_], $$expected[$_], "$name (#$_)") for (0..$count-1); 177 197 } 178 198 … … 182 202 direction => 'descend', 183 203 limit => 2 }); 184 are_objects(\@tmp, [ reverse @foo ], 'Two Foos newest-first load() ');204 are_objects(\@tmp, [ reverse @foo ], 'Two Foos newest-first load() finds Foos #2 and #1'); 185 205 186 206 ## Load using descending sort by created_on, no limit … … 188 208 sort => 'created_on', 189 209 direction => 'descend' }); 190 are_objects(\@tmp, [ reverse @foo ], 'All Foos newest-first load() ');210 are_objects(\@tmp, [ reverse @foo ], 'All Foos newest-first load() finds Foos #2 and #1'); 191 211 192 212 ## Load using ascending sort by status, no limit 193 213 @tmp = Foo->load(undef, { sort => 'status', }); 194 are_objects(\@tmp, \@foo, 'All Foos lowest-status-first load() ');214 are_objects(\@tmp, \@foo, 'All Foos lowest-status-first load() finds Foos #1 and #2'); 195 215 196 216 ## Load using 'last' where status == 0 … … 199 219 direction => 'descend', 200 220 limit => 1 }); 201 is_object($tmp, $foo[0], 'Newest status=0 Foo ');221 is_object($tmp, $foo[0], 'Newest status=0 Foo is Foo #1'); 202 222 203 223 ## Load using range search, one less than foo[1]->created_on and newer … … 205 225 { created_on => [ $foo[1]->column('created_on')-1 ] }, 206 226 { range => { created_on => 1 } }); 207 is_object($tmp, $foo[1], 'Foo from open-ended date range before Foo #2 ');227 is_object($tmp, $foo[1], 'Foo from open-ended date range before Foo #2 is Foo #2'); 208 228 209 229 ## Load using EXCLUSIVE range search, up through the momment $foo[1] created … … 226 246 { range_incl => { created_on => 1 } }); 227 247 ok($tmp, 'Loaded an object based on range_incl (ts-1 to ts)'); 228 is_object($tmp, $foo[1], "Foo from inclusive date-range load() ending at Foo #1's date ");248 is_object($tmp, $foo[1], "Foo from inclusive date-range load() ending at Foo #1's date is Foo #2"); 229 249 230 250 $tmp = Foo->load( … … 233 253 { range_incl => { created_on => 1 } }); 234 254 ok($tmp, 'Loaded an object based on range_incl (ts to ts+1)'); 235 is_object($tmp, $foo[1], "Foo from inclusive date-range load() starting at Foo #1's date ");255 is_object($tmp, $foo[1], "Foo from inclusive date-range load() starting at Foo #1's date is Foo #2"); 236 256 237 257 ## Check that range searches return nothing when nothing is in the range. … … 244 264 { created_on => [ undef, $foo[1]->column('created_on')-1 ] }, 245 265 { range => { created_on => 1 } }); 246 is_object($tmp, $foo[0], "Foo from exclusive open-started date-range load() ending before Foo #1 ");266 is_object($tmp, $foo[0], "Foo from exclusive open-started date-range load() ending before Foo #1 is Foo #1"); 247 267 248 268 ## Get count of objects … … 267 287 direction => 'ascend', 268 288 start_val => $foo[0]->created_on }); 269 is_object($tmp, $foo[1], 'Next newer Foo after Foo #1 ');289 is_object($tmp, $foo[1], 'Next newer Foo after Foo #1 is Foo #2'); 270 290 271 291 ## Given the first Foo object, try to load the "previous" one … … 285 305 direction => 'descend', 286 306 start_val => $foo[1]->created_on }); 287 is_object($tmp, $foo[0], 'Next older Foo before Foo #2 ');307 is_object($tmp, $foo[0], 'Next older Foo before Foo #2 is Foo #1'); 288 308 289 309 ## Given the second Foo object, try to load the "next" one … … 303 323 direction => 'descend', 304 324 start_val => $foo[1]->created_on-1 }); 305 is_object($tmp, $foo[0], 'Next older Foo before just before Foo #2 ');325 is_object($tmp, $foo[0], 'Next older Foo before just before Foo #2 is Foo #1'); 306 326 307 327 ## Now, given the second Foo object's created_on - 1, try to … … 312 332 direction => 'ascend', 313 333 start_val => $foo[1]->created_on-1 }); 314 is_object($tmp, $foo[1], 'Next newer Foo after just before Foo #2 ');334 is_object($tmp, $foo[1], 'Next newer Foo after just before Foo #2 is Foo #2'); 315 335 316 336 ## Override created_on timestamp, make sure it works … … 323 343 direction => 'descend', 324 344 limit => 2 }); 325 are_objects(\@tmp, \@foo, 'Time-traveled Foos newest-first ');345 are_objects(\@tmp, \@foo, 'Time-traveled Foos newest-first are Foos #1 and #2'); 326 346 327 347 ## Test limit of 2 with direction descend, but without … … 331 351 direction => 'descend', 332 352 limit => 2 }); 333 are_objects(\@tmp, [ reverse @foo ], 'Foos highest-id-first ');353 are_objects(\@tmp, [ reverse @foo ], 'Foos highest-id-first are Foos #2 and #1'); 334 354 335 355 ## Test loading using offset. … … 340 360 limit => 1, 341 361 offset => 1 }); 342 is_object($tmp, $foo[1], 'Second newest Foo ');362 is_object($tmp, $foo[1], 'Second newest Foo is Foo #2'); 343 363 344 364 ## We only have 2 Foo objects, so this should load … … 349 369 limit => 2, 350 370 offset => 1 }); 351 are_objects(\@tmp, [ $foo[1] ], 'Second and third newest Foos ');371 are_objects(\@tmp, [ $foo[1] ], 'Second and third newest Foos is just Foo #2'); 352 372 353 373 ## Should load the first Foo object (ascend with offset of 1). … … 357 377 limit => 1, 358 378 offset => 1 }); 359 is_object($tmp, $foo[0], 'Second oldest Foo ');379 is_object($tmp, $foo[0], 'Second oldest Foo is Foo #1'); 360 380 361 381 ## Now test join loads.
