// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* DO NOT EDIT. Generated from {{module.path}} */
{%- if variant -%}
{%- set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%- set variant_path = module.path -%}
{%- endif %}
{%- import "module_macros.tmpl" as module_macros %}
#include "{{variant_path}}_c.h"
#include "base/check.h"
#include "testing/gtest/include/gtest/gtest.h"
{#--- Interface Stubs -#}
{% for interface in interfaces %}
{%- set interface_name = interface|get_name_for_kind %}
{% set test_class_name = interface_name %}
// Test of {{interface_name}} interface.
class {{test_class_name}}Test : public ::testing::Test {
public:
{{test_class_name}}Test(const {{test_class_name}}Test&) = delete;
{{test_class_name}}Test& operator=(const {{test_class_name}}Test&) = delete;
protected:
void SetUp() override {
}
void TearDown() override {
}
{{test_class_name}}Test() = default;
~{{test_class_name}}Test() override = default;
public:
{%- for method in interface.methods -%}
bool {{method.name}}_called_ = false;
{%- endfor %}
};
namespace {
// Implementation of {{interface_name}} methods for testing.
{%- for method in interface.methods -%}
{{module_macros.declare_c_return(method)}}
Test{{interface_name}}_{{method.name}}({{interface_name}}Ptr self
{%- if method.parameters %}, {{module_macros.declare_c_params("", method.parameters)}}
{%- endif %}) {
CHECK(self);
Cronet_ClientContext client_context = {{interface_name}}_GetClientContext(self);
auto* test = static_cast<{{interface_name}}Test*>(client_context);
CHECK(test);
test->{{method.name}}_called_ = true;
{%- if method.response_parameters and method.sync %}
{% set return_param = method.response_parameters|first %}
return static_cast<{{return_param.kind|c_wrapper_type}}>(0);
{%- endif %}
}
{%- endfor %}
} // namespace
// Test that {{test_class_name}} stub forwards function calls as expected.
TEST_F({{test_class_name}}Test, TestCreate) {
{{interface_name}}Ptr test = {{interface_name}}_CreateWith(
{%- for method in interface.methods -%}
Test{{interface_name}}_{{method.name}}
{%- if not loop.last %}, {% endif %}
{%- endfor %}
);
CHECK(test);
{{interface_name}}_SetClientContext(test, this);
{%- for method in interface.methods -%}
{%- if not method.parameters %}
{{interface_name}}_{{method.name}}(test);
CHECK({{method.name}}_called_);
{%- else %}
CHECK(!{{method.name}}_called_);
{%- endif %}
{%- endfor %}
{{interface_name}}_Destroy(test);
}
{%- endfor %}