2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/crc32.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
namespace rtc {
|
|
|
|
|
|
|
|
|
|
TEST(Crc32Test, TestBasic) {
|
|
|
|
|
EXPECT_EQ(0U, ComputeCrc32(""));
|
|
|
|
|
EXPECT_EQ(0x352441C2U, ComputeCrc32("abc"));
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
0x171A3F5FU,
|
|
|
|
|
ComputeCrc32("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Crc32Test, TestMultipleUpdates) {
|
|
|
|
|
std::string input =
|
|
|
|
|
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t c = 0;
|
2014-05-13 18:00:26 +00:00
|
|
|
for (size_t i = 0; i < input.size(); ++i) {
|
|
|
|
|
c = UpdateCrc32(c, &input[i], 1);
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(0x171A3F5FU, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|