Home | History | Annotate | Download | only in chromeos-dbus-bindings
      1 // Copyright 2014 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 #include "chromeos-dbus-bindings/proxy_generator.h"
      6 
      7 #include <string>
      8 #include <vector>
      9 
     10 #include <base/files/file_path.h>
     11 #include <base/files/file_util.h>
     12 #include <base/files/scoped_temp_dir.h>
     13 #include <gtest/gtest.h>
     14 
     15 #include "chromeos-dbus-bindings/interface.h"
     16 #include "chromeos-dbus-bindings/test_utils.h"
     17 
     18 using std::string;
     19 using std::vector;
     20 using testing::Test;
     21 
     22 namespace chromeos_dbus_bindings {
     23 
     24 namespace {
     25 
     26 const char kDBusTypeArryOfObjects[] = "ao";
     27 const char kDBusTypeArryOfStrings[] = "as";
     28 const char kDBusTypeBool[] = "b";
     29 const char kDBusTypeByte[] = "y";
     30 const char kDBusTypeInt32[] = "i";
     31 const char kDBusTypeInt64[] = "x";
     32 const char kDBusTypeString[] = "s";
     33 
     34 const char kExpectedContent[] = R"literal_string(
     35 #include <memory>
     36 #include <string>
     37 #include <vector>
     38 
     39 #include <base/bind.h>
     40 #include <base/callback.h>
     41 #include <base/logging.h>
     42 #include <base/macros.h>
     43 #include <base/memory/ref_counted.h>
     44 #include <brillo/any.h>
     45 #include <brillo/dbus/dbus_method_invoker.h>
     46 #include <brillo/dbus/dbus_property.h>
     47 #include <brillo/dbus/dbus_signal_handler.h>
     48 #include <brillo/errors/error.h>
     49 #include <brillo/variant_dictionary.h>
     50 #include <dbus/bus.h>
     51 #include <dbus/message.h>
     52 #include <dbus/object_manager.h>
     53 #include <dbus/object_path.h>
     54 #include <dbus/object_proxy.h>
     55 
     56 namespace org {
     57 namespace chromium {
     58 
     59 // Abstract interface proxy for org::chromium::TestInterface.
     60 class TestInterfaceProxyInterface {
     61  public:
     62   virtual ~TestInterfaceProxyInterface() = default;
     63 
     64   virtual bool Elements(
     65       const std::string& in_space_walk,
     66       const std::vector<dbus::ObjectPath>& in_ramblin_man,
     67       std::string* out_3,
     68       brillo::ErrorPtr* error,
     69       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     70 
     71   virtual void ElementsAsync(
     72       const std::string& in_space_walk,
     73       const std::vector<dbus::ObjectPath>& in_ramblin_man,
     74       const base::Callback<void(const std::string&)>& success_callback,
     75       const base::Callback<void(brillo::Error*)>& error_callback,
     76       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     77 
     78   virtual bool ReturnToPatagonia(
     79       int64_t* out_1,
     80       brillo::ErrorPtr* error,
     81       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     82 
     83   virtual void ReturnToPatagoniaAsync(
     84       const base::Callback<void(int64_t)>& success_callback,
     85       const base::Callback<void(brillo::Error*)>& error_callback,
     86       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     87 
     88   virtual bool NiceWeatherForDucks(
     89       bool in_1,
     90       brillo::ErrorPtr* error,
     91       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     92 
     93   virtual void NiceWeatherForDucksAsync(
     94       bool in_1,
     95       const base::Callback<void()>& success_callback,
     96       const base::Callback<void(brillo::Error*)>& error_callback,
     97       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
     98 
     99   // Comment line1
    100   // line2
    101   virtual bool ExperimentNumberSix(
    102       brillo::ErrorPtr* error,
    103       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
    104 
    105   // Comment line1
    106   // line2
    107   virtual void ExperimentNumberSixAsync(
    108       const base::Callback<void()>& success_callback,
    109       const base::Callback<void(brillo::Error*)>& error_callback,
    110       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
    111 
    112   virtual void RegisterCloserSignalHandler(
    113       const base::Closure& signal_callback,
    114       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
    115 
    116   virtual void RegisterTheCurseOfKaZarSignalHandler(
    117       const base::Callback<void(const std::vector<std::string>&,
    118                                 uint8_t)>& signal_callback,
    119       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
    120 
    121   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    122 };
    123 
    124 }  // namespace chromium
    125 }  // namespace org
    126 
    127 namespace org {
    128 namespace chromium {
    129 
    130 // Interface proxy for org::chromium::TestInterface.
    131 class TestInterfaceProxy final : public TestInterfaceProxyInterface {
    132  public:
    133   TestInterfaceProxy(
    134       const scoped_refptr<dbus::Bus>& bus,
    135       const std::string& service_name) :
    136           bus_{bus},
    137           service_name_{service_name},
    138           dbus_object_proxy_{
    139               bus_->GetObjectProxy(service_name_, object_path_)} {
    140   }
    141 
    142   ~TestInterfaceProxy() override {
    143   }
    144 
    145   void RegisterCloserSignalHandler(
    146       const base::Closure& signal_callback,
    147       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override {
    148     brillo::dbus_utils::ConnectToSignal(
    149         dbus_object_proxy_,
    150         "org.chromium.TestInterface",
    151         "Closer",
    152         signal_callback,
    153         on_connected_callback);
    154   }
    155 
    156   void RegisterTheCurseOfKaZarSignalHandler(
    157       const base::Callback<void(const std::vector<std::string>&,
    158                                 uint8_t)>& signal_callback,
    159       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override {
    160     brillo::dbus_utils::ConnectToSignal(
    161         dbus_object_proxy_,
    162         "org.chromium.TestInterface",
    163         "TheCurseOfKaZar",
    164         signal_callback,
    165         on_connected_callback);
    166   }
    167 
    168   void ReleaseObjectProxy(const base::Closure& callback) {
    169     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    170   }
    171 
    172   const dbus::ObjectPath& GetObjectPath() const override {
    173     return object_path_;
    174   }
    175 
    176   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    177 
    178   bool Elements(
    179       const std::string& in_space_walk,
    180       const std::vector<dbus::ObjectPath>& in_ramblin_man,
    181       std::string* out_3,
    182       brillo::ErrorPtr* error,
    183       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    184     auto response = brillo::dbus_utils::CallMethodAndBlockWithTimeout(
    185         timeout_ms,
    186         dbus_object_proxy_,
    187         "org.chromium.TestInterface",
    188         "Elements",
    189         error,
    190         in_space_walk,
    191         in_ramblin_man);
    192     return response && brillo::dbus_utils::ExtractMethodCallResults(
    193         response.get(), error, out_3);
    194   }
    195 
    196   void ElementsAsync(
    197       const std::string& in_space_walk,
    198       const std::vector<dbus::ObjectPath>& in_ramblin_man,
    199       const base::Callback<void(const std::string&)>& success_callback,
    200       const base::Callback<void(brillo::Error*)>& error_callback,
    201       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    202     brillo::dbus_utils::CallMethodWithTimeout(
    203         timeout_ms,
    204         dbus_object_proxy_,
    205         "org.chromium.TestInterface",
    206         "Elements",
    207         success_callback,
    208         error_callback,
    209         in_space_walk,
    210         in_ramblin_man);
    211   }
    212 
    213   bool ReturnToPatagonia(
    214       int64_t* out_1,
    215       brillo::ErrorPtr* error,
    216       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    217     auto response = brillo::dbus_utils::CallMethodAndBlockWithTimeout(
    218         timeout_ms,
    219         dbus_object_proxy_,
    220         "org.chromium.TestInterface",
    221         "ReturnToPatagonia",
    222         error);
    223     return response && brillo::dbus_utils::ExtractMethodCallResults(
    224         response.get(), error, out_1);
    225   }
    226 
    227   void ReturnToPatagoniaAsync(
    228       const base::Callback<void(int64_t)>& success_callback,
    229       const base::Callback<void(brillo::Error*)>& error_callback,
    230       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    231     brillo::dbus_utils::CallMethodWithTimeout(
    232         timeout_ms,
    233         dbus_object_proxy_,
    234         "org.chromium.TestInterface",
    235         "ReturnToPatagonia",
    236         success_callback,
    237         error_callback);
    238   }
    239 
    240   bool NiceWeatherForDucks(
    241       bool in_1,
    242       brillo::ErrorPtr* error,
    243       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    244     auto response = brillo::dbus_utils::CallMethodAndBlockWithTimeout(
    245         timeout_ms,
    246         dbus_object_proxy_,
    247         "org.chromium.TestInterface",
    248         "NiceWeatherForDucks",
    249         error,
    250         in_1);
    251     return response && brillo::dbus_utils::ExtractMethodCallResults(
    252         response.get(), error);
    253   }
    254 
    255   void NiceWeatherForDucksAsync(
    256       bool in_1,
    257       const base::Callback<void()>& success_callback,
    258       const base::Callback<void(brillo::Error*)>& error_callback,
    259       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    260     brillo::dbus_utils::CallMethodWithTimeout(
    261         timeout_ms,
    262         dbus_object_proxy_,
    263         "org.chromium.TestInterface",
    264         "NiceWeatherForDucks",
    265         success_callback,
    266         error_callback,
    267         in_1);
    268   }
    269 
    270   // Comment line1
    271   // line2
    272   bool ExperimentNumberSix(
    273       brillo::ErrorPtr* error,
    274       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    275     auto response = brillo::dbus_utils::CallMethodAndBlockWithTimeout(
    276         timeout_ms,
    277         dbus_object_proxy_,
    278         "org.chromium.TestInterface",
    279         "ExperimentNumberSix",
    280         error);
    281     return response && brillo::dbus_utils::ExtractMethodCallResults(
    282         response.get(), error);
    283   }
    284 
    285   // Comment line1
    286   // line2
    287   void ExperimentNumberSixAsync(
    288       const base::Callback<void()>& success_callback,
    289       const base::Callback<void(brillo::Error*)>& error_callback,
    290       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    291     brillo::dbus_utils::CallMethodWithTimeout(
    292         timeout_ms,
    293         dbus_object_proxy_,
    294         "org.chromium.TestInterface",
    295         "ExperimentNumberSix",
    296         success_callback,
    297         error_callback);
    298   }
    299 
    300  private:
    301   scoped_refptr<dbus::Bus> bus_;
    302   std::string service_name_;
    303   const dbus::ObjectPath object_path_{"/org/chromium/Test"};
    304   dbus::ObjectProxy* dbus_object_proxy_;
    305 
    306   DISALLOW_COPY_AND_ASSIGN(TestInterfaceProxy);
    307 };
    308 
    309 }  // namespace chromium
    310 }  // namespace org
    311 
    312 namespace org {
    313 namespace chromium {
    314 
    315 // Abstract interface proxy for org::chromium::TestInterface2.
    316 class TestInterface2ProxyInterface {
    317  public:
    318   virtual ~TestInterface2ProxyInterface() = default;
    319 
    320   virtual bool GetPersonInfo(
    321       std::string* out_name,
    322       int32_t* out_age,
    323       brillo::ErrorPtr* error,
    324       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
    325 
    326   virtual void GetPersonInfoAsync(
    327       const base::Callback<void(const std::string& /*name*/, int32_t /*age*/)>& success_callback,
    328       const base::Callback<void(brillo::Error*)>& error_callback,
    329       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) = 0;
    330 
    331   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    332 };
    333 
    334 }  // namespace chromium
    335 }  // namespace org
    336 
    337 namespace org {
    338 namespace chromium {
    339 
    340 // Interface proxy for org::chromium::TestInterface2.
    341 class TestInterface2Proxy final : public TestInterface2ProxyInterface {
    342  public:
    343   TestInterface2Proxy(
    344       const scoped_refptr<dbus::Bus>& bus,
    345       const std::string& service_name,
    346       const dbus::ObjectPath& object_path) :
    347           bus_{bus},
    348           service_name_{service_name},
    349           object_path_{object_path},
    350           dbus_object_proxy_{
    351               bus_->GetObjectProxy(service_name_, object_path_)} {
    352   }
    353 
    354   ~TestInterface2Proxy() override {
    355   }
    356 
    357   void ReleaseObjectProxy(const base::Closure& callback) {
    358     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    359   }
    360 
    361   const dbus::ObjectPath& GetObjectPath() const override {
    362     return object_path_;
    363   }
    364 
    365   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    366 
    367   bool GetPersonInfo(
    368       std::string* out_name,
    369       int32_t* out_age,
    370       brillo::ErrorPtr* error,
    371       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    372     auto response = brillo::dbus_utils::CallMethodAndBlockWithTimeout(
    373         timeout_ms,
    374         dbus_object_proxy_,
    375         "org.chromium.TestInterface2",
    376         "GetPersonInfo",
    377         error);
    378     return response && brillo::dbus_utils::ExtractMethodCallResults(
    379         response.get(), error, out_name, out_age);
    380   }
    381 
    382   void GetPersonInfoAsync(
    383       const base::Callback<void(const std::string& /*name*/, int32_t /*age*/)>& success_callback,
    384       const base::Callback<void(brillo::Error*)>& error_callback,
    385       int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) override {
    386     brillo::dbus_utils::CallMethodWithTimeout(
    387         timeout_ms,
    388         dbus_object_proxy_,
    389         "org.chromium.TestInterface2",
    390         "GetPersonInfo",
    391         success_callback,
    392         error_callback);
    393   }
    394 
    395  private:
    396   scoped_refptr<dbus::Bus> bus_;
    397   std::string service_name_;
    398   dbus::ObjectPath object_path_;
    399   dbus::ObjectProxy* dbus_object_proxy_;
    400 
    401   DISALLOW_COPY_AND_ASSIGN(TestInterface2Proxy);
    402 };
    403 
    404 }  // namespace chromium
    405 }  // namespace org
    406 )literal_string";
    407 
    408 const char kExpectedContentWithService[] = R"literal_string(
    409 #include <memory>
    410 #include <string>
    411 #include <vector>
    412 
    413 #include <base/bind.h>
    414 #include <base/callback.h>
    415 #include <base/logging.h>
    416 #include <base/macros.h>
    417 #include <base/memory/ref_counted.h>
    418 #include <brillo/any.h>
    419 #include <brillo/dbus/dbus_method_invoker.h>
    420 #include <brillo/dbus/dbus_property.h>
    421 #include <brillo/dbus/dbus_signal_handler.h>
    422 #include <brillo/errors/error.h>
    423 #include <brillo/variant_dictionary.h>
    424 #include <dbus/bus.h>
    425 #include <dbus/message.h>
    426 #include <dbus/object_manager.h>
    427 #include <dbus/object_path.h>
    428 #include <dbus/object_proxy.h>
    429 
    430 namespace org {
    431 namespace chromium {
    432 
    433 // Abstract interface proxy for org::chromium::TestInterface.
    434 class TestInterfaceProxyInterface {
    435  public:
    436   virtual ~TestInterfaceProxyInterface() = default;
    437 
    438   virtual void RegisterCloserSignalHandler(
    439       const base::Closure& signal_callback,
    440       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
    441 
    442   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    443 };
    444 
    445 }  // namespace chromium
    446 }  // namespace org
    447 
    448 namespace org {
    449 namespace chromium {
    450 
    451 // Interface proxy for org::chromium::TestInterface.
    452 class TestInterfaceProxy final : public TestInterfaceProxyInterface {
    453  public:
    454   TestInterfaceProxy(const scoped_refptr<dbus::Bus>& bus) :
    455       bus_{bus},
    456       dbus_object_proxy_{
    457           bus_->GetObjectProxy(service_name_, object_path_)} {
    458   }
    459 
    460   ~TestInterfaceProxy() override {
    461   }
    462 
    463   void RegisterCloserSignalHandler(
    464       const base::Closure& signal_callback,
    465       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override {
    466     brillo::dbus_utils::ConnectToSignal(
    467         dbus_object_proxy_,
    468         "org.chromium.TestInterface",
    469         "Closer",
    470         signal_callback,
    471         on_connected_callback);
    472   }
    473 
    474   void ReleaseObjectProxy(const base::Closure& callback) {
    475     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    476   }
    477 
    478   const dbus::ObjectPath& GetObjectPath() const override {
    479     return object_path_;
    480   }
    481 
    482   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    483 
    484  private:
    485   scoped_refptr<dbus::Bus> bus_;
    486   const std::string service_name_{"org.chromium.Test"};
    487   const dbus::ObjectPath object_path_{"/org/chromium/Test"};
    488   dbus::ObjectProxy* dbus_object_proxy_;
    489 
    490   DISALLOW_COPY_AND_ASSIGN(TestInterfaceProxy);
    491 };
    492 
    493 }  // namespace chromium
    494 }  // namespace org
    495 
    496 namespace org {
    497 namespace chromium {
    498 
    499 // Abstract interface proxy for org::chromium::TestInterface2.
    500 class TestInterface2ProxyInterface {
    501  public:
    502   virtual ~TestInterface2ProxyInterface() = default;
    503 
    504   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    505 };
    506 
    507 }  // namespace chromium
    508 }  // namespace org
    509 
    510 namespace org {
    511 namespace chromium {
    512 
    513 // Interface proxy for org::chromium::TestInterface2.
    514 class TestInterface2Proxy final : public TestInterface2ProxyInterface {
    515  public:
    516   TestInterface2Proxy(
    517       const scoped_refptr<dbus::Bus>& bus,
    518       const dbus::ObjectPath& object_path) :
    519           bus_{bus},
    520           object_path_{object_path},
    521           dbus_object_proxy_{
    522               bus_->GetObjectProxy(service_name_, object_path_)} {
    523   }
    524 
    525   ~TestInterface2Proxy() override {
    526   }
    527 
    528   void ReleaseObjectProxy(const base::Closure& callback) {
    529     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    530   }
    531 
    532   const dbus::ObjectPath& GetObjectPath() const override {
    533     return object_path_;
    534   }
    535 
    536   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    537 
    538  private:
    539   scoped_refptr<dbus::Bus> bus_;
    540   const std::string service_name_{"org.chromium.Test"};
    541   dbus::ObjectPath object_path_;
    542   dbus::ObjectProxy* dbus_object_proxy_;
    543 
    544   DISALLOW_COPY_AND_ASSIGN(TestInterface2Proxy);
    545 };
    546 
    547 }  // namespace chromium
    548 }  // namespace org
    549 )literal_string";
    550 
    551 const char kExpectedContentWithObjectManager[] = R"literal_string(
    552 #include <memory>
    553 #include <string>
    554 #include <vector>
    555 
    556 #include <base/bind.h>
    557 #include <base/callback.h>
    558 #include <base/logging.h>
    559 #include <base/macros.h>
    560 #include <base/memory/ref_counted.h>
    561 #include <brillo/any.h>
    562 #include <brillo/dbus/dbus_method_invoker.h>
    563 #include <brillo/dbus/dbus_property.h>
    564 #include <brillo/dbus/dbus_signal_handler.h>
    565 #include <brillo/errors/error.h>
    566 #include <brillo/variant_dictionary.h>
    567 #include <dbus/bus.h>
    568 #include <dbus/message.h>
    569 #include <dbus/object_manager.h>
    570 #include <dbus/object_path.h>
    571 #include <dbus/object_proxy.h>
    572 
    573 namespace org {
    574 namespace chromium {
    575 class ObjectManagerProxy;
    576 }  // namespace chromium
    577 }  // namespace org
    578 
    579 namespace org {
    580 namespace chromium {
    581 
    582 // Abstract interface proxy for org::chromium::Itf1.
    583 class Itf1ProxyInterface {
    584  public:
    585   virtual ~Itf1ProxyInterface() = default;
    586 
    587   virtual void RegisterCloserSignalHandler(
    588       const base::Closure& signal_callback,
    589       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
    590 
    591   static const char* DataName() { return "Data"; }
    592   virtual const std::string& data() const = 0;
    593   static const char* NameName() { return "Name"; }
    594   virtual const std::string& name() const = 0;
    595   virtual void set_name(const std::string& value,
    596                         const base::Callback<void(bool)>& callback) = 0;
    597 
    598   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    599 
    600   virtual void SetPropertyChangedCallback(
    601       const base::Callback<void(Itf1ProxyInterface*, const std::string&)>& callback) = 0;
    602 };
    603 
    604 }  // namespace chromium
    605 }  // namespace org
    606 
    607 namespace org {
    608 namespace chromium {
    609 
    610 // Interface proxy for org::chromium::Itf1.
    611 class Itf1Proxy final : public Itf1ProxyInterface {
    612  public:
    613   class PropertySet : public dbus::PropertySet {
    614    public:
    615     PropertySet(dbus::ObjectProxy* object_proxy,
    616                 const PropertyChangedCallback& callback)
    617         : dbus::PropertySet{object_proxy,
    618                             "org.chromium.Itf1",
    619                             callback} {
    620       RegisterProperty(DataName(), &data);
    621       RegisterProperty(NameName(), &name);
    622     }
    623 
    624     brillo::dbus_utils::Property<std::string> data;
    625     brillo::dbus_utils::Property<std::string> name;
    626 
    627    private:
    628     DISALLOW_COPY_AND_ASSIGN(PropertySet);
    629   };
    630 
    631   Itf1Proxy(
    632       const scoped_refptr<dbus::Bus>& bus,
    633       const std::string& service_name,
    634       PropertySet* property_set) :
    635           bus_{bus},
    636           service_name_{service_name},
    637           property_set_{property_set},
    638           dbus_object_proxy_{
    639               bus_->GetObjectProxy(service_name_, object_path_)} {
    640   }
    641 
    642   ~Itf1Proxy() override {
    643   }
    644 
    645   void RegisterCloserSignalHandler(
    646       const base::Closure& signal_callback,
    647       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override {
    648     brillo::dbus_utils::ConnectToSignal(
    649         dbus_object_proxy_,
    650         "org.chromium.Itf1",
    651         "Closer",
    652         signal_callback,
    653         on_connected_callback);
    654   }
    655 
    656   void ReleaseObjectProxy(const base::Closure& callback) {
    657     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    658   }
    659 
    660   const dbus::ObjectPath& GetObjectPath() const override {
    661     return object_path_;
    662   }
    663 
    664   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    665 
    666   void SetPropertyChangedCallback(
    667       const base::Callback<void(Itf1ProxyInterface*, const std::string&)>& callback) override {
    668     on_property_changed_ = callback;
    669   }
    670 
    671   const PropertySet* GetProperties() const { return property_set_; }
    672   PropertySet* GetProperties() { return property_set_; }
    673 
    674   const std::string& data() const override {
    675     return property_set_->data.value();
    676   }
    677 
    678   const std::string& name() const override {
    679     return property_set_->name.value();
    680   }
    681 
    682   void set_name(const std::string& value,
    683                 const base::Callback<void(bool)>& callback) override {
    684     property_set_->name.Set(value, callback);
    685   }
    686 
    687  private:
    688   void OnPropertyChanged(const std::string& property_name) {
    689     if (!on_property_changed_.is_null())
    690       on_property_changed_.Run(this, property_name);
    691   }
    692 
    693   scoped_refptr<dbus::Bus> bus_;
    694   std::string service_name_;
    695   const dbus::ObjectPath object_path_{"/org/chromium/Test/Object"};
    696   PropertySet* property_set_;
    697   base::Callback<void(Itf1ProxyInterface*, const std::string&)> on_property_changed_;
    698   dbus::ObjectProxy* dbus_object_proxy_;
    699 
    700   friend class org::chromium::ObjectManagerProxy;
    701   DISALLOW_COPY_AND_ASSIGN(Itf1Proxy);
    702 };
    703 
    704 }  // namespace chromium
    705 }  // namespace org
    706 
    707 namespace org {
    708 namespace chromium {
    709 
    710 // Abstract interface proxy for org::chromium::Itf2.
    711 class Itf2ProxyInterface {
    712  public:
    713   virtual ~Itf2ProxyInterface() = default;
    714 
    715   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    716 };
    717 
    718 }  // namespace chromium
    719 }  // namespace org
    720 
    721 namespace org {
    722 namespace chromium {
    723 
    724 // Interface proxy for org::chromium::Itf2.
    725 class Itf2Proxy final : public Itf2ProxyInterface {
    726  public:
    727   class PropertySet : public dbus::PropertySet {
    728    public:
    729     PropertySet(dbus::ObjectProxy* object_proxy,
    730                 const PropertyChangedCallback& callback)
    731         : dbus::PropertySet{object_proxy,
    732                             "org.chromium.Itf2",
    733                             callback} {
    734     }
    735 
    736 
    737    private:
    738     DISALLOW_COPY_AND_ASSIGN(PropertySet);
    739   };
    740 
    741   Itf2Proxy(
    742       const scoped_refptr<dbus::Bus>& bus,
    743       const std::string& service_name,
    744       const dbus::ObjectPath& object_path) :
    745           bus_{bus},
    746           service_name_{service_name},
    747           object_path_{object_path},
    748           dbus_object_proxy_{
    749               bus_->GetObjectProxy(service_name_, object_path_)} {
    750   }
    751 
    752   ~Itf2Proxy() override {
    753   }
    754 
    755   void ReleaseObjectProxy(const base::Closure& callback) {
    756     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
    757   }
    758 
    759   const dbus::ObjectPath& GetObjectPath() const override {
    760     return object_path_;
    761   }
    762 
    763   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
    764 
    765  private:
    766   scoped_refptr<dbus::Bus> bus_;
    767   std::string service_name_;
    768   dbus::ObjectPath object_path_;
    769   dbus::ObjectProxy* dbus_object_proxy_;
    770 
    771   DISALLOW_COPY_AND_ASSIGN(Itf2Proxy);
    772 };
    773 
    774 }  // namespace chromium
    775 }  // namespace org
    776 
    777 namespace org {
    778 namespace chromium {
    779 
    780 class ObjectManagerProxy : public dbus::ObjectManager::Interface {
    781  public:
    782   ObjectManagerProxy(const scoped_refptr<dbus::Bus>& bus,
    783                      const std::string& service_name)
    784       : bus_{bus},
    785         service_name_{service_name},
    786         dbus_object_manager_{bus->GetObjectManager(
    787             service_name,
    788             dbus::ObjectPath{"/org/chromium/Test"})} {
    789     dbus_object_manager_->RegisterInterface("org.chromium.Itf1", this);
    790     dbus_object_manager_->RegisterInterface("org.chromium.Itf2", this);
    791   }
    792 
    793   ~ObjectManagerProxy() override {
    794     dbus_object_manager_->UnregisterInterface("org.chromium.Itf1");
    795     dbus_object_manager_->UnregisterInterface("org.chromium.Itf2");
    796   }
    797 
    798   dbus::ObjectManager* GetObjectManagerProxy() const {
    799     return dbus_object_manager_;
    800   }
    801 
    802   org::chromium::Itf1ProxyInterface* GetItf1Proxy() {
    803     if (itf1_instances_.empty())
    804       return nullptr;
    805     return itf1_instances_.begin()->second.get();
    806   }
    807   std::vector<org::chromium::Itf1ProxyInterface*> GetItf1Instances() const {
    808     std::vector<org::chromium::Itf1ProxyInterface*> values;
    809     values.reserve(itf1_instances_.size());
    810     for (const auto& pair : itf1_instances_)
    811       values.push_back(pair.second.get());
    812     return values;
    813   }
    814   void SetItf1AddedCallback(
    815       const base::Callback<void(org::chromium::Itf1ProxyInterface*)>& callback) {
    816     on_itf1_added_ = callback;
    817   }
    818   void SetItf1RemovedCallback(
    819       const base::Callback<void(const dbus::ObjectPath&)>& callback) {
    820     on_itf1_removed_ = callback;
    821   }
    822 
    823   org::chromium::Itf2ProxyInterface* GetItf2Proxy(
    824       const dbus::ObjectPath& object_path) {
    825     auto p = itf2_instances_.find(object_path);
    826     if (p != itf2_instances_.end())
    827       return p->second.get();
    828     return nullptr;
    829   }
    830   std::vector<org::chromium::Itf2ProxyInterface*> GetItf2Instances() const {
    831     std::vector<org::chromium::Itf2ProxyInterface*> values;
    832     values.reserve(itf2_instances_.size());
    833     for (const auto& pair : itf2_instances_)
    834       values.push_back(pair.second.get());
    835     return values;
    836   }
    837   void SetItf2AddedCallback(
    838       const base::Callback<void(org::chromium::Itf2ProxyInterface*)>& callback) {
    839     on_itf2_added_ = callback;
    840   }
    841   void SetItf2RemovedCallback(
    842       const base::Callback<void(const dbus::ObjectPath&)>& callback) {
    843     on_itf2_removed_ = callback;
    844   }
    845 
    846  private:
    847   void OnPropertyChanged(const dbus::ObjectPath& object_path,
    848                          const std::string& interface_name,
    849                          const std::string& property_name) {
    850     if (interface_name == "org.chromium.Itf1") {
    851       auto p = itf1_instances_.find(object_path);
    852       if (p == itf1_instances_.end())
    853         return;
    854       p->second->OnPropertyChanged(property_name);
    855       return;
    856     }
    857   }
    858 
    859   void ObjectAdded(
    860       const dbus::ObjectPath& object_path,
    861       const std::string& interface_name) override {
    862     if (interface_name == "org.chromium.Itf1") {
    863       auto property_set =
    864           static_cast<org::chromium::Itf1Proxy::PropertySet*>(
    865               dbus_object_manager_->GetProperties(object_path, interface_name));
    866       std::unique_ptr<org::chromium::Itf1Proxy> itf1_proxy{
    867         new org::chromium::Itf1Proxy{bus_, service_name_, property_set}
    868       };
    869       auto p = itf1_instances_.emplace(object_path, std::move(itf1_proxy));
    870       if (!on_itf1_added_.is_null())
    871         on_itf1_added_.Run(p.first->second.get());
    872       return;
    873     }
    874     if (interface_name == "org.chromium.Itf2") {
    875       std::unique_ptr<org::chromium::Itf2Proxy> itf2_proxy{
    876         new org::chromium::Itf2Proxy{bus_, service_name_, object_path}
    877       };
    878       auto p = itf2_instances_.emplace(object_path, std::move(itf2_proxy));
    879       if (!on_itf2_added_.is_null())
    880         on_itf2_added_.Run(p.first->second.get());
    881       return;
    882     }
    883   }
    884 
    885   void ObjectRemoved(
    886       const dbus::ObjectPath& object_path,
    887       const std::string& interface_name) override {
    888     if (interface_name == "org.chromium.Itf1") {
    889       auto p = itf1_instances_.find(object_path);
    890       if (p != itf1_instances_.end()) {
    891         if (!on_itf1_removed_.is_null())
    892           on_itf1_removed_.Run(object_path);
    893         itf1_instances_.erase(p);
    894       }
    895       return;
    896     }
    897     if (interface_name == "org.chromium.Itf2") {
    898       auto p = itf2_instances_.find(object_path);
    899       if (p != itf2_instances_.end()) {
    900         if (!on_itf2_removed_.is_null())
    901           on_itf2_removed_.Run(object_path);
    902         itf2_instances_.erase(p);
    903       }
    904       return;
    905     }
    906   }
    907 
    908   dbus::PropertySet* CreateProperties(
    909       dbus::ObjectProxy* object_proxy,
    910       const dbus::ObjectPath& object_path,
    911       const std::string& interface_name) override {
    912     if (interface_name == "org.chromium.Itf1") {
    913       return new org::chromium::Itf1Proxy::PropertySet{
    914           object_proxy,
    915           base::Bind(&ObjectManagerProxy::OnPropertyChanged,
    916                      weak_ptr_factory_.GetWeakPtr(),
    917                      object_path,
    918                      interface_name)
    919       };
    920     }
    921     if (interface_name == "org.chromium.Itf2") {
    922       return new org::chromium::Itf2Proxy::PropertySet{
    923           object_proxy,
    924           base::Bind(&ObjectManagerProxy::OnPropertyChanged,
    925                      weak_ptr_factory_.GetWeakPtr(),
    926                      object_path,
    927                      interface_name)
    928       };
    929     }
    930     LOG(FATAL) << "Creating properties for unsupported interface "
    931                << interface_name;
    932     return nullptr;
    933   }
    934 
    935   scoped_refptr<dbus::Bus> bus_;
    936   std::string service_name_;
    937   dbus::ObjectManager* dbus_object_manager_;
    938   std::map<dbus::ObjectPath,
    939            std::unique_ptr<org::chromium::Itf1Proxy>> itf1_instances_;
    940   base::Callback<void(org::chromium::Itf1ProxyInterface*)> on_itf1_added_;
    941   base::Callback<void(const dbus::ObjectPath&)> on_itf1_removed_;
    942   std::map<dbus::ObjectPath,
    943            std::unique_ptr<org::chromium::Itf2Proxy>> itf2_instances_;
    944   base::Callback<void(org::chromium::Itf2ProxyInterface*)> on_itf2_added_;
    945   base::Callback<void(const dbus::ObjectPath&)> on_itf2_removed_;
    946   base::WeakPtrFactory<ObjectManagerProxy> weak_ptr_factory_{this};
    947 
    948   DISALLOW_COPY_AND_ASSIGN(ObjectManagerProxy);
    949 };
    950 
    951 }  // namespace chromium
    952 }  // namespace org
    953 )literal_string";
    954 
    955 const char kExpectedContentWithObjectManagerAndServiceName[] = R"literal_string(
    956 #include <memory>
    957 #include <string>
    958 #include <vector>
    959 
    960 #include <base/bind.h>
    961 #include <base/callback.h>
    962 #include <base/logging.h>
    963 #include <base/macros.h>
    964 #include <base/memory/ref_counted.h>
    965 #include <brillo/any.h>
    966 #include <brillo/dbus/dbus_method_invoker.h>
    967 #include <brillo/dbus/dbus_property.h>
    968 #include <brillo/dbus/dbus_signal_handler.h>
    969 #include <brillo/errors/error.h>
    970 #include <brillo/variant_dictionary.h>
    971 #include <dbus/bus.h>
    972 #include <dbus/message.h>
    973 #include <dbus/object_manager.h>
    974 #include <dbus/object_path.h>
    975 #include <dbus/object_proxy.h>
    976 
    977 namespace org {
    978 namespace chromium {
    979 class ObjectManagerProxy;
    980 }  // namespace chromium
    981 }  // namespace org
    982 
    983 namespace org {
    984 namespace chromium {
    985 
    986 // Abstract interface proxy for org::chromium::Itf1.
    987 class Itf1ProxyInterface {
    988  public:
    989   virtual ~Itf1ProxyInterface() = default;
    990 
    991   virtual void RegisterCloserSignalHandler(
    992       const base::Closure& signal_callback,
    993       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
    994 
    995   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
    996 };
    997 
    998 }  // namespace chromium
    999 }  // namespace org
   1000 
   1001 namespace org {
   1002 namespace chromium {
   1003 
   1004 // Interface proxy for org::chromium::Itf1.
   1005 class Itf1Proxy final : public Itf1ProxyInterface {
   1006  public:
   1007   class PropertySet : public dbus::PropertySet {
   1008    public:
   1009     PropertySet(dbus::ObjectProxy* object_proxy,
   1010                 const PropertyChangedCallback& callback)
   1011         : dbus::PropertySet{object_proxy,
   1012                             "org.chromium.Itf1",
   1013                             callback} {
   1014     }
   1015 
   1016 
   1017    private:
   1018     DISALLOW_COPY_AND_ASSIGN(PropertySet);
   1019   };
   1020 
   1021   Itf1Proxy(const scoped_refptr<dbus::Bus>& bus) :
   1022       bus_{bus},
   1023       dbus_object_proxy_{
   1024           bus_->GetObjectProxy(service_name_, object_path_)} {
   1025   }
   1026 
   1027   ~Itf1Proxy() override {
   1028   }
   1029 
   1030   void RegisterCloserSignalHandler(
   1031       const base::Closure& signal_callback,
   1032       dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override {
   1033     brillo::dbus_utils::ConnectToSignal(
   1034         dbus_object_proxy_,
   1035         "org.chromium.Itf1",
   1036         "Closer",
   1037         signal_callback,
   1038         on_connected_callback);
   1039   }
   1040 
   1041   void ReleaseObjectProxy(const base::Closure& callback) {
   1042     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
   1043   }
   1044 
   1045   const dbus::ObjectPath& GetObjectPath() const override {
   1046     return object_path_;
   1047   }
   1048 
   1049   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
   1050 
   1051  private:
   1052   scoped_refptr<dbus::Bus> bus_;
   1053   const std::string service_name_{"org.chromium.Test"};
   1054   const dbus::ObjectPath object_path_{"/org/chromium/Test/Object"};
   1055   dbus::ObjectProxy* dbus_object_proxy_;
   1056 
   1057   DISALLOW_COPY_AND_ASSIGN(Itf1Proxy);
   1058 };
   1059 
   1060 }  // namespace chromium
   1061 }  // namespace org
   1062 
   1063 namespace org {
   1064 namespace chromium {
   1065 
   1066 // Abstract interface proxy for org::chromium::Itf2.
   1067 class Itf2ProxyInterface {
   1068  public:
   1069   virtual ~Itf2ProxyInterface() = default;
   1070 
   1071   virtual const dbus::ObjectPath& GetObjectPath() const = 0;
   1072 };
   1073 
   1074 }  // namespace chromium
   1075 }  // namespace org
   1076 
   1077 namespace org {
   1078 namespace chromium {
   1079 
   1080 // Interface proxy for org::chromium::Itf2.
   1081 class Itf2Proxy final : public Itf2ProxyInterface {
   1082  public:
   1083   class PropertySet : public dbus::PropertySet {
   1084    public:
   1085     PropertySet(dbus::ObjectProxy* object_proxy,
   1086                 const PropertyChangedCallback& callback)
   1087         : dbus::PropertySet{object_proxy,
   1088                             "org.chromium.Itf2",
   1089                             callback} {
   1090     }
   1091 
   1092 
   1093    private:
   1094     DISALLOW_COPY_AND_ASSIGN(PropertySet);
   1095   };
   1096 
   1097   Itf2Proxy(
   1098       const scoped_refptr<dbus::Bus>& bus,
   1099       const dbus::ObjectPath& object_path) :
   1100           bus_{bus},
   1101           object_path_{object_path},
   1102           dbus_object_proxy_{
   1103               bus_->GetObjectProxy(service_name_, object_path_)} {
   1104   }
   1105 
   1106   ~Itf2Proxy() override {
   1107   }
   1108 
   1109   void ReleaseObjectProxy(const base::Closure& callback) {
   1110     bus_->RemoveObjectProxy(service_name_, object_path_, callback);
   1111   }
   1112 
   1113   const dbus::ObjectPath& GetObjectPath() const override {
   1114     return object_path_;
   1115   }
   1116 
   1117   dbus::ObjectProxy* GetObjectProxy() const { return dbus_object_proxy_; }
   1118 
   1119  private:
   1120   scoped_refptr<dbus::Bus> bus_;
   1121   const std::string service_name_{"org.chromium.Test"};
   1122   dbus::ObjectPath object_path_;
   1123   dbus::ObjectProxy* dbus_object_proxy_;
   1124 
   1125   DISALLOW_COPY_AND_ASSIGN(Itf2Proxy);
   1126 };
   1127 
   1128 }  // namespace chromium
   1129 }  // namespace org
   1130 
   1131 namespace org {
   1132 namespace chromium {
   1133 
   1134 class ObjectManagerProxy : public dbus::ObjectManager::Interface {
   1135  public:
   1136   ObjectManagerProxy(const scoped_refptr<dbus::Bus>& bus)
   1137       : bus_{bus},
   1138         dbus_object_manager_{bus->GetObjectManager(
   1139             "org.chromium.Test",
   1140             dbus::ObjectPath{"/org/chromium/Test"})} {
   1141     dbus_object_manager_->RegisterInterface("org.chromium.Itf1", this);
   1142     dbus_object_manager_->RegisterInterface("org.chromium.Itf2", this);
   1143   }
   1144 
   1145   ~ObjectManagerProxy() override {
   1146     dbus_object_manager_->UnregisterInterface("org.chromium.Itf1");
   1147     dbus_object_manager_->UnregisterInterface("org.chromium.Itf2");
   1148   }
   1149 
   1150   dbus::ObjectManager* GetObjectManagerProxy() const {
   1151     return dbus_object_manager_;
   1152   }
   1153 
   1154   org::chromium::Itf1ProxyInterface* GetItf1Proxy() {
   1155     if (itf1_instances_.empty())
   1156       return nullptr;
   1157     return itf1_instances_.begin()->second.get();
   1158   }
   1159   std::vector<org::chromium::Itf1ProxyInterface*> GetItf1Instances() const {
   1160     std::vector<org::chromium::Itf1ProxyInterface*> values;
   1161     values.reserve(itf1_instances_.size());
   1162     for (const auto& pair : itf1_instances_)
   1163       values.push_back(pair.second.get());
   1164     return values;
   1165   }
   1166   void SetItf1AddedCallback(
   1167       const base::Callback<void(org::chromium::Itf1ProxyInterface*)>& callback) {
   1168     on_itf1_added_ = callback;
   1169   }
   1170   void SetItf1RemovedCallback(
   1171       const base::Callback<void(const dbus::ObjectPath&)>& callback) {
   1172     on_itf1_removed_ = callback;
   1173   }
   1174 
   1175   org::chromium::Itf2ProxyInterface* GetItf2Proxy(
   1176       const dbus::ObjectPath& object_path) {
   1177     auto p = itf2_instances_.find(object_path);
   1178     if (p != itf2_instances_.end())
   1179       return p->second.get();
   1180     return nullptr;
   1181   }
   1182   std::vector<org::chromium::Itf2ProxyInterface*> GetItf2Instances() const {
   1183     std::vector<org::chromium::Itf2ProxyInterface*> values;
   1184     values.reserve(itf2_instances_.size());
   1185     for (const auto& pair : itf2_instances_)
   1186       values.push_back(pair.second.get());
   1187     return values;
   1188   }
   1189   void SetItf2AddedCallback(
   1190       const base::Callback<void(org::chromium::Itf2ProxyInterface*)>& callback) {
   1191     on_itf2_added_ = callback;
   1192   }
   1193   void SetItf2RemovedCallback(
   1194       const base::Callback<void(const dbus::ObjectPath&)>& callback) {
   1195     on_itf2_removed_ = callback;
   1196   }
   1197 
   1198  private:
   1199   void OnPropertyChanged(const dbus::ObjectPath& /* object_path */,
   1200                          const std::string& /* interface_name */,
   1201                          const std::string& /* property_name */) {}
   1202 
   1203   void ObjectAdded(
   1204       const dbus::ObjectPath& object_path,
   1205       const std::string& interface_name) override {
   1206     if (interface_name == "org.chromium.Itf1") {
   1207       std::unique_ptr<org::chromium::Itf1Proxy> itf1_proxy{
   1208         new org::chromium::Itf1Proxy{bus_}
   1209       };
   1210       auto p = itf1_instances_.emplace(object_path, std::move(itf1_proxy));
   1211       if (!on_itf1_added_.is_null())
   1212         on_itf1_added_.Run(p.first->second.get());
   1213       return;
   1214     }
   1215     if (interface_name == "org.chromium.Itf2") {
   1216       std::unique_ptr<org::chromium::Itf2Proxy> itf2_proxy{
   1217         new org::chromium::Itf2Proxy{bus_, object_path}
   1218       };
   1219       auto p = itf2_instances_.emplace(object_path, std::move(itf2_proxy));
   1220       if (!on_itf2_added_.is_null())
   1221         on_itf2_added_.Run(p.first->second.get());
   1222       return;
   1223     }
   1224   }
   1225 
   1226   void ObjectRemoved(
   1227       const dbus::ObjectPath& object_path,
   1228       const std::string& interface_name) override {
   1229     if (interface_name == "org.chromium.Itf1") {
   1230       auto p = itf1_instances_.find(object_path);
   1231       if (p != itf1_instances_.end()) {
   1232         if (!on_itf1_removed_.is_null())
   1233           on_itf1_removed_.Run(object_path);
   1234         itf1_instances_.erase(p);
   1235       }
   1236       return;
   1237     }
   1238     if (interface_name == "org.chromium.Itf2") {
   1239       auto p = itf2_instances_.find(object_path);
   1240       if (p != itf2_instances_.end()) {
   1241         if (!on_itf2_removed_.is_null())
   1242           on_itf2_removed_.Run(object_path);
   1243         itf2_instances_.erase(p);
   1244       }
   1245       return;
   1246     }
   1247   }
   1248 
   1249   dbus::PropertySet* CreateProperties(
   1250       dbus::ObjectProxy* object_proxy,
   1251       const dbus::ObjectPath& object_path,
   1252       const std::string& interface_name) override {
   1253     if (interface_name == "org.chromium.Itf1") {
   1254       return new org::chromium::Itf1Proxy::PropertySet{
   1255           object_proxy,
   1256           base::Bind(&ObjectManagerProxy::OnPropertyChanged,
   1257                      weak_ptr_factory_.GetWeakPtr(),
   1258                      object_path,
   1259                      interface_name)
   1260       };
   1261     }
   1262     if (interface_name == "org.chromium.Itf2") {
   1263       return new org::chromium::Itf2Proxy::PropertySet{
   1264           object_proxy,
   1265           base::Bind(&ObjectManagerProxy::OnPropertyChanged,
   1266                      weak_ptr_factory_.GetWeakPtr(),
   1267                      object_path,
   1268                      interface_name)
   1269       };
   1270     }
   1271     LOG(FATAL) << "Creating properties for unsupported interface "
   1272                << interface_name;
   1273     return nullptr;
   1274   }
   1275 
   1276   scoped_refptr<dbus::Bus> bus_;
   1277   dbus::ObjectManager* dbus_object_manager_;
   1278   std::map<dbus::ObjectPath,
   1279            std::unique_ptr<org::chromium::Itf1Proxy>> itf1_instances_;
   1280   base::Callback<void(org::chromium::Itf1ProxyInterface*)> on_itf1_added_;
   1281   base::Callback<void(const dbus::ObjectPath&)> on_itf1_removed_;
   1282   std::map<dbus::ObjectPath,
   1283            std::unique_ptr<org::chromium::Itf2Proxy>> itf2_instances_;
   1284   base::Callback<void(org::chromium::Itf2ProxyInterface*)> on_itf2_added_;
   1285   base::Callback<void(const dbus::ObjectPath&)> on_itf2_removed_;
   1286   base::WeakPtrFactory<ObjectManagerProxy> weak_ptr_factory_{this};
   1287 
   1288   DISALLOW_COPY_AND_ASSIGN(ObjectManagerProxy);
   1289 };
   1290 
   1291 }  // namespace chromium
   1292 }  // namespace org
   1293 )literal_string";
   1294 }  // namespace
   1295 
   1296 class ProxyGeneratorTest : public Test {
   1297  public:
   1298   void SetUp() override {
   1299     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
   1300   }
   1301 
   1302  protected:
   1303   base::FilePath CreateInputFile(const string& contents) {
   1304     base::FilePath path;
   1305     EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &path));
   1306     int written = base::WriteFile(path, contents.c_str(), contents.size());
   1307     EXPECT_EQ(contents.size(), static_cast<size_t>(written));
   1308     return path;
   1309   }
   1310 
   1311   base::ScopedTempDir temp_dir_;
   1312 };
   1313 
   1314 TEST_F(ProxyGeneratorTest, GenerateAdaptors) {
   1315   Interface interface;
   1316   interface.name = "org.chromium.TestInterface";
   1317   interface.path = "/org/chromium/Test";
   1318   interface.methods.emplace_back(
   1319       "Elements",
   1320       vector<Interface::Argument>{
   1321           {"space_walk", kDBusTypeString},
   1322           {"ramblin_man", kDBusTypeArryOfObjects}},
   1323       vector<Interface::Argument>{{"", kDBusTypeString}});
   1324   interface.methods.emplace_back(
   1325       "ReturnToPatagonia",
   1326       vector<Interface::Argument>{},
   1327       vector<Interface::Argument>{{"", kDBusTypeInt64}});
   1328   interface.methods.emplace_back(
   1329       "NiceWeatherForDucks",
   1330       vector<Interface::Argument>{{"", kDBusTypeBool}},
   1331       vector<Interface::Argument>{});
   1332   interface.methods.emplace_back("ExperimentNumberSix");
   1333   interface.signals.emplace_back("Closer");
   1334   interface.signals.emplace_back(
   1335       "TheCurseOfKaZar",
   1336       vector<Interface::Argument>{
   1337           {"", kDBusTypeArryOfStrings},
   1338           {"", kDBusTypeByte}});
   1339   interface.methods.back().doc_string = "Comment line1\nline2";
   1340   Interface interface2;
   1341   interface2.name = "org.chromium.TestInterface2";
   1342   interface2.methods.emplace_back(
   1343       "GetPersonInfo",
   1344       vector<Interface::Argument>{},
   1345       vector<Interface::Argument>{
   1346           {"name", kDBusTypeString},
   1347           {"age", kDBusTypeInt32}});
   1348   vector<Interface> interfaces{interface, interface2};
   1349   base::FilePath output_path = temp_dir_.path().Append("output.h");
   1350   ServiceConfig config;
   1351   EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path));
   1352   string contents;
   1353   EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
   1354   // The header guards contain the (temporary) filename, so we search for
   1355   // the content we need within the string.
   1356   test_utils::EXPECT_TEXT_CONTAINED(kExpectedContent, contents);
   1357 }
   1358 
   1359 TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithServiceName) {
   1360   Interface interface;
   1361   interface.name = "org.chromium.TestInterface";
   1362   interface.path = "/org/chromium/Test";
   1363   interface.signals.emplace_back("Closer");
   1364   Interface interface2;
   1365   interface2.name = "org.chromium.TestInterface2";
   1366   vector<Interface> interfaces{interface, interface2};
   1367   base::FilePath output_path = temp_dir_.path().Append("output2.h");
   1368   ServiceConfig config;
   1369   config.service_name = "org.chromium.Test";
   1370   EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path));
   1371   string contents;
   1372   EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
   1373   // The header guards contain the (temporary) filename, so we search for
   1374   // the content we need within the string.
   1375   test_utils::EXPECT_TEXT_CONTAINED(kExpectedContentWithService, contents);
   1376 }
   1377 
   1378 TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithObjectManager) {
   1379   Interface interface;
   1380   interface.name = "org.chromium.Itf1";
   1381   interface.path = "/org/chromium/Test/Object";
   1382   interface.signals.emplace_back("Closer");
   1383   interface.properties.emplace_back("Data", "s", "read");
   1384   interface.properties.emplace_back("Name", "s", "readwrite");
   1385   Interface interface2;
   1386   interface2.name = "org.chromium.Itf2";
   1387   vector<Interface> interfaces{interface, interface2};
   1388   base::FilePath output_path = temp_dir_.path().Append("output3.h");
   1389   ServiceConfig config;
   1390   config.object_manager.name = "org.chromium.ObjectManager";
   1391   config.object_manager.object_path = "/org/chromium/Test";
   1392   EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path));
   1393   string contents;
   1394   EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
   1395   // The header guards contain the (temporary) filename, so we search for
   1396   // the content we need within the string.
   1397   test_utils::EXPECT_TEXT_CONTAINED(
   1398       kExpectedContentWithObjectManager, contents);
   1399 }
   1400 
   1401 TEST_F(ProxyGeneratorTest, GenerateAdaptorsWithObjectManagerAndServiceName) {
   1402   Interface interface;
   1403   interface.name = "org.chromium.Itf1";
   1404   interface.path = "/org/chromium/Test/Object";
   1405   interface.signals.emplace_back("Closer");
   1406   Interface interface2;
   1407   interface2.name = "org.chromium.Itf2";
   1408   vector<Interface> interfaces{interface, interface2};
   1409   base::FilePath output_path = temp_dir_.path().Append("output4.h");
   1410   ServiceConfig config;
   1411   config.service_name = "org.chromium.Test";
   1412   config.object_manager.name = "org.chromium.ObjectManager";
   1413   config.object_manager.object_path = "/org/chromium/Test";
   1414   EXPECT_TRUE(ProxyGenerator::GenerateProxies(config, interfaces, output_path));
   1415   string contents;
   1416   EXPECT_TRUE(base::ReadFileToString(output_path, &contents));
   1417   // The header guards contain the (temporary) filename, so we search for
   1418   // the content we need within the string.
   1419   test_utils::EXPECT_TEXT_CONTAINED(
   1420       kExpectedContentWithObjectManagerAndServiceName, contents);
   1421 }
   1422 
   1423 }  // namespace chromeos_dbus_bindings
   1424