-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decode: [WIP] Provide tests for most use cases
- Loading branch information
Showing
2 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* This file is part of Valum. | ||
* | ||
* Valum is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* Valum is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Valum. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using Valum; | ||
using VSGI.Mock; | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_gzip () { | ||
var req = new Request.with_method ("POST", new Soup.URI ("http://127.0.0.1/")); | ||
var res = new Response (req); | ||
|
||
req.headers.append ("Content-Encoding", "gzip"); | ||
|
||
assert ("gzip" == req.headers.get_list ("Content-Encoding")); | ||
|
||
try { | ||
decode () (req, res, () => { | ||
assert ("" == req.headers.get_list ("Content-Encoding")); | ||
return true; | ||
}, new Context ()); | ||
} catch (Error err) { | ||
assert_not_reached (); | ||
} | ||
} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_deflate () { | ||
var req = new Request.with_method ("POST", new Soup.URI ("http://127.0.0.1/")); | ||
var res = new Response (req); | ||
|
||
req.headers.append ("Content-Encoding", "deflate"); | ||
|
||
assert ("deflate" == req.headers.get_list ("Content-Encoding")); | ||
|
||
try { | ||
decode () (req, res, () => { | ||
assert ("" == req.headers.get_list ("Content-Encoding")); | ||
return true; | ||
}, new Context ()); | ||
} catch (Error err) { | ||
assert_not_reached (); | ||
} | ||
} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_identity () { | ||
var req = new Request.with_method ("POST", new Soup.URI ("http://127.0.0.1/")); | ||
var res = new Response (req); | ||
|
||
req.headers.append ("Content-Encoding", "identity"); | ||
|
||
assert ("deflate" == req.headers.get_list ("Content-Encoding")); | ||
|
||
try { | ||
decode () (req, res, () => { | ||
assert ("identity" == req.headers.get_list ("Content-Encoding")); | ||
return true; | ||
}, new Context ()); | ||
} catch (Error err) { | ||
assert_not_reached (); | ||
} | ||
} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_unknown_encoding () { | ||
var req = new Request.with_method ("POST", new Soup.URI ("http://127.0.0.1/")); | ||
var res = new Response (req); | ||
|
||
try { | ||
decode () (req, res, () => { | ||
assert_not_reached (); | ||
}, new Context ()); | ||
assert_not_reached (); | ||
} catch (ServerError.NOT_IMPLEMENTED err) { | ||
|
||
} catch (Error err) { | ||
assert_not_reached (); | ||
} | ||
} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_forward_remaining_encodings () { | ||
var req = new Request.with_method ("POST", new Soup.URI ("http://127.0.0.1/")); | ||
var res = new Response (req); | ||
|
||
req.headers.append ("Content-Encoding", "gzip, brotli, deflate"); // brotli is not handled | ||
|
||
try { | ||
decode (DecodeFlags.FORWARD_REMAINING_ENCODINGS) (req, res, () => { | ||
assert ("gzip brotli" == req.headers.get_list ("Content-Encoding")); | ||
return true; | ||
}, new Context ()); | ||
} catch (Error err) { | ||
assert_not_reached (); | ||
} | ||
} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void tset_decode_charset () {} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void tset_decode_charset_fallback_charset () {} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_charset_ignore_non_text () {} | ||
|
||
/** | ||
* @since 0.3 | ||
*/ | ||
public void test_decode_charset_unknown_charset () {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters