Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/common/blob_cache/id_util.h" | |
| 6 #include "crypto/sha2.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace blimp { | |
| 10 namespace { | |
| 11 const char kInput[] = "\xde\xad\xbe\xef\x4b\x1d\xc0\xd3\xff\xfe"; | |
|
Wez
2016/04/23 00:08:52
kBlobData?
nit: Blank line between namespace and
nyquist
2016/04/25 08:11:17
Done.
| |
| 12 | |
| 13 // Caution: If these expected outputs ever change, it means that all client-side | |
| 14 // caches will effectively be invalidated. | |
| 15 const char kExpected[] = | |
|
Wez
2016/04/23 00:08:52
kBlobId and kBlobIdString, say?
nyquist
2016/04/25 08:11:17
Done.
| |
| 16 "\x31\xda\x00\xaf\x5e\xd6\x64\xd6\x5f\xb1\xe6\x34\x99\xd3\xf5\x12\x21\xc8" | |
| 17 "\xf8\x51\x19\xfd\x1d\x17\xaa\x0b\x5e\x85\x10\x4f\x17\x15"; | |
| 18 const char kExpectedFormatted[] = | |
| 19 "31da00af5ed664d65fb1e63499d3f51221c8f85119fd1d17aa0b5e85104f1715"; | |
| 20 | |
| 21 class IdUtilTest : public testing::Test { | |
|
Wez
2016/04/23 00:08:52
Why are we overriding testing::Test if we're not a
nyquist
2016/04/25 08:11:17
Done.
| |
| 22 public: | |
| 23 IdUtilTest() {} | |
| 24 ~IdUtilTest() override {} | |
| 25 }; | |
| 26 | |
| 27 TEST_F(IdUtilTest, VerifyHashCalculationCreatesExpectedHash) { | |
|
Wez
2016/04/23 00:08:52
Suggest calling this just BlobIdIsCorrect or Corre
nyquist
2016/04/25 08:11:17
Done.
| |
| 28 BlobId id = CalculateBlobId(kInput, 10); | |
| 29 EXPECT_EQ(crypto::kSHA256Length, id.length()); | |
| 30 for (size_t i = 0; i < crypto::kSHA256Length; i++) | |
| 31 EXPECT_EQ(kExpected[i], static_cast<int>(id[i])); | |
| 32 EXPECT_EQ(kExpectedFormatted, FormatBlobId(id)); | |
| 33 } | |
| 34 | |
| 35 TEST_F(IdUtilTest, VerifyLengthChecker) { | |
|
Wez
2016/04/23 00:08:52
This looks like two different tests; one is verify
nyquist
2016/04/25 08:11:17
Done.
| |
| 36 BlobId id1 = CalculateBlobId(kInput, 10); | |
| 37 EXPECT_EQ(crypto::kSHA256Length, id1.length()); | |
| 38 EXPECT_TRUE(BlobIdHasCorrectLength(id1)); | |
| 39 | |
| 40 BlobId id2 = CalculateBlobId(kInput, 8); | |
| 41 EXPECT_EQ(crypto::kSHA256Length, id2.length()); | |
| 42 EXPECT_TRUE(BlobIdHasCorrectLength(id2)); | |
| 43 | |
| 44 EXPECT_FALSE(BlobIdHasCorrectLength(BlobId(""))); | |
| 45 EXPECT_FALSE(BlobIdHasCorrectLength(BlobId("123"))); | |
| 46 EXPECT_TRUE( | |
| 47 BlobIdHasCorrectLength(BlobId("12345678901234567890123456789012"))); | |
| 48 EXPECT_FALSE( | |
| 49 BlobIdHasCorrectLength(BlobId("12345678901234567890123456789012fff"))); | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 } // namespace blimp | |
| OLD | NEW |