|
| 1 | +// Verify compat.eui-neo's `sdl2` window backend and `network` feature. |
| 2 | +// |
| 3 | +// Both are asserted at COMPILE time first, because both fail silently at |
| 4 | +// runtime otherwise: a window backend that did not switch just uses GLFW, and |
| 5 | +// `network` that did not switch leaves core/platform/network.cpp compiled as |
| 6 | +// stubs that return failure. Neither shows up without a display or a network. |
| 7 | +#include <eui_neo.h> |
| 8 | +// SDL_MAIN_HANDLED before <SDL.h>: on Windows SDL_main.h does |
| 9 | +// `#define main SDL_main` and expects the real entry point to come from |
| 10 | +// SDL2main (src/main/windows/SDL_windows_main.c). This package does not ship |
| 11 | +// that — a library consumer should not be handed an entry point — so the test |
| 12 | +// takes SDL's documented alternative and keeps its own main, pairing it with |
| 13 | +// SDL_SetMainReady() below. Without this the link fails with |
| 14 | +// "LNK1561: entry point must be defined". |
| 15 | +#define SDL_MAIN_HANDLED |
| 16 | +#include <SDL.h> |
| 17 | +#include <curl/curl.h> |
| 18 | +import std; |
| 19 | + |
| 20 | +#if !defined(EUI_WINDOW_BACKEND_SDL2) |
| 21 | +#error "sdl2 feature requested but EUI_WINDOW_BACKEND_SDL2 is not defined" |
| 22 | +#endif |
| 23 | +#if !defined(EUI_HAS_CURL) |
| 24 | +#error "network feature requested but EUI_HAS_CURL is not defined" |
| 25 | +#endif |
| 26 | + |
| 27 | +namespace app { |
| 28 | + |
| 29 | +const DslAppConfig& dslAppConfig() { |
| 30 | + static const DslAppConfig config = DslAppConfig{}.title("sdl2 + network test"); |
| 31 | + return config; |
| 32 | +} |
| 33 | + |
| 34 | +void compose(eui::Ui&, const eui::Screen&) {} |
| 35 | + |
| 36 | +} // namespace app |
| 37 | + |
| 38 | +int main() { |
| 39 | + // SDL's dummy driver is a real driver, so unlike the GL/Vulkan backends |
| 40 | + // this actually runs: init, create, query, tear down. |
| 41 | + SDL_SetMainReady(); |
| 42 | + SDL_SetHint(SDL_HINT_VIDEODRIVER, "dummy"); |
| 43 | + if (SDL_Init(SDL_INIT_VIDEO) != 0) { |
| 44 | + std::println("SDL_Init failed: {}", SDL_GetError()); |
| 45 | + return 1; |
| 46 | + } |
| 47 | + SDL_Window* window = SDL_CreateWindow("eui-neo", SDL_WINDOWPOS_UNDEFINED, |
| 48 | + SDL_WINDOWPOS_UNDEFINED, 200, 100, |
| 49 | + SDL_WINDOW_HIDDEN); |
| 50 | + if (window == nullptr) { |
| 51 | + std::println("SDL_CreateWindow failed: {}", SDL_GetError()); |
| 52 | + SDL_Quit(); |
| 53 | + return 2; |
| 54 | + } |
| 55 | + const char* driver = SDL_GetCurrentVideoDriver(); |
| 56 | + SDL_DestroyWindow(window); |
| 57 | + SDL_Quit(); |
| 58 | + |
| 59 | + // libcurl came in through the feature's dependency, and it has TLS — the |
| 60 | + // thing EUI-NEO's downloader needs and the thing a misconfigured curl |
| 61 | + // silently lacks. No connection is made. |
| 62 | + if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) { |
| 63 | + std::println("curl_global_init failed"); |
| 64 | + return 3; |
| 65 | + } |
| 66 | + const curl_version_info_data* curlInfo = curl_version_info(CURLVERSION_NOW); |
| 67 | + const bool haveTls = curlInfo != nullptr && |
| 68 | + (curlInfo->features & CURL_VERSION_SSL) != 0 && |
| 69 | + curlInfo->ssl_version != nullptr; |
| 70 | + curl_global_cleanup(); |
| 71 | + if (!haveTls) { |
| 72 | + std::println("libcurl reached us without TLS"); |
| 73 | + return 4; |
| 74 | + } |
| 75 | + |
| 76 | + // Still eui-neo underneath — a headless facade from the base source set. |
| 77 | + eui::json::Document doc; |
| 78 | + if (!doc.parse(R"({"window": "sdl2"})")) { |
| 79 | + std::println("parse failed: {}", doc.error().message); |
| 80 | + return 5; |
| 81 | + } |
| 82 | + std::string windowBackend; |
| 83 | + if (!doc.stringAt("/window", windowBackend) || windowBackend != "sdl2") { |
| 84 | + std::println("unexpected /window: '{}'", windowBackend); |
| 85 | + return 6; |
| 86 | + } |
| 87 | + |
| 88 | + std::println("compat.eui-neo[sdl2,network]: ok (SDL driver={}, curl {} ssl={})", |
| 89 | + driver, curlInfo->version, curlInfo->ssl_version); |
| 90 | + return 0; |
| 91 | +} |
0 commit comments