Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 1 | // 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 Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 14 | #include <imageloader/dbus-proxy-mocks.h> |
Amin Hassani | d488ced | 2020-04-07 15:33:56 -0700 | [diff] [blame] | 15 | #include <update_engine/proto_bindings/update_engine.pb.h> |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 16 | #include <update_engine/dbus-proxy-mocks.h> |
| 17 | |
| 18 | #include "dlcservice/dlc.h" |
| 19 | #include "dlcservice/dlc_service.h" |
| 20 | |
| 21 | namespace dlcservice { |
| 22 | |
| 23 | extern const char kFirstDlc[]; |
| 24 | extern const char kSecondDlc[]; |
| 25 | extern const char kThirdDlc[]; |
| 26 | extern const char kPackage[]; |
| 27 | extern const char kDefaultOmahaUrl[]; |
| 28 | |
| 29 | class 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 | |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 39 | void CreateImageFileWithRightSize(const base::FilePath& image_path, |
| 40 | const base::FilePath& manifest_path, |
| 41 | const std::string& id, |
| 42 | const std::string& package); |
| 43 | |
| 44 | // Will create |path|/|id|/|package|/dlc.img file. |
| 45 | void SetUpDlcWithoutSlots(const std::string& id); |
| 46 | |
| 47 | // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files. |
| 48 | void SetUpDlcWithSlots(const std::string& id); |
| 49 | |
| 50 | void SetMountPath(const std::string& mount_path_expected); |
| 51 | |
| 52 | protected: |
| 53 | brillo::ErrorPtr err_; |
| 54 | |
| 55 | base::ScopedTempDir scoped_temp_dir_; |
| 56 | |
| 57 | base::FilePath testdata_path_; |
| 58 | base::FilePath manifest_path_; |
| 59 | base::FilePath preloaded_content_path_; |
| 60 | base::FilePath content_path_; |
Amin Hassani | fe63fc2 | 2020-04-07 11:34:34 -0700 | [diff] [blame] | 61 | base::FilePath prefs_path_; |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 62 | base::FilePath mount_path_; |
| 63 | |
| 64 | using ImageLoaderProxyMock = org::chromium::ImageLoaderInterfaceProxyMock; |
| 65 | std::unique_ptr<ImageLoaderProxyMock> mock_image_loader_proxy_; |
| 66 | ImageLoaderProxyMock* mock_image_loader_proxy_ptr_; |
| 67 | |
| 68 | using UpdateEngineProxyMock = org::chromium::UpdateEngineInterfaceProxyMock; |
| 69 | std::unique_ptr<UpdateEngineProxyMock> mock_update_engine_proxy_; |
| 70 | UpdateEngineProxyMock* mock_update_engine_proxy_ptr_; |
| 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(BaseTest); |
| 74 | }; |
| 75 | |
| 76 | } // namespace dlcservice |
| 77 | |
| 78 | #endif // DLCSERVICE_TEST_UTILS_H_ |