Commit Graph

22 Commits

Author SHA1 Message Date
Philip Withnall
d02f5816bf Merge branch 'wip/pwithnall/gdump-tests' into 'main'
tests: Add basic tests for gdump.c in libgirepository

See merge request GNOME/glib!4102
2024-06-04 15:17:03 +00:00
Philip Withnall
5b26ef2e46
tests: Add basic tests for gdump.c in libgirepository
It’s currently completely untested. Let’s add a few basic tests so that
adding more tests in future is easier.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-04 15:52:05 +01:00
Andoni Morales Alastruey
99382cfb4b girepository: fix autoptr tests build
In macOS compilation fails with the following error:
```
In file included from ../girepository/tests/autoptr.c:23:
../girepository/girffi.h:30:10: fatal error: 'ffi.h' file not found
```
2024-06-04 13:00:45 +02:00
Philip Withnall
81b16a88d1
girepository: Make gi_repository_find_by_gtype() deterministic
When faced with a `GType` which is present in multiple typelibs, the old
implementation was not deterministic, as it iterated over a hash table
of typelibs. The iteration order of a hash table is not deterministic.

Use the new `ordered_typelibs` and `ordered_lazy_typelibs` arrays to
iterate instead, making the order deterministic.

Add a unit test to check this. In particular, to check that symbols
which are present in both `Gio` and `GioUnix` are correctly resolved as
being from `GioUnix`.

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

Helps: #3303
2024-05-16 22:47:35 +01:00
Marco Trevisan (Treviño)
3de5264f24 girrepository/tests: Add full gir dependencies on tests
Tests may have runtime dependencies that are related to the typelib
dependencies, so we need to satify them or the tests will fail at
runtime if we're not building their prerequisite for other reasons.

That's saying that the tests are currently failing when explicitly
running as standalone in meson.

Co-Authored-By: Philip Withnall <philip@tecnocode.co.uk>
2024-05-09 15:48:58 +02:00
Philip Withnall
06a7258a8c girepository: Add g_autoptr() and g_auto() support
This should make the code a bit more usable in situations where people
aren’t potentially using MSVC.

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

Helps: #3255
2024-02-14 11:54:48 +00:00
Philip Withnall
0fd99a9f16 gibaseinfo: Stop building GIBoxedInfo instances
Instead, add a method on `GIRegisteredTypeInfo` which indicates whether
the registered type is a boxed type. This will return true for
`GIStructInfo` and `GIUnionInfo` instances which are boxed (not all
structs and unions are).

This makes `GIBoxedInfo` redundant, and it’ll be dropped in a following
commit.

---

There are several different things which typelibs need to be able to
represent:
 1. Plain old datatype (POD) structs
 2. POD unions
 3. Structs with a copy func and/or free func
 4. Unions with a copy func and/or free func
 5. Structs which are the ‘GType struct’ for an object or interface (i.e.
    the class or instance or interface struct)
 6. Structs with a copy func and free func *and* boxed GType
 7. Unions with a copy func and free func *and* boxed GType
 8. Boxed GTypes which represent something other than a struct or union

So there’s a lot going on here. In commit
e28078c70cbf4a57c7dbd39626f43f9bd2674145, a lot of this was reworked,
and support was added for boxed unions and boxed ‘others’ (the last item
on the list above).

Since then, support for boxed types other than structs seems to have
atrophied a bit, and the whole lot has got a bit confusing.

It was perhaps less confusing when all the `GIBaseInfo` subclasses were
actually aliases of each other, but now they have subtype relationships,
the position of `GIBoxedInfo` in that type hierarchy has become unclear.
How is it related to `GIStructInfo`, `GIUnionInfo` and
`GIRegisteredTypeInfo`?

Since a boxed type is necessarily a `GIRegisteredTypeInfo`, and the
methods of `GIRegisteredTypeInfo` are all written to allow a `GType` to
be optional, so that `GIStructInfo` and `GIUnionInfo` can safely derive
from it and still be used to represent plain old datatypes without
`GType`s, it makes sense to add a method to `GIRegisteredTypeInfo` to
indicate that the registered type is derived from `G_TYPE_BOXED`.

