Improved BASE64 to update has_error when decoding.
Added manual tests.
This commit is contained in:
@@ -34,6 +34,38 @@ feature -- Test routines
|
||||
assert ("decoded encoded string is same", u ~ s)
|
||||
end
|
||||
|
||||
feature -- Tests
|
||||
|
||||
test_valid_64_encoding
|
||||
do
|
||||
assert ("Expected encoded True:", is_valid_base64_encoding ((create {BASE64}).encoded_string ("content")))
|
||||
end
|
||||
|
||||
test_not_valid64_encoding
|
||||
do
|
||||
assert ("Expected encoded False:", not is_valid_base64_encoding ("content"))
|
||||
assert ("Expected encoded False:", not is_valid_base64_encoding ("!@#$%%^"))
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
is_valid_base64_encoding (a_string: STRING): BOOLEAN
|
||||
-- is `a_string' base64 encoded?
|
||||
local
|
||||
l_encoder: BASE64
|
||||
l_string: STRING
|
||||
l_retry: BOOLEAN
|
||||
do
|
||||
if not l_retry then
|
||||
create l_encoder
|
||||
l_string := l_encoder.decoded_string (a_string)
|
||||
Result := not l_encoder.has_error
|
||||
end
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
Reference in New Issue
Block a user