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 | |
12 const char kBlobdata[] = "\xde\xad\xbe\xef\x4b\x1d\xc0\xd3\xff\xfe"; | |
13 | |
14 // Caution: If these expected outputs ever change, it means that all client-side | |
15 // caches will effectively be invalidated. | |
16 const char kBlobId[] = | |
17 "\x31\xda\x00\xaf\x5e\xd6\x64\xd6\x5f\xb1\xe6\x34\x99\xd3\xf5\x12\x21\xc8" | |
18 "\xf8\x51\x19\xfd\x1d\x17\xaa\x0b\x5e\x85\x10\x4f\x17\x15"; | |
19 const char kBlobIdString[] = | |
20 "31da00af5ed664d65fb1e63499d3f51221c8f85119fd1d17aa0b5e85104f1715"; | |
21 | |
22 TEST(IdUtilTest, BlobIdIsCorrect) { | |
23 BlobId id = CalculateBlobId(kBlobdata, 10); | |
24 EXPECT_EQ(crypto::kSHA256Length, id.length()); | |
25 for (size_t i = 0; i < crypto::kSHA256Length; i++) | |
26 EXPECT_EQ(kBlobId[i], static_cast<int>(id[i])); | |
27 EXPECT_EQ(kBlobIdString, BlobIdToString(id)); | |
28 } | |
29 | |
30 TEST(IdUtilTest, BlobIdsAreCorrectLength) { | |
31 BlobId id1 = CalculateBlobId(kBlobdata, 10); | |
32 EXPECT_EQ(crypto::kSHA256Length, id1.length()); | |
33 EXPECT_TRUE(IsValidBlobId(id1)); | |
34 | |
35 BlobId id2 = CalculateBlobId(kBlobdata, 8); | |
36 EXPECT_EQ(crypto::kSHA256Length, id2.length()); | |
37 EXPECT_TRUE(IsValidBlobId(id2)); | |
38 } | |
39 | |
40 TEST(IdUtilTest, BlobIdLengthCheck) { | |
41 EXPECT_FALSE(IsValidBlobId(BlobId(""))); | |
42 EXPECT_FALSE(IsValidBlobId(BlobId("123"))); | |
43 EXPECT_TRUE(IsValidBlobId(BlobId("12345678901234567890123456789012"))); | |
44 EXPECT_FALSE(IsValidBlobId(BlobId("12345678901234567890123456789012fff"))); | |
45 } | |
46 | |
47 } // namespace | |
48 } // namespace blimp | |
OLD | NEW |