Path: blob/main/test/browser/test_glfw3_default_hints.c
4150 views
/*1* Copyright 2023 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <GLFW/glfw3.h>8#include <assert.h>9#include <emscripten/html5.h>1011static void checkDefaultWindowHints() {12int ok = EM_ASM_INT({13var res = 1;14for (var k in TEST_GLFW3_DEFAULTS_HINTS) {15if (GLFW.defaultHints[k] !== TEST_GLFW3_DEFAULTS_HINTS[k])16res = 0;17}18return res;19});20assert(ok == 1);21}2223int main() {2425EM_ASM(26TEST_GLFW3_DEFAULTS_HINTS = {};27TEST_GLFW3_DEFAULTS_HINTS[0x00020001] = 0;28TEST_GLFW3_DEFAULTS_HINTS[0x00020002] = 0;29TEST_GLFW3_DEFAULTS_HINTS[0x00020003] = 1;30TEST_GLFW3_DEFAULTS_HINTS[0x00020004] = 1;31TEST_GLFW3_DEFAULTS_HINTS[0x00020005] = 1;32TEST_GLFW3_DEFAULTS_HINTS[0x0002000A] = 0;33TEST_GLFW3_DEFAULTS_HINTS[0x0002200C] = 0;3435TEST_GLFW3_DEFAULTS_HINTS[0x00021001] = 8;36TEST_GLFW3_DEFAULTS_HINTS[0x00021002] = 8;37TEST_GLFW3_DEFAULTS_HINTS[0x00021003] = 8;38TEST_GLFW3_DEFAULTS_HINTS[0x00021004] = 8;39TEST_GLFW3_DEFAULTS_HINTS[0x00021005] = 24;40TEST_GLFW3_DEFAULTS_HINTS[0x00021006] = 8;41TEST_GLFW3_DEFAULTS_HINTS[0x00021007] = 0;42TEST_GLFW3_DEFAULTS_HINTS[0x00021008] = 0;43TEST_GLFW3_DEFAULTS_HINTS[0x00021009] = 0;44TEST_GLFW3_DEFAULTS_HINTS[0x0002100A] = 0;45TEST_GLFW3_DEFAULTS_HINTS[0x0002100B] = 0;46TEST_GLFW3_DEFAULTS_HINTS[0x0002100C] = 0;47TEST_GLFW3_DEFAULTS_HINTS[0x0002100D] = 0;48TEST_GLFW3_DEFAULTS_HINTS[0x0002100E] = 0;49TEST_GLFW3_DEFAULTS_HINTS[0x0002100F] = 0;5051TEST_GLFW3_DEFAULTS_HINTS[0x00022001] = 0x00030001;52TEST_GLFW3_DEFAULTS_HINTS[0x00022002] = 1;53TEST_GLFW3_DEFAULTS_HINTS[0x00022003] = 0;54TEST_GLFW3_DEFAULTS_HINTS[0x00022004] = 0;55TEST_GLFW3_DEFAULTS_HINTS[0x00022005] = 0;56TEST_GLFW3_DEFAULTS_HINTS[0x00022006] = 0;57TEST_GLFW3_DEFAULTS_HINTS[0x00022007] = 0;58TEST_GLFW3_DEFAULTS_HINTS[0x00022008] = 0;59);6061assert(glfwInit() == GLFW_TRUE);6263// Use case: after glfwInit, default window hints are correct64{65checkDefaultWindowHints();66}6768// Use case: updates a window hint69// Expected results: window hint is properly updated70// default window hints are not affected71{72// GLFW_DEPTH_BITS73assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 24);74glfwWindowHint(GLFW_DEPTH_BITS, 16);75assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 16);76checkDefaultWindowHints();77}7879// Use case: resets window hints to default80// Expected results: previously changed window hint is back to its default value81// default window hints are not affected82{83glfwDefaultWindowHints();84assert(EM_ASM_INT(return GLFW.hints[0x00021005];) == 24);85checkDefaultWindowHints();86}8788// Use case: change window hint, create window, then change window hint89// Expected results: the window hint set at creation time (which is now a90// window attribute that can be read with glfwGetWindowAttrib)91// does not change92{93glfwDefaultWindowHints();94glfwWindowHint(GLFW_DEPTH_BITS, 16);95GLFWwindow* window = glfwCreateWindow(640, 480, "test_glfw3_default_hints.c", NULL, NULL);96assert(glfwGetWindowAttrib(window, GLFW_DEPTH_BITS) == 16);97glfwWindowHint(GLFW_DEPTH_BITS, 24);98assert(glfwGetWindowAttrib(window, GLFW_DEPTH_BITS) == 16);99}100101glfwTerminate();102103return 0;104}105106107