| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "gtest/gtest.h"
- #include "../../core/src/Utils.h"
- using namespace std;
- using namespace AlibabaCloud;
- namespace {
- TEST(UtilsTest, ComputeContentMD5) {
- const std::string src = "abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1";
- const std::string md5 = ComputeContentMD5(src.c_str(), src.size());
- EXPECT_TRUE(md5 == "WL7+fwrxHSlBTsfU9WCSbA==");
- }
- TEST(UtilsTest, GenerateUuid) {
- const std::string uuid1 = GenerateUuid();
- const std::string uuid2 = GenerateUuid();
- EXPECT_TRUE(uuid1 != uuid2);
- }
- TEST(UtilsTest, HttpMethodToString){
- std::string method = HttpMethodToString(HttpRequest::Method::Head);
- EXPECT_TRUE(method == "HEAD");
- method = HttpMethodToString(HttpRequest::Method::Post);
- EXPECT_TRUE(method == "POST");
- method = HttpMethodToString(HttpRequest::Method::Put);
- EXPECT_TRUE(method == "PUT");
- method = HttpMethodToString(HttpRequest::Method::Delete);
- EXPECT_TRUE(method == "DELETE");
- method = HttpMethodToString(HttpRequest::Method::Connect);
- EXPECT_TRUE(method == "CONNECT");
- method = HttpMethodToString(HttpRequest::Method::Options);
- EXPECT_TRUE(method == "OPTIONS");
- method = HttpMethodToString(HttpRequest::Method::Patch);
- EXPECT_TRUE(method == "PATCH");
- method = HttpMethodToString(HttpRequest::Method::Trace);
- EXPECT_TRUE(method == "TRACE");
- method = HttpMethodToString(HttpRequest::Method::Get);
- EXPECT_TRUE(method == "GET");
- }
- TEST(UtilsTest, StringReplace) {
- std::string src = "abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1";
- StringReplace(src, "abc", "http");
- EXPECT_TRUE(src == "http://username:password@example.com:123/path/data?key=value&key2=value2#fragid1");
- StringReplace(src, "value", "VALUE");
- EXPECT_TRUE(src == "http://username:password@example.com:123/path/data?key=VALUE&key2=VALUE2#fragid1");
- }
- TEST(UtilsTest, Encode) {
- const std::string url = "http://username:password@example.com:123/path/data?key=value&key2=value2#fragid1";
- const std::string encoded = "http%3A%2F%2Fusername%3Apassword%40example.com%3A123%2Fpath%2Fdata%3Fkey%3Dvalue%26key2%3Dvalue2%23fragid1";
- const std::string enc = UrlEncode(url);
- EXPECT_TRUE(enc == encoded);
- }
- TEST(UtilsTest, Decode) {
- const std::string url = "http://username:password@example.com:123/path/data?key=value&key2=value2#fragid1";
- const std::string encoded = "http%3A%2F%2Fusername%3Apassword%40example.com%3A123%2Fpath%2Fdata%3Fkey%3Dvalue%26key2%3Dvalue2%23fragid1";
- const std::string decoded = UrlDecode(encoded);
- EXPECT_TRUE(decoded == url);
- }
- }
|