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.
|
|
|
|
|
2018-12-08 10:35:53 +00:00
|
|
|
#include "mock_dawn.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"] %}
|
2017-05-09 14:56:10 +00:00
|
|
|
{% for method in native_methods(type) if len(method.arguments) < 10 %}
|
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-03-11 16:52:42 +00:00
|
|
|
void ProcTableAsClass::GetProcTableAndDevice(DawnProcTable* table, DawnDevice* device) {
|
2017-04-20 18:38:20 +00:00
|
|
|
*device = GetNewDevice();
|
|
|
|
|
|
|
|
{% for type in by_category["object"] %}
|
2017-05-09 14:56:10 +00:00
|
|
|
{% for method in native_methods(type) if len(method.arguments) < 10 %}
|
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 %}
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:43:56 +00:00
|
|
|
void ProcTableAsClass::DeviceSetUncapturedErrorCallback(DawnDevice self,
|
2019-08-27 21:41:56 +00:00
|
|
|
DawnErrorCallback callback,
|
2019-05-29 13:03:50 +00:00
|
|
|
void* userdata) {
|
2017-05-16 20:05:51 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->deviceErrorCallback = callback;
|
|
|
|
object->userdata1 = userdata;
|
|
|
|
|
2019-08-27 21:43:56 +00:00
|
|
|
OnDeviceSetUncapturedErrorCallback(self, callback, userdata);
|
2017-05-16 20:05:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 22:54:03 +00:00
|
|
|
bool ProcTableAsClass::DevicePopErrorScope(DawnDevice self, DawnErrorCallback callback, void* userdata) {
|
|
|
|
return OnDevicePopErrorScopeCallback(self, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-06-14 17:35:56 +00:00
|
|
|
void ProcTableAsClass::DeviceCreateBufferMappedAsync(DawnDevice self,
|
|
|
|
const DawnBufferDescriptor* descriptor,
|
|
|
|
DawnBufferCreateMappedCallback callback,
|
|
|
|
void* userdata) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->createBufferMappedCallback = callback;
|
|
|
|
object->userdata1 = userdata;
|
|
|
|
|
|
|
|
OnDeviceCreateBufferMappedAsyncCallback(self, descriptor, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-05-29 13:03:50 +00:00
|
|
|
void ProcTableAsClass::BufferMapReadAsync(DawnBuffer self,
|
|
|
|
DawnBufferMapReadCallback callback,
|
|
|
|
void* userdata) {
|
2017-06-09 14:51:29 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->mapReadCallback = callback;
|
|
|
|
object->userdata1 = userdata;
|
|
|
|
|
2019-02-14 19:31:17 +00:00
|
|
|
OnBufferMapReadAsyncCallback(self, callback, userdata);
|
2017-06-09 14:51:29 +00:00
|
|
|
}
|
|
|
|
|
2019-05-29 13:03:50 +00:00
|
|
|
void ProcTableAsClass::BufferMapWriteAsync(DawnBuffer self,
|
|
|
|
DawnBufferMapWriteCallback callback,
|
|
|
|
void* userdata) {
|
2018-03-21 00:56:39 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->mapWriteCallback = callback;
|
|
|
|
object->userdata1 = userdata;
|
|
|
|
|
2019-02-14 19:31:17 +00:00
|
|
|
OnBufferMapWriteAsyncCallback(self, callback, userdata);
|
2018-03-21 00:56:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 16:52:42 +00:00
|
|
|
void ProcTableAsClass::FenceOnCompletion(DawnFence self,
|
2018-12-03 16:57:34 +00:00
|
|
|
uint64_t value,
|
2019-03-11 16:52:42 +00:00
|
|
|
DawnFenceOnCompletionCallback callback,
|
2019-05-29 13:03:50 +00:00
|
|
|
void* userdata) {
|
2018-12-03 16:57:34 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(self);
|
|
|
|
object->fenceOnCompletionCallback = callback;
|
|
|
|
object->userdata1 = userdata;
|
|
|
|
|
|
|
|
OnFenceOnCompletionCallback(self, value, callback, userdata);
|
|
|
|
}
|
|
|
|
|
2019-08-27 21:41:56 +00:00
|
|
|
void ProcTableAsClass::CallDeviceErrorCallback(DawnDevice device, DawnErrorType type, const char* message) {
|
2017-05-17 15:16:00 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
2019-08-27 21:41:56 +00:00
|
|
|
object->deviceErrorCallback(type, message, object->userdata1);
|
2017-05-17 15:16:00 +00:00
|
|
|
}
|
2019-06-14 17:35:56 +00:00
|
|
|
void ProcTableAsClass::CallCreateBufferMappedCallback(DawnDevice device, DawnBufferMapAsyncStatus status, DawnCreateBufferMappedResult result) {
|
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(device);
|
|
|
|
object->createBufferMappedCallback(status, result, object->userdata1);
|
|
|
|
}
|
|
|
|
void ProcTableAsClass::CallMapReadCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, const void* data, uint64_t dataLength) {
|
2017-06-09 14:51:29 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
|
2019-02-14 19:31:17 +00:00
|
|
|
object->mapReadCallback(status, data, dataLength, object->userdata1);
|
2017-06-09 14:51:29 +00:00
|
|
|
}
|
2017-05-17 15:16:00 +00:00
|
|
|
|
2019-06-14 17:35:56 +00:00
|
|
|
void ProcTableAsClass::CallMapWriteCallback(DawnBuffer buffer, DawnBufferMapAsyncStatus status, void* data, uint64_t dataLength) {
|
2018-03-21 00:56:39 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(buffer);
|
2019-02-14 19:31:17 +00:00
|
|
|
object->mapWriteCallback(status, data, dataLength, object->userdata1);
|
2018-03-21 00:56:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 16:52:42 +00:00
|
|
|
void ProcTableAsClass::CallFenceOnCompletionCallback(DawnFence fence,
|
|
|
|
DawnFenceCompletionStatus status) {
|
2018-12-03 16:57:34 +00:00
|
|
|
auto object = reinterpret_cast<ProcTableAsClass::Object*>(fence);
|
|
|
|
object->fenceOnCompletionCallback(status, object->userdata1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
MockProcTable::MockProcTable() {
|
|
|
|
}
|
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 %}
|
|
|
|
}
|