blob: 5f94ef3c1b748f11a0fc1efc5898875083b6b892 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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//
Sen Jiang8cc502d2015-08-10 10:04:54 -070016
17#include "update_engine/payload_generator/blob_file_writer.h"
18
19#include <string>
20
21#include <gtest/gtest.h>
22
Alex Deymo39910dc2015-11-09 17:04:30 -080023#include "update_engine/common/test_utils.h"
24#include "update_engine/common/utils.h"
Sen Jiang8cc502d2015-08-10 10:04:54 -070025
26using chromeos_update_engine::test_utils::FillWithData;
27using std::string;
28
29namespace chromeos_update_engine {
30
31class BlobFileWriterTest : public ::testing::Test {};
32
33TEST(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;
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070043 brillo::Blob blob(blob_size);
Sen Jiang8cc502d2015-08-10 10:04:54 -070044 FillWithData(&blob);
45 EXPECT_EQ(0, blob_file.StoreBlob(blob));
46 EXPECT_EQ(blob_size, blob_file.StoreBlob(blob));
47
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070048 brillo::Blob stored_blob(blob_size);
Sen Jiang8cc502d2015-08-10 10:04:54 -070049 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