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 class
REST_RESPONSE 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 create
make make
@@ -15,12 +26,7 @@ feature {NONE} -- Initialization
make (a_api: like api) make (a_api: like api)
do do
api := a_api api := a_api
initialize page_make
end
initialize
do
create headers.make
end end
feature -- Recycle feature -- Recycle
@@ -28,123 +34,17 @@ feature -- Recycle
recycle recycle
do do
headers.recycle headers.recycle
message := Void
end end
feature -- Access feature -- Access
headers: HTTP_HEADER
api: STRING api: STRING
-- Associated api query string. -- Associated api query string.
message: detachable STRING_8 invariant
-- Associated message to send with the response. note
copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
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"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software 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 warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
</option> </option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/> <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"> <library name="curl" location="$ISE_LIBRARY\library\cURL\cURL-safe.ecf">
<condition> <condition>
<version type="compiler" min="7.0.8.7340"/> <version type="compiler" min="7.0.8.7340"/>
@@ -23,17 +24,4 @@
<library name="encoder" location="..\..\text\encoder\encoder-safe.ecf"/> <library name="encoder" location="..\..\text\encoder\encoder-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/> <cluster name="src" location=".\src\" recursive="true"/>
</target> </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> </system>

View File

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

View File

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

View File

@@ -24,6 +24,15 @@ feature {NONE} -- Initialization
do do
make_request (a_url, a_session, ctx) make_request (a_url, a_session, ctx)
request_method := a_request_method 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 end
session: LIBCURL_HTTP_CLIENT_SESSION session: LIBCURL_HTTP_CLIENT_SESSION
@@ -40,7 +49,6 @@ feature -- Execution
l_curl_string: CURL_STRING l_curl_string: CURL_STRING
l_url: READABLE_STRING_8 l_url: READABLE_STRING_8
p: POINTER p: POINTER
a_data: CELL [detachable ANY]
l_form, l_last: CURL_FORM l_form, l_last: CURL_FORM
curl: CURL_EXTERNALS curl: CURL_EXTERNALS
curl_easy: CURL_EASY_EXTERNALS curl_easy: CURL_EASY_EXTERNALS
@@ -194,22 +202,32 @@ feature -- Execution
l_result := curl_easy.perform (curl_handle) l_result := curl_easy.perform (curl_handle)
if l_result = {CURL_CODES}.curle_ok then if l_result = {CURL_CODES}.curle_ok then
create a_data.put (Void) Result.status := response_status_code (curl_easy, curl_handle)
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
set_header_and_body_to (l_curl_string.string, Result) set_header_and_body_to (l_curl_string.string, Result)
else else
Result.set_error_occurred (True) Result.set_error_occurred (True)
Result.status := response_status_code (curl_easy, curl_handle)
end end
curl_easy.cleanup (curl_handle) curl_easy.cleanup (curl_handle)
end 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) set_header_and_body_to (a_source: READABLE_STRING_8; res: HTTP_CLIENT_RESPONSE)
-- Parse `a_source' 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 do
create sess.make ("http://www.google.com") create sess.make ("http://www.google.com")
if attached sess.get ("/search?q=eiffel", Void) as res then if attached sess.get ("/search?q=eiffel", Void) as res then
assert ("Get returned without error", not res.error_occurred)
create h.make_empty create h.make_empty
if attached res.headers as hds then if attached res.headers as hds then
across across
@@ -32,7 +33,9 @@ feature -- Test routines
end end
end end
if attached res.body as l_body then if attached res.body as l_body then
assert ("body not empty", not l_body.is_empty)
else
assert ("missing body", False)
end end
assert ("same headers", h.same_string (res.raw_header)) assert ("same headers", h.same_string (res.raw_header))
else else
@@ -67,20 +70,21 @@ feature -- Test routines
h.append (c.item.name + ": " + c.item.value + "%N") h.append (c.item.name + ": " + c.item.value + "%N")
end end
end end
assert ("Expected headers map", h.same_string ("[ assert ("Expected headers map", h.same_string (
normal: NORMAL "[
concat: ABC normal: NORMAL
concat: DEF concat: ABC
key1: KEY concat: DEF
key2: KEY key1: KEY
key3: KEY key2: KEY
value1: VALUE key3: KEY
value2: VALUE value1: VALUE
value3: VALUE value2: VALUE
value4: VALUE value3: VALUE
foo: BAR value4: VALUE
foo: BAR
]")) ]"))
end end
end end

View File

@@ -8,6 +8,11 @@ note
deferred class deferred class
ERROR ERROR
inherit
ANY
DEBUG_OUTPUT
feature -- Access feature -- Access
code: INTEGER code: INTEGER
@@ -16,13 +21,13 @@ feature -- Access
result_not_zero: Result /= 0 result_not_zero: Result /= 0
end end
name: STRING name: READABLE_STRING_8
deferred deferred
ensure ensure
result_attached: Result /= Void result_attached: Result /= Void
end end
message: detachable STRING_32 message: detachable READABLE_STRING_32
-- Potential error message -- Potential error message
deferred deferred
end end
@@ -47,6 +52,13 @@ feature -- String representation
end end
end end
feature -- Status report
debug_output: STRING
do
Result := string_representation.as_string_8
end
feature -- Change feature -- Change
set_parent (a_parent: like parent) set_parent (a_parent: like parent)
@@ -68,7 +80,7 @@ invariant
name_attached: name /= Void name_attached: name /= Void
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -16,12 +16,12 @@ create
feature {NONE} -- Initialization 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'. -- Initialize `Current'.
do do
code := a_code code := a_code
name := a_name name := a_name
if attached a_message then if a_message /= Void then
message := a_message message := a_message
else else
message := "Error: " + a_name + " (code=" + a_code.out + ")" message := "Error: " + a_name + " (code=" + a_code.out + ")"
@@ -32,9 +32,9 @@ feature -- Access
code: INTEGER code: INTEGER
name: STRING name: READABLE_STRING_8
message: STRING_32 message: detachable READABLE_STRING_32
feature -- Visitor feature -- Visitor
@@ -45,7 +45,7 @@ feature -- Visitor
end end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -21,7 +21,7 @@ feature {NONE} -- Initialization
make make
-- Initialize `Current'. -- Initialize `Current'.
do do
create {ARRAYED_LIST [ERROR]} errors.make (3) create {ARRAYED_LIST [like errors.item]} errors.make (3)
create error_added_actions create error_added_actions
end end
@@ -34,6 +34,7 @@ feature -- Status
end end
count: INTEGER count: INTEGER
-- Number of error
do do
Result := errors.count Result := errors.count
end end
@@ -60,12 +61,140 @@ feature -- Events
error_added_actions: ACTION_SEQUENCE [TUPLE [ERROR]] error_added_actions: ACTION_SEQUENCE [TUPLE [ERROR]]
-- Actions triggered when a new error is added -- 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 feature {NONE} -- Event: implementation
on_error_added (e: ERROR) on_error_added (e: ERROR)
-- Error `e' was just added -- Error `e' was just added
local
sync_list: LINKED_LIST [ERROR_HANDLER]
do do
error_added_actions.call ([e]) 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 end
feature -- Basic operation feature -- Basic operation
@@ -110,6 +239,7 @@ feature -- Basic operation
feature -- Access feature -- Access
as_single_error: detachable ERROR as_single_error: detachable ERROR
-- All error(s) concatenated into one single error.
do do
if count > 1 then if count > 1 then
create {ERROR_GROUP} Result.make (errors) create {ERROR_GROUP} Result.make (errors)
@@ -121,6 +251,7 @@ feature -- Access
end end
as_string_representation: STRING as_string_representation: STRING
-- String representation of all error(s).
require require
has_error has_error
do do
@@ -138,18 +269,40 @@ feature -- Element changes
-- Concatenate into a single error if any -- Concatenate into a single error if any
do do
if count > 1 and then attached as_single_error as e then if count > 1 and then attached as_single_error as e then
wipe_out reset
errors.force (e) add_error (e)
end end
end end
reset, wipe_out reset
-- Reset error handler
do 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 end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -31,7 +31,7 @@ feature -- Access
feature -- Output feature -- Output
output_string (a_str: detachable STRING_GENERAL) output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string -- Output Unicode string
do do
if a_str /= Void then if a_str /= Void then
@@ -50,4 +50,14 @@ feature -- Output
file.put_new_line file.put_new_line
end 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 end

