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