![]() - Fix annotations for gimp_export_options_get_image() to make it actually introspectable with the GimpImage being both input and output. Even though the logic doesn't change much (the input image may be overriden or not), it doesn't matter for introspection because images are handled centrally by libgimp and therefore must not be freed. Actually deleting the image from the central list of images though remains a manual action depending on code logic, not some automatic action to be handled by binding engines. - Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image() because ignoring the returned value is rarely a good idea (as you usually want to delete the image). - Remove gimp_export_options_new(): we don't need this constructor because at this point, the best is to tell plug-in developers to just pass NULL everywhere. This leaves us free to create a more useful default constructor if needed, in the future. Main description for GimpExportOptions has also been updated to say this. - Add a data_destroy callback for the user data passed in gimp_export_procedure_set_capabilities(). - Fixing annotations of 'export_options' object from pdb/pdb.pl: input args would actually be (nullable) and would not transfer ownership (calling code must still free the object). Return value's ownership on the other hand is fully transfered. - Add C and Python unit testing for GimpExportOptions and gimp_export_options_get_image() in particular. - Fix or improve various details. Note that I have also considered for a long time changing the signature of gimp_export_options_get_image() to return a boolean indicating whether `image` had been replaced (hence needed deletion) or not. This also meant getting rid of the GimpExportReturn enum. Right now it would work because there are no third case, but I was considering the future possibility that for instance we got some impossible conversion for some future capability. I'm not sure it would ever happen; and for sure, this is not desirable because it implies an export failure a bit late in the workflow. But just in case, let's keep the enum return value. It does not even make the using code that much more complicated (well just a value comparison instead of a simple boolean test). |
||
---|---|---|
.. | ||
pygimp | ||
README.md | ||
c-test-header.c | ||
libgimp-run-c-test.sh | ||
libgimp-run-python-test.sh | ||
meson.build | ||
test-color-parser.c | ||
test-color-parser.py | ||
test-export-options.c | ||
test-export-options.py | ||
test-image.c | ||
test-image.py | ||
test-palette.c | ||
test-palette.py | ||
test-selection-float.c | ||
test-selection-float.py | ||
test-unit.c | ||
test-unit.py |
README.md
Unit testing for libgimp
We should test every function in our released libraries and ensure they return the correct data. This test infrastructure does this for the C library and the Python 3 binding.
Every new test unit should be added both in C and Python 3.
Procedure to add the C unit
C functions are tested in a real plug-in which is run by the unit test
infrastructure. Most of the boiler-plate code is contained in c-test-header.c
therefore you don't have to care about it.
All you must do is create a gimp_c_test_run()
function with the following
template:
static GimpValueArray *
gimp_c_test_run (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
gint n_drawables,
GimpDrawable **drawables,
GimpProcedureConfig *config,
gpointer run_data)
{
/* Each test must be surrounded by GIMP_TEST_START() and GIMP_TEST_END()
* macros this way:
*/
GIMP_TEST_START("Test name for easy debugging")
/* Run some code and finish by an assert-like test. */
GIMP_TEST_END(testme > 0)
/* Do more tests as needed. */
/* Mandatorily end the function by this macro: */
GIMP_TEST_RETURN
}
This code must be in a file named only with alphanumeric letters and hyphens,
and prepended with test-
, such as: test-palette.c
.
The part between test-
and .c
must be added to the tests
list in
libgimp/tests/meson.build
.
Procedure to add the Python 3 unit
Unlike C, the Python 3 API is not run as a standalone plug-in, but as Python
code directly interpreted through the python-fu-eval
batch plug-in.
Simply add your code in a file named the same as the C file, but with .py
extension instead of .c
.
The file must mandatorily start with a shebang: #!/usr/bin/env python3
For testing, use gimp_assert()
as follows:
#!/usr/bin/env python3
# Add your test code here.
# Then test that it succeeded with the assert-like test:
gimp_assert('Test name for easy debugging', testme > 0)
# Repeat with more tests as needed.