test: add unittests

Signed-off-by: Myoungwon Oh <omwmw@sk.com>
This commit is contained in:
myoungwon oh 2019-05-27 19:01:44 +09:00
parent f745a7d35f
commit 75ca528b03

View File

@ -2911,6 +2911,86 @@ TEST(BufferList, TestSHA1) {
}
}
TEST(BufferList, TestSHA256) {
{
bufferlist bl;
sha256_digest_t sha256 = bl.sha256();
EXPECT_EQ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", sha256.to_str());
}
{
bufferlist bl;
bl.append("");
sha256_digest_t sha256 = bl.sha256();
EXPECT_EQ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", sha256.to_str());
}
{
bufferlist bl;
bl.append("Hello");
sha256_digest_t sha256 = bl.sha256();
EXPECT_EQ("185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969", sha256.to_str());
}
{
bufferlist bl, bl2;
bl.append("Hello");
bl2.append(", world!");
bl.claim_append(bl2);
sha256_digest_t sha256 = bl.sha256();
EXPECT_EQ("315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3", sha256.to_str());
bl2.append(" How are you today?");
bl.claim_append(bl2);
sha256 = bl.sha256();
EXPECT_EQ("e85f57f8bb018bd4f7beed6f27488cef22b13d5e06e8b8a27cac8b087c2a549e", sha256.to_str());
}
{
bufferptr p(65536);
memset(p.c_str(), 0, 65536);
bufferlist bl;
bl.append(p);
sha256_digest_t sha256 = bl.sha256();
EXPECT_EQ("de2f256064a0af797747c2b97505dc0b9f3df0de4f489eac731c23ae9ca9cc31", sha256.to_str());
}
}
TEST(BufferList, TestSHA512) {
{
bufferlist bl;
sha512_digest_t sha512 = bl.sha512();
EXPECT_EQ("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", sha512.to_str());
}
{
bufferlist bl;
bl.append("");
sha512_digest_t sha512 = bl.sha512();
EXPECT_EQ("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", sha512.to_str());
}
{
bufferlist bl;
bl.append("Hello");
sha512_digest_t sha512 = bl.sha512();
EXPECT_EQ("3615f80c9d293ed7402687f94b22d58e529b8cc7916f8fac7fddf7fbd5af4cf777d3d795a7a00a16bf7e7f3fb9561ee9baae480da9fe7a18769e71886b03f315", sha512.to_str());
}
{
bufferlist bl, bl2;
bl.append("Hello");
bl2.append(", world!");
bl.claim_append(bl2);
sha512_digest_t sha512 = bl.sha512();
EXPECT_EQ("c1527cd893c124773d811911970c8fe6e857d6df5dc9226bd8a160614c0cd963a4ddea2b94bb7d36021ef9d865d5cea294a82dd49a0bb269f51f6e7a57f79421", sha512.to_str());
bl2.append(" How are you today?");
bl.claim_append(bl2);
sha512 = bl.sha512();
EXPECT_EQ("7d50e299496754f9a0d158e018d4b733f2ef51c487b43b50719ffdabe3c3da5a347029741056887b4ffa2ddd0aa9e0dd358b8ed9da9a4f3455f44896fc8e5395", sha512.to_str());
}
{
bufferptr p(65536);
memset(p.c_str(), 0, 65536);
bufferlist bl;
bl.append(p);
sha512_digest_t sha512 = bl.sha512();
EXPECT_EQ("73e4153936dab198397b74ee9efc26093dda721eaab2f8d92786891153b45b04265a161b169c988edb0db2c53124607b6eaaa816559c5ce54f3dbc9fa6a7a4b2", sha512.to_str());
}
}
TEST(BufferHash, all) {
{
bufferlist bl;