Debian Codegraph @

tests/framework/util/equality_helpers.h

raw
1 /*
2 * Copyright (c) 2025 The Khronos Group Inc.
3 * Copyright (c) 2025 Valve Corporation
4 * Copyright (c) 2025 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials are
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice(s) and this permission notice shall be included in
14 * all copies or substantial portions of the Materials.
15 *
16 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS.
24 *
25 */
26
27 #pragma once
28
29 #include <string.h>
30
31 #include <algorithm>
32 #include <vector>
33
34 #include <vulkan/vulkan.h>
35
36 inline bool string_eq(const char* a, const char* b) noexcept { return a && b && strcmp(a, b) == 0; }
37 inline bool string_eq(const char* a, const char* b, size_t len) noexcept { return a && b && strncmp(a, b, len) == 0; }
38
39 bool operator==(const VkExtent3D& a, const VkExtent3D& b);
40 bool operator!=(const VkExtent3D& a, const VkExtent3D& b);
41
42 bool operator==(const VkQueueFamilyProperties& a, const VkQueueFamilyProperties& b);
43 bool operator!=(const VkQueueFamilyProperties& a, const VkQueueFamilyProperties& b);
44
45 bool operator==(const VkQueueFamilyProperties& a, const VkQueueFamilyProperties2& b);
46 bool operator!=(const VkQueueFamilyProperties& a, const VkQueueFamilyProperties2& b);
47
48 bool operator==(const VkLayerProperties& a, const VkLayerProperties& b);
49 bool operator!=(const VkLayerProperties& a, const VkLayerProperties& b);
50
51 bool operator==(const VkExtensionProperties& a, const VkExtensionProperties& b);
52 bool operator!=(const VkExtensionProperties& a, const VkExtensionProperties& b);
53
54 bool operator==(const VkPhysicalDeviceFeatures& feats1, const VkPhysicalDeviceFeatures2& feats2);
55
56 bool operator==(const VkPhysicalDeviceMemoryProperties& props1, const VkPhysicalDeviceMemoryProperties2& props2);
57 bool operator==(const VkSparseImageFormatProperties& props1, const VkSparseImageFormatProperties& props2);
58 bool operator==(const VkSparseImageFormatProperties& props1, const VkSparseImageFormatProperties2& props2);
59 bool operator==(const VkExternalMemoryProperties& props1, const VkExternalMemoryProperties& props2);
60 bool operator==(const VkExternalSemaphoreProperties& props1, const VkExternalSemaphoreProperties& props2);
61 bool operator==(const VkExternalFenceProperties& props1, const VkExternalFenceProperties& props2);
62 bool operator==(const VkSurfaceCapabilitiesKHR& props1, const VkSurfaceCapabilitiesKHR& props2);
63 bool operator==(const VkSurfacePresentScalingCapabilitiesEXT& caps1, const VkSurfacePresentScalingCapabilitiesEXT& caps2);
64 bool operator==(const VkSurfaceFormatKHR& format1, const VkSurfaceFormatKHR& format2);
65 bool operator==(const VkSurfaceFormatKHR& format1, const VkSurfaceFormat2KHR& format2);
66 bool operator==(const VkDisplayPropertiesKHR& props1, const VkDisplayPropertiesKHR& props2);
67 bool operator==(const VkDisplayPropertiesKHR& props1, const VkDisplayProperties2KHR& props2);
68 bool operator==(const VkDisplayModePropertiesKHR& disp1, const VkDisplayModePropertiesKHR& disp2);
69
70 bool operator==(const VkDisplayModePropertiesKHR& disp1, const VkDisplayModeProperties2KHR& disp2);
71 bool operator==(const VkDisplayPlaneCapabilitiesKHR& caps1, const VkDisplayPlaneCapabilitiesKHR& caps2);
72
73 bool operator==(const VkDisplayPlaneCapabilitiesKHR& caps1, const VkDisplayPlaneCapabilities2KHR& caps2);
74 bool operator==(const VkDisplayPlanePropertiesKHR& props1, const VkDisplayPlanePropertiesKHR& props2);
75 bool operator==(const VkDisplayPlanePropertiesKHR& props1, const VkDisplayPlaneProperties2KHR& props2);
76 bool operator==(const VkExtent2D& ext1, const VkExtent2D& ext2);
77
78 // Allow comparison of vectors of different types as long as their elements are comparable (just has to make sure to only apply when
79 // T != U)
80 template <typename T, typename U, typename = std::enable_if_t<!std::is_same_v<T, U>>>
81 bool operator==(const std::vector<T>& a, const std::vector<U>& b) {
82 return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](const auto& left, const auto& right) { return left == right; });
83 }