test003.tcl
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. # See the file LICENSE for redistribution information.
  2. #
  3. # Copyright (c) 1996, 1997, 1998, 1999, 2000
  4. # Sleepycat Software.  All rights reserved.
  5. #
  6. # $Id: test003.tcl,v 11.18 2000/08/25 14:21:54 sue Exp $
  7. #
  8. # DB Test 3 {access method}
  9. # Take the source files and dbtest executable and enter their names as the
  10. # key with their contents as data.  After all are entered, retrieve all;
  11. # compare output to original. Close file, reopen, do retrieve and re-verify.
  12. proc test003 { method args} {
  13. global names
  14. source ./include.tcl
  15. set args [convert_args $method $args]
  16. set omethod [convert_method $method]
  17. if {[is_fixed_length $method] == 1} {
  18. puts "Test003 skipping for method $method"
  19. return
  20. }
  21. puts "Test003: $method ($args) filename=key filecontents=data pairs"
  22. # Create the database and open the dictionary
  23. set eindex [lsearch -exact $args "-env"]
  24. #
  25. # If we are using an env, then testfile should just be the db name.
  26. # Otherwise it is the test directory and the name.
  27. if { $eindex == -1 } {
  28. set testfile $testdir/test003.db
  29. set env NULL
  30. } else {
  31. set testfile test003.db
  32. incr eindex
  33. set env [lindex $args $eindex]
  34. }
  35. set t1 $testdir/t1
  36. set t2 $testdir/t2
  37. set t3 $testdir/t3
  38. set t4 $testdir/t4
  39. cleanup $testdir $env
  40. set db [eval {berkdb_open 
  41.      -create -truncate -mode 0644} $args $omethod $testfile]
  42. error_check_good dbopen [is_valid_db $db] TRUE
  43. set pflags ""
  44. set gflags ""
  45. set txn ""
  46. if { [is_record_based $method] == 1 } {
  47. set checkfunc test003_recno.check
  48. append gflags "-recno"
  49. } else {
  50. set checkfunc test003.check
  51. }
  52. # Here is the loop where we put and get each key/data pair
  53. set file_list [ glob 
  54.     { $test_path/../*/*.[ch] } $test_path/*.tcl *.{a,o,lo,exe} 
  55.     $test_path/file.1 ]
  56. puts "tTest003.a: put/get loop"
  57. set count 0
  58. foreach f $file_list {
  59. if { [string compare [file type $f] "file"] != 0 } {
  60. continue
  61. }
  62. if { [is_record_based $method] == 1 } {
  63. set key [expr $count + 1]
  64. set names([expr $count + 1]) $f
  65. } else {
  66. set key $f
  67. }
  68. # Should really catch errors
  69. set fid [open $f r]
  70. fconfigure $fid -translation binary
  71. set data [read $fid]
  72. close $fid
  73. set ret [eval {$db put} 
  74.     $txn $pflags {$key [chop_data $method $data]}]
  75. error_check_good put $ret 0
  76. # Should really catch errors
  77. set fid [open $t4 w]
  78. fconfigure $fid -translation binary
  79. if [catch {eval {$db get} $gflags {$key}} data] {
  80. puts -nonewline $fid $data
  81. } else {
  82. # Data looks like {{key data}}
  83. set key [lindex [lindex $data 0] 0]
  84. set data [lindex [lindex $data 0] 1]
  85. puts -nonewline $fid [pad_data $method $data]
  86. }
  87. close $fid
  88. error_check_good 
  89.     Test003:diff($f,$t4) [filecmp $f $t4] 0
  90. incr count
  91. }
  92. # Now we will get each key from the DB and compare the results
  93. # to the original.
  94. puts "tTest003.b: dump file"
  95. dump_bin_file $db $txn $t1 $checkfunc
  96. error_check_good db_close [$db close] 0
  97. # Now compare the keys to see if they match the entries in the
  98. # current directory
  99. if { [is_record_based $method] == 1 } {
  100. set oid [open $t2 w]
  101. for {set i 1} {$i <= $count} {set i [incr i]} {
  102. puts $oid $i
  103. }
  104. close $oid
  105. file rename -force $t1 $t3
  106. } else {
  107. set oid [open $t2.tmp w]
  108. foreach f $file_list {
  109. if { [string compare [file type $f] "file"] != 0 } {
  110. continue
  111. }
  112. puts $oid $f
  113. }
  114. close $oid
  115. filesort $t2.tmp $t2
  116. fileremove $t2.tmp
  117. filesort $t1 $t3
  118. }
  119. error_check_good 
  120.     Test003:diff($t3,$t2) [filecmp $t3 $t2] 0
  121. # Now, reopen the file and run the last test again.
  122. puts "tTest003.c: close, open, and dump file"
  123. open_and_dump_file $testfile $env $txn $t1 $checkfunc 
  124.     dump_bin_file_direction "-first" "-next"
  125. if { [is_record_based $method] == 1 } {
  126. filesort $t1 $t3 -n
  127. }
  128. error_check_good 
  129.     Test003:diff($t3,$t2) [filecmp $t3 $t2] 0
  130. # Now, reopen the file and run the last test again in reverse direction.
  131. puts "tTest003.d: close, open, and dump file in reverse direction"
  132. open_and_dump_file $testfile $env $txn $t1 $checkfunc 
  133.     dump_bin_file_direction "-last" "-prev"
  134. if { [is_record_based $method] == 1 } {
  135. filesort $t1 $t3 -n
  136. }
  137. error_check_good 
  138.     Test003:diff($t3,$t2) [filecmp $t3 $t2] 0
  139. }
  140. # Check function for test003; key should be file name; data should be contents
  141. proc test003.check { binfile tmpfile } {
  142. source ./include.tcl
  143. error_check_good Test003:datamismatch($binfile,$tmpfile) 
  144.     [filecmp $binfile $tmpfile] 0
  145. }
  146. proc test003_recno.check { binfile tmpfile } {
  147. global names
  148. source ./include.tcl
  149. set fname $names($binfile)
  150. error_check_good key"$binfile"_exists [info exists names($binfile)] 1
  151. error_check_good Test003:datamismatch($fname,$tmpfile) 
  152.     [filecmp $fname $tmpfile] 0
  153. }