chromeos-dbus-bindings: Added proxy mock generation

Now it is possible to generate Mocks for D-Bus proxy objects to
mock out the D-Bus interfaces in tests.

A new option --mock=<file> is added to the generator to specify
the output file for the mock objects. If used with --proxy,
the mock header file will include the proxy header file to share
the definition of the common interface proxy abstract interface.
Otherwise, the mock header file will provide its own definition
of that abstract interface.

As a result, the proxy generation has been changed to include
the base abstract interface for the D-Bus interface proxy class
which the proxy and/or mock objects derive from.

The code using the proxy objects can be updated to pass around
the abstract interface instead of concrete proxy classes which
will make it possible to substruture proxies with mocks and
facilitate testing of the code using D-Bus proxies.

GYP action now has another variable 'mock_output_file' which
can be used along with 'proxy_output_file' to control the
location of the generated mock header file:

'actions': [
  {
    'action_name': 'generate-buffet-proxies',
    'variables': {
      'dbus_service_config': 'dbus_bindings/dbus-service-config.json',
      'proxy_output_file': 'include/buffet/dbus-proxies.h'
      'mock_output_file': 'include/buffet/dbus-mocks.h'
    },
    'sources': [
      'dbus_bindings/org.chromium.Buffet.Command.xml',
      'dbus_bindings/org.chromium.Buffet.Manager.xml',
    ],
    'includes': ['../common-mk/generate-dbus-proxies.gypi'],
  },
],

BUG=chromium:449176
TEST=FEATURES=test emerge-link chromeos-dbus-bindings
     Manually tested the generated proxy and mock classes with
     buffet.

Change-Id: I1fb84cfbfd751793df72ad5b050ee1cf00a64d62
Reviewed-on: https://chromium-review.googlesource.com/242276
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/chromeos-dbus-bindings/proxy_generator.h b/chromeos-dbus-bindings/proxy_generator.h
index 682e6dc..aa9e89e 100644
--- a/chromeos-dbus-bindings/proxy_generator.h
+++ b/chromeos-dbus-bindings/proxy_generator.h
@@ -31,14 +31,29 @@
                               const std::vector<Interface>& interfaces,
                               const base::FilePath& output_file);
 
+  static bool GenerateMocks(const ServiceConfig& config,
+                            const std::vector<Interface>& interfaces,
+                            const base::FilePath& mock_file,
+                            const base::FilePath& proxy_file);
+
  private:
   friend class ProxyGeneratorTest;
 
+  // Generates an abstract interface for one D-Bus interface proxy.
+  static void GenerateInterfaceProxyInterface(const ServiceConfig& config,
+                                              const Interface& interface,
+                                              IndentedText* text);
+
   // Generates one interface proxy.
   static void GenerateInterfaceProxy(const ServiceConfig& config,
                                      const Interface& interface,
                                      IndentedText* text);
 
+  // Generates one interface mock object.
+  static void GenerateInterfaceMock(const ServiceConfig& config,
+                                    const Interface& interface,
+                                    IndentedText* text);
+
   // Generates the constructor and destructor for the proxy.
   static void AddConstructor(const ServiceConfig& config,
                              const Interface& interface,
@@ -76,18 +91,31 @@
   // Generates the property accessors.
   static void AddProperties(const ServiceConfig& config,
                             const Interface& interface,
+                            bool declaration_only,
                             IndentedText* text);
 
   // Generates a native C++ method which calls a D-Bus method on the proxy.
   static void AddMethodProxy(const Interface::Method& interface,
                              const std::string& interface_name,
+                             bool declaration_only,
                              IndentedText* text);
 
   // Generates a native C++ method which calls a D-Bus method asynchronously.
   static void AddAsyncMethodProxy(const Interface::Method& interface,
                                   const std::string& interface_name,
+                                  bool declaration_only,
                                   IndentedText* text);
 
+  // Generates a mock for blocking D-Bus method.
+  static void AddMethodMock(const Interface::Method& interface,
+                            const std::string& interface_name,
+                            IndentedText* text);
+
+  // Generates a mock for asynchronous D-Bus method.
+  static void AddAsyncMethodMock(const Interface::Method& interface,
+                                 const std::string& interface_name,
+                                 IndentedText* text);
+
   // Generates the Object Manager proxy class.
   struct ObjectManager {
     // Generates the top-level class for Object Manager proxy.