Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | //* Copyright 2017 The Dawn Authors |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 2 | //* |
| 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 | |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 15 | {% set api = metadata.api.lower() %} |
| 16 | #include "mock_{{api}}.h" |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 17 | |
Corentin Wallez | d754fb2 | 2019-03-28 10:44:41 +0000 | [diff] [blame] | 18 | using namespace testing; |
| 19 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 20 | namespace { |
| 21 | {% for type in by_category["object"] %} |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 22 | {% for method in c_methods(type) %} |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 23 | {{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 Wallez | 1b7c5e3 | 2017-05-16 22:05:51 +0200 | [diff] [blame] | 29 | auto object = reinterpret_cast<ProcTableAsClass::Object*>(self); |
| 30 | return object->procs->{{as_MethodSuffix(type.name, method.name)}}(self |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 31 | {%- for arg in method.arguments -%} |
| 32 | , {{as_varName(arg.name)}} |
| 33 | {%- endfor -%} |
| 34 | ); |
| 35 | } |
| 36 | {% endfor %} |
| 37 | |
| 38 | {% endfor %} |
| 39 | } |
| 40 | |
| 41 | ProcTableAsClass::~ProcTableAsClass() { |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 42 | } |
| 43 | |
fujunwei | 16ae3b8 | 2021-12-15 04:35:26 +0000 | [diff] [blame] | 44 | {% set Prefix = metadata.proc_table_prefix %} |
| 45 | void ProcTableAsClass::GetProcTable({{Prefix}}ProcTable* table) { |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 46 | {% for type in by_category["object"] %} |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 47 | {% for method in c_methods(type) %} |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 48 | 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 Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 53 | {% 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 Wallez | 1b7c5e3 | 2017-05-16 22:05:51 +0200 | [diff] [blame] | 56 | |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 57 | {{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)}}); |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 64 | {% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %} |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 65 | 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 Wallez | 1b7c5e3 | 2017-05-16 22:05:51 +0200 | [diff] [blame] | 75 | |
fujunwei | 23f7162 | 2021-12-02 07:41:21 +0000 | [diff] [blame] | 76 | {% for callback_arg in method.arguments if callback_arg.type.category == 'function pointer' %} |
Austin Eng | 8d38c01 | 2020-12-17 17:59:37 +0000 | [diff] [blame] | 77 | 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 Shao | 03e1400 | 2020-10-21 04:37:41 +0000 | [diff] [blame] | 93 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 94 | {% for type in by_category["object"] %} |
| 95 | {{as_cType(type.name)}} ProcTableAsClass::GetNew{{type.name.CamelCase()}}() { |
Corentin Wallez | 42dbde1 | 2017-11-23 16:04:26 -0500 | [diff] [blame] | 96 | mObjects.emplace_back(new Object); |
| 97 | mObjects.back()->procs = this; |
| 98 | return reinterpret_cast<{{as_cType(type.name)}}>(mObjects.back().get()); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 99 | } |
| 100 | {% endfor %} |
Corentin Wallez | 82b6573 | 2018-08-22 15:37:29 +0200 | [diff] [blame] | 101 | |
Corentin Wallez | 3741f73 | 2020-04-16 18:08:23 +0000 | [diff] [blame] | 102 | MockProcTable::MockProcTable() = default; |
| 103 | |
| 104 | MockProcTable::~MockProcTable() = default; |
Corentin Wallez | d754fb2 | 2019-03-28 10:44:41 +0000 | [diff] [blame] | 105 | |
| 106 | void MockProcTable::IgnoreAllReleaseCalls() { |
| 107 | {% for type in by_category["object"] %} |
| 108 | EXPECT_CALL(*this, {{as_MethodSuffix(type.name, Name("release"))}}(_)).Times(AnyNumber()); |
| 109 | {% endfor %} |
| 110 | } |