Commit Graph

398 Commits

Author SHA1 Message Date
Philip Withnall
5c50aec060 Merge branch 'glib-mkenums_parse_trigraph' into 'main'
Take double-quote characters into account when parsing trigraph

Closes #65

See merge request GNOME/glib!3452
2023-05-30 14:45:54 +00:00
Emmanuel Fleury
7e5607d534 Take double-quote characters into account when parsing trigraph
For now, the function parse_trigraph() defined in gobject/glib-mkenums
script was not taking double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': '"eek', 'a': None}

This patch take double-quotes characters into account:

>>> parse_trigraph('name="eek, a comma"')
{'name': 'eek, a comma'}

Closes issue #65
2023-05-30 15:22:05 +02:00
Marco Trevisan (Treviño)
bfc599b8a2 gsignal: Reduce lock/unlock operations when calling signal_emit_unlocked_R
We used to call this function as unlocked, with a node value that
could be invalid at the point of the call, so let's ensure that when
we call such function it's defined, and then reduce the access to the
signal node members when we're unlocked or after a lock/unlock operation
that may have changed it.

As per this, add more tests handling multiple signal hooks cases that we
did not cover before.
2023-05-30 13:52:08 +01:00
Marco Trevisan (Treviño)
0bc725d4fe gobject/tests/signals: Add tests for g_object_emitv
It's very much used by bindings but we didn't really test it locally.
2023-05-30 13:52:07 +01:00
Eric Blake
2ab2ce57e6 gtestutils: Improve g_assert_cmpuint
While x86_64 has enough precision in long double to do a round trip
from guint64 to long double and back, this is platform-specific, and
is a disservice to users trying to debug failing unit tests on other
architectures where it loses precision for g_assert_cmp{int,uint,hex}.
See also https://bugzilla.gnome.org/show_bug.cgi?id=788385 which
mentions having to add casts to specifically silence the compiler on
platforms where the precision loss occurs.

Meanwhile, g_assert_cmpuint() does an unsigned comparison, but outputs
signed values if the comparison fails, which is confusing.

Fix both issues by introducing a new g_assertion_message_cmpint()
function with a new 'u' numtype.  For backwards compatibility, the
macros still call into the older g_assertion_message_cmpnum() when not
targetting 2.78, and that function still works when passed 'i' and 'x'
types even though code compiled for 2.78 and later will never invoke
it with numtype anything other than 'f'.  Note that g_assert_cmpmem
can also take advantage of the new code, even though in practice,
comparison between two size_t values representing array lengths that
can actually be compiled is unlikely to have ever hit the precision
loss.  The macros in signals.c test code does not have to worry about
versioning, since it is not part of the glib library proper.

Closes #2997
Signed-off-by: Eric Blake <eblake@redhat.com>
2023-05-09 08:28:09 -05:00
Przemyslaw Gorszkowski
74d49e447f Test g_signal_handlers_disconnect_matched for G_SIGNAL_MATCH_ID match
Signed-off-by: Przemyslaw Gorszkowski <pgorszkowski@igalia.com>
2023-04-18 12:50:55 +02:00
Przemyslaw Gorszkowski
b264585f3c gsignal: Support G_SIGNAL_MATCH_ID in g_signal_handlers_block/unblock/disconnect_matched()
Calling g_signal_handlers_block/unblock/disconnect_matched with only G_SIGNAL_MATCH_ID
do not match any handlers and return 0.

Fixes: #2980

Signed-off-by: Przemyslaw Gorszkowski <pgorszkowski@igalia.com>
2023-04-14 15:27:11 +01:00
Philip Withnall
2d8e38c00d gsignal: Clarify documentation for GSignalMatchType matching
The use of ‘OR’ in the existing documentation suggests that the matching
is disjunctive, but it’s actually conjunctive. Clarify that in the
documentation and add a test.

Spotted while reviewing
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3376.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-04-14 13:55:20 +01:00
Philip Withnall
d1eb9c840c tests: Add type flag tests for interfaces
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #252
2023-04-13 15:39:37 +01:00
Philip Withnall
3d7e88a77d build: Drop old .gitignore files from test directories
They just listed built files. Since the move to Meson, these are all
kept in a separate build directory, not the source tree, so don’t need
to be ignored.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-20 12:09:02 +00:00
Philip Withnall
0e84e28978 tests: Don’t run the GObject performance tests under valgrind
They take too long and time out, and are not particularly useful to run
under valgrind because they aren’t designed to test code coverage.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-16 12:52:30 +00:00
Marco Trevisan (Treviño)
1594cf77eb meson: Use exitcode protocol for some c++ and gobject definition tests
In all these cases we don't really care about running the test file,
while building and basic execution it is relevant.

