diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/.clang-tidy | 2 | ||||
-rw-r--r-- | test/cpp/.clang-tidy | 38 | ||||
-rw-r--r-- | test/cpp/meson.build | 106 | ||||
-rw-r--r-- | test/cpp/test_build.cpp (renamed from test/test_build.cpp) | 0 | ||||
-rw-r--r-- | test/cpp/test_inline_cpp.cpp (renamed from test/test_inline_cpp.cpp) | 0 | ||||
-rw-r--r-- | test/cpp/test_inline_objcpp.mm (renamed from test/test_inline_objcpp.mm) | 0 | ||||
-rw-r--r-- | test/headers/.clang-tidy | 16 | ||||
-rw-r--r-- | test/headers/meson.build | 35 | ||||
-rw-r--r-- | test/headers/test_headers.c | 22 | ||||
-rw-r--r-- | test/meson.build | 103 | ||||
-rw-r--r-- | test/test_redisplay.c | 24 | ||||
-rw-r--r-- | test/test_update.c | 2 | ||||
-rw-r--r-- | test/test_utils.h | 5 |
13 files changed, 241 insertions, 112 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy index c88c7b3..456eb2e 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -7,10 +7,8 @@ Checks: > -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..1d936a2 --- /dev/null +++ b/test/cpp/.clang-tidy @@ -0,0 +1,38 @@ +# Copyright 2020-2025 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR ISC + +Checks: > + -*-use-auto, + -*-use-nullptr, + -bugprone-easily-swappable-parameters, + -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..73e2320 --- /dev/null +++ b/test/cpp/meson.build @@ -0,0 +1,106 @@ +# 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, + 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, + include_directories: include_directories('../../include'), + ), + suite: 'unit', + ) +endif diff --git a/test/test_build.cpp b/test/cpp/test_build.cpp index 4fd2dac..4fd2dac 100644 --- a/test/test_build.cpp +++ b/test/cpp/test_build.cpp diff --git a/test/test_inline_cpp.cpp b/test/cpp/test_inline_cpp.cpp index f5694eb..f5694eb 100644 --- a/test/test_inline_cpp.cpp +++ b/test/cpp/test_inline_cpp.cpp diff --git a/test/test_inline_objcpp.mm b/test/cpp/test_inline_objcpp.mm index 1c9079b..1c9079b 100644 --- a/test/test_inline_objcpp.mm +++ b/test/cpp/test_inline_objcpp.mm 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..c0adabd --- /dev/null +++ b/test/headers/meson.build @@ -0,0 +1,35 @@ +# 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 = cpp.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], + ), + 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..f015596 100644 --- a/test/meson.build +++ b/test/meson.build @@ -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) @@ -144,7 +130,6 @@ 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), ), @@ -153,86 +138,14 @@ if vulkan_dep.found() endforeach endif -unified_args = core_args -unified_deps = [core_deps] -if cairo_dep.found() - unified_args += ['-DWITH_CAIRO'] - unified_deps += [cairo_dep] -endif +################### +# Header Warnings # +################### -if opengl_dep.found() - unified_args += ['-DWITH_OPENGL'] - unified_deps += [opengl_dep] -endif +subdir('headers') -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') +####################### +# C++ / Objective C++ # +####################### - 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', - ) - -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 - - 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, - include_directories: include_directories(includes), - ), - suite: 'unit', - ) -endif +subdir('cpp') diff --git a/test/test_redisplay.c b/test/test_redisplay.c index 1276136..ae7267d 100644 --- a/test/test_redisplay.c +++ b/test/test_redisplay.c @@ -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; @@ -128,7 +130,7 @@ 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; + 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_update.c b/test/test_update.c index 4710ca2..c5997ba 100644 --- a/test/test_update.c +++ b/test/test_update.c @@ -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; diff --git a/test/test_utils.h b/test/test_utils.h index 214b360..4ebd985 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -471,11 +471,10 @@ 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)); + puglViewHintString((PuglViewHint)i), + puglGetViewHint(view, (PuglViewHint)i)); } } |