Move SetPropertyChangedCallback to proxy interface and add a mock
Moved the declaration of SetPropertyChangedCallback() to D-Bus proxy
interface so this method can be used with an interface as well as
mocked out properly.
BUG: 26092352
Change-Id: Id6077eaacaac13672e5ce02614fd7574b2397150
diff --git a/chromeos-dbus-bindings/proxy_generator.cc b/chromeos-dbus-bindings/proxy_generator.cc
index 8bcc5cb..3a9cce1 100644
--- a/chromeos-dbus-bindings/proxy_generator.cc
+++ b/chromeos-dbus-bindings/proxy_generator.cc
@@ -213,6 +213,8 @@
AddProperties(config, interface, true, text);
text->AddBlankLine();
text->AddLine("virtual const dbus::ObjectPath& GetObjectPath() const = 0;");
+ if (!config.object_manager.name.empty() && !interface.properties.empty())
+ AddPropertyPublicMethods(proxy_name, true, text);
text->PopOffset();
text->AddLine("};");
@@ -250,7 +252,7 @@
AddGetObjectPath(text);
AddGetObjectProxy(text);
if (!config.object_manager.name.empty() && !interface.properties.empty())
- AddPropertyPublicMethods(proxy_name, text);
+ AddPropertyPublicMethods(proxy_name, false, text);
for (const auto& method : interface.methods) {
AddMethodProxy(method, interface.name, false, text);
AddAsyncMethodProxy(method, interface.name, false, text);
@@ -349,6 +351,14 @@
}
text->AddLine(
"MOCK_CONST_METHOD0(GetObjectPath, const dbus::ObjectPath&());");
+ if (!config.object_manager.name.empty() && !interface.properties.empty()) {
+ text->AddLineAndPushOffsetTo(
+ "MOCK_CONST_METHOD1(SetPropertyChangedCallback,", 1, '(');
+ text->AddLine(StringPrintf(
+ "void(const base::Callback<void(%sInterface*, const std::string&)>&));",
+ proxy_name.c_str()));
+ text->PopOffset();
+ }
text->PopOffset();
text->AddBlankLine();
@@ -440,20 +450,26 @@
// static
void ProxyGenerator::AddPropertyPublicMethods(const string& class_name,
+ bool declaration_only,
IndentedText* text) {
text->AddBlankLine();
- text->AddLine("void SetPropertyChangedCallback(");
+ text->AddLine(StringPrintf("%svoid SetPropertyChangedCallback(",
+ declaration_only ? "virtual " : ""));
text->AddLineWithOffset(
StringPrintf("const base::Callback<void(%sInterface*, "
- "const std::string&)>& callback) {", class_name.c_str()),
+ "const std::string&)>& callback) %s",
+ class_name.c_str(),
+ declaration_only ? "= 0;" : "override {"),
kLineContinuationOffset);
- text->AddLineWithOffset("on_property_changed_ = callback;", kBlockOffset);
- text->AddLine("}");
- text->AddBlankLine();
+ if (!declaration_only) {
+ text->AddLineWithOffset("on_property_changed_ = callback;", kBlockOffset);
+ text->AddLine("}");
+ text->AddBlankLine();
- text->AddLine("const PropertySet* GetProperties() const "
- "{ return property_set_; }");
- text->AddLine("PropertySet* GetProperties() { return property_set_; }");
+ text->AddLine(
+ "const PropertySet* GetProperties() const { return property_set_; }");
+ text->AddLine("PropertySet* GetProperties() { return property_set_; }");
+ }
}
// static
diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h
index d6cfbaf..57af0e0 100644
--- a/chromeos-dbus-bindings/proxy_generator.h
+++ b/chromeos-dbus-bindings/proxy_generator.h
@@ -75,6 +75,7 @@
// Generates SetPropertyChangedCallback/GetProperties() methods.
static void AddPropertyPublicMethods(const std::string& class_name,
+ bool declaration_only,
IndentedText* text);
// Generates OnPropertyChanged() method.
diff --git a/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc b/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
index 692ca84..6ba24ca 100644
--- a/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
+++ b/chromeos-dbus-bindings/proxy_generator_mock_unittest.cc
@@ -152,6 +152,8 @@
MOCK_CONST_METHOD0(name, const std::string&());
MOCK_METHOD2(set_name, void(const std::string&, const base::Callback<bool>&));
MOCK_CONST_METHOD0(GetObjectPath, const dbus::ObjectPath&());
+ MOCK_CONST_METHOD1(SetPropertyChangedCallback,
+ void(const base::Callback<void(TestInterface2ProxyInterface*, const std::string&)>&));
private:
DISALLOW_COPY_AND_ASSIGN(TestInterface2ProxyMock);
@@ -235,6 +237,7 @@
base::FilePath output_path = temp_dir_.path().Append("output.h");
base::FilePath proxy_path = temp_dir_.path().Append("proxies.h");
ServiceConfig config;
+ config.object_manager.name = "ObjectManager";
EXPECT_TRUE(ProxyGenerator::GenerateMocks(config, interfaces, output_path,
proxy_path, false));
string contents;
diff --git a/chromeos-dbus-bindings/proxy_generator_unittest.cc b/chromeos-dbus-bindings/proxy_generator_unittest.cc
index 63ac43b..4eda77c 100644
--- a/chromeos-dbus-bindings/proxy_generator_unittest.cc
+++ b/chromeos-dbus-bindings/proxy_generator_unittest.cc
@@ -596,6 +596,9 @@
const base::Callback<void(bool)>& callback) = 0;
virtual const dbus::ObjectPath& GetObjectPath() const = 0;
+
+ virtual void SetPropertyChangedCallback(
+ const base::Callback<void(Itf1ProxyInterface*, const std::string&)>& callback) = 0;
};
} // namespace chromium
@@ -661,7 +664,7 @@
dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
void SetPropertyChangedCallback(
- const base::Callback<void(Itf1ProxyInterface*, const std::string&)>& callback) {
+ const base::Callback<void(Itf1ProxyInterface*, const std::string&)>& callback) override {
on_property_changed_ = callback;
}