blob: 5c6d63dfccce1b62db3419ab13b7a62c1e04e088 [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>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070014#include <imageloader/dbus-proxy-mocks.h>
Amin Hassani759090b2020-04-13 12:31:10 -070015#include <session_manager/dbus-proxy-mocks.h>
Amin Hassanid488ced2020-04-07 15:33:56 -070016#include <update_engine/proto_bindings/update_engine.pb.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070017#include <update_engine/dbus-proxy-mocks.h>
18
19#include "dlcservice/dlc.h"
20#include "dlcservice/dlc_service.h"
21
22namespace dlcservice {
23
24extern const char kFirstDlc[];
25extern const char kSecondDlc[];
26extern const char kThirdDlc[];
27extern const char kPackage[];
28extern const char kDefaultOmahaUrl[];
29
30class BaseTest : public testing::Test {
31 public:
32 BaseTest();
33
34 void SetUp() override;
35
36 void SetUpFilesAndDirectories();
37
38 int64_t GetFileSize(const base::FilePath& path);
39
Amin Hassani10c8c6c2020-04-06 12:28:59 -070040 void CreateImageFileWithRightSize(const base::FilePath& image_path,
41 const base::FilePath& manifest_path,
42 const std::string& id,
43 const std::string& package);
44
45 // Will create |path|/|id|/|package|/dlc.img file.
46 void SetUpDlcWithoutSlots(const std::string& id);
47
48 // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files.
49 void SetUpDlcWithSlots(const std::string& id);
50
51 void SetMountPath(const std::string& mount_path_expected);
52
53 protected:
54 brillo::ErrorPtr err_;
55
56 base::ScopedTempDir scoped_temp_dir_;
57
58 base::FilePath testdata_path_;
59 base::FilePath manifest_path_;
60 base::FilePath preloaded_content_path_;
61 base::FilePath content_path_;
Amin Hassanife63fc22020-04-07 11:34:34 -070062 base::FilePath prefs_path_;
Amin Hassani10c8c6c2020-04-06 12:28:59 -070063 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
Amin Hassani759090b2020-04-13 12:31:10 -070073 using SessionManagerProxyMock =
74 org::chromium::SessionManagerInterfaceProxyMock;
75 std::unique_ptr<SessionManagerProxyMock> mock_session_manager_proxy_;
76 SessionManagerProxyMock* mock_session_manager_proxy_ptr_;
77
Amin Hassani10c8c6c2020-04-06 12:28:59 -070078 private:
79 DISALLOW_COPY_AND_ASSIGN(BaseTest);
80};
81
82} // namespace dlcservice
83
84#endif // DLCSERVICE_TEST_UTILS_H_