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
TEST(BlobFileWriterTest,SimpleTest)33 TEST(BlobFileWriterTest, SimpleTest) {
34 ScopedTempFile blob_file("BlobFileWriterTest.XXXXXX", true);
35 off_t blob_file_size = 0;
36 BlobFileWriter blob_file_writer(blob_file.fd(), &blob_file_size);
37
38 const off_t kBlobSize = 1024;
39 brillo::Blob blob(kBlobSize);
40 FillWithData(&blob);
41 EXPECT_EQ(0, blob_file_writer.StoreBlob(blob));
42 EXPECT_EQ(kBlobSize, blob_file_writer.StoreBlob(blob));
43
44 brillo::Blob stored_blob(kBlobSize);
45 ssize_t bytes_read;
46 ASSERT_TRUE(utils::PReadAll(
47 blob_file.fd(), stored_blob.data(), kBlobSize, 0, &bytes_read));
48 EXPECT_EQ(bytes_read, kBlobSize);
49 EXPECT_EQ(blob, stored_blob);
50 }
51
52 } // namespace chromeos_update_engine
53