mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Consolidate unittests in one binary
This commit is contained in:
committed by
Corentin Wallez
parent
314f3852a3
commit
0a58812f34
89
src/tests/unittests/ToBackendTests.cpp
Normal file
89
src/tests/unittests/ToBackendTests.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// Copyright 2017 The NXT 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 <gtest/gtest.h>
|
||||
|
||||
#include "backend/common/RefCounted.h"
|
||||
#include "backend/common/ToBackend.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
// Make our own Base - Backend object pair, reusing the CommandBuffer name
|
||||
namespace backend {
|
||||
class CommandBufferBase : public RefCounted {
|
||||
};
|
||||
}
|
||||
|
||||
using namespace backend;
|
||||
|
||||
class MyCommandBuffer : public CommandBufferBase {
|
||||
};
|
||||
|
||||
struct MyBackendTraits {
|
||||
using CommandBufferType = MyCommandBuffer;
|
||||
};
|
||||
|
||||
// Instanciate ToBackend for our "backend"
|
||||
template<typename T>
|
||||
auto ToBackend(T&& common) -> decltype(ToBackendBase<MyBackendTraits>(common)) {
|
||||
return ToBackendBase<MyBackendTraits>(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<decltype(backendCmdBuf), const MyCommandBuffer*>::value, "");
|
||||
ASSERT_EQ(cmdBuf, backendCmdBuf);
|
||||
|
||||
cmdBuf->Release();
|
||||
}
|
||||
{
|
||||
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
|
||||
CommandBufferBase* base = cmdBuf;
|
||||
|
||||
auto backendCmdBuf = ToBackend(base);
|
||||
static_assert(std::is_same<decltype(backendCmdBuf), MyCommandBuffer*>::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<CommandBufferBase> base(cmdBuf);
|
||||
|
||||
const auto& backendCmdBuf = ToBackend(base);
|
||||
static_assert(std::is_same<decltype(ToBackend(base)), const Ref<MyCommandBuffer>&>::value, "");
|
||||
ASSERT_EQ(cmdBuf, backendCmdBuf.Get());
|
||||
|
||||
cmdBuf->Release();
|
||||
}
|
||||
{
|
||||
MyCommandBuffer* cmdBuf = new MyCommandBuffer;
|
||||
Ref<CommandBufferBase> base(cmdBuf);
|
||||
|
||||
auto backendCmdBuf = ToBackend(base);
|
||||
static_assert(std::is_same<decltype(ToBackend(base)), Ref<MyCommandBuffer>&>::value, "");
|
||||
ASSERT_EQ(cmdBuf, backendCmdBuf.Get());
|
||||
|
||||
cmdBuf->Release();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user