Add more tests for decoding and encoding URL functions
This commit is contained in:
parent
eefee8125b
commit
5d76036af5
@ -69,6 +69,7 @@ namespace Exiv2
|
||||
@param str The url needs encoding.
|
||||
@return the url-encoded version of str.
|
||||
@note Source: http://www.geekhideout.com/urlcode.shtml
|
||||
@todo This function can probably be hidden into the implementation details
|
||||
*/
|
||||
EXIV2API std::string urlencode(const char* str);
|
||||
|
||||
@ -79,11 +80,13 @@ namespace Exiv2
|
||||
|
||||
@note Be sure to free() the returned string after use
|
||||
Source: http://www.geekhideout.com/urlcode.shtml
|
||||
@todo This function can probably be hidden into the implementation details
|
||||
*/
|
||||
EXIV2API char* urldecode(const char* str);
|
||||
|
||||
/*!
|
||||
@brief Like urlencode(char* str) but accept the input url in the std::string and modify it.
|
||||
@todo This function can probably be hidden into the implementation details
|
||||
*/
|
||||
EXIV2API void urldecode(std::string& str);
|
||||
|
||||
|
||||
@ -83,3 +83,26 @@ TEST(urlencode, encodesGivenUrl)
|
||||
const std::string url = urlencode("http://www.geekhideout.com/urlcode.shtml");
|
||||
ASSERT_STREQ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml", url.c_str());
|
||||
}
|
||||
|
||||
TEST(urlencode, encodesGivenUrlWithSpace)
|
||||
{
|
||||
const std::string url = urlencode("http://www.geekhideout.com/url code.shtml");
|
||||
ASSERT_STREQ("http%3a%2f%2fwww.geekhideout.com%2furl+code.shtml", url.c_str());
|
||||
}
|
||||
|
||||
TEST(urldecode, decodesGivenUrl)
|
||||
{
|
||||
const std::string expectedDecodedUrl ("http://www.geekhideout.com/urlcode.shtml");
|
||||
const std::string url ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml");
|
||||
char * url3 = urldecode(url.c_str());
|
||||
ASSERT_STREQ(expectedDecodedUrl.c_str(), url3);
|
||||
free(url3);
|
||||
}
|
||||
|
||||
TEST(urldecode, decodesGivenUrlInPlace)
|
||||
{
|
||||
const std::string expectedDecodedUrl ("http://www.geekhideout.com/urlcode.shtml");
|
||||
std::string url ("http%3a%2f%2fwww.geekhideout.com%2furlcode.shtml");
|
||||
urldecode(url);
|
||||
ASSERT_STREQ(expectedDecodedUrl.c_str(), url.c_str());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user