Accordingly, the things above are now represented in libgirepository’s
type system as:
 1. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info
 2. `GIUnionInfo` instance similarly
 3. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info, `gi_struct_info_get_{copy,free}_function_name()` return
    non-`NULL` values
 4. `GIUnionInfo` instance similarly
 5. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return no
    `GType` info, `gi_struct_info_is_gtype_struct()` returns true
 6. `GIStructInfo` instance, `GIRegisteredTypeInfo` methods return valid
    `GType` information, `gi_registered_type_info_is_boxed()` returns
    true, `gi_struct_info_get_{copy,free}_function_name()` return
    `NULL` values (because the copy/free functions are hidden inside the
    boxed type registration at runtime)
 7. `GIUnionInfo` instance similarly
 8. Not representable, but could be represented in future by re-adding a
    `GIBoxedInfo` type which derives from `GIRegisteredTypeInfo` and is
    used solely for boxed ‘other’ types, *not* boxed structs or unions

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

Fixes: #3245
2024-02-12 13:16:07 +00:00
Philip Withnall
e1cff511e5 Merge branch '3155-union-tests' into 'main'
gitypes: Fix integer values of GIInfoType and add unit tests for GIUnionInfo

See merge request GNOME/glib!3888
2024-02-08 10:25:13 +00:00
Philip Withnall
44e3ebccd1 tests: Add basic tests for GIUnionInfo
These would have caught the regression fixed in the previous commit.

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

Helps: #3155
2024-02-06 13:42:43 +00:00
Philip Chimento
614437107a tests: Add a test for finding methods and vfuncs in a GIObjectInfo
Helps: #3246
2024-02-05 18:40:58 +00:00
Evan Welsh
5d997cad03 girepository: Update gi-compile-repository and use it to compile GIRs
Adapt gi-compile-repository sources to compile against the updated
libgirepository that is included with GLib.

This also renames "g-ir-compiler" to "gi-compile-repository" to avoid
overwriting the existing binary and to simplify the binary name going
forward.
2024-01-31 11:13:16 +00:00
Evan Welsh
f75221c7ea girepository: Move GIR generation into girepository and prior to tests
To enable tests which depend on libgirepository's GIR and typelib,
we need to refactor the order we're currently building these items.

We can also move everything under girepository/ to cleanup the
top-level.
2024-01-30 00:50:40 -06:00
Philip Chimento
cda9ebeb03 tests: Port over some GIRepository tests from g-i 1.x
These tests come from gobject-introspection/tests/repository/. They
include whatever wasn't already covered by the existing tests.

The original files didn't have copyright information. That's been
reconstructed from commit messages of commits that added a test or a
substantial part of one.
2024-01-23 22:04:52 -08:00
Philip Chimento
b8a65edb01 tests: Use fixture in GIRepository tests
This deduplicates some code and will allow writing further tests more
easily.
2024-01-23 22:04:52 -08:00
Philip Chimento
d41f05e9cf build: Add libffi dependency to girepository/function-info test
I found that this dependency is needed for girffi.h to find ffi.h.
2024-01-23 21:59:38 -08:00
Philip Withnall
3e157c688e girffi: Add a test for gi_function_info_prep_invoker()
This test case was originally written by Philip Chimento as a reproducer
for #3218. Let’s add it to the test suite to catch regressions in
stack-allocated `GIBaseInfo` handling.

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

Helps: #3218
2024-01-23 18:10:03 +00:00
Simon McVittie
25ec19723c girepository: Exclude private symbols from the ABI
This removes the gthash utility functions from the ABI, so link those
into their automated test statically.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-01-19 12:07:30 +00:00
Marco Trevisan (Treviño)
18d0b0eb40 girepository: Move cmph-bdz test to tests subfolder
We can avoid to maintain the special case and still works fine
2024-01-15 21:26:40 +00:00
Marco Trevisan (Treviño)
8a4755106d girepository: Add gthash test to tests and run it 2024-01-15 18:16:56 +01:00
Marco Trevisan (Treviño)
a8588b803e girepository/tests: Add search paths tests
Add some more tests to ensure search paths behavior follows the expected
one.
2023-12-21 03:02:27 +01:00
Marco Trevisan (Treviño)
2fbe6ca53e cleanup: Add missing final ending line to meson girrepository files 2023-12-21 03:02:27 +01:00
Philip Withnall
e699037fef girepository: Add a couple of very simple unit tests
For the moment, this is enough to roughly verify that the port to
`GTypeInstance` has not massively broken things. It’s not anywhere near
sufficient to qualify as a proper test suite though.

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

Helps: #3155
2023-12-12 16:58:27 +00:00