blob: bf8f8710120e55cd65e91b10b47d444081110ff5 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001//* Copyright 2017 The Dawn Authors
Corentin Wallezf07e3bd2017-04-20 14:38:20 -04002//*
3//* Licensed under the Apache License, Version 2.0 (the "License");
4//* you may not use this file except in compliance with the License.
5//* You may obtain a copy of the License at
6//*
7//* http://www.apache.org/licenses/LICENSE-2.0
8//*
9//* Unless required by applicable law or agreed to in writing, software
10//* distributed under the License is distributed on an "AS IS" BASIS,
11//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//* See the License for the specific language governing permissions and
13//* limitations under the License.
14
fujunwei16ae3b82021-12-15 04:35:26 +000015{% set api = metadata.api.lower() %}
16#include "mock_{{api}}.h"
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040017
Corentin Wallezd754fb22019-03-28 10:44:41 +000018using namespace testing;
19
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040020namespace {
21 {% for type in by_category["object"] %}
Austin Eng8d38c012020-12-17 17:59:37 +000022 {% for method in c_methods(type) %}
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040023 {{as_cType(method.return_type.name)}} Forward{{as_MethodSuffix(type.name, method.name)}}(
24 {{-as_cType(type.name)}} self
25 {%- for arg in method.arguments -%}
26 , {{as_annotated_cType(arg)}}
27 {%- endfor -%}
28 ) {
Corentin Wallez1b7c5e32017-05-16 22:05:51 +020029 auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
30 return object->procs->{{as_MethodSuffix(type.name, method.name)}}(self
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040031 {%- for arg in method.arguments -%}
32 , {{as_varName(arg.name)}}
33 {%- endfor -%}
34 );
35 }
36 {% endfor %}
37
38 {% endfor %}
39}
40
41ProcTableAsClass::~ProcTableAsClass() {
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040042}
43
fujunwei16ae3b82021-12-15 04:35:26 +000044{% set Prefix = metadata.proc_table_prefix %}
45void ProcTableAsClass::GetProcTable({{Prefix}}ProcTable* table) {
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040046 {% for type in by_category["object"] %}
Austin Eng8d38c012020-12-17 17:59:37 +000047 {% for method in c_methods(type) %}
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040048 table->{{as_varName(type.name, method.name)}} = reinterpret_cast<{{as_cProc(type.name, method.name)}}>(Forward{{as_MethodSuffix(type.name, method.name)}});
49 {% endfor %}
50 {% endfor %}
51}
52
Austin Eng8d38c012020-12-17 17:59:37 +000053{% for type in by_category["object"] %}
54 {% for method in type.methods if has_callback_arguments(method) %}
55 {% set Suffix = as_MethodSuffix(type.name, method.name) %}
Corentin Wallez1b7c5e32017-05-16 22:05:51 +020056
Austin Eng8d38c012020-12-17 17:59:37 +000057 {{as_cType(method.return_type.name)}} ProcTableAsClass::{{Suffix}}(
58 {{-as_cType(type.name)}} {{as_varName(type.name)}}
59 {%- for arg in method.arguments -%}
60 , {{as_annotated_cType(arg)}}
61 {%- endfor -%}
62 ) {
63 ProcTableAsClass::Object* object = reinterpret_cast<ProcTableAsClass::Object*>({{as_varName(type.name)}});
fujunwei23f71622021-12-02 07:41:21 +000064 {% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %}
Austin Eng8d38c012020-12-17 17:59:37 +000065 object->m{{as_MethodSuffix(type.name, method.name)}}Callback = {{as_varName(callback_arg.name)}};
66 {% endfor %}
67 object->userdata = userdata;
68 return On{{as_MethodSuffix(type.name, method.name)}}(
69 {{-as_varName(type.name)}}
70 {%- for arg in method.arguments -%}
71 , {{as_varName(arg.name)}}
72 {%- endfor -%}
73 );
74 }
Corentin Wallez1b7c5e32017-05-16 22:05:51 +020075
fujunwei23f71622021-12-02 07:41:21 +000076 {% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %}
Austin Eng8d38c012020-12-17 17:59:37 +000077 void ProcTableAsClass::Call{{Suffix}}Callback(
78 {{-as_cType(type.name)}} {{as_varName(type.name)}}
79 {%- for arg in callback_arg.type.arguments -%}
80 {%- if not loop.last -%}, {{as_annotated_cType(arg)}}{%- endif -%}
81 {%- endfor -%}
82 ) {
83 ProcTableAsClass::Object* object = reinterpret_cast<ProcTableAsClass::Object*>({{as_varName(type.name)}});
84 object->m{{Suffix}}Callback(
85 {%- for arg in callback_arg.type.arguments -%}
86 {%- if not loop.last -%}{{as_varName(arg.name)}}, {% endif -%}
87 {%- endfor -%}
88 object->userdata);
89 }
90 {% endfor %}
91 {% endfor %}
92{% endfor %}
Jiawei Shao03e14002020-10-21 04:37:41 +000093
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040094{% for type in by_category["object"] %}
95 {{as_cType(type.name)}} ProcTableAsClass::GetNew{{type.name.CamelCase()}}() {
Corentin Wallez42dbde12017-11-23 16:04:26 -050096 mObjects.emplace_back(new Object);
97 mObjects.back()->procs = this;
98 return reinterpret_cast<{{as_cType(type.name)}}>(mObjects.back().get());
Corentin Wallezf07e3bd2017-04-20 14:38:20 -040099 }
100{% endfor %}
Corentin Wallez82b65732018-08-22 15:37:29 +0200101
Corentin Wallez3741f732020-04-16 18:08:23 +0000102MockProcTable::MockProcTable() = default;
103
104MockProcTable::~MockProcTable() = default;
Corentin Wallezd754fb22019-03-28 10:44:41 +0000105
106void MockProcTable::IgnoreAllReleaseCalls() {
107 {% for type in by_category["object"] %}
108 EXPECT_CALL(*this, {{as_MethodSuffix(type.name, Name("release"))}}(_)).Times(AnyNumber());
109 {% endfor %}
110}