Home | History | Annotate | Download | only in payload_generator
      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 
     17 #include "update_engine/payload_generator/blob_file_writer.h"
     18 
     19 #include <string>
     20 
     21 #include <gtest/gtest.h>
     22 
     23 #include "update_engine/common/test_utils.h"
     24 #include "update_engine/common/utils.h"
     25 
     26 using chromeos_update_engine::test_utils::FillWithData;
     27 using std::string;
     28 
     29 namespace chromeos_update_engine {
     30 
     31 class BlobFileWriterTest : public ::testing::Test {};
     32 
     33 TEST(BlobFileWriterTest, SimpleTest) {
     34   string blob_path;
     35   int blob_fd;
     36   EXPECT_TRUE(utils::MakeTempFile("BlobFileWriterTest.XXXXXX",
     37                                   &blob_path,
     38                                   &blob_fd));
     39   off_t blob_file_size = 0;
     40   BlobFileWriter blob_file(blob_fd, &blob_file_size);
     41 
     42   off_t blob_size = 1024;
     43   brillo::Blob blob(blob_size);
     44   FillWithData(&blob);
     45   EXPECT_EQ(0, blob_file.StoreBlob(blob));
     46   EXPECT_EQ(blob_size, blob_file.StoreBlob(blob));
     47 
     48   brillo::Blob stored_blob(blob_size);
     49   ssize_t bytes_read;
     50   ASSERT_TRUE(utils::PReadAll(blob_fd,
     51                               stored_blob.data(),
     52                               blob_size,
     53                               0,
     54                               &bytes_read));
     55   EXPECT_EQ(bytes_read, blob_size);
     56   EXPECT_EQ(blob, stored_blob);
     57 }
     58 
     59 }  // namespace chromeos_update_engine
     60