Index: trunk/phase3/maintenance/cdb-test.php |
— | — | @@ -0,0 +1,65 @@ |
| 2 | +<?php |
| 3 | +require( 'commandLine.inc' ); |
| 4 | +function randomString() { |
| 5 | + $len = mt_rand( 0, 10 ); |
| 6 | + $s = ''; |
| 7 | + for ( $j = 0; $j < $len; $j++ ) { |
| 8 | + $s .= chr( mt_rand( 0, 255 ) ); |
| 9 | + } |
| 10 | + return $s; |
| 11 | +} |
| 12 | +function cdbAssert( $msg, $key, $v1, $v2 ) { |
| 13 | + if ( $v1 !== $v2 ) { |
| 14 | + echo $msg . ', k=' . bin2hex( $key ) . |
| 15 | + ', v1=' . bin2hex( $v1 ) . |
| 16 | + ', v2=' . bin2hex( $v2 ) . "\n"; |
| 17 | + return false; |
| 18 | + } else { |
| 19 | + return true; |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +echo "Write test...\n"; |
| 25 | + |
| 26 | +$w1 = new CdbWriter_PHP( 'php.cdb' ); |
| 27 | +$w2 = new CdbWriter_DBA( 'dba.cdb' ); |
| 28 | + |
| 29 | +$data = array(); |
| 30 | +for ( $i = 0; $i < 100000; $i++ ) { |
| 31 | + $key = randomString(); |
| 32 | + $value = randomString(); |
| 33 | + $w1->set( $key, $value ); |
| 34 | + $w2->set( $key, $value ); |
| 35 | + |
| 36 | + if ( !isset( $data[$key] ) ) { |
| 37 | + $data[$key] = $value; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +$w1->close(); |
| 42 | +$w2->close(); |
| 43 | + |
| 44 | +passthru( 'md5sum php.cdb dba.cdb' ); |
| 45 | + |
| 46 | +echo "Read test...\n"; |
| 47 | + |
| 48 | +$r1 = new CdbReader_PHP( 'php.cdb' ); |
| 49 | +$r2 = new CdbReader_DBA( 'dba.cdb' ); |
| 50 | + |
| 51 | +foreach ( $data as $key => $value ) { |
| 52 | + if ( $key === '' ) { |
| 53 | + // Known bug |
| 54 | + continue; |
| 55 | + } |
| 56 | + $v1 = $r1->get( $key ); |
| 57 | + $v2 = $r2->get( $key ); |
| 58 | + |
| 59 | + $v1 = $v1 === false ? '(not found)' : $v1; |
| 60 | + $v2 = $v2 === false ? '(not found)' : $v2; |
| 61 | + |
| 62 | + #cdbAssert( 'Mismatch', $key, $v1, $v2 ); |
| 63 | + cdbAssert( "PHP error", $key, $v1, $value ); |
| 64 | + cdbAssert( "DBA error", $key, $v2, $value ); |
| 65 | +} |
| 66 | +echo "Done.\n"; |
Property changes on: trunk/phase3/maintenance/cdb-test.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 67 | + native |