123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #ifndef UPDATE_ENGINE_FAKE_P2P_MANAGER_CONFIGURATION_H_
- #define UPDATE_ENGINE_FAKE_P2P_MANAGER_CONFIGURATION_H_
- #include "update_engine/p2p_manager.h"
- #include <string>
- #include <vector>
- #include <base/files/scoped_temp_dir.h>
- #include <base/strings/string_util.h>
- #include <gtest/gtest.h>
- namespace chromeos_update_engine {
- class FakeP2PManagerConfiguration : public P2PManager::Configuration {
- public:
- FakeP2PManagerConfiguration() { EXPECT_TRUE(p2p_dir_.CreateUniqueTempDir()); }
-
- base::FilePath GetP2PDir() override { return p2p_dir_.GetPath(); }
-
- std::vector<std::string> GetInitctlArgs(bool is_start) override {
- return is_start ? initctl_start_args_ : initctl_stop_args_;
- }
-
- std::vector<std::string> GetP2PClientArgs(const std::string& file_id,
- size_t minimum_size) override {
- std::vector<std::string> formatted_command = p2p_client_cmd_format_;
-
- std::string str_minimum_size = std::to_string(minimum_size);
- for (std::string& arg : formatted_command) {
- base::ReplaceSubstringsAfterOffset(&arg, 0, "{file_id}", file_id);
- base::ReplaceSubstringsAfterOffset(
- &arg, 0, "{minsize}", str_minimum_size);
- }
- return formatted_command;
- }
-
-
- void SetInitctlStartCommand(const std::vector<std::string>& command) {
- initctl_start_args_ = command;
- }
-
-
- void SetInitctlStopCommand(const std::vector<std::string>& command) {
- initctl_stop_args_ = command;
- }
-
-
-
-
-
-
-
- void SetP2PClientCommand(const std::vector<std::string>& command_format) {
- p2p_client_cmd_format_ = command_format;
- }
- private:
-
- base::ScopedTempDir p2p_dir_;
-
- std::vector<std::string> initctl_start_args_{"initctl", "start", "p2p"};
-
- std::vector<std::string> initctl_stop_args_{"initctl", "stop", "p2p"};
-
-
- std::vector<std::string> p2p_client_cmd_format_{
- "p2p-client", "--get-url={file_id}", "--minimum-size={minsize}"};
- DISALLOW_COPY_AND_ASSIGN(FakeP2PManagerConfiguration);
- };
- }
- #endif
|