diff options
| author | Simon Ser <contact@emersion.fr> | 2024-07-07 18:48:44 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2024-08-24 17:43:43 +0200 |
| commit | 619d99cbba9dbe0a9e9c7bee2d870085416c866a (patch) | |
| tree | 313fa819aab3c3c9e5b108c33413599d3d5302cc | |
| parent | scanner: fix validator for bitfields (diff) | |
| download | wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar.gz wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar.bz2 wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar.lz wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar.xz wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.tar.zst wayland-619d99cbba9dbe0a9e9c7bee2d870085416c866a.zip | |
tests: add enum bitfield test
Signed-off-by: Simon Ser <contact@emersion.fr>
(cherry picked from commit fa1811ce3e1475a95aa39e00cfa083797661d651)
| -rw-r--r-- | tests/data/small-client-core.h | 23 | ||||
| -rw-r--r-- | tests/data/small-client.h | 23 | ||||
| -rw-r--r-- | tests/data/small-server-core.h | 41 | ||||
| -rw-r--r-- | tests/data/small-server.h | 41 | ||||
| -rw-r--r-- | tests/data/small.xml | 7 | ||||
| -rw-r--r-- | tests/enum-validator-test.c | 15 |
6 files changed, 150 insertions, 0 deletions
diff --git a/tests/data/small-client-core.h b/tests/data/small-client-core.h index 0e72244..03f889c 100644 --- a/tests/data/small-client-core.h +++ b/tests/data/small-client-core.h @@ -106,6 +106,29 @@ enum intf_A_foo { #define INTF_A_FOO_DEPRECATED_SINCE_VERSION 2 #endif /* INTF_A_FOO_ENUM */ +#ifndef INTF_A_BAR_ENUM +#define INTF_A_BAR_ENUM +enum intf_A_bar { + /** + * this is the first + */ + INTF_A_BAR_FIRST = 0x01, + /** + * this is the second + */ + INTF_A_BAR_SECOND = 0x02, + /** + * this is the third + * @since 2 + */ + INTF_A_BAR_THIRD = 0x04, +}; +/** + * @ingroup iface_intf_A + */ +#define INTF_A_BAR_THIRD_SINCE_VERSION 2 +#endif /* INTF_A_BAR_ENUM */ + /** * @ingroup iface_intf_A * @struct intf_A_listener diff --git a/tests/data/small-client.h b/tests/data/small-client.h index ad43592..0d5b605 100644 --- a/tests/data/small-client.h +++ b/tests/data/small-client.h @@ -106,6 +106,29 @@ enum intf_A_foo { #define INTF_A_FOO_DEPRECATED_SINCE_VERSION 2 #endif /* INTF_A_FOO_ENUM */ +#ifndef INTF_A_BAR_ENUM +#define INTF_A_BAR_ENUM +enum intf_A_bar { + /** + * this is the first + */ + INTF_A_BAR_FIRST = 0x01, + /** + * this is the second + */ + INTF_A_BAR_SECOND = 0x02, + /** + * this is the third + * @since 2 + */ + INTF_A_BAR_THIRD = 0x04, +}; +/** + * @ingroup iface_intf_A + */ +#define INTF_A_BAR_THIRD_SINCE_VERSION 2 +#endif /* INTF_A_BAR_ENUM */ + /** * @ingroup iface_intf_A * @struct intf_A_listener diff --git a/tests/data/small-server-core.h b/tests/data/small-server-core.h index e696cde..d447695 100644 --- a/tests/data/small-server-core.h +++ b/tests/data/small-server-core.h @@ -133,6 +133,47 @@ intf_A_foo_is_valid(uint32_t value, uint32_t version) { } #endif /* INTF_A_FOO_ENUM */ +#ifndef INTF_A_BAR_ENUM +#define INTF_A_BAR_ENUM +enum intf_A_bar { + /** + * this is the first + */ + INTF_A_BAR_FIRST = 0x01, + /** + * this is the second + */ + INTF_A_BAR_SECOND = 0x02, + /** + * this is the third + * @since 2 + */ + INTF_A_BAR_THIRD = 0x04, +}; +/** + * @ingroup iface_intf_A + */ +#define INTF_A_BAR_THIRD_SINCE_VERSION 2 +/** + * @ingroup iface_intf_A + * Validate a intf_A bar value. + * + * @return true on success, false on error. + * @ref intf_A_bar + */ +static inline bool +intf_A_bar_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= INTF_A_BAR_FIRST; + if (version >= 1) + valid |= INTF_A_BAR_SECOND; + if (version >= 2) + valid |= INTF_A_BAR_THIRD; + return (value & ~valid) == 0; +} +#endif /* INTF_A_BAR_ENUM */ + /** * @ingroup iface_intf_A * @struct intf_A_interface diff --git a/tests/data/small-server.h b/tests/data/small-server.h index 009d9cd..9cafcd9 100644 --- a/tests/data/small-server.h +++ b/tests/data/small-server.h @@ -133,6 +133,47 @@ intf_A_foo_is_valid(uint32_t value, uint32_t version) { } #endif /* INTF_A_FOO_ENUM */ +#ifndef INTF_A_BAR_ENUM +#define INTF_A_BAR_ENUM +enum intf_A_bar { + /** + * this is the first + */ + INTF_A_BAR_FIRST = 0x01, + /** + * this is the second + */ + INTF_A_BAR_SECOND = 0x02, + /** + * this is the third + * @since 2 + */ + INTF_A_BAR_THIRD = 0x04, +}; +/** + * @ingroup iface_intf_A + */ +#define INTF_A_BAR_THIRD_SINCE_VERSION 2 +/** + * @ingroup iface_intf_A + * Validate a intf_A bar value. + * + * @return true on success, false on error. + * @ref intf_A_bar + */ +static inline bool +intf_A_bar_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= INTF_A_BAR_FIRST; + if (version >= 1) + valid |= INTF_A_BAR_SECOND; + if (version >= 2) + valid |= INTF_A_BAR_THIRD; + return (value & ~valid) == 0; +} +#endif /* INTF_A_BAR_ENUM */ + /** * @ingroup iface_intf_A * @struct intf_A_interface diff --git a/tests/data/small.xml b/tests/data/small.xml index ac52779..ab29749 100644 --- a/tests/data/small.xml +++ b/tests/data/small.xml @@ -58,5 +58,12 @@ <entry name="negative" value="-1" since="2" summary="this is a negative value"/> <entry name="deprecated" value="3" since="2" deprecated-since="3" summary="this is a deprecated value"/> </enum> + + <enum name="bar" bitfield="true"> + <entry name="first" value="0x01" summary="this is the first"/> + <entry name="second" value="0x02" summary="this is the second"/> + <entry name="third" value="0x04" since="2" summary="this is the third"/> + </enum> + </interface> </protocol> diff --git a/tests/enum-validator-test.c b/tests/enum-validator-test.c index 92037cf..8fb05b4 100644 --- a/tests/enum-validator-test.c +++ b/tests/enum-validator-test.c @@ -10,4 +10,19 @@ main(int argc, char *argv[]) { assert(intf_A_foo_is_valid(INTF_A_FOO_THIRD, 2)); assert(intf_A_foo_is_valid(INTF_A_FOO_NEGATIVE, 2)); + + assert(intf_A_bar_is_valid(INTF_A_BAR_FIRST, 1)); + assert(intf_A_bar_is_valid(INTF_A_BAR_FIRST, 2)); + assert(intf_A_bar_is_valid(INTF_A_BAR_SECOND, 1)); + assert(intf_A_bar_is_valid(INTF_A_BAR_SECOND, 2)); + assert(intf_A_bar_is_valid(INTF_A_BAR_FIRST | INTF_A_BAR_SECOND, 1)); + assert(intf_A_bar_is_valid(INTF_A_BAR_FIRST | INTF_A_BAR_SECOND, 2)); + + assert(!intf_A_bar_is_valid(INTF_A_BAR_THIRD, 1)); + assert(!intf_A_bar_is_valid(INTF_A_BAR_FIRST | INTF_A_BAR_THIRD, 1)); + assert(intf_A_bar_is_valid(INTF_A_BAR_THIRD, 2)); + assert(intf_A_bar_is_valid(INTF_A_BAR_FIRST | INTF_A_BAR_THIRD, 2)); + + assert(!intf_A_bar_is_valid(0xFF, 1)); + assert(!intf_A_bar_is_valid(0xFF, 2)); } |
