| 1 |
# GObject Introspection Tests |
| 2 |
|
| 3 |
This is a git submodule containing C source files. |
| 4 |
These files are compiled into shared libraries intended for testing language |
| 5 |
bindings for the GNOME platform. |
| 6 |
They are also used to test the `g-ir-scanner` tool from [gobject-introspection]. |
| 7 |
|
| 8 |
[gobject-introspection]: https://gitlab.gnome.org/GNOME/gobject-introspection |
| 9 |
|
| 10 |
## Available modules |
| 11 |
|
| 12 |
**Regress** test suite — a library designed as a general regression test suite, |
| 13 |
accumulated over the lifetime of gobject-introspection. |
| 14 |
Consists of `regress.c`, `annotation.c`, `drawable.c`, `foo.c`, and their |
| 15 |
associated header files. |
| 16 |
|
| 17 |
**GIMarshallingTests** suite — a library designed to exercise how every kind |
| 18 |
of C value used in GNOME platform APIs is converted to and from native values |
| 19 |
from the language binding. |
| 20 |
|
| 21 |
**Utility** test suite — a library for testing external type references. |
| 22 |
|
| 23 |
**WarnLib** test suite — a library with a number of conditions that |
| 24 |
`g-ir-scanner` will warn about, used to test how language bindings deal with |
| 25 |
typelibs that contain non-ideal C code. |
| 26 |
|
| 27 |
## How to Use in a Dynamic Language Binding |
| 28 |
|
| 29 |
Include this repository as a git submodule in your sources. |
| 30 |
|
| 31 |
```sh |
| 32 |
git submodule add https://gitlab.gnome.org/GNOME/gobject-introspection-tests.git |
| 33 |
``` |
| 34 |
|
| 35 |
If you use the Meson build system, you can also add it as a Meson subproject, |
| 36 |
and simply write: |
| 37 |
|
| 38 |
```meson |
| 39 |
gi_tests = subproject('gobject-introspection-tests') |
| 40 |
``` |
| 41 |
|
| 42 |
The subproject exports variables `gimarshallingtests_typelib`, |
| 43 |
`regress_typelib`, `utility_typelib`, and `warnlib_typelib` which you can access |
| 44 |
with `gi_tests.get_variable('regress_typelib')` etc. |
| 45 |
You will have to decide which modules you want to use. |
| 46 |
Most language bindings will want to use at least Regress and GIMarshallingTests. |
| 47 |
|
| 48 |
Now you can write tests that load the module, call each of its functions with |
| 49 |
the expected input, and check for the expected output. |
| 50 |
You will need to add the build folder to the environment variables |
| 51 |
`LD_LIBRARY_PATH` and `GI_TYPELIB_PATH`, something like this: |
| 52 |
|
| 53 |
```meson |
| 54 |
tests_environment = environment() |
| 55 |
gi_tests_builddir = meson.project_build_root() / 'subprojects' / 'gobject-introspection-tests' |
| 56 |
tests_environment.prepend('LD_LIBRARY_PATH', gi_tests_builddir) |
| 57 |
tests_environment.prepend('GI_TYPELIB_PATH', gi_tests_builddir) |
| 58 |
``` |
| 59 |
|
| 60 |
and then pass `env: tests_environment` in your call to `test()`. |
| 61 |
|
| 62 |
If your language binding supports installed tests, you will have to install the |
| 63 |
built modules manually, to a private location where your installed tests can |
| 64 |
find them. |
| 65 |
Do not install them in the default typelibs directory, where they may conflict |
| 66 |
with other language bindings' installed tests. |
| 67 |
Depending on how your build system is structured it might look something like |
| 68 |
this, using GIMarshallingTests as an example: |
| 69 |
|
| 70 |
```meson |
| 71 |
gi_tests = subproject('gobject-introspection-tests', |
| 72 |
default_options: ['install_dir=@0@'.format(installed_tests_dir)]) |
| 73 |
``` |
| 74 |
|
| 75 |
For build systems other than Meson, simply ignore the `meson.build` file and add |
| 76 |
code to your build system to build the modules as if it was a regular |
| 77 |
subdirectory. |