diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a703b07..58fa8d3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -55,6 +55,7 @@ add_subdirectory(DispatchLoaderDynamic) add_subdirectory(DispatchLoaderDynamicSharedLibrary) add_subdirectory(DispatchLoaderDynamicSharedLibraryClient) add_subdirectory(DispatchLoaderStatic) +add_subdirectory(Flags) add_subdirectory(FormatTraits) add_subdirectory(Hash) add_subdirectory(NoExceptions) diff --git a/tests/Flags/CMakeLists.txt b/tests/Flags/CMakeLists.txt new file mode 100644 index 0000000..ae0b7f5 --- /dev/null +++ b/tests/Flags/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright(c) 2023, NVIDIA CORPORATION. All rights reserved. +# +# 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. + +cmake_minimum_required(VERSION 3.2) + +project(Flags) + +set(HEADERS +) + +set(SOURCES + Flags.cpp +) + +source_group(headers FILES ${HEADERS}) +source_group(sources FILES ${SOURCES}) + +add_executable(Flags + ${HEADERS} + ${SOURCES} +) + +set_target_properties(Flags PROPERTIES FOLDER "Tests") +target_link_libraries(Flags PRIVATE utils) diff --git a/tests/Flags/Flags.cpp b/tests/Flags/Flags.cpp new file mode 100644 index 0000000..a8ffbcd --- /dev/null +++ b/tests/Flags/Flags.cpp @@ -0,0 +1,102 @@ +// Copyright(c) 2023, NVIDIA CORPORATION. All rights reserved. +// +// 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. +// +// VulkanHpp Samples : Flags +// Compile test on using vk::Flags + +// for test purposes, define this to allow access to Flags::m_mask +// You should not use that in production code!! +#define VULKAN_HPP_FLAGS_MASK_TYPE_AS_PUBLIC + +// in this test, we ignore some warnings +// You should not do that in production code !! +#if defined( __GNUC__ ) +# pragma GCC diagnostic ignored "-Wunused-variable" +#else +// unknow compiler... just ignore the warnings for yourselves ;) +#endif + +#include + +int main( int /*argc*/, char ** /*argv*/ ) +{ + vk::MemoryHeapFlags mhf0; + assert( mhf0.m_mask == 0 ); + + vk::MemoryHeapFlags mhf1( vk::MemoryHeapFlagBits::eDeviceLocal ); + assert( mhf1.m_mask == VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ); + + vk::MemoryHeapFlags mhf2( mhf1 ); + assert( mhf2.m_mask == VK_MEMORY_HEAP_DEVICE_LOCAL_BIT ); + + VkMemoryHeapFlags vkmhf = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT | VK_MEMORY_HEAP_MULTI_INSTANCE_BIT; + vk::MemoryHeapFlags mhf3( vkmhf ); + assert( mhf3.m_mask == ( VK_MEMORY_HEAP_DEVICE_LOCAL_BIT | VK_MEMORY_HEAP_MULTI_INSTANCE_BIT ) ); + + // error + // vk::MemoryHeapFlags mhf4( vk::MemoryHeapFlagBits::eDeviceLocal | vk::ImageAspectFlagBits::eDepth ); + + assert( mhf0 < mhf1 ); + assert( !( mhf1 < mhf2 ) ); + + assert( mhf0 <= mhf1 ); + assert( mhf1 <= mhf2 ); + assert( !( mhf3 <= mhf2 ) ); + + assert( mhf1 > mhf0 ); + assert( !( mhf2 > mhf1 ) ); + + assert( mhf1 >= mhf0 ); + assert( mhf2 >= mhf1 ); + assert( !( mhf2 >= mhf3 ) ); + + assert( !( mhf0 == mhf1 ) ); + assert( mhf1 == mhf2 ); + + assert( mhf0 != mhf1 ); + assert( !( mhf1 != mhf2 ) ); + + assert( !mhf0 ); + assert( !!mhf1 ); + + assert( mhf1 & vk::MemoryHeapFlagBits::eDeviceLocal ); + assert( !( mhf0 & vk::MemoryHeapFlagBits::eDeviceLocal ) ); + + assert( ( mhf0 | vk::MemoryHeapFlagBits::eDeviceLocal ) == vk::MemoryHeapFlagBits::eDeviceLocal ); + assert( ( mhf1 | vk::MemoryHeapFlagBits::eDeviceLocal ) == vk::MemoryHeapFlagBits::eDeviceLocal ); + + assert( ( mhf0 ^ mhf1 ) == mhf1 ); + assert( ( mhf1 ^ mhf2 ) == mhf0 ); + + vk::MemoryHeapFlags mhf4( ~mhf0 ); + assert( mhf4 == ( vk::MemoryHeapFlagBits::eDeviceLocal | vk::MemoryHeapFlagBits::eMultiInstance ) ); + + mhf0 = mhf1; + assert( mhf0 == mhf1 ); + + mhf0 |= vk::MemoryHeapFlagBits::eMultiInstance; + assert( mhf0 & vk::MemoryHeapFlagBits::eMultiInstance ); + + mhf0 &= vk::MemoryHeapFlagBits::eDeviceLocal; + assert( mhf0 & vk::MemoryHeapFlagBits::eDeviceLocal ); + + mhf0 ^= mhf3; + assert( mhf0 == ( vk::MemoryHeapFlagBits::eMultiInstance ) ); + + assert( mhf0 ); + + vkmhf = static_cast(mhf0); + + return 0; +}