summaryrefslogtreecommitdiff
path: root/test/fop002.tcl
diff options
context:
space:
mode:
authorZhang Qiang <qiang.z.zhang@intel.com>2012-05-29 12:22:00 +0800
committerZhang Qiang <qiang.z.zhang@intel.com>2012-05-29 12:22:00 +0800
commit02f0634ac29e19c68279e5544cac963e7f1203b8 (patch)
treeb983472f94ef063cedf866d8ecfb55939171779d /test/fop002.tcl
parente776056ea09ba0b6d9505ced6913c9190a12d632 (diff)
downloaddb4-02f0634ac29e19c68279e5544cac963e7f1203b8.tar.gz
db4-02f0634ac29e19c68279e5544cac963e7f1203b8.tar.bz2
db4-02f0634ac29e19c68279e5544cac963e7f1203b8.zip
Sync source code from Tizen:BaseHEAD2.0_alphamaster2.0alpha1.0_post
Diffstat (limited to 'test/fop002.tcl')
-rw-r--r--test/fop002.tcl135
1 files changed, 135 insertions, 0 deletions
diff --git a/test/fop002.tcl b/test/fop002.tcl
new file mode 100644
index 0000000..9a1aa54
--- /dev/null
+++ b/test/fop002.tcl
@@ -0,0 +1,135 @@
+# See the file LICENSE for redistribution information.
+#
+# Copyright (c) 2000-2009 Oracle. All rights reserved.
+#
+# $Id$
+#
+# TEST fop002.tcl
+# TEST Test file system operations in the presence of bad permissions.
+proc fop002 { method args } {
+ source ./include.tcl
+
+ set args [convert_args $method $args]
+ set omethod [convert_method $method]
+
+ env_cleanup $testdir
+ puts "\nFop002: ($method) File system ops and permissions."
+ if { $is_windows_test == 1 } {
+ puts "\tSkipping permissions test for Windows platform."
+ return
+ }
+
+ # Create database with -rw-r--r-- permissions.
+ set perms "0644"
+ set testfile $testdir/a.db
+ set destfile $testdir/b.db
+
+ set db [eval \
+ {berkdb_open -create} $omethod $args -mode $perms $testfile]
+ error_check_good db_open [is_valid_db $db] TRUE
+ error_check_good db_put [$db put 1 [chop_data $method a]] 0
+ error_check_good db_close [$db close] 0
+
+ # Eliminate all read and write permission, and try to execute
+ # file ops. They should fail.
+ set res [exec chmod 0000 $testfile]
+ error_check_good remove_permissions [llength $res] 0
+ # Put remove last on the list of ops since it should succeed
+ # at the end of the test, removing the test file.
+ set ops [list open_create open rename remove]
+ set rdonly 0
+
+ puts "\tFop002.a: Test with neither read nor write permission."
+ foreach op $ops {
+ puts "\t\tFop002.a: Testing $op for failure."
+ switch $op {
+ open {
+ test_$op $testfile $omethod $args $rdonly 1
+ }
+ rename {
+ test_$op $testfile $destfile 1
+ }
+ open_create {
+ test_$op $testfile $omethod $args 1
+ }
+ remove {
+ test_$op $testfile 1
+ }
+ }
+ }
+
+ # Change permissions to read-only.
+ puts "\tFop002.b: Test with read-only permission."
+ set rdonly 1
+
+ set res [exec chmod 0444 $testfile]
+ error_check_good set_readonly [llength $res] 0
+
+ foreach op $ops {
+ puts "\t\tFop002.b: Testing $op for success."
+ switch $op {
+ open {
+ test_$op $testfile $omethod $args $rdonly 0
+ }
+ rename {
+ test_$op $testfile $destfile 0
+ # Move it back so later tests work
+ test_$op $destfile $testfile 0
+ }
+ open_create {
+ puts "\t\tSkipping open_create with read-only."
+ }
+ remove {
+ test_$op $testfile 0
+ }
+ }
+ }
+}
+
+proc test_remove { testfile {expectfail 0} } {
+ catch { berkdb dbremove $testfile } res
+ if { $expectfail == 1 } {
+ error_check_good remove_err $res "db remove:permission denied"
+ } else {
+ error_check_good remove $res 0
+ }
+}
+
+proc test_rename { testfile destfile {expectfail 0} } {
+ catch { berkdb dbrename $testfile $destfile } res
+ if { $expectfail == 1 } {
+ error_check_good rename_err $res "db rename:permission denied"
+ } else {
+ error_check_good rename $res 0
+ }
+}
+
+proc test_open_create { testfile omethod args {expectfail 0} } {
+ set stat [catch { set db \
+ [eval {berkdb_open -create} $omethod $args $testfile]} res]
+ if { $expectfail == 1 } {
+ error_check_good open_create_err $res \
+ "db open:permission denied"
+ } else {
+ error_check_good open_create $stat 0
+ # Since we succeeded, we have to close the db.
+ error_check_good db_close [$db close] 0
+ }
+}
+
+proc test_open { testfile omethod args {readonly 0} {expectfail 0} } {
+ if { $readonly == 1 } {
+ set stat [catch {set db \
+ [eval {berkdb_open -rdonly} $omethod $args $testfile]} res]
+ } else {
+ set stat [catch {set db [berkdb_open $omethod $testfile]} res]
+ }
+ if { $expectfail == 1 } {
+ error_check_good open_err $res \
+ "db open:permission denied"
+ } else {
+ error_check_good db_open $stat 0
+ error_check_good db_close [$db close] 0
+ }
+}
+