blob: 61f0e1ac1e10ad3e4429a5756a9922f9e68ef1c9 [file] [log] [blame]
Amin Hassani10c8c6c2020-04-06 12:28:59 -07001// Copyright 2020 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef DLCSERVICE_TEST_UTILS_H_
6#define DLCSERVICE_TEST_UTILS_H_
7
8#include <memory>
9#include <string>
10
11#include <base/files/file_path.h>
12#include <base/files/scoped_temp_dir.h>
13#include <dlcservice/proto_bindings/dlcservice.pb.h>
14#include <update_engine/proto_bindings/update_engine.pb.h>
15#include <imageloader/dbus-proxy-mocks.h>
16#include <update_engine/dbus-proxy-mocks.h>
17
18#include "dlcservice/dlc.h"
19#include "dlcservice/dlc_service.h"
20
21namespace dlcservice {
22
23extern const char kFirstDlc[];
24extern const char kSecondDlc[];
25extern const char kThirdDlc[];
26extern const char kPackage[];
27extern const char kDefaultOmahaUrl[];
28
29class BaseTest : public testing::Test {
30 public:
31 BaseTest();
32
33 void SetUp() override;
34
35 void SetUpFilesAndDirectories();
36
37 int64_t GetFileSize(const base::FilePath& path);
38
39 void ResizeImageFile(const base::FilePath& image_path, int64_t image_size);
40
41 void CreateImageFileWithRightSize(const base::FilePath& image_path,
42 const base::FilePath& manifest_path,
43 const std::string& id,
44 const std::string& package);
45
46 // Will create |path|/|id|/|package|/dlc.img file.
47 void SetUpDlcWithoutSlots(const std::string& id);
48
49 // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files.
50 void SetUpDlcWithSlots(const std::string& id);
51
52 void SetMountPath(const std::string& mount_path_expected);
53
54 protected:
55 brillo::ErrorPtr err_;
56
57 base::ScopedTempDir scoped_temp_dir_;
58
59 base::FilePath testdata_path_;
60 base::FilePath manifest_path_;
61 base::FilePath preloaded_content_path_;
62 base::FilePath content_path_;
63 base::FilePath mount_path_;
64
65 using ImageLoaderProxyMock = org::chromium::ImageLoaderInterfaceProxyMock;
66 std::unique_ptr<ImageLoaderProxyMock> mock_image_loader_proxy_;
67 ImageLoaderProxyMock* mock_image_loader_proxy_ptr_;
68
69 using UpdateEngineProxyMock = org::chromium::UpdateEngineInterfaceProxyMock;
70 std::unique_ptr<UpdateEngineProxyMock> mock_update_engine_proxy_;
71 UpdateEngineProxyMock* mock_update_engine_proxy_ptr_;
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(BaseTest);
75};
76
77} // namespace dlcservice
78
79#endif // DLCSERVICE_TEST_UTILS_H_