Adds a modified copy of talk/base to webrtc/base. It is the first step in migrating talk/base to webrtc/base.
BUG=N/A R=andrew@webrtc.org, wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12199004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6107 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
81
webrtc/base/urlencode_unittest.cc
Normal file
81
webrtc/base/urlencode_unittest.cc
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
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, 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, UrlDecode(source, dest));
|
||||
ASSERT_STREQ("A^ ", dest);
|
||||
}
|
||||
|
||||
TEST(Urldecode, Decoding2) {
|
||||
char source[] = "A%5E+";
|
||||
char dest[8];
|
||||
ASSERT_EQ(3, UrlDecodeWithoutEncodingSpaceAsPlus(source, dest));
|
||||
ASSERT_STREQ("A^+", dest);
|
||||
}
|
Reference in New Issue
Block a user