View File

@@ -13,7 +13,7 @@ inherit
feature -- Output feature -- Output
output_string (a_str: detachable STRING_GENERAL) output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string -- Output Unicode string
deferred deferred
end end
@@ -21,7 +21,7 @@ feature -- Output
output_any (obj: detachable ANY) output_any (obj: detachable ANY)
-- Output Unicode string -- Output Unicode string
do 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") to_implement ("Convert into UTF-8 or console encoding before output")
output_string (l_str) output_string (l_str)
elseif obj /= Void then elseif obj /= Void then

View File

@@ -31,7 +31,7 @@ feature -- Access
feature -- Output feature -- Output
output_string (a_str: detachable STRING_GENERAL) output_string (a_str: detachable READABLE_STRING_GENERAL)
-- Output Unicode string -- Output Unicode string
do do
if a_str /= Void then if a_str /= Void then
@@ -50,4 +50,14 @@ feature -- Output
buffer.append_character ('%N') buffer.append_character ('%N')
end 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 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"/> <platform value="windows"/>
</condition> </condition>
</external_library> </external_library>
<external_library location="/usr/local/lib/libfcgi.so"> <external_library location="/usr/lib/libfcgi.so">
<condition> <condition>
<platform excluded_value="windows"/> <platform excluded_value="windows"/>
</condition> </condition>

