Enabled assertion on content_negotiation during autotests

The tests project is now void-safe

Using force instead of put_left seems to work fine
  and is better for performance,
  and no need to check for precondition "not before"
This commit is contained in:
2013-10-14 18:54:36 +02:00
parent 0f7dca0701
commit 3072ce7dec
6 changed files with 55 additions and 37 deletions

View File

@@ -34,7 +34,7 @@ feature -- Initialization
set_charset_default (a_charset)
set_encoding_default (a_encoding)
ensure
mime_default_set: mime = a_mime
mime_default_set: mime_default = a_mime
language_default_set: language_default = a_language
charset_default_set: charset_default = a_charset
encoding_default_set: encoding_default = a_encoding

View File

@@ -1,7 +1,7 @@
note
description: "[
COMMON_ACCEPT_HEADER_PARSER, this class allows to parse Accept-Charset and Accept-Encoding headers
]"
date: "$Date$"
revision: "$Revision$"
@@ -52,7 +52,7 @@ feature -- Parser
Result.set_field (trim (l_header))
end
fitness_and_quality_parsed (a_field: READABLE_STRING_8; parsed_charsets: LIST [COMMON_RESULTS]): FITNESS_AND_QUALITY
fitness_and_quality_parsed (a_field: READABLE_STRING_8; a_parsed_charsets: LIST [COMMON_RESULTS]): FITNESS_AND_QUALITY
-- Find the best match for a given charset/encoding against a list of charsets/encodings
-- that have already been parsed by parse_common. Returns a
-- tuple of the fitness value and the value of the 'q' quality parameter of
@@ -82,11 +82,11 @@ feature -- Parser
end
if attached target.field as l_target_field then
from
parsed_charsets.start
a_parsed_charsets.start
until
parsed_charsets.after
a_parsed_charsets.after
loop
range := parsed_charsets.item_for_iteration
range := a_parsed_charsets.item_for_iteration
if attached range.field as l_range_common then
if l_target_field.same_string (l_range_common) or l_target_field.same_string ("*") or l_range_common.same_string ("*") then
if l_range_common.same_string (l_target_field) then
@@ -105,7 +105,7 @@ feature -- Parser
end
end
end
parsed_charsets.forth
a_parsed_charsets.forth
end
end
create Result.make (best_fitness, best_fit_q)
@@ -130,13 +130,13 @@ feature -- Parser
do
l_commons := commons.split (',')
from
create res.make (10);
create res.make (10)
l_commons.start
until
l_commons.after
loop
p_res := parse_common (l_commons.item_for_iteration)
res.put_left (p_res)
res.force (p_res)
l_commons.forth
end
Result := quality_parsed (a_field, res)

View File

@@ -193,7 +193,7 @@ feature -- Parser
l_ranges.after
loop
p_res := parse_language_range (l_ranges.item_for_iteration)
res.put_left (p_res)
res.force (p_res)
l_ranges.forth
end
Result := quality_parsed (a_language, res)

View File

@@ -189,7 +189,7 @@ feature -- Parser
l_ranges.after
loop
p_res := parse_media_range (l_ranges.item_for_iteration)
res.put_left (p_res)
res.force (p_res)
l_ranges.forth
end
Result := quality_parsed (a_mime_type, res)

View File

