OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <math.h> | 5 #include <math.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include <glib.h> | 10 #include <glib.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 OmahaHashCalculator calc; | 44 OmahaHashCalculator calc; |
45 calc.Update("h", 1); | 45 calc.Update("h", 1); |
46 calc.Update("i", 1); | 46 calc.Update("i", 1); |
47 calc.Finalize(); | 47 calc.Finalize(); |
48 EXPECT_EQ(kExpectedHash, calc.hash()); | 48 EXPECT_EQ(kExpectedHash, calc.hash()); |
49 vector<char> raw_hash(kExpectedRawHash, | 49 vector<char> raw_hash(kExpectedRawHash, |
50 kExpectedRawHash + arraysize(kExpectedRawHash)); | 50 kExpectedRawHash + arraysize(kExpectedRawHash)); |
51 EXPECT_TRUE(raw_hash == calc.raw_hash()); | 51 EXPECT_TRUE(raw_hash == calc.raw_hash()); |
52 } | 52 } |
53 | 53 |
| 54 TEST(OmahaHashCalculatorTest, ContextTest) { |
| 55 OmahaHashCalculator calc; |
| 56 calc.Update("h", 1); |
| 57 OmahaHashCalculator calc_next; |
| 58 calc_next.SetContext(calc.GetContext()); |
| 59 calc_next.Update("i", 1); |
| 60 calc_next.Finalize(); |
| 61 // Generated by running this on a linux shell: |
| 62 // $ echo -n hi | openssl dgst -sha256 -binary | openssl base64 |
| 63 EXPECT_EQ("j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ=", calc_next.hash()); |
| 64 } |
| 65 |
54 TEST(OmahaHashCalculatorTest, BigTest) { | 66 TEST(OmahaHashCalculatorTest, BigTest) { |
55 OmahaHashCalculator calc; | 67 OmahaHashCalculator calc; |
56 | 68 |
57 for (int i = 0; i < 1000000; i++) { | 69 for (int i = 0; i < 1000000; i++) { |
58 char buf[8]; | 70 char buf[8]; |
59 ASSERT_EQ(0 == i ? 1 : static_cast<int>(floorf(logf(i) / logf(10))) + 1, | 71 ASSERT_EQ(0 == i ? 1 : static_cast<int>(floorf(logf(i) / logf(10))) + 1, |
60 snprintf(buf, sizeof(buf), "%d", i)) << " i = " << i; | 72 snprintf(buf, sizeof(buf), "%d", i)) << " i = " << i; |
61 calc.Update(buf, strlen(buf)); | 73 calc.Update(buf, strlen(buf)); |
62 } | 74 } |
63 calc.Finalize(); | 75 calc.Finalize(); |
(...skipping 12 matching lines...) Expand all Loading... |
76 { | 88 { |
77 OmahaHashCalculator calc; | 89 OmahaHashCalculator calc; |
78 } | 90 } |
79 { | 91 { |
80 OmahaHashCalculator calc; | 92 OmahaHashCalculator calc; |
81 calc.Update("h", 1); | 93 calc.Update("h", 1); |
82 } | 94 } |
83 } | 95 } |
84 | 96 |
85 } // namespace chromeos_update_engine | 97 } // namespace chromeos_update_engine |
OLD | NEW |