|
| 1 | +#define GLFW_INCLUDE_NONE |
| 2 | +#include <GLFW/glfw3.h> |
| 3 | +#include <cstdio> |
| 4 | +#include <cstring> |
| 5 | + |
| 6 | +static void error(int code, const char* description) { |
| 7 | + std::fprintf(stderr, "GLFW error %d: %s\n", code, description); |
| 8 | +} |
| 9 | + |
| 10 | +static bool window_test(int platform) { |
| 11 | + glfwInitHint(GLFW_PLATFORM, platform); |
| 12 | + if (!glfwInit()) return false; |
| 13 | + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); |
| 14 | + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
| 15 | + GLFWwindow* window = glfwCreateWindow(640, 480, "compat.glfw smoke", nullptr, nullptr); |
| 16 | + bool ok = window && glfwGetPlatform() == platform; |
| 17 | + if (window) { |
| 18 | + int width = 0, height = 0; |
| 19 | + glfwGetWindowSize(window, &width, &height); |
| 20 | + int marker = 42; |
| 21 | + glfwSetWindowUserPointer(window, &marker); |
| 22 | + ok = ok && width == 640 && height == 480 && |
| 23 | + glfwGetWindowUserPointer(window) == &marker && |
| 24 | + !glfwWindowShouldClose(window); |
| 25 | + if (!ok) std::fprintf(stderr, "platform %x: size=%dx%d, expected=640x480, user_pointer=%d, should_close=%d\n", |
| 26 | + platform, width, height, |
| 27 | + glfwGetWindowUserPointer(window) == &marker, |
| 28 | + glfwWindowShouldClose(window)); |
| 29 | + glfwSetWindowShouldClose(window, GLFW_TRUE); |
| 30 | + ok = ok && glfwWindowShouldClose(window); |
| 31 | + glfwPollEvents(); |
| 32 | + glfwDestroyWindow(window); |
| 33 | + } |
| 34 | + glfwTerminate(); |
| 35 | + return ok; |
| 36 | +} |
| 37 | + |
| 38 | +int main() { |
| 39 | + glfwSetErrorCallback(error); |
| 40 | + int major = 0, minor = 0, revision = 0; |
| 41 | + glfwGetVersion(&major, &minor, &revision); |
| 42 | + if (major != 3 || minor != 4 || revision != 0) return 1; |
| 43 | + if (!window_test(GLFW_PLATFORM_NULL)) return 2; |
| 44 | +#ifdef _WIN32 |
| 45 | + // Require the real Win32 backend too: a null-only test misses native links. |
| 46 | + if (!glfwPlatformSupported(GLFW_PLATFORM_WIN32)) return 3; |
| 47 | + if (!std::strstr(glfwGetVersionString(), "Win32")) return 4; |
| 48 | + if (!window_test(GLFW_PLATFORM_WIN32)) return 5; |
| 49 | +#endif |
| 50 | + return 0; |
| 51 | +} |
0 commit comments