blob_file_writer_unittest.cc revision 8cc502dacbccdab96824d42287f230ce04004784
1// Copyright 2015 The Chromium OS 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 "update_engine/payload_generator/blob_file_writer.h" 6 7#include <string> 8 9#include <gtest/gtest.h> 10 11#include "update_engine/test_utils.h" 12#include "update_engine/utils.h" 13 14using chromeos_update_engine::test_utils::FillWithData; 15using std::string; 16 17namespace chromeos_update_engine { 18 19class BlobFileWriterTest : public ::testing::Test {}; 20 21TEST(BlobFileWriterTest, SimpleTest) { 22 string blob_path; 23 int blob_fd; 24 EXPECT_TRUE(utils::MakeTempFile("BlobFileWriterTest.XXXXXX", 25 &blob_path, 26 &blob_fd)); 27 off_t blob_file_size = 0; 28 BlobFileWriter blob_file(blob_fd, &blob_file_size); 29 30 off_t blob_size = 1024; 31 chromeos::Blob blob(blob_size); 32 FillWithData(&blob); 33 EXPECT_EQ(0, blob_file.StoreBlob(blob)); 34 EXPECT_EQ(blob_size, blob_file.StoreBlob(blob)); 35 36 chromeos::Blob stored_blob(blob_size); 37 ssize_t bytes_read; 38 ASSERT_TRUE(utils::PReadAll(blob_fd, 39 stored_blob.data(), 40 blob_size, 41 0, 42 &bytes_read)); 43 EXPECT_EQ(bytes_read, blob_size); 44 EXPECT_EQ(blob, stored_blob); 45} 46 47} // namespace chromeos_update_engine 48