Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: omaha_hash_calculator_unittest.cc

Issue 3521016: AU: Start checkpointing update progress. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: address review comments Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_hash_calculator.cc ('k') | omaha_response_handler_action.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « omaha_hash_calculator.cc ('k') | omaha_response_handler_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698