2018-07-18 09:40:26 +00:00
|
|
|
//* Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//*
|
|
|
|
//* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
//* you may not use this file except in compliance with the License.
|
|
|
|
//* You may obtain a copy of the License at
|
|
|
|
//*
|
|
|
|
//* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//*
|
|
|
|
//* Unless required by applicable law or agreed to in writing, software
|
|
|
|
//* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//* See the License for the specific language governing permissions and
|
|
|
|
//* limitations under the License.
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
#include "mock_webgpu.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2019-03-28 10:44:41 +00:00
|
|
|
using namespace testing;
|
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
namespace {
|
|
|
|
{% for type in by_category["object"] %}
|
2020-12-17 17:59:37 +00:00
|
|
|
{% for method in c_methods(type) %}
|
2017-04-20 18:38:20 +00:00
|
|
|
{{as_cType(method.return_type.name)}} Forward{{as_MethodSuffix(type.name, method.name)}}(
|
|
|
|
{{-as_cType(type.name)}} self
|
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_annotated_cType(arg)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
) {
|
2017-05-16 20:05:51 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
return object->procs->{{as_MethodSuffix(type.name, method.name)}}(self
|
2017-04-20 18:38:20 +00:00
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_varName(arg.name)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcTableAsClass::~ProcTableAsClass() {
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:15:47 +00:00
|
|
|
void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, WGPUDevice* device) {
|
2017-04-20 18:38:20 +00:00
|
|
|
*device = GetNewDevice();
|
|
|
|
|
|
|
|
{% for type in by_category["object"] %}
|
2020-12-17 17:59:37 +00:00
|
|
|
{% for method in c_methods(type) %}
|
2017-04-20 18:38:20 +00:00
|
|
|
table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:59:37 +00:00
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{% for method in type.methods if has_callback_arguments(method) %}
|
|
|
|
{% set Suffix = as_MethodSuffix(type.name, method.name) %}
|
|
|
|
|
|
|
|
{{as_cType(method.return_type.name)}} ProcTableAsClass::{{Suffix}}(
|
|
|
|
{{-as_cType(type.name)}} {{as_varName(type.name)}}
|
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_annotated_cType(arg)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
) {
|
|
|
|
ProcTableAsClass::Object* object = reinterpret_cast<ProcTableAsClass::Object*>({{as_varName(type.name)}});
|
2021-12-02 07:41:21 +00:00
|
|
|
{% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %}
|
2020-12-17 17:59:37 +00:00
|
|
|
object->m{{as_MethodSuffix(type.name, method.name)}}Callback = {{as_varName(callback_arg.name)}};
|
|
|
|
{% endfor %}
|
|
|
|
object->userdata = userdata;
|
|
|
|
return On{{as_MethodSuffix(type.name, method.name)}}(
|
|
|
|
{{-as_varName(type.name)}}
|
|
|
|
{%- for arg in method.arguments -%}
|
|
|
|
, {{as_varName(arg.name)}}
|
|
|
|
{%- endfor -%}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-02 07:41:21 +00:00
|
|
|
{% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %}
|
2020-12-17 17:59:37 +00:00
|
|
|
void ProcTableAsClass::Call{{Suffix}}Callback(
|
|
|
|
{{-as_cType(type.name)}} {{as_varName(type.name)}}
|
|
|
|
{%- for arg in callback_arg.type.arguments -%}
|
|
|
|
{%- if not loop.last -%}, {{as_annotated_cType(arg)}}{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
) {
|
|
|
|
ProcTableAsClass::Object* object = reinterpret_cast<ProcTableAsClass::Object*>({{as_varName(type.name)}});
|
|
|
|
object->m{{Suffix}}Callback(
|
|
|
|
{%- for arg in callback_arg.type.arguments -%}
|
|
|
|
{%- if not loop.last -%}{{as_varName(arg.name)}}, {% endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
object->userdata);
|
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2020-10-21 04:37:41 +00:00
|
|
|
|
2017-04-20 18:38:20 +00:00
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
{{as_cType(type.name)}} ProcTableAsClass::GetNew{{type.name.CamelCase()}}() {
|
2017-11-23 21:04:26 +00:00
|
|
|
mObjects.emplace_back(new Object);
|
|
|
|
mObjects.back()->procs = this;
|
|
|
|
return reinterpret_cast<{{as_cType(type.name)}}>(mObjects.back().get());
|
2017-04-20 18:38:20 +00:00
|
|
|
}
|
|
|
|
{% endfor %}
|
2018-08-22 13:37:29 +00:00
|
|
|
|
2020-04-16 18:08:23 +00:00
|
|
|
MockProcTable::MockProcTable() = default;
|
|
|
|
|
|
|
|
MockProcTable::~MockProcTable() = default;
|
2019-03-28 10:44:41 +00:00
|
|
|
|
|
|
|
void MockProcTable::IgnoreAllReleaseCalls() {
|
|
|
|
{% for type in by_category["object"] %}
|
|
|
|
EXPECT_CALL(*this, {{as_MethodSuffix(type.name, Name("release"))}}(_)).Times(AnyNumber());
|
|
|
|
{% endfor %}
|
|
|
|
}
|