| Index: omaha_hash_calculator_unittest.cc
|
| diff --git a/omaha_hash_calculator_unittest.cc b/omaha_hash_calculator_unittest.cc
|
| index 597b21f4d74638b2992d3f21e94a824ad7602250..5ba3ac1805c9f82b32c19547a674a932acc0a801 100644
|
| --- a/omaha_hash_calculator_unittest.cc
|
| +++ b/omaha_hash_calculator_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include <math.h>
|
| #include <unistd.h>
|
|
|
| +#include <string>
|
| #include <vector>
|
|
|
| #include <glib.h>
|
| @@ -12,7 +13,9 @@
|
|
|
| #include "update_engine/libcurl_http_fetcher.h"
|
| #include "update_engine/omaha_hash_calculator.h"
|
| +#include "update_engine/utils.h"
|
|
|
| +using std::string;
|
| using std::vector;
|
|
|
| namespace chromeos_update_engine {
|
| @@ -54,13 +57,16 @@ TEST(OmahaHashCalculatorTest, MultiUpdateTest) {
|
| TEST(OmahaHashCalculatorTest, ContextTest) {
|
| OmahaHashCalculator calc;
|
| calc.Update("h", 1);
|
| + string calc_context = calc.GetContext();
|
| + calc.Finalize();
|
| OmahaHashCalculator calc_next;
|
| - calc_next.SetContext(calc.GetContext());
|
| + calc_next.SetContext(calc_context);
|
| calc_next.Update("i", 1);
|
| calc_next.Finalize();
|
| - // Generated by running this on a linux shell:
|
| - // $ echo -n hi | openssl dgst -sha256 -binary | openssl base64
|
| - EXPECT_EQ("j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ=", calc_next.hash());
|
| + EXPECT_EQ(kExpectedHash, calc_next.hash());
|
| + vector<char> raw_hash(kExpectedRawHash,
|
| + kExpectedRawHash + arraysize(kExpectedRawHash));
|
| + EXPECT_TRUE(raw_hash == calc_next.raw_hash());
|
| }
|
|
|
| TEST(OmahaHashCalculatorTest, BigTest) {
|
| @@ -83,6 +89,37 @@ TEST(OmahaHashCalculatorTest, BigTest) {
|
| EXPECT_EQ("NZf8k6SPBkYMvhaX8YgzuMgbkLP1XZ+neM8K5wcSsf8=", calc.hash());
|
| }
|
|
|
| +TEST(OmahaHashCalculatorTest, UpdateFileSimpleTest) {
|
| + string data_path;
|
| + ASSERT_TRUE(
|
| + utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
|
| + ScopedPathUnlinker data_path_unlinker(data_path);
|
| + ASSERT_TRUE(utils::WriteFile(data_path.c_str(), "hi", 2));
|
| +
|
| + static const int kLengths[] = { -1, 2, 10 };
|
| + for (size_t i = 0; i < arraysize(kLengths); i++) {
|
| + OmahaHashCalculator calc;
|
| + EXPECT_EQ(2, calc.UpdateFile(data_path, kLengths[i]));
|
| + EXPECT_TRUE(calc.Finalize());
|
| + EXPECT_EQ(kExpectedHash, calc.hash());
|
| + vector<char> raw_hash(kExpectedRawHash,
|
| + kExpectedRawHash + arraysize(kExpectedRawHash));
|
| + EXPECT_TRUE(raw_hash == calc.raw_hash());
|
| + }
|
| +
|
| + OmahaHashCalculator calc;
|
| + EXPECT_EQ(0, calc.UpdateFile(data_path, 0));
|
| + EXPECT_EQ(1, calc.UpdateFile(data_path, 1));
|
| + EXPECT_TRUE(calc.Finalize());
|
| + // echo -n h | openssl dgst -sha256 -binary | openssl base64
|
| + EXPECT_EQ("qqlAJmTxpB9A67xSyZk+tmrrNmYClY/fqig7ceZNsSM=", calc.hash());
|
| +}
|
| +
|
| +TEST(OmahaHashCalculatorTest, UpdateFileNonexistentTest) {
|
| + OmahaHashCalculator calc;
|
| + EXPECT_EQ(-1, calc.UpdateFile("/some/non-existent/file", -1));
|
| +}
|
| +
|
| TEST(OmahaHashCalculatorTest, AbortTest) {
|
| // Just make sure we don't crash and valgrind doesn't detect memory leaks
|
| {
|
|
|