// Copyright 2020 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef SRC_DAWN_TESTS_MOCKCALLBACK_H_ #define SRC_DAWN_TESTS_MOCKCALLBACK_H_ #include <memory> #include <set> #include <tuple> #include <utility> #include "dawn/common/Assert.h" #include "gmock/gmock.h" namespace testing { template <typename F> class MockCallback; // Helper class for mocking callbacks used for Dawn callbacks with |void* userdata| // as the last callback argument. // // Example Usage: // MockCallback<WGPUDeviceLostCallback> mock; // // void* foo = XYZ; // this is the callback userdata // // wgpuDeviceSetDeviceLostCallback(device, mock.Callback(), mock.MakeUserdata(foo)); // EXPECT_CALL(mock, Call(_, foo)); MockCallback<R (*)(Args...)>; template <typename F> class MockCppCallback; // Helper wrapper class for C++ entry point callbacks. // Example Usage: // MockCppCallback<void (*)(wgpu::PopErrorScopeStatus, wgpu::ErrorType, const char*)> mock; // // device.PopErrorScope(wgpu::CallbackMode::AllowProcessEvents, mock.Callback()); // EXPECT_CALL(mock, Call(wgpu::PopErrorScopeStatus::Success, _, _)); MockCppCallback<R (*)(Args...)>; } // namespace testing #endif // SRC_DAWN_TESTS_MOCKCALLBACK_H_