@@ -33,8 +33,12 @@ feature -- Test routines
mime_types_supported := l_types.split(',')
media_variants := conneg.media_type_preference (mime_types_supported, "text/html")
assert ("Expected Not Acceptable", not media_variants.is_acceptable)
assert ("Same Value at 1",mime_types_supported.at (1).is_equal (media_variants.supported_variants.at (1)))
assert ("Same count",mime_types_supported.count = media_variants.supported_variants.count)
if attached media_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",mime_types_supported.first.same_string (l_supported_variants.first))
assert ("Same count",mime_types_supported.count = l_supported_variants.count)
else
assert ("Has supported_variants results", False)
end
assert ("Variant header is void",media_variants.variant_header = Void)
assert ("Media type is void",media_variants.type = Void)
@@ -42,15 +46,15 @@ feature -- Test routines
media_variants := conneg.media_type_preference (mime_types_supported, "")
assert ("Expected Acceptable", media_variants.is_acceptable)
assert ("Variants is dettached",media_variants.supported_variants = Void)
assert ("Mime is defaul", conneg.mime_default.is_equal (media_variants.type))
assert ("Mime is default", attached media_variants.type as l_type and then conneg.mime_default.is_equal (l_type))
assert ("Variant header", media_variants.variant_header = Void)
--Scenario 3, the server select the best match, and set the vary header
media_variants := conneg.media_type_preference (mime_types_supported, "text/*,application/json;q=0.5")
assert ("Expected Acceptable", media_variants.is_acceptable)
assert ("Variants is dettached",media_variants.supported_variants = Void)
assert ("Variant Header", media_variants.variant_header.is_equal ("Accept"))
assert ("Media Type is application/json", media_variants.type.is_equal ("application/json"))
assert ("Variant Header", attached media_variants.variant_header as l_variant_header and then l_variant_header.same_string ("Accept"))
assert ("Media Type is application/json", attached media_variants.type as l_type and then l_type.same_string ("application/json"))
end
@@ -67,8 +71,12 @@ feature -- Test routines
charset_supported := l_charset.split(',')
charset_variants := conneg.charset_preference (charset_supported, "unicode-1-1")
assert ("Expected Not Acceptable", not charset_variants.is_acceptable)
assert ("Same Value at 1",charset_supported.at (1).is_equal (charset_variants.supported_variants.at (1)))
assert ("Same count",charset_supported.count = charset_variants.supported_variants.count)
if attached charset_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",charset_supported.first.same_string (l_supported_variants.first))
assert ("Same count",charset_supported.count = l_supported_variants.count)
else
assert("Has supported_variants results", False)
end
assert ("Variant header is void",charset_variants.variant_header = Void)
assert ("Character type is void",charset_variants.type = Void)
@@ -77,7 +85,7 @@ feature -- Test routines
charset_variants := conneg.charset_preference (charset_supported, "")
assert ("Expected Acceptable", charset_variants.is_acceptable)
assert ("Variants is dettached",charset_variants.supported_variants = Void)
assert ("Charset is defaul", conneg.charset_default.is_equal (charset_variants.type))
assert ("Charset is defaul", attached charset_variants.type as l_type and then conneg.charset_default.is_equal (l_type))
assert ("Variant header", charset_variants.variant_header = Void)
@@ -85,8 +93,8 @@ feature -- Test routines
charset_variants := conneg.charset_preference (charset_supported, "unicode-1-1, UTF-8;q=0.3, iso-8859-5")
assert ("Expected Acceptable", charset_variants.is_acceptable)
assert ("Variants is dettached",charset_variants.supported_variants = Void)
assert ("Variant Header", charset_variants.variant_header.is_equal ("Accept-Charset"))
assert ("Character Type is iso-8859-5", charset_variants.type.is_equal ("iso-8859-5"))
assert ("Variant Header", attached charset_variants.variant_header as l_variant_header and then l_variant_header.same_string ("Accept-Charset"))
assert ("Character Type is iso-8859-5", attached charset_variants.type as l_type and then l_type.same_string ("iso-8859-5"))
end
test_compression_negotiation
@@ -100,8 +108,12 @@ feature -- Test routines
compression_supported := l_compression.split(',')
compression_variants := conneg.encoding_preference (compression_supported, "gzip")
assert ("Expected Not Acceptable", not compression_variants.is_acceptable)
assert ("Same Value at 1",compression_supported.at (1).is_equal (compression_variants.supported_variants.at (1)))
assert ("Same count",compression_supported.count = compression_variants.supported_variants.count)
if attached compression_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1",compression_supported.at (1).is_equal (l_supported_variants.first))
assert ("Same count",compression_supported.count = l_supported_variants.count)
else
assert ("Has supported_variants results", False)
end
assert ("Variant header is void",compression_variants.variant_header = Void)
assert ("Compression type is void",compression_variants.type = Void)
@@ -110,7 +122,7 @@ feature -- Test routines
compression_variants := conneg.encoding_preference (compression_supported, "")
assert ("Expected Acceptable", compression_variants.is_acceptable)
assert ("Variants is dettached",compression_variants.supported_variants = Void)
assert ("Compression is defaul", conneg.encoding_default.is_equal (compression_variants.type))
assert ("Compression is defaul", attached compression_variants.type as l_type and then conneg.encoding_default.same_string (l_type))
assert ("Variant header", compression_variants.variant_header = Void)
@@ -121,8 +133,8 @@ feature -- Test routines
compression_variants := conneg.encoding_preference (compression_supported, "compress,gzip;q=0.7")
assert ("Expected Acceptable", compression_variants.is_acceptable)
assert ("Variants is dettached",compression_variants.supported_variants = Void)
assert ("Variant Header", compression_variants.variant_header.is_equal ("Accept-Encoding"))
assert ("Encoding Type is gzip", compression_variants.type.is_equal ("gzip"))
assert ("Variant Header", attached compression_variants.variant_header as l_variant_header and then l_variant_header.same_string ("Accept-Encoding"))
assert ("Encoding Type is gzip", attached compression_variants.type as l_type and then l_type.same_string ("gzip"))
end
@@ -138,17 +150,21 @@ feature -- Test routines
languages_supported := l_languages.split(',')
language_variants := conneg.language_preference (languages_supported, "de")
assert ("Expected Not Acceptable", not language_variants.is_acceptable)
assert ("Same Value at 1",languages_supported.at (1).is_equal (language_variants.supported_variants.at (1)))
assert ("Same count",languages_supported.count = language_variants.supported_variants.count)
assert ("Variant header is void",language_variants.variant_header = Void)
assert ("Language type is void",language_variants.type = Void)
if attached language_variants.supported_variants as l_supported_variants then
assert ("Same Value at 1", languages_supported.first.same_string (l_supported_variants.first))
assert ("Same count",languages_supported.count = l_supported_variants.count)
else
assert ("Has supported variants results", False)
end
-- Scenario 2, the client doesnt send values in the header, Accept-Language:
language_variants := conneg.language_preference (languages_supported, "")
assert ("Expected Acceptable", language_variants.is_acceptable)
assert ("Variants is dettached",language_variants.supported_variants = Void)
assert ("Language is defaul", conneg.language_default.is_equal (language_variants.type))
assert ("Language is default", attached language_variants.type as l_type and then conneg.language_default.same_string (l_type))
assert ("Variant header", language_variants.variant_header = Void)
@@ -156,10 +172,8 @@ feature -- Test routines
language_variants := conneg.language_preference (languages_supported, "fr,es;q=0.4")
assert ("Expected Acceptable", language_variants.is_acceptable)
assert ("Variants is dettached",language_variants.supported_variants = Void)
assert ("Variant Header", language_variants.variant_header.is_equal ("Accept-Language"))
assert ("Language Type is fr", language_variants.type.is_equal ("fr"))
assert ("Variant Header", attached language_variants.variant_header as l_variant_header and then l_variant_header.same_string ("Accept-Language"))
assert ("Language Type is fr", attached language_variants.type as l_type and then l_type.same_string ("fr"))
end
feature -- Implementation

View File

@@ -1,19 +1,23 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-6-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-6-0 http://www.eiffel.com/developers/xml/configuration-1-6-0.xsd" name="test" uuid="7860561C-779A-4E45-A7B9-06A1E0E984E8">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="test" uuid="7860561C-779A-4E45-A7B9-06A1E0E984E8">
<target name="test">
<root class="APPLICATION" feature="make"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
<exclude>/.git$</exclude>
</file_rule>
<option warning="true">
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="conneg" location="..\conneg-safe.ecf" readonly="false">
<option>
<assertions precondition="true" postcondition="true" check="true" invariant="true" supplier_precondition="true"/>
</option>
</library>
<library name="http" location="..\..\http\http-safe.ecf" readonly="false"/>
<library name="conneg" location="..\conneg-safe.ecf"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<cluster name="test" location=".\" recursive="true"/>
</target>