1# See the file LICENSE for redistribution information. 2# 3# Copyright (c) 1999,2008 Oracle. All rights reserved. 4# 5# $Id: test022.tcl,v 12.6 2008/01/08 20:58:53 bostic Exp $ 6# 7# TEST test022 8# TEST Test of DB->getbyteswapped(). 9proc test022 { method args } { 10 source ./include.tcl 11 12 set args [convert_args $method $args] 13 set omethod [convert_method $method] 14 15 puts "Test022 ($args) $omethod: DB->getbyteswapped()" 16 17 set txnenv 0 18 set eindex [lsearch -exact $args "-env"] 19 # 20 # If we are using an env, then testfile should just be the db name. 21 # Otherwise it is the test directory and the name. 22 if { $eindex == -1 } { 23 set testfile1 "$testdir/test022a.db" 24 set testfile2 "$testdir/test022b.db" 25 set env NULL 26 } else { 27 set testfile1 "test022a.db" 28 set testfile2 "test022b.db" 29 incr eindex 30 set env [lindex $args $eindex] 31 set txnenv [is_txnenv $env] 32 if { $txnenv == 1 } { 33 append args " -auto_commit " 34 } 35 set testdir [get_home $env] 36 } 37 cleanup $testdir $env 38 39 # Create two databases, one in each byte order. 40 set db1 [eval {berkdb_open -create \ 41 -mode 0644} $omethod $args {-lorder 1234} $testfile1] 42 error_check_good db1_open [is_valid_db $db1] TRUE 43 44 set db2 [eval {berkdb_open -create \ 45 -mode 0644} $omethod $args {-lorder 4321} $testfile2] 46 error_check_good db2_open [is_valid_db $db2] TRUE 47 48 # Call DB->get_byteswapped on both of them. 49 set db1_order [$db1 is_byteswapped] 50 set db2_order [$db2 is_byteswapped] 51 52 # Make sure that both answers are either 1 or 0, 53 # and that exactly one of them is 1. 54 error_check_good is_byteswapped_sensible_1 \ 55 [expr ($db1_order == 1 && $db2_order == 0) || \ 56 ($db1_order == 0 && $db2_order == 1)] 1 57 58 error_check_good db1_close [$db1 close] 0 59 error_check_good db2_close [$db2 close] 0 60 puts "\tTest022 complete." 61} 62