1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/base/common.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/thread.h"
#include "webrtc/base/urlencode.h"
using rtc::UrlEncode;
TEST(Urlencode, SourceTooLong) {
char source[] = "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^";
char dest[1];
ASSERT_EQ(0, UrlEncode(source, dest, ARRAY_SIZE(dest)));
ASSERT_EQ('\0', dest[0]);
dest[0] = 'a';
ASSERT_EQ(0, UrlEncode(source, dest, 0));
ASSERT_EQ('a', dest[0]);
}
TEST(Urlencode, OneCharacterConversion) {
char source[] = "^";
char dest[4];
ASSERT_EQ(3, UrlEncode(source, dest, ARRAY_SIZE(dest)));
ASSERT_STREQ("%5E", dest);
}
TEST(Urlencode, ShortDestinationNoEncoding) {
// In this case we have a destination that would not be
// big enough to hold an encoding but is big enough to
// hold the text given.
char source[] = "aa";
char dest[3];
ASSERT_EQ(2, UrlEncode(source, dest, ARRAY_SIZE(dest)));
ASSERT_STREQ("aa", dest);
}
TEST(Urlencode, ShortDestinationEncoding) {
// In this case we have a destination that is not
// big enough to hold the encoding.
char source[] = "&";
char dest[3];
ASSERT_EQ(0, UrlEncode(source, dest, ARRAY_SIZE(dest)));
ASSERT_EQ('\0', dest[0]);
}
TEST(Urlencode, Encoding1) {
char source[] = "A^ ";
char dest[8];
ASSERT_EQ(5, UrlEncode(source, dest, ARRAY_SIZE(dest)));
ASSERT_STREQ("A%5E+", dest);
}
TEST(Urlencode, Encoding2) {
char source[] = "A^ ";
char dest[8];
ASSERT_EQ(7, rtc::UrlEncodeWithoutEncodingSpaceAsPlus(source, dest,
ARRAY_SIZE(dest)));
ASSERT_STREQ("A%5E%20", dest);
}
TEST(Urldecode, Decoding1) {
char source[] = "A%5E+";
char dest[8];
ASSERT_EQ(3, rtc::UrlDecode(source, dest));
ASSERT_STREQ("A^ ", dest);
}
TEST(Urldecode, Decoding2) {
char source[] = "A%5E+";
char dest[8];
ASSERT_EQ(3, rtc::UrlDecodeWithoutEncodingSpaceAsPlus(source, dest));
ASSERT_STREQ("A^+", dest);
}
|