Also they don't support TAP at all.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
58031feb17 meson: Use 'tap' test protocol by default
Meson supports tap protocol results parsing, allowing us to track better
the tests that are running (and the ones that are actually skipped) without
manually parsing the test output.

However this also implies that using the verbose mode for a test doesn't
show its output by default (unless there are failures).
2023-01-17 21:08:48 +01:00
Philip Withnall
251bab3e71 gobject: Add a missing NULL check for the return from lookup_type_node_I()
This can cause a `NULL` dereference on the next line if there is no
`TypeNode` for `iface_type`, for example if `iface_type ==
G_TYPE_INVALID`.

Unlikely, but possible since this API is public.

Spotted by Coverity.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1501602
2022-12-21 19:16:10 +00:00
Marco Trevisan (Treviño)
bc59ed8fba gobject: Avoid the ref/unref dance if assigning the same to a value
g_value_set_object could lead to perform unneeded ref/unref operations in
case we were trying to set again an object to a GValue
2022-12-20 17:48:21 +01:00
Marco Trevisan (Treviño)
e9979b540f meson: Add test to check for strict cast alignments if supported 2022-12-16 20:48:47 +01:00
Thomas Haller
938a1caf89 gtype: avoid "-Wcast-align" warning with optimized G_TYPE_CHECK_INSTANCE_CAST()
We can get a "-Wcast-align", if the target type that we cast to ("ct") has a
larger alignment than GTypeInstance.

That can happen on i686 architecture, if the GObject type has larger
alignment than the parent struct (or GObject). Since on i686, embeding
a "long long" or a "long double" in a struct still does not increase
the alignment beyond 4 bytes, this usually only happens when using the
__attribute__() to increase the alignment (or to have a field that has
the alignment increased).

It can happen on x86_64 when having a "long double" field.

The compiler warning is hard to avoid but not very useful, because it purely
operates on the pointer types at compile time. G_TYPE_CHECK_INSTANCE_CAST()
instead asserts (in non-optimized mode) that the pointer really points
to the expected GTypeInstance (and if that's the case, then the alignment
should be suitable already).

