Merge branch 'master' of git://github.com/jocelyn/Eiffel-Web-Framework

This commit is contained in:
jvelilla
2012-02-17 07:28:57 -03:00
32 changed files with 656 additions and 256 deletions

View File

@@ -7,6 +7,17 @@ note
class
REST_RESPONSE
inherit
WSF_PAGE_RESPONSE
rename
header as headers,
body as message,
set_body as set_message,
put_string as append_message,
make as page_make,
send_to as send
end
create
make
@@ -15,12 +26,7 @@ feature {NONE} -- Initialization
make (a_api: like api)
do
api := a_api
initialize
end
initialize
do
create headers.make
page_make
end
feature -- Recycle
@@ -28,123 +34,17 @@ feature -- Recycle
recycle
do
headers.recycle
message := Void
end
feature -- Access
headers: HTTP_HEADER
api: STRING
-- Associated api query string.
message: detachable STRING_8
-- Associated message to send with the response.
feature -- Element change
set_message (m: like message)
-- Set `message' to `m'
do
message := m
end
append_message (m: attached like message)
-- Append message `m' to current `message' value
-- create `message' is Void
require
m_not_empty: m /= Void and then not m.is_empty
do
if attached message as msg then
msg.append (m)
else
set_message (m.string)
end
end
append_message_file_content (fn: STRING)
-- Append file content from `fn' to the response
--| To use with care.
--| You should avoid using this for big or binary content ...
local
f: RAW_FILE
do
create f.make (fn)
if f.exists and then f.is_readable then
f.open_read
from
until
f.exhausted
loop
f.read_stream (1024)
append_message (f.last_string)
end
f.close
end
end
feature -- Output
update_content_length (a_overwrite: BOOLEAN)
-- Update content length
-- if the header already exists it won't change it,
-- unless `a_overwrite' is set to True
local
hds: like headers
len: INTEGER
do
hds := headers
if a_overwrite or else not hds.has_content_length then
if attached message as m then
len := m.count
-- if {PLATFORM}.is_windows then
-- len := len + m.occurrences ('%N') --| FIXME: find better solution
-- end
else
len := 0
end
hds.put_content_length (len)
end
end
compute
-- Compute the string output
do
update_content_length (False)
internal_headers_string := headers.string
end
headers_string: STRING
local
o: like internal_headers_string
do
o := internal_headers_string
if o = Void then
compute
o := internal_headers_string
if o = Void then
check output_computed: False end
create o.make_empty
end
end
Result := o
end
send (res: WSF_RESPONSE)
do
compute
res.set_status_code (200)
res.put_header_text (headers_string)
if attached message as m then
res.put_string (m)
end
end
feature {NONE} -- Implementation: output
internal_headers_string: detachable like headers_string
;note
copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
invariant
note
copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -10,6 +10,7 @@
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="curl" location="$ISE_LIBRARY\library\cURL\cURL-safe.ecf">
<condition>
<version type="compiler" min="7.0.8.7340"/>
@@ -23,17 +24,4 @@
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="tests" extends="http_client">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
<assertions precondition="true"/>
</option>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location=".\tests\"/>
</target>
</system>

View File

@@ -10,6 +10,7 @@
<option warning="true" full_class_checking="true" void_safety="none" syntax="provisional">
</option>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
<library name="curl" location="$ISE_LIBRARY\library\cURL\cURL.ecf">
<condition>
<version type="compiler" min="7.0.8.7340"/>

View File

@@ -1,12 +1,29 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
description : "[
HTTP_CLIENT_SESSION represent a session
and is used to call get, post, .... request
with predefined settings such as
base_url
specific common headers
timeout and so on ...
]"
author: "$Author$"
date: "$Date$"
revision: "$Revision$"
deferred class
HTTP_CLIENT_SESSION
inherit
ANY
HTTP_CLIENT_CONSTANTS
rename
auth_type_id as auth_type_id_from_string
export
{NONE} all
end
feature {NONE} -- Initialization
make (a_base_url: READABLE_STRING_8)
@@ -154,37 +171,36 @@ feature -- Change
set_auth_type (s: READABLE_STRING_8)
do
auth_type := s
auth_type_id := http_client_constants.auth_type_id (s)
auth_type_id := auth_type_id_from_string (s)
end
set_basic_auth_type
do
auth_type := "basic"
auth_type_id := {HTTP_CLIENT_CONSTANTS}.auth_type_basic
auth_type_id := Auth_type_basic
end
set_digest_auth_type
do
auth_type := "digest"
auth_type_id := {HTTP_CLIENT_CONSTANTS}.auth_type_digest
auth_type_id := Auth_type_digest
end
set_any_auth_type
do
auth_type := "any"
auth_type_id := {HTTP_CLIENT_CONSTANTS}.auth_type_any
auth_type_id := Auth_type_any
end
set_anysafe_auth_type
do
auth_type := "anysafe"
auth_type_id := {HTTP_CLIENT_CONSTANTS}.auth_type_anysafe
auth_type_id := Auth_type_anysafe
end
feature {NONE} -- Implementation
http_client_constants: HTTP_CLIENT_CONSTANTS
once
create Result
set_max_redirects (n: like max_redirects)
do
max_redirects := n
end
end

View File

@@ -24,6 +24,15 @@ feature {NONE} -- Initialization
do
make_request (a_url, a_session, ctx)
request_method := a_request_method
apply_workaround
end
apply_workaround
-- Due to issue with Eiffel cURL on Windows 32bits
-- we need to do the following workaround
once
if attached (create {INET_ADDRESS_FACTORY}).create_localhost then
end
end
session: LIBCURL_HTTP_CLIENT_SESSION
@@ -40,7 +49,6 @@ feature -- Execution
l_curl_string: CURL_STRING
l_url: READABLE_STRING_8
p: POINTER
a_data: CELL [detachable ANY]
l_form, l_last: CURL_FORM
curl: CURL_EXTERNALS
curl_easy: CURL_EASY_EXTERNALS
@@ -194,22 +202,32 @@ feature -- Execution
l_result := curl_easy.perform (curl_handle)
if l_result = {CURL_CODES}.curle_ok then
create a_data.put (Void)
l_result := curl_easy.getinfo (curl_handle, {CURL_INFO_CONSTANTS}.curlinfo_response_code, a_data)
if l_result = 0 and then attached {INTEGER} a_data.item as l_http_status then
Result.status := l_http_status
else
Result.status := 0
end
Result.status := response_status_code (curl_easy, curl_handle)
set_header_and_body_to (l_curl_string.string, Result)
else
Result.set_error_occurred (True)
Result.status := response_status_code (curl_easy, curl_handle)
end
curl_easy.cleanup (curl_handle)
end
feature {NONE} -- Implementation
response_status_code (curl_easy: CURL_EASY_EXTERNALS; curl_handle: POINTER): INTEGER
local
l_result: INTEGER
a_data: CELL [detachable ANY]
do
create a_data.put (Void)
l_result := curl_easy.getinfo (curl_handle, {CURL_INFO_CONSTANTS}.curlinfo_response_code, a_data)
if l_result = 0 and then attached {INTEGER} a_data.item as l_http_status then
Result := l_http_status
else
Result := 0
end
end
set_header_and_body_to (a_source: READABLE_STRING_8; res: HTTP_CLIENT_RESPONSE)
-- Parse `a_source' response

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="test_http_client" uuid="920E5C50-41E1-4DAC-8D48-D9C860E49228">
<target name="test_http_client">
<root class="TEST" feature="make"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http_client" location="..\http_client-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location=".\"/>
</target>
</system>

