// 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> 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>(); } 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(); }