Commit 9195e49f authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

arcvm: Move FakeCrosConfig

Move the FakeCrosConfig class into its own .cc/.h files so that it can
be used by other tests and fuzzers.

Bug: b:148803654
Test: components_unittests --gtest_filter=ArcPropertyUtilTest.*
Change-Id: I3bddeff8d55fe741290e5c766703b574c9d8bf58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2163729Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762163}
parent 2038d0d7
......@@ -309,6 +309,8 @@ static_library("arc_test_support") {
"test/fake_bluetooth_instance.h",
"test/fake_clipboard_instance.cc",
"test/fake_clipboard_instance.h",
"test/fake_cros_config.cc",
"test/fake_cros_config.h",
"test/fake_file_system_instance.cc",
"test/fake_file_system_instance.h",
"test/fake_intent_helper_instance.cc",
......
......@@ -4,7 +4,6 @@
#include "components/arc/session/arc_property_util.h"
#include <map>
#include <memory>
#include "base/command_line.h"
......@@ -12,6 +11,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/arc/test/fake_cros_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
......@@ -19,34 +19,6 @@ namespace {
constexpr char kCrosConfigPropertiesPath[] = "/arc/build-properties";
class FakeCrosConfig : public arc::CrosConfig {
public:
FakeCrosConfig() = default;
~FakeCrosConfig() override = default;
FakeCrosConfig(const FakeCrosConfig&) = delete;
FakeCrosConfig& operator=(const FakeCrosConfig&) = delete;
bool GetString(const std::string& path,
const std::string& property,
std::string* val_out) override {
auto it = overrides_.find(property);
if (it != overrides_.end()) {
*val_out = it->second;
return true;
}
return arc::CrosConfig::GetString(path, property, val_out);
}
void SetString(const std::string& path,
const std::string& property,
const std::string& value) {
overrides_.emplace(property, value);
}
private:
std::map<std::string, std::string> overrides_;
};
class ArcPropertyUtilTest : public testing::Test {
public:
ArcPropertyUtilTest() = default;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/arc/test/fake_cros_config.h"
namespace arc {
FakeCrosConfig::FakeCrosConfig() = default;
FakeCrosConfig::~FakeCrosConfig() = default;
bool FakeCrosConfig::GetString(const std::string& path,
const std::string& property,
std::string* val_out) {
auto it = overrides_.find(property);
if (it != overrides_.end()) {
*val_out = it->second;
return true;
}
return arc::CrosConfig::GetString(path, property, val_out);
}
void FakeCrosConfig::SetString(const std::string& path,
const std::string& property,
const std::string& value) {
overrides_.emplace(property, value);
}
} // namespace arc
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ARC_TEST_FAKE_CROS_CONFIG_H_
#define COMPONENTS_ARC_TEST_FAKE_CROS_CONFIG_H_
#include <map>
#include <string>
#include "components/arc/session/arc_property_util.h"
namespace arc {
// A fake arc::CrosConfig used for testing.
class FakeCrosConfig : public arc::CrosConfig {
public:
FakeCrosConfig();
~FakeCrosConfig() override;
FakeCrosConfig(const FakeCrosConfig&) = delete;
FakeCrosConfig& operator=(const FakeCrosConfig&) = delete;
// arc::CrosConfig:
bool GetString(const std::string& path,
const std::string& property,
std::string* val_out) override;
// Sets the value of a property specified by |path| and |property| to |value|.
void SetString(const std::string& path,
const std::string& property,
const std::string& value);
private:
// A map of overridden properties to their values.
std::map<std::string, std::string> overrides_;
};
} // namespace arc
#endif // COMPONENTS_ARC_TEST_FAKE_CROS_CONFIG_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment