Fixed ERROR_HANDLER.destroy
Fixed and export ERROR_HANDLER.remove_synchronized_handler Added comments Added associated autotests
This commit is contained in:
@@ -21,13 +21,13 @@ feature -- Access
|
||||
result_not_zero: Result /= 0
|
||||
end
|
||||
|
||||
name: STRING
|
||||
name: READABLE_STRING_8
|
||||
deferred
|
||||
ensure
|
||||
result_attached: Result /= Void
|
||||
end
|
||||
|
||||
message: detachable STRING_32
|
||||
message: detachable READABLE_STRING_32
|
||||
-- Potential error message
|
||||
deferred
|
||||
end
|
||||
@@ -80,7 +80,7 @@ invariant
|
||||
name_attached: name /= Void
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
copyright: "2011-2012, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -16,12 +16,12 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_code: INTEGER; a_name: STRING; a_message: detachable like message)
|
||||
make (a_code: INTEGER; a_name: like name; a_message: detachable like message)
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
code := a_code
|
||||
name := a_name
|
||||
if attached a_message then
|
||||
if a_message /= Void then
|
||||
message := a_message
|
||||
else
|
||||
message := "Error: " + a_name + " (code=" + a_code.out + ")"
|
||||
@@ -32,9 +32,9 @@ feature -- Access
|
||||
|
||||
code: INTEGER
|
||||
|
||||
name: STRING
|
||||
name: READABLE_STRING_8
|
||||
|
||||
message: STRING_32
|
||||
message: detachable READABLE_STRING_32
|
||||
|
||||
feature -- Visitor
|
||||
|
||||
@@ -45,7 +45,7 @@ feature -- Visitor
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
copyright: "2011-2012, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
@@ -34,6 +34,7 @@ feature -- Status
|
||||
end
|
||||
|
||||
count: INTEGER
|
||||
-- Number of error
|
||||
do
|
||||
Result := errors.count
|
||||
end
|
||||
@@ -63,10 +64,9 @@ feature -- Events
|
||||
feature -- Synchronization
|
||||
|
||||
add_synchronized_handler (h: ERROR_HANDLER)
|
||||
-- Add synchronization between `h' and `Current'
|
||||
--| the same handler can be added more than once
|
||||
--| it will be synchronized only once
|
||||
require
|
||||
no_cycle: not has_synchronized_handler_in_cycle (h)
|
||||
local
|
||||
lst: like synchronized_handlers
|
||||
do
|
||||
@@ -84,9 +84,20 @@ feature -- Synchronization
|
||||
end
|
||||
end
|
||||
|
||||
has_synchronized_handler_in_cycle (h: ERROR_HANDLER): BOOLEAN
|
||||
remove_synchronized_handler (h: ERROR_HANDLER)
|
||||
-- Remove synchronization between `h' and `Current'
|
||||
do
|
||||
Result := False
|
||||
if attached synchronized_handlers as lst and then not lst.is_empty then
|
||||
synchronized_handlers := Void
|
||||
lst.prune_all (h)
|
||||
|
||||
h.remove_synchronized_handler (Current)
|
||||
|
||||
synchronized_handlers := lst
|
||||
if lst.is_empty then
|
||||
synchronized_handlers := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {ERROR_HANDLER} -- Synchronization implementation
|
||||
@@ -143,16 +154,6 @@ feature {ERROR_HANDLER} -- Synchronization implementation
|
||||
end
|
||||
end
|
||||
|
||||
remove_synchronized_handler (h: ERROR_HANDLER)
|
||||
do
|
||||
if attached synchronized_handlers as lst then
|
||||
lst.prune_all (h)
|
||||
if lst.is_empty then
|
||||
synchronized_handlers := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Event: implementation
|
||||
|
||||
on_error_added (e: ERROR)
|
||||
@@ -177,6 +178,7 @@ feature {NONE} -- Event: implementation
|
||||
end
|
||||
|
||||
on_reset
|
||||
-- `reset' was just called
|
||||
local
|
||||
sync_list: LINKED_LIST [ERROR_HANDLER]
|
||||
do
|
||||
@@ -237,6 +239,7 @@ feature -- Basic operation
|
||||
feature -- Access
|
||||
|
||||
as_single_error: detachable ERROR
|
||||
-- All error(s) concatenated into one single error.
|
||||
do
|
||||
if count > 1 then
|
||||
create {ERROR_GROUP} Result.make (errors)
|
||||
@@ -248,6 +251,7 @@ feature -- Access
|
||||
end
|
||||
|
||||
as_string_representation: STRING
|
||||
-- String representation of all error(s).
|
||||
require
|
||||
has_error
|
||||
do
|
||||
@@ -271,20 +275,30 @@ feature -- Element changes
|
||||
end
|
||||
|
||||
reset
|
||||
-- Reset error handler
|
||||
do
|
||||
if errors.count > 0 then
|
||||
errors.wipe_out
|
||||
on_reset
|
||||
end
|
||||
ensure
|
||||
has_no_error: not has_error
|
||||
count = 0
|
||||
end
|
||||
|
||||
destroy
|
||||
-- Destroy Current, and remove any synchronization
|
||||
do
|
||||
error_added_actions.wipe_out
|
||||
if attached synchronized_handlers as lst then
|
||||
lst.item.remove_synchronized_handler (Current)
|
||||
across
|
||||
lst as c
|
||||
loop
|
||||
c.item.remove_synchronized_handler (Current)
|
||||
end
|
||||
end
|
||||
synchronized_handlers := Void
|
||||
reset
|
||||
end
|
||||
|
||||
note
|
||||
|
||||
@@ -108,6 +108,64 @@ feature -- Test routines
|
||||
|
||||
end
|
||||
|
||||
test_remove_sync
|
||||
note
|
||||
testing: "error"
|
||||
local
|
||||
h1, h2, h3: ERROR_HANDLER
|
||||
-- cl: CELL [INTEGER]
|
||||
do
|
||||
create h1.make
|
||||
create h2.make
|
||||
create h3.make
|
||||
|
||||
h1.add_synchronized_handler (h2)
|
||||
h2.add_synchronized_handler (h3)
|
||||
h3.add_synchronized_handler (h1)
|
||||
|
||||
h1.add_custom_error (123, "abc", "abc error occurred")
|
||||
h1.add_custom_error (456, "def", "def error occurred")
|
||||
|
||||
assert ("has 2 errors", h1.count = 2 and h2.count = h1.count and h3.count = h2.count)
|
||||
|
||||
h2.remove_synchronized_handler (h3)
|
||||
h2.remove_synchronized_handler (h1)
|
||||
|
||||
h1.add_custom_error (789, "ghi", "ghi error occurred")
|
||||
assert ("correct count of errors", h1.count = 3 and h2.count = 2 and h3.count = h1.count)
|
||||
|
||||
h1.reset
|
||||
assert ("reset then no error", h1.count = 0 and h2.count = 2 and h3.count = h1.count)
|
||||
end
|
||||
|
||||
test_destroy
|
||||
note
|
||||
testing: "error"
|
||||
local
|
||||
h1, h2, h3: ERROR_HANDLER
|
||||
-- cl: CELL [INTEGER]
|
||||
do
|
||||
create h1.make
|
||||
create h2.make
|
||||
create h3.make
|
||||
|
||||
h1.add_synchronized_handler (h2)
|
||||
h2.add_synchronized_handler (h3)
|
||||
h3.add_synchronized_handler (h1)
|
||||
|
||||
h1.add_custom_error (123, "abc", "abc error occurred")
|
||||
h1.add_custom_error (456, "def", "def error occurred")
|
||||
|
||||
assert ("has 2 errors", h1.count = 2 and h2.count = h1.count and h3.count = h2.count)
|
||||
|
||||
h2.destroy
|
||||
|
||||
h1.add_custom_error (789, "ghi", "ghi error occurred")
|
||||
assert ("correct count of errors", h1.count = 3 and h2.count = 0 and h3.count = h1.count)
|
||||
|
||||
h1.reset
|
||||
assert ("reset then no error", h1.count = 0 and h2.count = h1.count and h3.count = h1.count)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
|
||||
Reference in New Issue
Block a user