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 string blob_path;
35 int blob_fd;
36 EXPECT_TRUE(
37 utils::MakeTempFile("BlobFileWriterTest.XXXXXX", &blob_path, &blob_fd));
38 off_t blob_file_size = 0;
39 BlobFileWriter blob_file(blob_fd, &blob_file_size);
40
41 off_t blob_size = 1024;
42 brillo::Blob blob(blob_size);
43 FillWithData(&blob);
44 EXPECT_EQ(0, blob_file.StoreBlob(blob));
45 EXPECT_EQ(blob_size, blob_file.StoreBlob(blob));
46
47 brillo::Blob stored_blob(blob_size);
48 ssize_t bytes_read;
49 ASSERT_TRUE(
50 utils::PReadAll(blob_fd, stored_blob.data(), blob_size, 0, &bytes_read));
51 EXPECT_EQ(bytes_read, blob_size);
52 EXPECT_EQ(blob, stored_blob);
53 }
54
55 } // namespace chromeos_update_engine
56