This is like in commit ed553e8e30 ('gtype: Eliminate -Wcast-align warnings
with G_TYPE_CHECK_INSTANCE_CAST'). But also fix the optimized code path.

With the unpatched G_TYPE_CHECK_INSTANCE_CAST() macro, the unit test would
now show the problem (with gcc-9.3.1-2.fc30.i686 or
gcc-12.2.1-4.fc37.x86_64):

  $ export G_DISABLE_CAST_CHECKS=1
  $ export CFLAGS='-Wcast-align=strict'
  $ meson build
  $ ninja -C build
  ...
  In file included from ../gobject/gobject.h:26,
                   from ../gobject/gbinding.h:31,
                   from ../glib/glib-object.h:24,
                   from ../gobject/tests/objects-refcount1.c:2:
  ../gobject/tests/objects-refcount1.c: In function ‘my_test_dispose’:
  ../gobject/gtype.h:2523:42: warning: cast increases required alignment of target type [-Wcast-align]
   2523 | #  define _G_TYPE_CIC(ip, gt, ct)       ((ct*) ip)
        |                                          ^
  ../gobject/gtype.h:517:66: note: in expansion of macro ‘_G_TYPE_CIC’
    517 | #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
        |                                                                  ^~~~~~~~~~~
  ../gobject/tests/objects-refcount1.c:9:37: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_CAST’
      9 | #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
        |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ../gobject/tests/objects-refcount1.c:96:10: note: in expansion of macro ‘MY_TEST’
     96 |   test = MY_TEST (object);
        |          ^~~~~~~
2022-12-16 20:48:06 +01:00
Marco Trevisan (Treviño)
c6f252108c gobject/tests/performance: Add object get/set performance tests 2022-12-14 03:05:50 +01:00
Marco Trevisan (Treviño)
77a2d26ea2 gobject/tests/performance: Add object notify performance tests 2022-12-14 03:05:50 +01:00
Marco Trevisan (Treviño)
6a0591f06c gobject/tests/type-flags: Add tests for type final type flags
Ensure that final flag is properly checked and used.
2022-12-12 19:03:48 +01:00
Marco Trevisan (Treviño)
0918ce013a gobject: Do not call toggle down notifications if current refcount is not 1
When an object is revitalized and a notify callbacks increased the reference
counter of the object, we are calling the toggle notifier twice, while it
should only happen if also the actual reference count value is 1 (after
having been decremented from 2).
2022-12-06 04:38:26 +01:00
Marco Trevisan (Treviño)
1f852863ec gobject: Check for toggle references only if the old ref is relevant
If an object gets revitalized during the dispose vfunc, we need to call
toggle refs notifiers only if we had 2 references and if the object has
the toggle references enabled.

This may change in case an object notifier handler changes this status,
so do this check only after we've called the notifiers so that in case
toggle notifications are enabled afterwards we still call the handlers.
2022-12-06 04:28:31 +01:00
Marco Trevisan (Treviño)
5e2b288033 gobject/tests/reference: Add test for notify during dispose
We need to check whether notifications and toggle references are working
properly if an object gets revitalized during the dispose vfunc.
2022-12-06 04:28:31 +01:00
Marco Trevisan (Treviño)
ea0c4d45b2 gobject/tests/reference: Add test for toggle reference up/down during dispose 2022-12-06 03:32:51 +01:00
Simon McVittie
b13e12b363 type-flags test: Force G_ENABLE_DIAGNOSTIC=1 to be set
Otherwise this test will succeed at build-time, but will fail when run
as an as-installed test via ginsttest-runner.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-14 12:36:32 +00:00
Matthias Clasen
fd0dd9e93c gobject: Add G_TYPE_FLAG_DEPRECATED
This can be used to mark entire types as deprecated,
and trigger a warning when they are instantiated
and `G_ENABLE_DIAGNOSTIC=1` is set in the environment.

There's currently no convenient macros for defining
types with the new flag, but you can do:

```c
_G_DEFINE_TYPE_EXTENDED_BEGIN (GtkAppChooserWidget,
                               gtk_app_chooser_widget,
                               GTK_TYPE_WIDGET,
                               G_TYPE_FLAG_DEPRECATED)
...
_G_DEFINE_TYPE_EXTENDED_END ()
```

Includes a unit test by Philip Withnall.
2022-11-09 12:07:31 +00:00
Philip Withnall
e2b9e28ece Merge branch 'wip/3v1n0/meson-fix-tests-binary-dependencies' into 'main'
test/meson: Add tests dependencies on built programs, libraries and modules

See merge request GNOME/glib!3015
2022-11-08 12:30:53 +00:00
Philip Withnall
9a0c8a585d Merge branch 'mkenums' into 'main'
glib-mkenums: feature use of previous symbols in evaluation

See merge request GNOME/glib!3043
2022-11-08 11:12:40 +00:00
Simon McVittie
2673b262aa custom-dispatch: Change SPDX-License-Identifier to match license grant
The SPDX-License-Identifier said LGPL-2.1-or-later, but the license
grant was a permissive license, which we now identify as
LicenseRef-old-glib-tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-02 12:35:45 +00:00
Simon McVittie
32b0dd24e3 Add a SPDX LicenseRef for the license historically used for tests
Some of GLib's unit tests are under an apparently GLib-specific
permissive license, vaguely similar to the BSD/MIT family but with the
GPL's lack-of-warranty wording. This is not on SPDX's list of
well-known licenses, so we need to use a custom license name prefixed
with LicenseRef if we want to represent this in SPDX/REUSE syntax.

Most of the newer tests seem to be licensed under LGPL-2.1-or-later
instead.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-02 12:34:19 +00:00
Patrick Monnerat
f2c590f494 tests/mkenums.py: add a test case for symbolic expression evaluation 2022-11-01 16:06:20 +01:00
Patrick Monnerat
96fa9752b2 glib-mkenums: evaluate private symbols too
This allows them to be referenced in other symbols value computation.

In addition, this fixes the automatically assigned value of a public
symbol that is preceded by a private one:

        typedef enum {
          /*< private >*/
          ENUM_VALUE_PRIVATE,
          /*< public >*/
          ENUM_VALUE_PUBLIC,                    <--- value is 1, not 0.
        } SomeExampleEnum;
2022-11-01 15:46:13 +01:00
Marco Trevisan (Treviño)
038ef36b99 gobject/tests/meson: Make gobject-query.py test depend on gobject-query util
The utility is used by the script, so we need to depend on it.
2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
a106ce4445 gobject/tests/meson: Add support to add extra depends args to python tests 2022-11-01 01:56:27 +01:00
Marco Trevisan (Treviño)
3c56d661d8 meson: Use test setup environment instead of repeating it everywhere 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
54a9e797fe ci: Mark failing windows tests as can-fail and do not ignore test failures 2022-10-31 14:08:31 +01:00
Marco Trevisan (Treviño)
62dca6c1cf meson, ci: Support tests that can fail under certain conditions
We have tests that are failing in some environments, but it's
difficult to handle them because:
 - for some environments we just allow all the tests to fail: DANGEROUS
 - when we don't allow failures we have flacky tests: A CI pain

So, to avoid this and ensure that:
 - New failing tests are tracked in all platforms
 - gitlab integration on tests reports is working
 - coverage is reported also for failing tests

Add support for `can_fail` keyword on tests that would mark the test as
part of the `failing` test suite.
Not adding the suite directly when defining the tests as this is
definitely simpler and allows to define conditions more clearly (see next
commits).

Now, add a default test setup that does not run the failing and flaky tests
by default (not to bother distributors with testing well-known issues) and
eventually run all the tests in CI:
 - Non-flaky tests cannot fail in all platforms
 - Failing and Flaky tests can fail

In both cases we save the test reports so that gitlab integration is
preserved.
2022-10-31 14:08:29 +01:00
Simon McVittie
a62dd272d8 tests: Test that we can include all headers with an old MAX_VERSION
In principle we could script this so that each max-version.c is compiled
26 times, once per possible MAX_VERSION, but I haven't implemented
that here: just pinning to the oldest possible version is sufficient to
reproduce #2796.

These aren't included in the installed-tests, since they don't really
do anything at runtime (the important thing is that they compile
without warnings).

Reproduces: #2796
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-27 14:50:48 +01:00
Simon McVittie
65016fddd9 Replace all uses of G_VA_COPY with Standard C va_copy
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-26 18:07:55 +01:00
Matthias Clasen
e79af74d1b gobject: Always ref-sink variants in g_object_set
When collecting varargs, ignore the NOCOPY_CONTENTS
flag for variants. That is what our docs advice for
refcounted types, and it fixes a regression that
was inadvertendly introduced when we stopped doing
some extra GValue copies.

Includes a test case by Philip Withnall.

Fixes: #2774
2022-10-24 10:47:35 +01:00
Philip Withnall
59541e335a tests: Fix code style in Python files to satisfy black and flake8
This should make the style-check-diff CI job happy again.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-10-19 12:28:08 +01:00
Philip Withnall
292c117b98 Merge branch 'w32-tests' into 'main'
Various win32 test fixes

See merge request GNOME/glib!2952
2022-10-17 09:53:44 +00:00
Marc-André Lureau
8c0fa77a71 tests/gobject-query.py: make it work on msys2/win32
For unclear reasons, universal_newlines=True doesn't seem to set the
text encoding correctly. Even if I set only encoding='utf-8', the test
fails. The combination here works for me, \o/.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 11:01:53 +04:00
Marc-André Lureau
fdfe94fb16 tests/gobject-query: it is not a script (anymore?)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-10-17 11:01:51 +04:00
Philip Withnall
4bc284fca6 Merge branch 'wip/smcv/deprecated-prop-followup' into 'main'
Run tests with G_ENABLE_DIAGNOSTIC=1

See merge request GNOME/glib!2889
2022-10-15 21:31:29 +00:00
Philip Withnall
350b92821c Merge branch 'wip/smcv/deprecated-construct-prop' into 'main'
gobject: Only emit deprecation warnings for user-specified properties

Closes #2748

See merge request GNOME/glib!2912
2022-10-12 13:56:46 +00:00
Philip Withnall
e90733a457 Merge branch 'atomic-older-cplusplus' into 'main'
gatomic: fix the atomic compare_and_exchange macros on older C++ standard versions

See merge request GNOME/glib!2864
2022-10-12 09:56:19 +00:00
Marco Trevisan (Treviño)
80cf66034b gobject/tests/param: Add unit test for handling invalid NULL param spec
This was fixed by !2921 but there was no test with the MR, so add one.
2022-10-10 21:01:10 +02:00
Simon McVittie
7254fd7aa3 gobject/tests: Don't unref a floating object reference by mistake
This goes undiagnosed under normal circumstances, but is a critical
warning (which is fatal by default) under G_ENABLE_DIAGNOSTIC. This is a
programming error, so we should only exercise it under
g_test_undefined(), and only in a test that is intentionally doing this
(as in the previous commit).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-21 11:19:52 +01:00
Simon McVittie
0bba27eea9 gobject/tests: Exercise a floating object reaching last-unref
This was previously exercised (probably by mistake) in
gobject/tests/type.c, but without making any assertions about what
happened, and the test would fail under G_ENABLE_DIAGNOSTIC if GLib was
compiled with debug enabled.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-21 11:19:41 +01:00