View File

@@ -0,0 +1,50 @@
class TEST
create
make
feature -- Init
make
do
test_http_client
end
test_http_client
-- New test routine
local
sess: LIBCURL_HTTP_CLIENT_SESSION
h: STRING_8
do
create sess.make ("http://www.google.com")
if attached sess.get ("/search?q=eiffel", Void) as res then
assert ("Get returned without error", not res.error_occurred)
create h.make_empty
if attached res.headers as hds then
across
hds as c
loop
h.append (c.item.name + ": " + c.item.value + "%R%N")
end
end
if attached res.body as l_body then
assert ("body not empty", not l_body.is_empty)
end
assert ("same headers", h.same_string (res.raw_header))
else
assert ("Not found", False)
end
end
assert (m: READABLE_STRING_8; b: BOOLEAN)
local
e: DEVELOPER_EXCEPTION
do
if not b then
create e
e.set_message (m)
e.raise
end
end
end

View File

@@ -23,6 +23,7 @@ feature -- Test routines
do
create sess.make ("http://www.google.com")
if attached sess.get ("/search?q=eiffel", Void) as res then
assert ("Get returned without error", not res.error_occurred)
create h.make_empty
if attached res.headers as hds then
across
@@ -32,7 +33,9 @@ feature -- Test routines
end
end
if attached res.body as l_body then
assert ("body not empty", not l_body.is_empty)
else
assert ("missing body", False)
end
assert ("same headers", h.same_string (res.raw_header))
else
@@ -67,20 +70,21 @@ feature -- Test routines
h.append (c.item.name + ": " + c.item.value + "%N")
end
end
assert ("Expected headers map", h.same_string ("[
normal: NORMAL
concat: ABC
concat: DEF
key1: KEY
key2: KEY
key3: KEY
value1: VALUE
value2: VALUE
value3: VALUE
value4: VALUE
foo: BAR
assert ("Expected headers map", h.same_string (
"[
normal: NORMAL
concat: ABC
concat: DEF
key1: KEY
key2: KEY
key3: KEY
value1: VALUE
value2: VALUE
value3: VALUE
value4: VALUE
foo: BAR
]"))
]"))
end
end

View File

@@ -8,6 +8,11 @@ note
deferred class
ERROR
inherit
ANY
DEBUG_OUTPUT
feature -- Access
code: INTEGER
@@ -16,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
@@ -47,6 +52,13 @@ feature -- String representation
end
end
feature -- Status report
debug_output: STRING
do
Result := string_representation.as_string_8
end
feature -- Change
set_parent (a_parent: like parent)
@@ -68,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

View File

@@ -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

View File

@@ -21,7 +21,7 @@ feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
create {ARRAYED_LIST [ERROR]} errors.make (3)
create {ARRAYED_LIST [like errors.item]} errors.make (3)
create error_added_actions
end
@@ -34,6 +34,7 @@ feature -- Status
end
count: INTEGER
-- Number of error
do
Result := errors.count
end
@@ -60,12 +61,140 @@ feature -- Events
error_added_actions: ACTION_SEQUENCE [TUPLE [ERROR]]
-- Actions triggered when a new error is added
feature -- Synchronization
add_synchronization (h: ERROR_HANDLER)
-- Add synchronization between `h' and `Current'
--| the same handler can be added more than once
--| it will be synchronized only once
local
lst: like synchronized_handlers
do
lst := synchronized_handlers
if lst = Void then
create {ARRAYED_LIST [like synchronized_handlers.item]} lst.make (0)
lst.compare_references
synchronized_handlers := lst
end
if lst.has (h) then
check attached h.synchronized_handlers as h_lst and then h_lst.has (Current) end
else
lst.extend (h)
h.add_synchronization (Current)
end
end
remove_synchronization (h: ERROR_HANDLER)
-- Remove synchronization between `h' and `Current'
do
if attached synchronized_handlers as lst and then not lst.is_empty then
synchronized_handlers := Void
lst.prune_all (h)
h.remove_synchronization (Current)
synchronized_handlers := lst
if lst.is_empty then
synchronized_handlers := Void
end
end
end
feature {ERROR_HANDLER} -- Synchronization implementation
synchronized_handlers: detachable LIST [ERROR_HANDLER]
-- Synchronized handlers
synchronize_error_from (e: ERROR; h_lst: LIST [ERROR_HANDLER])
-- Called by error_handler during synchronization process
-- if `synchronized_handlers' is Void, this means Current is synchronizing
-- this is to prevent infinite cycle iteration
require
not h_lst.has (Current)
do
h_lst.extend (Current)
if attached synchronized_handlers as lst then
synchronized_handlers := Void
add_error (e)
across
lst as c
loop
if not h_lst.has (c.item) then
c.item.synchronize_error_from (e, h_lst)
end
end
synchronized_handlers := lst
else
-- In synchronization
end
end
synchronize_reset_from (h_lst: LIST [ERROR_HANDLER])
-- Called by error_handler during synchronization process
-- if `synchronized_handlers' is Void, this means Current is synchronizing
-- this is to prevent infinite cycle iteration
require
not h_lst.has (Current)
do
h_lst.extend (Current)
if attached synchronized_handlers as lst then
synchronized_handlers := Void
reset
across
lst as c
loop
if not h_lst.has (c.item) then
c.item.synchronize_reset_from (h_lst)
end
end
synchronized_handlers := lst
else
-- In synchronization
end
end
feature {NONE} -- Event: implementation
on_error_added (e: ERROR)
-- Error `e' was just added
local
sync_list: LINKED_LIST [ERROR_HANDLER]
do
error_added_actions.call ([e])
if attached synchronized_handlers as lst then
synchronized_handlers := Void
create sync_list.make
sync_list.extend (Current)
across
lst as c
loop
if not sync_list.has (c.item) then
c.item.synchronize_error_from (e, sync_list)
end
end
synchronized_handlers := lst
end
end
on_reset
-- `reset' was just called
local
sync_list: LINKED_LIST [ERROR_HANDLER]
do
if attached synchronized_handlers as lst then
synchronized_handlers := Void
create sync_list.make
sync_list.extend (Current)
across
lst as c
loop
if not sync_list.has (c.item) then
c.item.synchronize_reset_from (sync_list)
end
end
synchronized_handlers := lst
end
end
feature -- Basic operation
@@ -110,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)
@@ -121,6 +251,7 @@ feature -- Access
end
as_string_representation: STRING
-- String representation of all error(s).
require
has_error
do
@@ -138,18 +269,40 @@ feature -- Element changes
-- Concatenate into a single error if any
do
if count > 1 and then attached as_single_error as e then
wipe_out
errors.force (e)
reset
add_error (e)
end
end
reset, wipe_out
reset
-- Reset error handler
do
errors.wipe_out
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
across
lst as c
loop
c.item.remove_synchronization (Current)
end
end
synchronized_handlers := Void
reset
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

View File

@@ -31,7 +31,7 @@ feature -- Access
feature -- Output
output_string (a_str: detachable STRING_GENERAL)
output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string
do
if a_str /= Void then
@@ -50,4 +50,14 @@ feature -- Output
file.put_new_line
end
note
copyright: "2011-2012, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -13,7 +13,7 @@ inherit
feature -- Output
output_string (a_str: detachable STRING_GENERAL)
output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string
deferred
end
@@ -21,7 +21,7 @@ feature -- Output
output_any (obj: detachable ANY)
-- Output Unicode string
do
if attached {STRING_GENERAL} obj as l_str then
if attached {READABLE_STRING_GENERAL} obj as l_str then
to_implement ("Convert into UTF-8 or console encoding before output")
output_string (l_str)
elseif obj /= Void then

View File

@@ -31,7 +31,7 @@ feature -- Access
feature -- Output
output_string (a_str: detachable STRING_GENERAL)
output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string
do
if a_str /= Void then
@@ -50,4 +50,14 @@ feature -- Output
buffer.append_character ('%N')
end
note
copyright: "2011-2012, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,182 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_ERROR
inherit
EQA_TEST_SET
feature -- Test routines
test_error
note
testing: "error"
local
h: ERROR_HANDLER
cl: CELL [INTEGER]
do
create h.make
h.add_custom_error (123, "abc", "abc error occurred")
h.add_custom_error (456, "abc", "abc error occurred")
assert ("has 2 errors", h.count = 2)
h.reset
assert ("reset then no error", h.count = 0)
-- error_added_actions
create cl.put (0)
h.error_added_actions.extend (agent (i_e: ERROR; i_cl: CELL [INTEGER]) do i_cl.replace (i_cl.item + 1) end(?, cl))
h.add_custom_error (123, "abc", "abc error occurred")
h.add_custom_error (456, "abc", "abc error occurred")
assert ("has 2 errors, same as counted", h.count = 2 and h.count = cl.item)
end
test_sync_2
note
testing: "error"
local
h1, h2: ERROR_HANDLER
-- cl: CELL [INTEGER]
do
create h1.make
create h2.make
h1.add_synchronization (h2)
h1.add_custom_error (123, "abc", "abc error occurred")
h1.add_custom_error (456, "abc", "abc error occurred")
assert ("has 2 errors", h1.count = 2 and h2.count = h1.count)
h1.reset
assert ("reset then no error", h1.count = 0 and h2.count = h1.count)
end
test_sync_3
note
testing: "error"
local
h1, h2, h3: ERROR_HANDLER
-- cl: CELL [INTEGER]
do
create h1.make
create h2.make
create h3.make
h1.add_synchronization (h2)
h2.add_synchronization (h3)
h1.add_custom_error (123, "abc", "abc error occurred")
h1.add_custom_error (456, "abc", "abc error occurred")
assert ("has 2 errors", h1.count = 2 and h2.count = h1.count and h3.count = h2.count)
h1.reset
assert ("reset then no error", h1.count = 0 and h2.count = h1.count and h3.count = h2.count)
end
test_sync_3_with_cycle
note
testing: "error"
local
h1, h2, h3: ERROR_HANDLER
-- cl: CELL [INTEGER]
do
create h1.make
create h2.make
create h3.make
h1.add_synchronization (h2)
h2.add_synchronization (h3)
h3.add_synchronization (h1)
h1.add_custom_error (123, "abc", "abc error occurred")
h1.add_custom_error (456, "abc", "abc error occurred")
assert ("has 2 errors", h1.count = 2 and h2.count = h1.count and h3.count = h2.count)
h1.reset
assert ("reset then no error", h1.count = 0 and h2.count = h1.count and h3.count = h2.count)
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_synchronization (h2)
h2.add_synchronization (h3)
h3.add_synchronization (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_synchronization (h3)
h2.remove_synchronization (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_synchronization (h2)
h2.add_synchronization (h3)
h3.add_synchronization (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"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="error_tests" uuid="54F59BB2-AD49-42C7-ABAA-B60765F4F926">
<target name="error_tests">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="error" location="..\error-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location=".\"/>
</target>
</system>

View File

@@ -0,0 +1,21 @@
note
description: "Summary description for {WGI_CHUNKED_INPUT_STREAM}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred
class
WGI_CHUNKED_INPUT_STREAM
note
copyright: "2011-2012, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -25,7 +25,7 @@
<platform value="windows"/>
</condition>
</external_library>
<external_library location="/usr/local/lib/libfcgi.so">
<external_library location="/usr/lib/libfcgi.so">
<condition>
<platform excluded_value="windows"/>
</condition>

View File

@@ -60,6 +60,8 @@ feature -- Element change
set_body (a_body: like body)
do
body := a_body
ensure
body_set: a_body /= Void implies body = a_body
end
put_string (a_string: READABLE_STRING_8)

View File

@@ -29,17 +29,4 @@
</cluster>
</cluster>
</target>
<target name="tests" extends="encoder">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
<assertions precondition="true"/>
</option>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location=".\tests\"/>
</target>
</system>

View File

@@ -29,19 +29,4 @@
</cluster>
</cluster>
</target>
<target name="tests" extends="encoder" >
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true">
<assertions precondition="true"/>
</option>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
<tests name="tests" location="./tests"/>
</target>
</system>

View File

@@ -13,7 +13,7 @@ class
HTML_ENCODER
inherit
ENCODER [STRING_32, STRING_8]
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM
export
@@ -33,7 +33,7 @@ feature -- Status report
feature -- Encoder
encoded_string (s: STRING_32): STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- HTML-encoded value of `s'.
local
i, n: INTEGER
@@ -67,7 +67,7 @@ feature -- Encoder
feature -- Decoder
decoded_string (v: STRING_8): STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The HTML-encoded equivalent of the given string
local
i, n: INTEGER
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end
note
copyright: "2011-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

View File

@@ -12,7 +12,7 @@ class
JSON_ENCODER
inherit
ENCODER [STRING_32, STRING_8]
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM
export
@@ -32,7 +32,7 @@ feature -- Status report
feature -- Encoder
encoded_string (s: STRING_32): STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- JSON-encoded value of `s'.
local
i, j, n: INTEGER
@@ -82,7 +82,7 @@ feature -- Encoder
feature -- Decoder
decoded_string (v: STRING_8): STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The JSON-encoded equivalent of the given string
local
i, n: INTEGER

View File

@@ -33,17 +33,15 @@ feature -- Status report
feature -- Encoder
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- URL-encoded value of `s'.
local
i, n: INTEGER
uc: CHARACTER_32
c: CHARACTER_8
s8: STRING_8
do
has_error := False
create s8.make (s.count + s.count // 10)
Result := s8
create Result.make (s.count + s.count // 10)
n := s.count
from i := 1 until i > n loop
uc := s.item (i)
@@ -55,14 +53,14 @@ feature -- Encoder
'a' .. 'z', '0' .. '9',
'.', '-', '~', '_'
then
s8.extend (c)
Result.extend (c)
when ' ' then
s8.extend ('+')
Result.extend ('+')
else
s8.append (url_encoded_char (uc))
Result.append (url_encoded_char (uc))
end
else
s8.append (url_encoded_char (uc))
Result.append (url_encoded_char (uc))
end
i := i + 1
end
@@ -134,19 +132,17 @@ feature {NONE} -- encoder character
feature -- Decoder
decoded_string (v: READABLE_STRING_8): READABLE_STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The URL-encoded equivalent of the given string
local
i, n: INTEGER
c: CHARACTER
pr: CELL [INTEGER]
s32: STRING_32
changed: BOOLEAN
do
has_error := False
n := v.count
create s32.make (n)
Result := s32
create Result.make (n)
from i := 1
until i > n
loop
@@ -154,19 +150,19 @@ feature -- Decoder
inspect c
when '+' then
changed := True
s32.append_character ({CHARACTER_32}' ')
Result.append_character ({CHARACTER_32}' ')
when '%%' then
-- An escaped character ?
if i = n then
s32.append_character (c.to_character_32)
Result.append_character (c.to_character_32)
else
changed := True
create pr.put (i)
s32.append (url_decoded_char (v, pr))
Result.append (url_decoded_char (v, pr))
i := pr.item
end
else
s32.append_character (c.to_character_32)
Result.append_character (c.to_character_32)
end
i := i + 1
end
@@ -367,7 +363,7 @@ feature {NONE} -- Hexadecimal and strings
end
note
copyright: "2011-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

View File

@@ -13,7 +13,7 @@ class
UTF8_ENCODER
inherit
ENCODER [STRING_32, STRING_8]
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
UTF8_ENCODER_HELPER
@@ -35,7 +35,7 @@ feature -- Status report
feature -- Encoder
encoded_string (s: STRING_32): STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- UTF8-encoded value of `s'.
do
Result := utf32_to_utf8 (s)
@@ -44,7 +44,7 @@ feature -- Encoder
feature -- Decoder
decoded_string (v: STRING_8): STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The UTF8-encoded equivalent of the given string
do
Result := utf8_to_utf32 (v)
@@ -52,7 +52,7 @@ feature -- Decoder
end
note
copyright: "2011-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

View File

@@ -42,7 +42,7 @@ feature -- Access
feature -- Encoder
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- URL-encoded value of `s'.
do
Result := Precursor (s)
@@ -64,7 +64,7 @@ feature -- Encoder
feature -- Decoder
decoded_string (v: READABLE_STRING_8): READABLE_STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The URL-encoded equivalent of the given string
do
Result := Precursor (v)
@@ -77,7 +77,7 @@ feature -- Decoder
end
note
copyright: "2011-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

View File

@@ -13,7 +13,7 @@ class
XML_ENCODER
inherit
ENCODER [STRING_32, STRING_8]
ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM
export
@@ -33,7 +33,7 @@ feature -- Status report
feature -- Encoder
encoded_string (s: STRING_32): STRING_8
encoded_string (s: READABLE_STRING_32): STRING_8
-- XML-encoded value of `s'.
local
i, n: INTEGER
@@ -67,7 +67,7 @@ feature -- Encoder
feature -- Decoder
decoded_string (v: STRING_8): STRING_32
decoded_string (v: READABLE_STRING_8): STRING_32
-- The XML-encoded equivalent of the given string
local
i, n: INTEGER
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end
note
copyright: "2011-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

View File

@@ -20,6 +20,7 @@ feature -- Test routines
testing: "json-encoded"
do
test_json_encoded_encoding ({STRING_32}"il était une fois %"Ni & Hao%" (你好) \a\b\c")
test_json_encoded_encoding ({STRING_32}" it's `abc ")
end
test_json_encoded_encoding (s: STRING_32)

View File

@@ -19,10 +19,11 @@ feature -- Test routines
note
testing: "url-encoded"
do
test_url_encoded_encoding ("http://domain.tld/foo/bar/script.php?test='toto'&foo=bar&title=il <20>tait une fois")
test_url_encoded_encoding ("<22>t<EFBFBD>")
test_url_encoded_decoding ("%%E9t%%E9", "<22>t<EFBFBD>")
test_url_encoded_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
test_url_encoded_encoding ({STRING_32}"http://domain.tld/foo/bar/script.php?test='toto'&foo=bar&title=il <20>tait une fois")
test_url_encoded_encoding ({STRING_32}"<22>t<EFBFBD>")
test_url_encoded_decoding ({STRING_8}"%%E9t%%E9", {STRING_32}"<22>t<EFBFBD>")
test_utf8_url_encoded_decoding ({STRING_8}"%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
end
test_url_encoded_encoding (s: STRING_32)
@@ -47,6 +48,16 @@ feature -- Test routines
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
end
test_utf8_url_encoded_decoding (s: STRING_8; e: STRING_32)
local
u: STRING_32
b: UTF8_URL_ENCODER
do
create b
u := b.decoded_string (s)
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
end
note
copyright: "2011-2011, Eiffel Software and others"

View File

@@ -19,8 +19,7 @@ feature -- Test routines
note
testing: "url-encoded"
do
-- test_utf8_decoding ("summer=<3D>t<EFBFBD>&weird=<3D>", "summer=<3D>t<EFBFBD>&weird=<EFBFBD>")
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
test_utf8_decoding ("%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
end
test_utf8_decoding (s: STRING_8; e: STRING_32)

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-9-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-9-0 http://www.eiffel.com/developers/xml/configuration-1-9-0.xsd" name="encoder_tests" uuid="C6F56AE3-8E9C-4568-85CA-CA5F1EF15DCE">
<target name="encoder_tests">
<root class="ANY" feature="default_create"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="encoder" location="../encoder-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<tests name="tests" location="."/>
</target>
</system>