summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2015-12-10 10:49:40 -0800
committerAlex Vakulenko <avakulenko@google.com>2015-12-10 10:49:40 -0800
commitdaea81b234ad10d0ecd0410521e517fa89f7b2e0 (patch)
tree55e9e63bd462848fb41c1ca43f5fd424172b98f3
parentd0eca9d166717a07605c7080f9d859a2f09bd4ef (diff)
downloaddbus-binding-generator-daea81b234ad10d0ecd0410521e517fa89f7b2e0.tar.gz
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
-rw-r--r--chromeos-dbus-bindings/proxy_generator.cc34
-rw-r--r--chromeos-dbus-bindings/proxy_generator.h1
-rw-r--r--chromeos-dbus-bindings/proxy_generator_mock_unittest.cc3
-rw-r--r--chromeos-dbus-bindings/proxy_generator_unittest.cc5
4 files changed, 33 insertions, 10 deletions
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 @@ void ProxyGenerator::GenerateInterfaceProxyInterface(
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 @@ void ProxyGenerator::GenerateInterfaceProxy(const ServiceConfig& config,
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 @@ void ProxyGenerator::GenerateInterfaceMock(const ServiceConfig& config,
}
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 @@ void ProxyGenerator::AddGetObjectProxy(IndentedText* text) {
// 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 @@ class ProxyGenerator : public HeaderGenerator {
// 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 @@ class TestInterface2ProxyMock : public TestInterface2ProxyInterface {
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 @@ TEST_F(ProxyGeneratorMockTest, GenerateMocks) {
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 @@ class Itf1ProxyInterface {
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 @@ class Itf1Proxy final : public Itf1ProxyInterface {
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;
}