// Copyright 2017 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 #include "dawn_native/RefCounted.h" #include "dawn_native/ToBackend.h" #include // Make our own Base - Backend object pair, reusing the CommandBuffer name namespace dawn_native { class CommandBufferBase : public RefCounted { }; } using namespace dawn_native; class MyCommandBuffer : public CommandBufferBase { }; struct MyBackendTraits { using CommandBufferType = MyCommandBuffer; }; // Instanciate ToBackend for our "backend" template auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { return ToBackendBase(common); } // Test that ToBackend correctly converts pointers to base classes. TEST(ToBackend, Pointers) { { MyCommandBuffer* cmdBuf = new MyCommandBuffer; const CommandBufferBase* base = cmdBuf; auto backendCmdBuf = ToBackend(base); static_assert(std::is_same::value, ""); ASSERT_EQ(cmdBuf, backendCmdBuf); cmdBuf->Release(); } { MyCommandBuffer* cmdBuf = new MyCommandBuffer; CommandBufferBase* base = cmdBuf; auto backendCmdBuf = ToBackend(base); static_assert(std::is_same::value, ""); ASSERT_EQ(cmdBuf, backendCmdBuf); cmdBuf->Release(); } } // Test that ToBackend correctly converts Refs to base classes. TEST(ToBackend, Ref) { { MyCommandBuffer* cmdBuf = new MyCommandBuffer; const Ref base(cmdBuf); const auto& backendCmdBuf = ToBackend(base); static_assert(std::is_same&>::value, ""); ASSERT_EQ(cmdBuf, backendCmdBuf.Get()); cmdBuf->Release(); } { MyCommandBuffer* cmdBuf = new MyCommandBuffer; Ref base(cmdBuf); auto backendCmdBuf = ToBackend(base); static_assert(std::is_same&>::value, ""); ASSERT_EQ(cmdBuf, backendCmdBuf.Get()); cmdBuf->Release(); } }