diff options
Diffstat (limited to 'test')
33 files changed, 391 insertions, 842 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy index c88c7b3..4dbdc80 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -3,14 +3,11 @@ Checks: > -bugprone-multi-level-implicit-pointer-conversion, - -bugprone-suspicious-include, -cert-err33-c, -cert-err34-c, -clang-analyzer-optin.core.EnumCastOutOfRange, - -google-runtime-references, -hicpp-multiway-paths-covered, -hicpp-signed-bitwise, -llvm-header-guard, - -modernize-use-trailing-return-type, -readability-function-cognitive-complexity, InheritParentConfig: true diff --git a/test/cpp/.clang-tidy b/test/cpp/.clang-tidy new file mode 100644 index 0000000..fe7d8ec --- /dev/null +++ b/test/cpp/.clang-tidy @@ -0,0 +1,39 @@ +# Copyright 2020-2025 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR ISC + +Checks: > + -*-use-auto, + -*-use-nullptr, + -bugprone-easily-swappable-parameters, + -bugprone-suspicious-include, + -cert-dcl50-cpp, + -cppcoreguidelines-avoid-c-arrays, + -cppcoreguidelines-avoid-do-while, + -cppcoreguidelines-macro-usage, + -cppcoreguidelines-no-malloc, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-member-init, + -cppcoreguidelines-pro-type-union-access, + -cppcoreguidelines-pro-type-vararg, + -google-readability-casting, + -google-runtime-int, + -hicpp-avoid-c-arrays, + -hicpp-member-init, + -hicpp-named-parameter, + -hicpp-no-array-decay, + -hicpp-no-malloc, + -hicpp-vararg, + -misc-use-anonymous-namespace, + -modernize-avoid-c-arrays, + -modernize-loop-convert, + -modernize-loop-convert, + -modernize-redundant-void-arg, + -modernize-use-trailing-return-type, + -modernize-use-using, + -performance-enum-size, + -readability-named-parameter, +InheritParentConfig: true diff --git a/test/cpp/meson.build b/test/cpp/meson.build new file mode 100644 index 0000000..94c64d1 --- /dev/null +++ b/test/cpp/meson.build @@ -0,0 +1,108 @@ +# Copyright 2021-2025 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR ISC + +test_cpp_args = [] +if get_option('warning_level') == 'everything' and is_variable('cpp') + if cpp.get_id() == 'clang' + test_cpp_args += [ + '-Wno-documentation', # Cairo + '-Wno-documentation-unknown-command', # Cairo + '-Wno-old-style-cast', + ] + endif + + test_cpp_args = cpp.get_supported_arguments(test_cpp_args) +endif + +unified_args = core_args +unified_deps = [core_deps] +if cairo_dep.found() + unified_args += ['-DWITH_CAIRO'] + unified_deps += [cairo_dep] +endif + +if opengl_dep.found() + unified_args += ['-DWITH_OPENGL'] + unified_deps += [opengl_dep] +endif + +if vulkan_dep.found() + unified_args += ['-DWITH_VULKAN'] + unified_deps += [vulkan_deps] +endif + +if host_machine.system() == 'darwin' + add_languages(['objcpp'], native: false) + + objcpp = meson.get_compiler('objcpp') + + objcpp_unified_args = unified_args + if objcpp.get_id() == 'clang' + objcpp_unified_args += [ + '-Wno-c++98-compat', + '-Wno-c++98-compat-pedantic', + '-Wno-deprecated-declarations', + '-Wno-direct-ivar-access', + ] + endif + + objcpp_unified_args = objcpp.get_supported_arguments(objcpp_unified_args) + + test( + 'inline_objcpp', + executable( + 'test_inline_objcpp', + 'test_inline_objcpp.mm', + dependencies: unified_deps, + implicit_include_directories: false, + include_directories: include_directories('../../include'), + objcpp_args: objcpp_unified_args, + ), + suite: 'unit', + ) + +elif is_variable('cpp') + cpp_unified_args = unified_args + if cpp.get_id() == 'clang' + cpp_unified_args += [ + '-Wno-old-style-cast', + '-Wno-switch-default', + '-Wno-switch-enum', + '-Wno-unused-macros', # Mac + ] + if host_machine.system() == 'windows' + cpp_unified_args += [ + '-Wno-cast-function-type', + '-Wno-deprecated-declarations', + '-Wno-nonportable-system-include-path', + ] + endif + elif cpp.get_id() == 'gcc' + cpp_unified_args += [ + '-Wno-conditionally-supported', + '-Wno-old-style-cast', + '-Wno-switch-default', + '-Wno-switch-enum', + '-Wno-useless-cast', + ] + elif cpp.get_id() == 'msvc' + cpp_unified_args += [ + '/wd4464', # relative include path contains '..' + ] + endif + + cpp_unified_args = cpp.get_supported_arguments(cpp_unified_args) + + test( + 'inline_cpp', + executable( + 'test_inline_cpp', + 'test_inline_cpp.cpp', + cpp_args: cpp_unified_args, + dependencies: unified_deps, + implicit_include_directories: false, + include_directories: include_directories('../../include'), + ), + suite: 'unit', + ) +endif diff --git a/test/cpp/test_build.cpp b/test/cpp/test_build.cpp new file mode 100644 index 0000000..2419be9 --- /dev/null +++ b/test/cpp/test_build.cpp @@ -0,0 +1,16 @@ +// Copyright 2020 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +// Tests that C++ headers compile without any warnings + +#include <pugl/cairo.hpp> // IWYU pragma: keep +#include <pugl/gl.hpp> // IWYU pragma: keep +#include <pugl/pugl.h> // IWYU pragma: keep +#include <pugl/pugl.hpp> // IWYU pragma: keep +#include <pugl/stub.hpp> // IWYU pragma: keep + +int +main() +{ + return 0; +} diff --git a/test/test_inline_cpp.cpp b/test/cpp/test_inline_cpp.cpp index f5694eb..4c47ffb 100644 --- a/test/test_inline_cpp.cpp +++ b/test/cpp/test_inline_cpp.cpp @@ -23,34 +23,34 @@ # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" #endif -#include "../src/common.c" // IWYU pragma: keep -#include "../src/internal.c" // IWYU pragma: keep +#include "../../src/common.c" // IWYU pragma: keep +#include "../../src/internal.c" // IWYU pragma: keep #if defined(_WIN32) -# include "../src/win.c" // IWYU pragma: keep -# include "../src/win.h" // IWYU pragma: keep -# include "../src/win_stub.c" // IWYU pragma: keep +# include "../../src/win.c" // IWYU pragma: keep +# include "../../src/win.h" // IWYU pragma: keep +# include "../../src/win_stub.c" // IWYU pragma: keep # if defined(WITH_CAIRO) -# include "../src/win_cairo.c" // IWYU pragma: keep +# include "../../src/win_cairo.c" // IWYU pragma: keep # endif # if defined(WITH_OPENGL) -# include "../src/win_gl.c" // IWYU pragma: keep +# include "../../src/win_gl.c" // IWYU pragma: keep # endif # if defined(WITH_VULKAN) -# include "../src/win_vulkan.c" // IWYU pragma: keep +# include "../../src/win_vulkan.c" // IWYU pragma: keep # endif #else -# include "../src/x11.c" // IWYU pragma: keep -# include "../src/x11_stub.c" // IWYU pragma: keep +# include "../../src/x11.c" // IWYU pragma: keep +# include "../../src/x11_stub.c" // IWYU pragma: keep # if defined(WITH_CAIRO) -# include "../src/x11_cairo.c" // IWYU pragma: keep +# include "../../src/x11_cairo.c" // IWYU pragma: keep # endif # if defined(WITH_OPENGL) -# include "../src/x11_gl.c" // IWYU pragma: keep +# include "../../src/x11_gl.c" // IWYU pragma: keep # endif # if defined(WITH_VULKAN) -# include "../src/x11_vulkan.c" // IWYU pragma: keep +# include "../../src/x11_vulkan.c" // IWYU pragma: keep # endif #endif diff --git a/test/test_inline_objcpp.mm b/test/cpp/test_inline_objcpp.mm index 1c9079b..b4d65c6 100644 --- a/test/test_inline_objcpp.mm +++ b/test/cpp/test_inline_objcpp.mm @@ -9,22 +9,22 @@ # pragma clang diagnostic ignored "-Wold-style-cast" #endif -#include "../src/common.c" // IWYU pragma: keep -#include "../src/internal.c" // IWYU pragma: keep -#include "../src/mac.h" // IWYU pragma: keep -#include "../src/mac.m" // IWYU pragma: keep -#include "../src/mac_stub.m" // IWYU pragma: keep +#include "../../src/common.c" // IWYU pragma: keep +#include "../../src/internal.c" // IWYU pragma: keep +#include "../../src/mac.h" // IWYU pragma: keep +#include "../../src/mac.m" // IWYU pragma: keep +#include "../../src/mac_stub.m" // IWYU pragma: keep #if defined(WITH_CAIRO) -# include "../src/mac_cairo.m" // IWYU pragma: keep +# include "../../src/mac_cairo.m" // IWYU pragma: keep #endif #if defined(WITH_OPENGL) -# include "../src/mac_gl.m" // IWYU pragma: keep +# include "../../src/mac_gl.m" // IWYU pragma: keep #endif #if defined(WITH_VULKAN) -# include "../src/mac_vulkan.m" // IWYU pragma: keep +# include "../../src/mac_vulkan.m" // IWYU pragma: keep #endif #if defined(__clang__) diff --git a/test/headers/.clang-tidy b/test/headers/.clang-tidy new file mode 100644 index 0000000..7ec81cf --- /dev/null +++ b/test/headers/.clang-tidy @@ -0,0 +1,16 @@ +# Copyright 2020-2025 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR ISC + +Checks: > + *, + -*-magic-numbers, + -altera-*, + -llvmlibc-*, +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: '0' + - key: readability-identifier-length.IgnoredParameterNames + value: '^(id)|(x)|(y)$' +FormatStyle: file +HeaderFilterRegex: '.*' +WarningsAsErrors: '*' diff --git a/test/headers/meson.build b/test/headers/meson.build new file mode 100644 index 0000000..69fd51b --- /dev/null +++ b/test/headers/meson.build @@ -0,0 +1,36 @@ +# Copyright 2020-2025 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR ISC + +header_c_suppressions = [] + +if get_option('warning_level') == 'everything' + if cc.get_id() == 'clang' + if not meson.is_cross_build() + header_c_suppressions += ['-Wno-poison-system-directories'] + endif + endif +endif + +header_c_suppressions = cc.get_supported_arguments(header_c_suppressions) + +test_headers_c_args = header_c_suppressions +test_headers_c_args += [ + '-DPUGL_NO_INCLUDE_GL_H', + '-DPUGL_NO_INCLUDE_GLU_H', +] + +if vulkan_dep.found() + test_headers_c_args += ['-DPUGL_TEST_VULKAN'] +endif + +test( + 'headers', + executable( + 'test_headers_c', + files('test_headers.c'), + c_args: test_headers_c_args, + dependencies: [pugl_dep, vulkan_dep], + implicit_include_directories: false, + ), + suite: 'unit', +) diff --git a/test/headers/test_headers.c b/test/headers/test_headers.c new file mode 100644 index 0000000..2e109f2 --- /dev/null +++ b/test/headers/test_headers.c @@ -0,0 +1,22 @@ +// Copyright 2022-2025 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include <pugl/attributes.h> // IWYU pragma: keep +#include <pugl/cairo.h> // IWYU pragma: keep +#include <pugl/gl.h> // IWYU pragma: keep +#include <pugl/glu.h> // IWYU pragma: keep +#include <pugl/pugl.h> // IWYU pragma: keep +#include <pugl/stub.h> // IWYU pragma: keep + +#ifdef PUGL_TEST_VULKAN +# include <pugl/vulkan.h> // IWYU pragma: keep +#endif + +#ifdef __GNUC__ +__attribute__((const)) +#endif +int +main(void) +{ + return 0; +} diff --git a/test/meson.build b/test/meson.build index 791cf04..f047ff0 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,4 +1,4 @@ -# Copyright 2021-2023 David Robillard <d@drobilla.net> +# Copyright 2021-2025 David Robillard <d@drobilla.net> # SPDX-License-Identifier: 0BSD OR ISC # Suppress some additional C warnings in tests @@ -17,20 +17,6 @@ if get_option('warning_level') == 'everything' test_c_args = cc.get_supported_arguments(test_c_args) endif -# Suppress some additional C++ warnings in tests -test_cpp_args = [] -if get_option('warning_level') == 'everything' and is_variable('cpp') - if cpp.get_id() == 'clang' - test_cpp_args += [ - '-Wno-documentation', # Cairo - '-Wno-documentation-unknown-command', # Cairo - '-Wno-old-style-cast', - ] - endif - - test_cpp_args = cpp.get_supported_arguments(test_cpp_args) -endif - # Check licensing metadata if not meson.is_subproject() and get_option('lint') reuse = find_program('reuse', required: false) @@ -70,11 +56,6 @@ if with_timers basic_tests += ['timer'] endif -includes = [ - '.', - '../include', -] - foreach test : basic_tests test( test, @@ -82,8 +63,8 @@ foreach test : basic_tests 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args, - dependencies: [pugl_dep, pugl_stub_dep], - include_directories: include_directories(includes), + dependencies: [pugl_dep, pugl_stub_dep, puglutil_dep], + implicit_include_directories: false, ), suite: 'unit', ) @@ -96,8 +77,8 @@ foreach test : basic_exclusive_tests 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args, - dependencies: [pugl_dep, pugl_stub_dep], - include_directories: include_directories(includes), + dependencies: [pugl_dep, pugl_stub_dep, puglutil_dep], + implicit_include_directories: false, ), is_parallel: false, suite: 'unit', @@ -112,8 +93,8 @@ if opengl_dep.found() 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args, - dependencies: [pugl_dep, pugl_gl_dep], - include_directories: include_directories(includes), + dependencies: [pugl_dep, pugl_gl_dep, puglutil_dep], + implicit_include_directories: false, ), suite: 'unit', ) @@ -128,8 +109,8 @@ if cairo_dep.found() 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args + cairo_args, - dependencies: [pugl_dep, pugl_cairo_dep], - include_directories: include_directories(includes), + dependencies: [pugl_dep, pugl_cairo_dep, puglutil_dep], + implicit_include_directories: false, ), suite: 'unit', ) @@ -144,95 +125,24 @@ if vulkan_dep.found() 'test_' + test, 'test_@0@.c'.format(test), c_args: test_c_args, - cpp_args: test_cpp_args, - dependencies: [pugl_dep, pugl_vulkan_dep], - include_directories: include_directories(includes), + dependencies: [pugl_dep, pugl_vulkan_dep, puglutil_dep], + implicit_include_directories: false, ), suite: 'unit', ) endforeach endif -unified_args = core_args -unified_deps = [core_deps] -if cairo_dep.found() - unified_args += ['-DWITH_CAIRO'] - unified_deps += [cairo_dep] -endif - -if opengl_dep.found() - unified_args += ['-DWITH_OPENGL'] - unified_deps += [opengl_dep] -endif - -if vulkan_dep.found() - unified_args += ['-DWITH_VULKAN'] - unified_deps += [vulkan_deps] -endif - -if host_machine.system() == 'darwin' - add_languages(['objcpp'], native: false) - - objcpp = meson.get_compiler('objcpp') - - objcpp_unified_args = unified_args - if objcpp.get_id() == 'clang' - objcpp_unified_args += [ - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-deprecated-declarations', - '-Wno-direct-ivar-access', - ] - endif - - objcpp_unified_args = objcpp.get_supported_arguments(objcpp_unified_args) - - test( - 'inline_objcpp', - executable( - 'test_inline_objcpp', - 'test_inline_objcpp.mm', - dependencies: unified_deps, - include_directories: include_directories(includes), - objcpp_args: objcpp_unified_args, - ), - suite: 'unit', - ) +################### +# Header Warnings # +################### -elif is_variable('cpp') - cpp_unified_args = unified_args - if cpp.get_id() == 'clang' - cpp_unified_args += [ - '-Wno-old-style-cast', - '-Wno-switch-default', - '-Wno-switch-enum', - '-Wno-unused-macros', # Mac - ] - elif cpp.get_id() == 'gcc' - cpp_unified_args += [ - '-Wno-conditionally-supported', - '-Wno-old-style-cast', - '-Wno-switch-default', - '-Wno-switch-enum', - '-Wno-useless-cast', - ] - elif cpp.get_id() == 'msvc' - cpp_unified_args += [ - '/wd4464', # relative include path contains '..' - ] - endif +subdir('headers') - cpp_unified_args = cpp.get_supported_arguments(cpp_unified_args) +####################### +# C++ / Objective C++ # +####################### - test( - 'inline_cpp', - executable( - 'test_inline_cpp', - 'test_inline_cpp.cpp', - cpp_args: cpp_unified_args, - dependencies: unified_deps, - include_directories: include_directories(includes), - ), - suite: 'unit', - ) +if is_variable('cpp') + subdir('cpp') endif diff --git a/test/test_build.c b/test/test_build.c index e28df3c..4f66eca 100644 --- a/test/test_build.c +++ b/test/test_build.c @@ -1,17 +1,13 @@ // Copyright 2020 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -/* - Tests that C headers compile without any warnings. -*/ +// Tests that C headers compile without any warnings -#define PUGL_DISABLE_DEPRECATED - -#include "pugl/cairo.h" // IWYU pragma: keep -#include "pugl/gl.h" // IWYU pragma: keep -#include "pugl/glu.h" // IWYU pragma: keep -#include "pugl/pugl.h" // IWYU pragma: keep -#include "pugl/stub.h" // IWYU pragma: keep +#include <pugl/cairo.h> // IWYU pragma: keep +#include <pugl/gl.h> // IWYU pragma: keep +#include <pugl/glu.h> // IWYU pragma: keep +#include <pugl/pugl.h> // IWYU pragma: keep +#include <pugl/stub.h> // IWYU pragma: keep int main(void) diff --git a/test/test_build.cpp b/test/test_build.cpp deleted file mode 100644 index 4fd2dac..0000000 --- a/test/test_build.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -/* - Tests that C++ headers compile without any warnings. -*/ - -#define PUGL_DISABLE_DEPRECATED - -#include "pugl/cairo.hpp" // IWYU pragma: keep -#include "pugl/gl.hpp" // IWYU pragma: keep -#include "pugl/pugl.h" // IWYU pragma: keep -#include "pugl/pugl.hpp" // IWYU pragma: keep -#include "pugl/stub.hpp" // IWYU pragma: keep - -int -main() -{ - return 0; -} diff --git a/test/test_cairo.c b/test/test_cairo.c index 11d6cce..9abc51e 100644 --- a/test/test_cairo.c +++ b/test/test_cairo.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/cairo.h" -#include "pugl/pugl.h" +#include <pugl/cairo.h> +#include <pugl/pugl.h> #include <cairo.h> @@ -66,7 +66,7 @@ main(int argc, char** argv) puglSetBackend(test.view, puglCairoBackend()); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 128, 896); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 896); puglShow(test.view, PUGL_SHOW_RAISE); // Drive event loop until the view gets exposed diff --git a/test/test_clipboard.c b/test/test_clipboard.c index debe8e3..054f71d 100644 --- a/test/test_clipboard.c +++ b/test/test_clipboard.c @@ -9,8 +9,8 @@ #include "test_utils.h" -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> diff --git a/test/test_cursor.c b/test/test_cursor.c index 9b0fa66..399f797 100644 --- a/test/test_cursor.c +++ b/test/test_cursor.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -52,7 +52,7 @@ main(int argc, char** argv) puglSetBackend(test.view, puglStubBackend()); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 896, 640); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 640); puglShow(test.view, PUGL_SHOW_RAISE); // Drive event loop until the view gets exposed diff --git a/test/test_gl.c b/test/test_gl.c index 8854cad..dac41b5 100644 --- a/test/test_gl.c +++ b/test/test_gl.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/gl.h" -#include "pugl/pugl.h" +#include <pugl/gl.h> +#include <pugl/pugl.h> #include <assert.h> #include <stdbool.h> @@ -85,7 +85,7 @@ main(int argc, char** argv) puglSetBackend(test.view, puglGlBackend()); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 384, 896); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 896); puglShow(test.view, PUGL_SHOW_RAISE); // Enter OpenGL context as if setting things up diff --git a/test/test_gl_free_unrealized.c b/test/test_gl_free_unrealized.c index ba0d895..7ff8913 100644 --- a/test/test_gl_free_unrealized.c +++ b/test/test_gl_free_unrealized.c @@ -9,8 +9,8 @@ #undef NDEBUG -#include "pugl/gl.h" -#include "pugl/pugl.h" +#include <pugl/gl.h> +#include <pugl/pugl.h> #include <assert.h> #include <stddef.h> @@ -32,7 +32,7 @@ main(void) puglSetBackend(test.view, puglGlBackend()); puglSetHandle(test.view, &test); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 640, 896); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 896); assert(!puglGetVisible(test.view)); diff --git a/test/test_gl_hints.c b/test/test_gl_hints.c index 250136a..824679a 100644 --- a/test/test_gl_hints.c +++ b/test/test_gl_hints.c @@ -1,16 +1,14 @@ // Copyright 2020 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -/* - Tests that all hints are set to real values after a view is realized. -*/ +// Tests that all hints are set to real values after a view is realized #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/gl.h" -#include "pugl/pugl.h" +#include <pugl/gl.h> +#include <pugl/pugl.h> #include <assert.h> @@ -35,7 +33,7 @@ main(void) puglSetBackend(view, puglGlBackend()); puglSetEventFunc(view, onEvent); puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(view, 128, 128); + puglSetPositionHint(view, PUGL_DEFAULT_POSITION, 128, 128); // Check invalid cases assert(puglSetViewHint(view, PUGL_CONTEXT_API, PUGL_DONT_CARE) == diff --git a/test/test_local_copy_paste.c b/test/test_local_copy_paste.c index 737f193..6d4899e 100644 --- a/test/test_local_copy_paste.c +++ b/test/test_local_copy_paste.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -133,7 +133,7 @@ main(int argc, char** argv) puglSetHandle(app.view, &app); puglSetEventFunc(app.view, onEvent); puglSetSizeHint(app.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(app.view, 384, 128); + puglSetPositionHint(app.view, PUGL_DEFAULT_POSITION, 384, 128); // Create and show window assert(!puglRealize(app.view)); diff --git a/test/test_realize.c b/test/test_realize.c index 7e37319..3d706ce 100644 --- a/test/test_realize.c +++ b/test/test_realize.c @@ -11,10 +11,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -75,7 +75,7 @@ main(int argc, char** argv) assert(puglRealize(test.view) == PUGL_BAD_CONFIGURATION); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 640, 128); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 128); // Create initially invisible window assert(!puglRealize(test.view)); diff --git a/test/test_redisplay.c b/test/test_redisplay.c index 1276136..01be5b6 100644 --- a/test/test_redisplay.c +++ b/test/test_redisplay.c @@ -8,10 +8,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -51,8 +51,11 @@ typedef struct { State state; } PuglTest; -static const PuglRect redisplayRect = {2, 4, 8, 16}; -static const uintptr_t postRedisplayId = 42; +static const PuglCoord obscureX = 2; +static const PuglCoord obscureY = 4; +static const PuglSpan obscureWidth = 8; +static const PuglSpan obscureHeight = 16; +static const uintptr_t obscureId = 42; static PuglStatus onEvent(PuglView* view, const PuglEvent* event) @@ -67,7 +70,7 @@ onEvent(PuglView* view, const PuglEvent* event) switch (event->type) { case PUGL_UPDATE: if (test->state == SHOULD_REDISPLAY) { - puglPostRedisplayRect(view, redisplayRect); + puglObscureRegion(view, obscureX, obscureY, obscureWidth, obscureHeight); test->state = POSTED_REDISPLAY; } break; @@ -75,13 +78,12 @@ onEvent(PuglView* view, const PuglEvent* event) case PUGL_EXPOSE: if (test->state == START) { test->state = EXPOSED; - } else if (test->state == POSTED_REDISPLAY && - event->expose.x <= redisplayRect.x && - event->expose.y <= redisplayRect.y && + } else if (test->state == POSTED_REDISPLAY && event->expose.x <= obscureX && + event->expose.y <= obscureY && (event->expose.x + event->expose.width >= - redisplayRect.x + redisplayRect.width) && + obscureX + obscureWidth) && (event->expose.y + event->expose.height >= - redisplayRect.y + redisplayRect.height)) { + obscureY + obscureHeight)) { test->state = REDISPLAYED; } else if (test->state == REDISPLAYED) { test->state = REREDISPLAYED; @@ -89,7 +91,7 @@ onEvent(PuglView* view, const PuglEvent* event) break; case PUGL_CLIENT: - if (event->client.data1 == postRedisplayId) { + if (event->client.data1 == obscureId) { test->state = SHOULD_REDISPLAY; } break; @@ -117,7 +119,7 @@ main(int argc, char** argv) puglSetHandle(test.view, &test); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 896, 128); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 128); // Create and show window assert(!puglRealize(test.view)); @@ -127,8 +129,8 @@ main(int argc, char** argv) } // Send a custom event to trigger a redisplay in the event loop - PuglEvent client_event = {{PUGL_CLIENT, 0}}; - client_event.client.data1 = postRedisplayId; + PuglEvent client_event = {{PUGL_CLIENT, 0U}}; + client_event.client.data1 = obscureId; client_event.client.data2 = 0; assert(!puglSendEvent(test.view, &client_event)); @@ -140,7 +142,7 @@ main(int argc, char** argv) } // Redisplay from outside the event handler - puglPostRedisplay(test.view); + puglObscureView(test.view); while (test.state != REREDISPLAYED) { assert(!puglUpdate(test.world, timeout)); } diff --git a/test/test_remote_copy_paste.c b/test/test_remote_copy_paste.c index a9f079e..3d1756b 100644 --- a/test/test_remote_copy_paste.c +++ b/test/test_remote_copy_paste.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -148,7 +148,7 @@ main(int argc, char** argv) puglSetHandle(app.copierView, &app); puglSetEventFunc(app.copierView, onCopierEvent); puglSetSizeHint(app.copierView, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(app.copierView, 640, 896); + puglSetPositionHint(app.copierView, PUGL_DEFAULT_POSITION, 640, 896); // Set up paster view app.pasterView = puglNewView(app.world); @@ -158,7 +158,7 @@ main(int argc, char** argv) puglSetHandle(app.pasterView, &app); puglSetEventFunc(app.pasterView, onPasterEvent); puglSetSizeHint(app.pasterView, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(app.pasterView, 896, 896); + puglSetPositionHint(app.pasterView, PUGL_DEFAULT_POSITION, 896, 896); // Create and show both views assert(!puglShow(app.copierView, PUGL_SHOW_RAISE)); diff --git a/test/test_show_hide.c b/test/test_show_hide.c index 1517203..8b67325 100644 --- a/test/test_show_hide.c +++ b/test/test_show_hide.c @@ -8,10 +8,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -115,7 +115,7 @@ main(int argc, char** argv) puglSetHandle(test.view, &test); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 128, 384); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 384); // Create initially invisible window assert(!puglRealize(test.view)); diff --git a/test/test_size.c b/test/test_size.c index e3f738a..9c9f518 100644 --- a/test/test_size.c +++ b/test/test_size.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -26,7 +26,8 @@ typedef struct { PuglView* view; PuglTestOptions opts; State state; - PuglRect configuredFrame; + PuglPoint configuredPos; + PuglArea configuredSize; } PuglTest; static PuglStatus @@ -47,10 +48,10 @@ onEvent(PuglView* view, const PuglEvent* event) if (test->state == REALIZED) { test->state = CONFIGURED; } - test->configuredFrame.x = event->configure.x; - test->configuredFrame.y = event->configure.y; - test->configuredFrame.width = event->configure.width; - test->configuredFrame.height = event->configure.height; + test->configuredPos.x = event->configure.x; + test->configuredPos.y = event->configure.y; + test->configuredSize.width = event->configure.width; + test->configuredSize.height = event->configure.height; break; case PUGL_UNREALIZE: test->state = UNREALIZED; @@ -73,7 +74,8 @@ main(int argc, char** argv) NULL, puglParseTestOptions(&argc, &argv), START, - {0, 0, 0U, 0U}}; + {0, 0}, + {0U, 0U}}; // Set up view with size bounds and an aspect ratio test.view = puglNewView(test.world); @@ -87,7 +89,7 @@ main(int argc, char** argv) puglSetSizeHint(test.view, PUGL_MIN_SIZE, minSize, minSize); puglSetSizeHint(test.view, PUGL_MAX_SIZE, maxSize, maxSize); puglSetSizeHint(test.view, PUGL_FIXED_ASPECT, 1, 1); - puglSetPosition(test.view, 384, 384); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 384); // Create and show window assert(!puglRealize(test.view)); @@ -97,21 +99,22 @@ main(int argc, char** argv) } // Check that the frame matches the last configure event - const PuglRect frame = puglGetFrame(test.view); - assert(frame.x == test.configuredFrame.x); - assert(frame.y == test.configuredFrame.y); - assert(frame.width == test.configuredFrame.width); - assert(frame.height == test.configuredFrame.height); + const PuglPoint pos = puglGetPositionHint(test.view, PUGL_CURRENT_POSITION); + const PuglArea size = puglGetSizeHint(test.view, PUGL_CURRENT_SIZE); + assert(pos.x == test.configuredPos.x); + assert(pos.y == test.configuredPos.y); + assert(size.width == test.configuredSize.width); + assert(size.height == test.configuredSize.height); #if defined(_WIN32) || defined(__APPLE__) /* Some window managers on Linux (particularly tiling ones) just disregard these hints entirely, so we only check that the size is in bounds on MacOS and Windows where this is more or less universally supported. */ - assert(frame.width >= minSize); - assert(frame.height >= minSize); - assert(frame.width <= maxSize); - assert(frame.height <= maxSize); + assert(size.width >= minSize); + assert(size.height >= minSize); + assert(size.width <= maxSize); + assert(size.height <= maxSize); #endif // Tear down diff --git a/test/test_strerror.c b/test/test_strerror.c index c120a93..4bce4eb 100644 --- a/test/test_strerror.c +++ b/test/test_strerror.c @@ -5,7 +5,7 @@ #undef NDEBUG -#include "pugl/pugl.h" +#include <pugl/pugl.h> #include <assert.h> #include <ctype.h> diff --git a/test/test_stub.c b/test/test_stub.c index bd8a0eb..7913fd4 100644 --- a/test/test_stub.c +++ b/test/test_stub.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -52,7 +52,7 @@ main(int argc, char** argv) puglSetBackend(test.view, puglStubBackend()); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 384, 896); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 896); puglShow(test.view, PUGL_SHOW_RAISE); // Drive event loop until the view gets exposed diff --git a/test/test_stub_hints.c b/test/test_stub_hints.c index b7d54e3..5694261 100644 --- a/test/test_stub_hints.c +++ b/test/test_stub_hints.c @@ -1,16 +1,14 @@ // Copyright 2020 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -/* - Tests that all hints are set to real values after a view is realized. -*/ +// Tests that all hints are set to real values after a view is realized #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> @@ -35,7 +33,7 @@ main(void) puglSetBackend(view, puglStubBackend()); puglSetEventFunc(view, onEvent); puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(view, 640, 384); + puglSetPositionHint(view, PUGL_DEFAULT_POSITION, 640, 384); // Check invalid cases assert(puglSetViewHint(view, (PuglViewHint)-1, 0) == PUGL_BAD_PARAMETER); diff --git a/test/test_timer.c b/test/test_timer.c index 405a5c2..8015b9a 100644 --- a/test/test_timer.c +++ b/test/test_timer.c @@ -8,10 +8,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <math.h> @@ -157,7 +157,7 @@ main(int argc, char** argv) puglSetHandle(test.view, &test); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 896, 384); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 896, 384); // Create and show window assert(!puglRealize(test.view)); diff --git a/test/test_update.c b/test/test_update.c index 4710ca2..c078e6b 100644 --- a/test/test_update.c +++ b/test/test_update.c @@ -8,10 +8,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -63,7 +63,7 @@ onEvent(PuglView* view, const PuglEvent* event) case PUGL_UPDATE: if (test->state == EXPOSED1) { test->state = UPDATED; - puglPostRedisplay(view); + puglObscureView(view); } break; @@ -90,7 +90,7 @@ main(int argc, char** argv) puglSetHandle(test.view, &test); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 128, 640); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 128, 640); // Create and show window assert(!puglRealize(test.view)); diff --git a/test/test_utils.h b/test/test_utils.h deleted file mode 100644 index 214b360..0000000 --- a/test/test_utils.h +++ /dev/null @@ -1,572 +0,0 @@ -// Copyright 2012-2023 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#ifndef TEST_TEST_UTILS_H -#define TEST_TEST_UTILS_H - -#include "pugl/pugl.h" - -#include <inttypes.h> -#include <stdarg.h> -#include <stdbool.h> -#include <stdio.h> -#include <string.h> - -#ifdef __GNUC__ -# define PUGL_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) -#else -# define PUGL_LOG_FUNC(fmt, arg1) -#endif - -typedef struct { - int samples; - int doubleBuffer; - int sync; - int glApi; - int glMajorVersion; - int glMinorVersion; - bool continuous; - bool help; - bool ignoreKeyRepeat; - bool resizable; - bool verbose; - bool errorChecking; -} PuglTestOptions; - -PUGL_LOG_FUNC(1, 2) -static int -logError(const char* fmt, ...) -{ - fprintf(stderr, "error: "); - - va_list args; // NOLINT - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - - return 1; -} - -static inline int -printModifiers(const uint32_t mods) -{ - return fprintf(stderr, - "Modifiers:%s%s%s%s%s%s%s\n", - (mods & PUGL_MOD_SHIFT) ? " Shift" : "", - (mods & PUGL_MOD_CTRL) ? " Ctrl" : "", - (mods & PUGL_MOD_ALT) ? " Alt" : "", - (mods & PUGL_MOD_SUPER) ? " Super" : "", - (mods & PUGL_MOD_NUM_LOCK) ? " Num" : "", - (mods & PUGL_MOD_SCROLL_LOCK) ? " Scroll" : "", - (mods & PUGL_MOD_CAPS_LOCK) ? " Caps" : ""); -} - -static inline const char* -crossingModeString(const PuglCrossingMode mode) -{ - switch (mode) { - case PUGL_CROSSING_NORMAL: - return "normal"; - case PUGL_CROSSING_GRAB: - return "grab"; - case PUGL_CROSSING_UNGRAB: - return "ungrab"; - } - - return "unknown"; -} - -static inline const char* -scrollDirectionString(const PuglScrollDirection direction) -{ - switch (direction) { - case PUGL_SCROLL_UP: - return "up"; - case PUGL_SCROLL_DOWN: - return "down"; - case PUGL_SCROLL_LEFT: - return "left"; - case PUGL_SCROLL_RIGHT: - return "right"; - case PUGL_SCROLL_SMOOTH: - return "smooth"; - } - - return "unknown"; -} - -static inline const char* -viewStyleFlagString(const PuglViewStyleFlag state) -{ - switch (state) { - case PUGL_VIEW_STYLE_MODAL: - return "modal"; - case PUGL_VIEW_STYLE_TALL: - return "tall"; - case PUGL_VIEW_STYLE_WIDE: - return "wide"; - case PUGL_VIEW_STYLE_HIDDEN: - return "hidden"; - case PUGL_VIEW_STYLE_FULLSCREEN: - return "fullscreen"; - case PUGL_VIEW_STYLE_ABOVE: - return "above"; - case PUGL_VIEW_STYLE_BELOW: - return "below"; - case PUGL_VIEW_STYLE_DEMANDING: - return "demanding"; - case PUGL_VIEW_STYLE_RESIZING: - return "resizing"; - case PUGL_VIEW_STYLE_MAPPED: - return "mapped"; - } - - return "unknown"; -} - -static inline const char* -keyString(const uint32_t key) -{ - switch (key) { - case PUGL_KEY_BACKSPACE: - return "BACKSPACE"; - case PUGL_KEY_TAB: - return "TAB"; - case PUGL_KEY_ENTER: - return "ENTER"; - case PUGL_KEY_ESCAPE: - return "ESCAPE"; - case PUGL_KEY_DELETE: - return "DELETE"; - case PUGL_KEY_SPACE: - return "SPACE"; - - case PUGL_KEY_F1: - return "F1"; - case PUGL_KEY_F2: - return "F2"; - case PUGL_KEY_F3: - return "F3"; - case PUGL_KEY_F4: - return "F4"; - case PUGL_KEY_F5: - return "F5"; - case PUGL_KEY_F6: - return "F6"; - case PUGL_KEY_F7: - return "F7"; - case PUGL_KEY_F8: - return "F8"; - case PUGL_KEY_F9: - return "F9"; - case PUGL_KEY_F10: - return "F10"; - case PUGL_KEY_F11: - return "F11"; - case PUGL_KEY_F12: - return "F12"; - - case PUGL_KEY_PAGE_UP: - return "PAGE_UP"; - case PUGL_KEY_PAGE_DOWN: - return "PAGE_DOWN"; - case PUGL_KEY_END: - return "END"; - case PUGL_KEY_HOME: - return "HOME"; - case PUGL_KEY_LEFT: - return "LEFT"; - case PUGL_KEY_UP: - return "UP"; - case PUGL_KEY_RIGHT: - return "RIGHT"; - case PUGL_KEY_DOWN: - return "DOWN"; - - case PUGL_KEY_PRINT_SCREEN: - return "PRINT_SCREEN"; - case PUGL_KEY_INSERT: - return "INSERT"; - case PUGL_KEY_PAUSE: - return "PAUSE"; - case PUGL_KEY_MENU: - return "MENU"; - case PUGL_KEY_NUM_LOCK: - return "NUM_LOCK"; - case PUGL_KEY_SCROLL_LOCK: - return "SCROLL_LOCK"; - case PUGL_KEY_CAPS_LOCK: - return "CAPS_LOCK"; - - case PUGL_KEY_SHIFT_L: - return "SHIFT_L"; - case PUGL_KEY_SHIFT_R: - return "SHIFT_R"; - case PUGL_KEY_CTRL_L: - return "CTRL_L"; - case PUGL_KEY_CTRL_R: - return "CTRL_R"; - case PUGL_KEY_ALT_L: - return "ALT_L"; - case PUGL_KEY_ALT_R: - return "ALT_R"; - case PUGL_KEY_SUPER_L: - return "SUPER_L"; - case PUGL_KEY_SUPER_R: - return "SUPER_R"; - - case PUGL_KEY_PAD_0: - return "PAD_0"; - case PUGL_KEY_PAD_1: - return "PAD_1"; - case PUGL_KEY_PAD_2: - return "PAD_2"; - case PUGL_KEY_PAD_3: - return "PAD_3"; - case PUGL_KEY_PAD_4: - return "PAD_4"; - case PUGL_KEY_PAD_5: - return "PAD_5"; - case PUGL_KEY_PAD_6: - return "PAD_6"; - case PUGL_KEY_PAD_7: - return "PAD_7"; - case PUGL_KEY_PAD_8: - return "PAD_8"; - case PUGL_KEY_PAD_9: - return "PAD_9"; - case PUGL_KEY_PAD_ENTER: - return "PAD_ENTER"; - - case PUGL_KEY_PAD_PAGE_UP: - return "PAD_PAGE_UP"; - case PUGL_KEY_PAD_PAGE_DOWN: - return "PAD_PAGE_DOWN"; - case PUGL_KEY_PAD_END: - return "PAD_END"; - case PUGL_KEY_PAD_HOME: - return "PAD_HOME"; - case PUGL_KEY_PAD_LEFT: - return "PAD_LEFT"; - case PUGL_KEY_PAD_UP: - return "PAD_UP"; - case PUGL_KEY_PAD_RIGHT: - return "PAD_RIGHT"; - case PUGL_KEY_PAD_DOWN: - return "PAD_DOWN"; - - case PUGL_KEY_PAD_CLEAR: - return "PAD_CLEAR"; - case PUGL_KEY_PAD_INSERT: - return "PAD_INSERT"; - case PUGL_KEY_PAD_DELETE: - return "PAD_DELETE"; - case PUGL_KEY_PAD_EQUAL: - return "PAD_EQUAL"; - - case PUGL_KEY_PAD_MULTIPLY: - return "PAD_MULTIPLY"; - case PUGL_KEY_PAD_ADD: - return "PAD_ADD"; - case PUGL_KEY_PAD_SEPARATOR: - return "PAD_SEPARATOR"; - case PUGL_KEY_PAD_SUBTRACT: - return "PAD_SUBTRACT"; - case PUGL_KEY_PAD_DECIMAL: - return "PAD_DECIMAL"; - case PUGL_KEY_PAD_DIVIDE: - return "PAD_DIVIDE"; - } - - return ""; -} - -static inline int -printEvent(const PuglEvent* event, const char* prefix, const bool verbose) -{ -#define PFFMT "%6.1f %6.1f" -#define PIFMT "%5d %5d" -#define PUFMT "%5u %5u" - -#define PRINT(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) - - switch (event->type) { - case PUGL_NOTHING: - return 0; - case PUGL_REALIZE: - return fprintf(stderr, "%sRealize\n", prefix); - case PUGL_UNREALIZE: - return fprintf(stderr, "%sUnrealize\n", prefix); - case PUGL_KEY_PRESS: - return (PRINT("%sKey press code %3u key U+%04X (%s) ", - prefix, - event->key.keycode, - event->key.key, - keyString(event->key.key)) + - printModifiers(event->scroll.state)); - case PUGL_KEY_RELEASE: - return (PRINT("%sKey release code %3u key U+%04X (%s) ", - prefix, - event->key.keycode, - event->key.key, - keyString(event->key.key)) + - printModifiers(event->scroll.state)); - case PUGL_TEXT: - return PRINT("%sText entry code %3u char U+%04X (%s)\n", - prefix, - event->text.keycode, - event->text.character, - event->text.string); - case PUGL_BUTTON_PRESS: - case PUGL_BUTTON_RELEASE: - return (PRINT("%sMouse %u %s at " PFFMT " ", - prefix, - event->button.button, - (event->type == PUGL_BUTTON_PRESS) ? "down" : "up ", - event->button.x, - event->button.y) + - printModifiers(event->scroll.state)); - case PUGL_SCROLL: - return (PRINT("%sScroll %5.1f %5.1f (%s) at " PFFMT " ", - prefix, - event->scroll.dx, - event->scroll.dy, - scrollDirectionString(event->scroll.direction), - event->scroll.x, - event->scroll.y) + - printModifiers(event->scroll.state)); - case PUGL_POINTER_IN: - return PRINT("%sMouse enter at " PFFMT " (%s)\n", - prefix, - event->crossing.x, - event->crossing.y, - crossingModeString(event->crossing.mode)); - case PUGL_POINTER_OUT: - return PRINT("%sMouse leave at " PFFMT " (%s)\n", - prefix, - event->crossing.x, - event->crossing.y, - crossingModeString(event->crossing.mode)); - case PUGL_FOCUS_IN: - return PRINT( - "%sFocus in (%s)\n", prefix, crossingModeString(event->crossing.mode)); - case PUGL_FOCUS_OUT: - return PRINT( - "%sFocus out (%s)\n", prefix, crossingModeString(event->crossing.mode)); - case PUGL_CLIENT: - return PRINT("%sClient %" PRIXPTR " %" PRIXPTR "\n", - prefix, - event->client.data1, - event->client.data2); - case PUGL_LOOP_ENTER: - return PRINT("%sLoop enter\n", prefix); - case PUGL_LOOP_LEAVE: - return PRINT("%sLoop leave\n", prefix); - case PUGL_DATA_OFFER: - return PRINT("%sData offer\n", prefix); - case PUGL_DATA: - return PRINT("%sData\n", prefix); - default: - break; - } - - if (verbose) { - switch (event->type) { - case PUGL_UPDATE: - return fprintf(stderr, "%sUpdate\n", prefix); - case PUGL_CONFIGURE: - PRINT("%sConfigure " PIFMT " " PUFMT " (", - prefix, - event->configure.x, - event->configure.y, - event->configure.width, - event->configure.height); - for (PuglViewStyleFlags mask = 1U; mask <= PUGL_MAX_VIEW_STYLE_FLAG; - mask <<= 1U) { - if (event->configure.style & mask) { - PRINT(" %s", viewStyleFlagString((PuglViewStyleFlag)mask)); - } - } - PRINT("%s\n", " )"); - return 0; - case PUGL_EXPOSE: - return PRINT("%sExpose " PIFMT " " PUFMT "\n", - prefix, - event->expose.x, - event->expose.y, - event->expose.width, - event->expose.height); - case PUGL_CLOSE: - return PRINT("%sClose\n", prefix); - case PUGL_MOTION: - return PRINT("%sMouse motion at " PFFMT "\n", - prefix, - event->motion.x, - event->motion.y); - case PUGL_TIMER: - return PRINT("%sTimer %" PRIuPTR "\n", prefix, event->timer.id); - default: - return PRINT("%sUnknown event type %d\n", prefix, (int)event->type); - } - } - -#undef PRINT -#undef PUFMT -#undef PIFMT -#undef PFFMT - - return 0; -} - -static inline const char* -puglViewHintString(const PuglViewHint hint) -{ - switch (hint) { - case PUGL_CONTEXT_API: - return "Context API"; - case PUGL_CONTEXT_VERSION_MAJOR: - return "Context major version"; - case PUGL_CONTEXT_VERSION_MINOR: - return "Context minor version"; - case PUGL_CONTEXT_PROFILE: - return "Context profile"; - case PUGL_CONTEXT_DEBUG: - return "Context debug"; - case PUGL_RED_BITS: - return "Red bits"; - case PUGL_GREEN_BITS: - return "Green bits"; - case PUGL_BLUE_BITS: - return "Blue bits"; - case PUGL_ALPHA_BITS: - return "Alpha bits"; - case PUGL_DEPTH_BITS: - return "Depth bits"; - case PUGL_STENCIL_BITS: - return "Stencil bits"; - case PUGL_SAMPLE_BUFFERS: - return "Sample buffers"; - case PUGL_SAMPLES: - return "Samples"; - case PUGL_DOUBLE_BUFFER: - return "Double buffer"; - case PUGL_SWAP_INTERVAL: - return "Swap interval"; - case PUGL_RESIZABLE: - return "Resizable"; - case PUGL_IGNORE_KEY_REPEAT: - return "Ignore key repeat"; - case PUGL_REFRESH_RATE: - return "Refresh rate"; - case PUGL_VIEW_TYPE: - return "View type"; - case PUGL_DARK_FRAME: - return "Dark frame"; - } - - return "Unknown"; -} - -static inline void -printViewHints(const PuglView* view) -{ - for (unsigned i = 0; i < PUGL_NUM_VIEW_HINTS; ++i) { - const PuglViewHint hint = (PuglViewHint)i; - fprintf(stderr, - "%s: %d\n", - puglViewHintString(hint), - puglGetViewHint(view, hint)); - } -} - -static inline void -puglPrintTestUsage(const char* prog, const char* posHelp) -{ - printf("Usage: %s [OPTION]... %s\n\n" - " -E Use OpenGL ES\n" - " -G OpenGL context version\n" - " -a Enable anti-aliasing\n" - " -b Block and only update on user input\n" - " -d Directly draw to window (no double-buffering)\n" - " -e Enable platform error-checking\n" - " -f Fast drawing, explicitly disable vertical sync\n" - " -h Display this help\n" - " -i Ignore key repeat\n" - " -v Print verbose output\n" - " -r Resizable window\n" - " -s Explicitly enable vertical sync\n", - prog, - posHelp); -} - -static inline PuglTestOptions -puglParseTestOptions(int* pargc, char*** pargv) -{ - PuglTestOptions opts = { - 0, - PUGL_TRUE, - PUGL_DONT_CARE, - PUGL_OPENGL_API, - 3, - 3, - true, - false, - false, - false, - false, - false, - }; - - char** const argv = *pargv; - int i = 1; - for (; i < *pargc; ++i) { - if (!strcmp(argv[i], "-E")) { - opts.glApi = PUGL_OPENGL_ES_API; - } else if (!strcmp(argv[i], "-G")) { - if (++i == *pargc) { - fprintf(stderr, "error: Missing OpenGL version argument\n"); - return opts; - } - - const int matches = - sscanf(argv[i], "%d.%d", &opts.glMajorVersion, &opts.glMinorVersion); - if (matches != 2) { - fprintf(stderr, "error: Invalid OpenGL version argument\n"); - return opts; - } - } else if (!strcmp(argv[i], "-a")) { - opts.samples = 4; - } else if (!strcmp(argv[i], "-b")) { - opts.continuous = false; - } else if (!strcmp(argv[i], "-d")) { - opts.doubleBuffer = PUGL_FALSE; - } else if (!strcmp(argv[i], "-e")) { - opts.errorChecking = PUGL_TRUE; - } else if (!strcmp(argv[i], "-f")) { - opts.sync = PUGL_FALSE; - } else if (!strcmp(argv[i], "-h")) { - opts.help = true; - return opts; - } else if (!strcmp(argv[i], "-i")) { - opts.ignoreKeyRepeat = true; - } else if (!strcmp(argv[i], "-r")) { - opts.resizable = true; - } else if (!strcmp(argv[i], "-s")) { - opts.sync = PUGL_TRUE; - } else if (!strcmp(argv[i], "-v")) { - opts.verbose = true; - } else if (argv[i][0] != '-') { - break; - } else { - opts.help = true; - logError("Unknown option: %s\n", argv[i]); - } - } - - *pargc -= i; - *pargv += i; - - return opts; -} - -#endif // TEST_TEST_UTILS_H diff --git a/test/test_view.c b/test/test_view.c index a6af9f2..08e5255 100644 --- a/test/test_view.c +++ b/test/test_view.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/stub.h" +#include <pugl/pugl.h> +#include <pugl/stub.h> #include <assert.h> #include <stdbool.h> @@ -73,7 +73,7 @@ main(int argc, char** argv) puglSetHandle(test.view, &test); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 384, 640); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 384, 640); // Check basic accessors assert(puglGetBackend(test.view) == puglStubBackend()); diff --git a/test/test_vulkan.c b/test/test_vulkan.c index 3a7c612..258f978 100644 --- a/test/test_vulkan.c +++ b/test/test_vulkan.c @@ -5,10 +5,10 @@ #undef NDEBUG -#include "test_utils.h" +#include <puglutil/test_utils.h> -#include "pugl/pugl.h" -#include "pugl/vulkan.h" +#include <pugl/pugl.h> +#include <pugl/vulkan.h> #include <vulkan/vulkan_core.h> @@ -172,7 +172,7 @@ main(int argc, char** argv) puglSetBackend(test.view, puglVulkanBackend()); puglSetEventFunc(test.view, onEvent); puglSetSizeHint(test.view, PUGL_DEFAULT_SIZE, 256, 256); - puglSetPosition(test.view, 640, 640); + puglSetPositionHint(test.view, PUGL_DEFAULT_POSITION, 640, 640); assert(!puglRealize(test.view)); // Create Vulkan surface for window diff --git a/test/test_world.c b/test/test_world.c index 18c8ef2..9d0d145 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -5,7 +5,7 @@ #undef NDEBUG -#include "pugl/pugl.h" +#include <pugl/pugl.h> #include <assert.h> #include <stdint.h> |