View File

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

View File

@@ -29,17 +29,4 @@
</cluster> </cluster>
</cluster> </cluster>
</target> </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> </system>

View File

@@ -29,19 +29,4 @@
</cluster> </cluster>
</cluster> </cluster>
</target> </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> </system>

View File

@@ -13,7 +13,7 @@ class
HTML_ENCODER HTML_ENCODER
inherit inherit
ENCODER [STRING_32, STRING_8] ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM PLATFORM
export export
@@ -33,7 +33,7 @@ feature -- Status report
feature -- Encoder feature -- Encoder
encoded_string (s: STRING_32): STRING_8 encoded_string (s: READABLE_STRING_32): STRING_8
-- HTML-encoded value of `s'. -- HTML-encoded value of `s'.
local local
i, n: INTEGER i, n: INTEGER
@@ -67,7 +67,7 @@ feature -- Encoder
feature -- Decoder 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 -- The HTML-encoded equivalent of the given string
local local
i, n: INTEGER i, n: INTEGER
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -1,7 +1,7 @@
note note
description: "[ description: "[
Summary description for {JSON_ENCODER}. Summary description for {JSON_ENCODER}.
]" ]"
legal: "See notice at end of class." legal: "See notice at end of class."
status: "See notice at end of class." status: "See notice at end of class."
@@ -12,7 +12,7 @@ class
JSON_ENCODER JSON_ENCODER
inherit inherit
ENCODER [STRING_32, STRING_8] ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM PLATFORM
export export
@@ -32,7 +32,7 @@ feature -- Status report
feature -- Encoder feature -- Encoder
encoded_string (s: STRING_32): STRING_8 encoded_string (s: READABLE_STRING_32): STRING_8
-- JSON-encoded value of `s'. -- JSON-encoded value of `s'.
local local
i, j, n: INTEGER i, j, n: INTEGER
@@ -82,7 +82,7 @@ feature -- Encoder
feature -- Decoder 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 -- The JSON-encoded equivalent of the given string
local local
i, n: INTEGER i, n: INTEGER

View File

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

View File

@@ -13,7 +13,7 @@ class
UTF8_ENCODER UTF8_ENCODER
inherit inherit
ENCODER [STRING_32, STRING_8] ENCODER [READABLE_STRING_32, READABLE_STRING_8]
UTF8_ENCODER_HELPER UTF8_ENCODER_HELPER
@@ -35,7 +35,7 @@ feature -- Status report
feature -- Encoder feature -- Encoder
encoded_string (s: STRING_32): STRING_8 encoded_string (s: READABLE_STRING_32): STRING_8
-- UTF8-encoded value of `s'. -- UTF8-encoded value of `s'.
do do
Result := utf32_to_utf8 (s) Result := utf32_to_utf8 (s)
@@ -44,7 +44,7 @@ feature -- Encoder
feature -- Decoder 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 -- The UTF8-encoded equivalent of the given string
do do
Result := utf8_to_utf32 (v) Result := utf8_to_utf32 (v)
@@ -52,7 +52,7 @@ feature -- Decoder
end end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -42,7 +42,7 @@ feature -- Access
feature -- Encoder feature -- Encoder
encoded_string (s: READABLE_STRING_32): READABLE_STRING_8 encoded_string (s: READABLE_STRING_32): STRING_8
-- URL-encoded value of `s'. -- URL-encoded value of `s'.
do do
Result := Precursor (s) Result := Precursor (s)
@@ -64,7 +64,7 @@ feature -- Encoder
feature -- Decoder 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 -- The URL-encoded equivalent of the given string
do do
Result := Precursor (v) Result := Precursor (v)
@@ -77,7 +77,7 @@ feature -- Decoder
end end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -13,7 +13,7 @@ class
XML_ENCODER XML_ENCODER
inherit inherit
ENCODER [STRING_32, STRING_8] ENCODER [READABLE_STRING_32, READABLE_STRING_8]
PLATFORM PLATFORM
export export
@@ -33,7 +33,7 @@ feature -- Status report
feature -- Encoder feature -- Encoder
encoded_string (s: STRING_32): STRING_8 encoded_string (s: READABLE_STRING_32): STRING_8
-- XML-encoded value of `s'. -- XML-encoded value of `s'.
local local
i, n: INTEGER i, n: INTEGER
@@ -67,7 +67,7 @@ feature -- Encoder
feature -- Decoder 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 -- The XML-encoded equivalent of the given string
local local
i, n: INTEGER i, n: INTEGER
@@ -259,7 +259,7 @@ feature {NONE} -- Implementation: decoder
end end
note 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)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software

View File

@@ -20,6 +20,7 @@ feature -- Test routines
testing: "json-encoded" testing: "json-encoded"
do do
test_json_encoded_encoding ({STRING_32}"il était une fois %"Ni & Hao%" (你好) \a\b\c") 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 end
test_json_encoded_encoding (s: STRING_32) test_json_encoded_encoding (s: STRING_32)

View File

@@ -19,10 +19,11 @@ feature -- Test routines
note note
testing: "url-encoded" testing: "url-encoded"
do 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 ({STRING_32}"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_encoding ({STRING_32}"<22>t<EFBFBD>")
test_url_encoded_decoding ("%%E9t%%E9", "<22>t<EFBFBD>") test_url_encoded_decoding ({STRING_8}"%%E9t%%E9", {STRING_32}"<22>t<EFBFBD>")
test_url_encoded_decoding ("%%C3%%A9t%%C3%%A9", "<22>t<EFBFBD>")
test_utf8_url_encoded_decoding ({STRING_8}"%%C3%%A9t%%C3%%A9", {STRING_32}"<22>t<EFBFBD>")
end end
test_url_encoded_encoding (s: STRING_32) test_url_encoded_encoding (s: STRING_32)
@@ -47,6 +48,16 @@ feature -- Test routines
assert ("decoded encoded string is same for %"" + s + "%"", u ~ e) assert ("decoded encoded string is same for %"" + s + "%"", u ~ e)
end 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 note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"

View File

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