webrtc_m130/webrtc/rtc_base/md5digest_unittest.cc
kjellander e96c45b662 Reland "Update includes for webrtc/{base => rtc_base} rename (3/3)"
I used a command like this to update the paths:
perl -pi -e "s/webrtc\/base/webrtc\/rtc_base/g" `find webrtc/rtc_base -name "*.cc" -o -name "*.h"`

Changes since last attempt: Some system headers were moved back to their original location since on Windows compilation breaks otherwise.

BUG=webrtc:7634
NOTRY=True
NOPRESUBMIT=True
TBR=kwiberg@webrtc.org

Review-Url: https://codereview.webrtc.org/2966523003
Cr-Commit-Position: refs/heads/master@{#18868}
2017-06-30 17:45:21 +00:00

80 lines
2.4 KiB
C++

/*
* Copyright 2012 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/rtc_base/md5digest.h"
#include "webrtc/rtc_base/gunit.h"
#include "webrtc/rtc_base/stringencode.h"
namespace rtc {
std::string Md5(const std::string& input) {
Md5Digest md5;
return ComputeDigest(&md5, input);
}
TEST(Md5DigestTest, TestSize) {
Md5Digest md5;
EXPECT_EQ(16, static_cast<int>(Md5Digest::kSize));
EXPECT_EQ(16U, md5.Size());
}
TEST(Md5DigestTest, TestBasic) {
// These are the standard MD5 test vectors from RFC 1321.
EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", Md5(""));
EXPECT_EQ("0cc175b9c0f1b6a831c399e269772661", Md5("a"));
EXPECT_EQ("900150983cd24fb0d6963f7d28e17f72", Md5("abc"));
EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", Md5("message digest"));
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b",
Md5("abcdefghijklmnopqrstuvwxyz"));
}
TEST(Md5DigestTest, TestMultipleUpdates) {
Md5Digest md5;
std::string input = "abcdefghijklmnopqrstuvwxyz";
char output[Md5Digest::kSize];
for (size_t i = 0; i < input.size(); ++i) {
md5.Update(&input[i], 1);
}
EXPECT_EQ(md5.Size(), md5.Finish(output, sizeof(output)));
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b",
hex_encode(output, sizeof(output)));
}
TEST(Md5DigestTest, TestReuse) {
Md5Digest md5;
std::string input = "message digest";
EXPECT_EQ("f96b697d7cb7938d525a2f31aaf161d0", ComputeDigest(&md5, input));
input = "abcdefghijklmnopqrstuvwxyz";
EXPECT_EQ("c3fcd3d76192e4007dfb496cca67e13b", ComputeDigest(&md5, input));
}
TEST(Md5DigestTest, TestBufferTooSmall) {
Md5Digest md5;
std::string input = "abcdefghijklmnopqrstuvwxyz";
char output[Md5Digest::kSize - 1];
md5.Update(input.c_str(), input.size());
EXPECT_EQ(0U, md5.Finish(output, sizeof(output)));
}
TEST(Md5DigestTest, TestBufferConst) {
Md5Digest md5;
const int kLongSize = 1000000;
std::string input(kLongSize, '\0');
for (int i = 0; i < kLongSize; ++i) {
input[i] = static_cast<char>(i);
}
md5.Update(input.c_str(), input.size());
for (int i = 0; i < kLongSize; ++i) {
EXPECT_EQ(static_cast<char>(i), input[i]);
}
}
} // namespace rtc