blob: ed6295ccdffd496fb1824f66938ffea632068ac4 [file] [log] [blame]
Chris Sosa45d9f102014-03-24 11:18:54 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "buffet/data_encoding.h"
6
7#include <gtest/gtest.h>
8
Alex Vakulenkoaf23b322014-05-08 16:25:45 -07009using namespace buffet::data_encoding; // NOLINT(build/namespaces)
Chris Sosa45d9f102014-03-24 11:18:54 -070010
11TEST(data_encoding, UrlEncoding) {
12 std::string test = "\"http://sample/path/0014.html \"";
13 std::string encoded = UrlEncode(test.c_str());
14 EXPECT_EQ("%22http%3A%2F%2Fsample%2Fpath%2F0014.html+%22",
15 encoded);
16 EXPECT_EQ(test, UrlDecode(encoded.c_str()));
17
18 test = "\"http://sample/path/0014.html \"";
19 encoded = UrlEncode(test.c_str(), false);
20 EXPECT_EQ("%22http%3A%2F%2Fsample%2Fpath%2F0014.html%20%22",
21 encoded);
22 EXPECT_EQ(test, UrlDecode(encoded.c_str()));
Chris Sosa45d9f102014-03-24 11:18:54 -070023}
24
25TEST(data_encoding, WebParamsEncoding) {
26 std::string encoded = WebParamsEncode({{"q", "test"},
27 {"path", "/usr/bin"},
28 {"#", "%"}});
29 EXPECT_EQ("q=test&path=%2Fusr%2Fbin&%23=%25", encoded);
30
31 auto params = WebParamsDecode(encoded);
32 EXPECT_EQ(3, params.size());
33 EXPECT_EQ("q", params[0].first);
34 EXPECT_EQ("test", params[0].second);
35 EXPECT_EQ("path", params[1].first);
36 EXPECT_EQ("/usr/bin", params[1].second);
37 EXPECT_EQ("#", params[2].first);
38 EXPECT_EQ("%", params[2].second);
39}