blob_file_writer_unittest.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Copyright (C) 2015 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include "update_engine/payload_generator/blob_file_writer.h"
  17. #include <string>
  18. #include <gtest/gtest.h>
  19. #include "update_engine/common/test_utils.h"
  20. #include "update_engine/common/utils.h"
  21. using chromeos_update_engine::test_utils::FillWithData;
  22. using std::string;
  23. namespace chromeos_update_engine {
  24. class BlobFileWriterTest : public ::testing::Test {};
  25. TEST(BlobFileWriterTest, SimpleTest) {
  26. string blob_path;
  27. int blob_fd;
  28. EXPECT_TRUE(
  29. utils::MakeTempFile("BlobFileWriterTest.XXXXXX", &blob_path, &blob_fd));
  30. off_t blob_file_size = 0;
  31. BlobFileWriter blob_file(blob_fd, &blob_file_size);
  32. off_t blob_size = 1024;
  33. brillo::Blob blob(blob_size);
  34. FillWithData(&blob);
  35. EXPECT_EQ(0, blob_file.StoreBlob(blob));
  36. EXPECT_EQ(blob_size, blob_file.StoreBlob(blob));
  37. brillo::Blob stored_blob(blob_size);
  38. ssize_t bytes_read;
  39. ASSERT_TRUE(
  40. utils::PReadAll(blob_fd, stored_blob.data(), blob_size, 0, &bytes_read));
  41. EXPECT_EQ(bytes_read, blob_size);
  42. EXPECT_EQ(blob, stored_blob);
  43. }
  44. } // namespace chromeos_update_engine