vk-bootstrap/tests/error_code_tests.cpp
Charles Giessen 04ec13b48d Update to latest headers & fix errors & cleanup generation script
VulkanSC was added to vk.xml and broke the generation script. This was an
easy fix, just needed to specify which API the version information should
use. Still, took the time to cleanup the code by running pylint and fixing
anything it warned about.
2023-09-19 15:52:27 -06:00

89 lines
3.4 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include "VkBootstrap.h"
TEST_CASE("is_error_code_enum", "[VkBootstrap.error_code]") {
STATIC_REQUIRE(std::is_error_code_enum<vkb::InstanceError>::value);
STATIC_REQUIRE(std::is_error_code_enum<vkb::PhysicalDeviceError>::value);
STATIC_REQUIRE(std::is_error_code_enum<vkb::QueueError>::value);
STATIC_REQUIRE(std::is_error_code_enum<vkb::DeviceError>::value);
STATIC_REQUIRE(std::is_error_code_enum<vkb::SwapchainError>::value);
}
TEST_CASE("make_error_code", "[VkBootstrap.error_code]") {
GIVEN("An InstanceError") {
const auto error = vkb::InstanceError::vulkan_unavailable;
WHEN("Creating an error code from it") {
std::error_code ec = make_error_code(error);
THEN("The error code is equal to the original error") { REQUIRE(ec == error); }
THEN("The error code is not equal to an unrelated error") {
REQUIRE(ec != vkb::InstanceError::failed_create_instance);
}
THEN("We can get the error message") { REQUIRE(ec.message() == "vulkan_unavailable"); }
}
}
GIVEN("A PhysicalDeviceError") {
const auto error = vkb::PhysicalDeviceError::no_physical_devices_found;
WHEN("Creating an error code from it") {
std::error_code ec = make_error_code(error);
THEN("The error code is equal to the original error") { REQUIRE(ec == error); }
THEN("The error code is not equal to an unrelated error") {
REQUIRE(ec != vkb::InstanceError::failed_create_instance);
}
THEN("We can get the error message") { REQUIRE(ec.message() == "no_physical_devices_found"); }
}
}
GIVEN("A QueueError") {
const auto error = vkb::QueueError::invalid_queue_family_index;
WHEN("Creating an error code from it") {
std::error_code ec = make_error_code(error);
THEN("The error code is equal to the original error") { REQUIRE(ec == error); }
THEN("The error code is not equal to an unrelated error") {
REQUIRE(ec != vkb::InstanceError::failed_create_instance);
}
THEN("We can get the error message") { REQUIRE(ec.message() == "invalid_queue_family_index"); }
}
}
GIVEN("A DeviceError") {
const auto error = vkb::DeviceError::failed_create_device;
WHEN("Creating an error code from it") {
std::error_code ec = make_error_code(error);
THEN("The error code is equal to the original error") { REQUIRE(ec == error); }
THEN("The error code is not equal to an unrelated error") {
REQUIRE(ec != vkb::InstanceError::failed_create_instance);
}
THEN("We can get the error message") { REQUIRE(ec.message() == "failed_create_device"); }
}
}
GIVEN("A SwapchainError") {
const auto error = vkb::SwapchainError::failed_create_swapchain;
WHEN("Creating an error code from it") {
std::error_code ec = make_error_code(error);
THEN("The error code is equal to the original error") { REQUIRE(ec == error); }
THEN("The error code is not equal to an unrelated error") {
REQUIRE(ec != vkb::InstanceError::failed_create_instance);
}
THEN("We can get the error message") { REQUIRE(ec.message() == "failed_create_swapchain"); }
}
}
}