#!/usr/bin/env ruby # == file test.rb # unit test for the Dazuko extension # { $license = < grant pid = help_schedule_access(file) rc = d.get_access() do |acc| assert(acc.class == Hash) assert(acc['deny'] == 0) assert(acc['pid'] == pid) assert(acc['filename'] == file) ret_deny end assert(rc == true) rc = help_exitcode_for_pid(pid) assert(rc != nil) ok = (rc == 0) assert(ok == exp_success) assert(d.unregister() == true) d = nil end # all the test_denyaccess_*() routines test if deny works, # while they check with different types of return values def test_denyaccess_num0 help_handle_rw_access(0, true) end def test_denyaccess_num1 help_handle_rw_access(1, false) end def test_denyaccess_false help_handle_rw_access(false, true) end def test_denyaccess_true help_handle_rw_access(true, false) end def test_denyaccess_str0 help_handle_rw_access('0', true) end def test_denyaccess_str1 help_handle_rw_access('1', false) end def test_denyaccess_strfalse help_handle_rw_access('false', true) end def test_denyaccess_strtrue help_handle_rw_access('true', false) end def test_denyaccess_strno help_handle_rw_access('no', true) end def test_denyaccess_stryes help_handle_rw_access('yes', false) end def test_denyaccess_nil help_handle_rw_access(nil, true) end # test the event handler's exception catching # (access will be denied should the application fail) def test_access_exception file = $PROGRAM_NAME file = help_make_absolute(file) d = Dazuko.new assert(d != nil) assert(d.register("example:ruby", "rw") == true) assert(d.set_mask(Dazuko::DAZUKO_ON_OPEN) == true) assert(d.add_include(file) == true) assert(d.add_exclude("/dev/") == true) assert(d.access_want("Hash") != nil) assert(d.silent("really_only_for_the_unit_test") != nil) # exception => deny pid = help_schedule_access(file) rc = d.get_access() do |acc| assert(acc.class == Hash) assert(acc['deny'] == 0) assert(acc['pid'] == pid) assert(acc['filename'] == file) throw "access handler oops" # UNREACH assert(false) end assert(rc == true) rc = help_exitcode_for_pid(pid) assert(rc != nil) assert(rc != 0) assert(d.unregister() == true) d = nil end end # ----- E O F ---------------------------------------------------