mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-13 19:01:24 +00:00
This same callback will be used for push/pop error scope. Bug: dawn:153 Change-Id: I2771539e13f8a4e6a59f13c8082689d25ba44905 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10460 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
// Copyright 2019 The Dawn Authors
|
|
//
|
|
// 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.
|
|
|
|
#include "tests/unittests/wire/WireTest.h"
|
|
|
|
using namespace testing;
|
|
using namespace dawn_wire;
|
|
|
|
namespace {
|
|
|
|
// Mock classes to add expectations on the wire calling callbacks
|
|
class MockDeviceErrorCallback {
|
|
public:
|
|
MOCK_METHOD3(Call, void(DawnErrorType type, const char* message, void* userdata));
|
|
};
|
|
|
|
std::unique_ptr<StrictMock<MockDeviceErrorCallback>> mockDeviceErrorCallback;
|
|
void ToMockDeviceErrorCallback(DawnErrorType type, const char* message, void* userdata) {
|
|
mockDeviceErrorCallback->Call(type, message, userdata);
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
class WireErrorCallbackTests : public WireTest {
|
|
public:
|
|
WireErrorCallbackTests() {
|
|
}
|
|
~WireErrorCallbackTests() override = default;
|
|
|
|
void SetUp() override {
|
|
WireTest::SetUp();
|
|
|
|
mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
|
|
}
|
|
|
|
void TearDown() override {
|
|
WireTest::TearDown();
|
|
|
|
mockDeviceErrorCallback = nullptr;
|
|
}
|
|
|
|
void FlushServer() {
|
|
WireTest::FlushServer();
|
|
|
|
Mock::VerifyAndClearExpectations(&mockDeviceErrorCallback);
|
|
}
|
|
};
|
|
|
|
// Test the return wire for device error callbacks
|
|
TEST_F(WireErrorCallbackTests, DeviceErrorCallback) {
|
|
dawnDeviceSetErrorCallback(device, ToMockDeviceErrorCallback, this);
|
|
|
|
// Setting the error callback should stay on the client side and do nothing
|
|
FlushClient();
|
|
|
|
// Calling the callback on the server side will result in the callback being called on the
|
|
// client side
|
|
api.CallDeviceErrorCallback(apiDevice, DAWN_ERROR_TYPE_VALIDATION, "Some error message");
|
|
|
|
EXPECT_CALL(*mockDeviceErrorCallback, Call(DAWN_ERROR_TYPE_VALIDATION, StrEq("Some error message"), this)).Times(1);
|
|
|
|
FlushServer();
|
|
}
|