chromium/mojo/public/tools/bindings/generators/cpp_templates/module-test-utils.h.tmpl

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

{%- from 'cpp_macros.tmpl' import
    namespace_begin, namespace_end, include_guard, variant_path %}

{%- set header_guard = include_guard("TEST_UTILS", module.path, variant) %}

#ifndef {{header_guard}}
#define {{header_guard}}

#include "{{variant_path(module.path, variant)}}.h"

{%- if export_header %}
#include "{{export_header}}"
{%- endif %}

{{namespace_begin(namespaces_as_array, variant)}}

{%- import "interface_macros.tmpl" as interface_macros %}

{%  for interface in interfaces %}

{#--- Testing interceptor #}
class {{export_attribute}} {{interface.name}}InterceptorForTesting : public {{interface.name}} {
  virtual {{interface.name}}* GetForwardingInterface() = 0;

{%- for method in interface.methods %}
  void {{method.name}}({{interface_macros.declare_request_params("", method)}}) override;
{%- endfor %}
};

{#--- Async wait helper for testing #}
class {{export_attribute}} {{interface.name}}AsyncWaiter {
 public:
  explicit {{interface.name}}AsyncWaiter({{interface.name}}* proxy);

  {{interface.name}}AsyncWaiter(const {{interface.name}}AsyncWaiter&) = delete;
  {{interface.name}}AsyncWaiter& operator=(const {{interface.name}}AsyncWaiter&) = delete;

  ~{{interface.name}}AsyncWaiter();

{%- for method in interface.methods if method.response_parameters != None %}
  void {{method.name}}(
      {{interface_macros.declare_sync_method_params("", method)}});
  {% if method.response_parameters|length == 1 -%}
    {%- set response_type = method.response_parameters[0].kind|cpp_wrapper_call_type -%}
    {{response_type}} {{method.name}}({{interface_macros.declare_params("", method.parameters)}});
  {%- endif %}

{%- endfor %}

 private:
  {{interface.name}}* const proxy_;
};

{%  endfor %}

{{namespace_end(namespaces_as_array, variant)}}

#endif  // {{header_guard}}