2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Window/Context.hpp>
|
|
|
|
|
2023-03-26 20:21:21 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/Window/ContextSettings.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-03-26 20:21:21 +08:00
|
|
|
|
|
|
|
#include <WindowUtil.hpp>
|
|
|
|
#include <string>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-03-26 20:21:21 +08:00
|
|
|
#if defined(SFML_SYSTEM_WINDOWS)
|
|
|
|
#define GLAPI __stdcall
|
|
|
|
#else
|
|
|
|
#define GLAPI
|
|
|
|
#endif
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
TEST_CASE("[Window] sf::Context", runDisplayTests())
|
2023-03-26 20:21:21 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(!std::is_copy_constructible_v<sf::Context>);
|
|
|
|
STATIC_CHECK(!std::is_copy_assignable_v<sf::Context>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Context>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::Context>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2023-03-26 20:21:21 +08:00
|
|
|
{
|
|
|
|
const sf::Context context;
|
|
|
|
CHECK(context.getSettings().majorVersion > 0);
|
2023-09-25 11:32:17 +08:00
|
|
|
CHECK(context.getActiveContext() == &context);
|
|
|
|
CHECK(context.getActiveContextId() != 0);
|
2023-03-26 20:21:21 +08:00
|
|
|
}
|
|
|
|
|
2023-09-25 11:32:17 +08:00
|
|
|
SECTION("setActive()")
|
2023-03-26 20:21:21 +08:00
|
|
|
{
|
|
|
|
sf::Context context;
|
2023-09-25 11:32:17 +08:00
|
|
|
CHECK(context.setActive(false));
|
|
|
|
CHECK(context.getActiveContext() == nullptr);
|
|
|
|
CHECK(context.getActiveContextId() == 0);
|
2023-03-26 20:21:21 +08:00
|
|
|
CHECK(context.setActive(true));
|
2023-09-25 11:32:17 +08:00
|
|
|
CHECK(context.getActiveContext() == &context);
|
|
|
|
CHECK(context.getActiveContextId() != 0);
|
|
|
|
}
|
2023-03-26 20:21:21 +08:00
|
|
|
|
2023-09-25 11:32:17 +08:00
|
|
|
SECTION("getActiveContext()/getActiveContextId()")
|
|
|
|
{
|
|
|
|
CHECK(sf::Context::getActiveContext() == nullptr);
|
|
|
|
CHECK(sf::Context::getActiveContextId() == 0);
|
|
|
|
|
|
|
|
{
|
|
|
|
const sf::Context context;
|
|
|
|
CHECK(context.getSettings().majorVersion > 0);
|
|
|
|
CHECK(sf::Context::getActiveContext() == &context);
|
|
|
|
CHECK(sf::Context::getActiveContextId() != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(sf::Context::getActiveContext() == nullptr);
|
|
|
|
CHECK(sf::Context::getActiveContextId() == 0);
|
|
|
|
}
|
2023-03-26 20:21:21 +08:00
|
|
|
|
2023-09-25 11:32:17 +08:00
|
|
|
SECTION("Version String")
|
|
|
|
{
|
|
|
|
sf::Context context;
|
|
|
|
CHECK(context.setActive(true));
|
2023-03-26 20:21:21 +08:00
|
|
|
|
2023-09-25 11:32:17 +08:00
|
|
|
using glGetStringFuncType = const char*(GLAPI*)(unsigned int);
|
|
|
|
const auto glGetStringFunc = reinterpret_cast<glGetStringFuncType>(sf::Context::getFunction("glGetString"));
|
2023-01-18 12:51:08 +08:00
|
|
|
REQUIRE(glGetStringFunc);
|
2023-03-26 20:21:21 +08:00
|
|
|
|
|
|
|
constexpr unsigned int glVendor = 0x1F00;
|
|
|
|
constexpr unsigned int glRenderer = 0x1F01;
|
|
|
|
constexpr unsigned int glVersion = 0x1F02;
|
|
|
|
|
|
|
|
const char* vendor = glGetStringFunc(glVendor);
|
|
|
|
const char* renderer = glGetStringFunc(glRenderer);
|
|
|
|
const char* version = glGetStringFunc(glVersion);
|
|
|
|
|
|
|
|
REQUIRE(vendor != nullptr);
|
|
|
|
REQUIRE(renderer != nullptr);
|
|
|
|
REQUIRE(version != nullptr);
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SUCCEED(std::string("OpenGL vendor: ") + vendor);
|
|
|
|
SUCCEED(std::string("OpenGL renderer: ") + renderer);
|
|
|
|
SUCCEED(std::string("OpenGL version: ") + version);
|
2023-03-26 20:21:21 +08:00
|
|
|
}
|
|
|
|
}
|