Change-Id: I4f53f7ee2d7f5147d09e0ff3bbde9f48f10ff85a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203324 Tested-by: Jenkins Reviewed-by: Hossein <hossein@libreoffice.org>
Codemaker Test Suite
This directory contains the integration test suite for the UNO code generators cppumaker and pythonmaker. The suite ensures that:
cppumakercorrectly generates C++ headers (.hppand.hdl), andpythonmakercorrectly generates Python stub files (.pyi)
from the same UNO IDL definitions. It verifies the syntactic correctness of the output and protects against future regressions.
The tests are automatically executed as part of the make check command for the codemaker module. They can also be run on their own with:
make codemaker.check
Testing Philosophy
The test suite follows a "Golden File" testing methodology. This is a standard and robust approach for testing compilers and code generators. The process is as follows:
- Source IDL: A single comprehensive test IDL file (
tests.idl) serves as the source of truth for all UNO constructs that the generators are expected to handle. Both tools are fed the same file. - Generate Output: During the test run, this IDL is compiled into a temporary
.rdbfile withunoidl-write, and each tool (cppumaker,pythonmaker) is executed to generate its output in its own temporary directory. - Compare Against "Golden" Files: The newly generated output is recursively compared against a set of manually verified, correct "golden" files:
expected_cppumaker_stubs/forcppumakerexpected_pythonmaker_stubs/forpythonmaker
- Pass/Fail: A test passes only if the generated output is an exact match to the golden files. Any difference (missing files, extra files, or content mismatches) causes the test to fail.
This approach ensures that any change to a generator that alters its output is immediately detected.
Directory Structure
tests.idl: The master IDL file containing all test cases. This includes enums, constants, typedefs, structs (plain, inherited, and polymorphic), exceptions, interfaces, services, and singletons. It also includes edge cases like the use of keywords as identifiers. All types live in the tool-neutral moduletest::codemaker::codemakertests, so the generated paths and namespaces (e.g.test/codemaker/codemakertests/...) are the same for both tools.expected_cppumaker_stubs/: The "golden".hppand.hdlfile structure thatcppumakeris expected to generate fromtests.idl. This is the reference standard for correctness ofcppumaker.expected_pythonmaker_stubs/: The "golden".pyifile structure thatpythonmakeris expected to generate fromtests.idl. This is the reference standard for correctness ofpythonmaker.codemakertests.py: The Python script that orchestrates the tests. It is executed by the build system and, for each tool, compiles the IDL, runs the tool, and compares the output directory with the matching golden directory. It contains one test class per tool (TestCppuMaker,TestPythonMaker) sharing a common implementation.README.md: This file.
The gbuild makefile that integrates the script into make check is codemaker/Test_codemaker.mk, registered in codemaker/Module_codemaker.mk. It depends on both the cppumaker and pythonmaker executables.
How to Modify or Extend the Test Suite
Future developers may need to modify these tests when fixing a bug or adding a new feature to either tool. Here is the standard workflow.
Regenerating the Golden Files
Both golden directories are regenerated from tests.idl with the freshly built tools. Run the following from instdir/program (the tools need the libraries located there):
mkdir -p ../../workdir/golden_tmp
# 1. Compile the shared IDL to an .rdb
../sdk/bin/unoidl-write.exe ../../workdir/UnoApiTarget/udkapi.rdb ../../codemaker/tests/tests.idl ../../workdir/golden_tmp/tests.rdb
# 2. Clear the old golden files
rm -rf ../../codemaker/tests/expected_cppumaker_stubs ../../codemaker/tests/expected_pythonmaker_stubs
mkdir -p ../../codemaker/tests/expected_cppumaker_stubs ../../codemaker/tests/expected_pythonmaker_stubs
# 3. Generate the stubs straight into the golden directories
../sdk/bin/cppumaker.exe -O ../../codemaker/tests/expected_cppumaker_stubs ../../workdir/golden_tmp/tests.rdb -X ../../workdir/UnoApiTarget/udkapi.rdb
../sdk/bin/pythonmaker.exe -O ../../codemaker/tests/expected_pythonmaker_stubs ../../workdir/golden_tmp/tests.rdb -X ../../workdir/UnoApiTarget/udkapi.rdb
# 4. Remove leftovers (the test ignores *.tmp files of pythonmaker)
find ../../codemaker/tests/expected_pythonmaker_stubs -name '*.tmp' -delete
rm -rf ../../workdir/golden_tmp
(On Linux/macOS, drop the .exe suffix; the SDK tools are in instdir/sdk/bin, or in the LibreOffice*_SDK/bin directory of the installation.) Only one of the two tools has to be regenerated if only one is affected; the other directory is left untouched. Always review the result with git diff before committing.
Scenario 1: Fixing a Bug in a Generator
If you have fixed a bug that was causing a tool to generate incorrect output, the corresponding test should now fail because the new, correct output will not match the old, incorrect golden files.
- Verify the Fix: After fixing the C++ code of the tool, run
make codemaker.checkto confirm that the test fails as expected. The error output lists the differing files and shows the first difference. - Regenerate the Golden Files: Follow the steps in "Regenerating the Golden Files" above.
- Review the Changes: Use
git diffto confirm that only the intended differences appear in the golden files. - Validate:
- For
cppumaker: ensure the new generated headers are syntactically correct and type-safe (often verified simply by checking that a full LibreOffice build succeeds with your newcppumaker). - For
pythonmaker: runmypy --strict codemaker/tests/expected_pythonmaker_stubs/to ensure the new golden files are syntactically correct and type-safe.
- For
- Commit: Commit the changes to the tool's C++ source code along with the updated golden files in your patch. The commit message should explain that the golden files were updated to reflect the bug fix.
Scenario 2: Adding a New Feature to a Generator
If you add support for a new IDL feature (e.g., a new type or an annotation), you should add a test case for it.
- Add a Test Case to the IDL:
- Open
codemaker/tests/tests.idl. - Add a new, simple example of the feature you've implemented. For example, add a new
interfacewith a specific attribute you are now supporting.
- Open
- Generate and Verify the New Golden Files:
- Since you've added a new type, new output files will be generated. Regenerate the golden files as described above. Note that the IDL is shared, so a change to
tests.idlmay also change the output of the other tool; review the golden files of both tools. - Locate the newly generated files for your new test case.
- Manually inspect these new files to ensure they are 100% correct (valid C++ for
cppumaker; runmypy --stricton them forpythonmaker).
- Since you've added a new type, new output files will be generated. Regenerate the golden files as described above. Note that the IDL is shared, so a change to
- Run the Full Test Suite: Run
make codemaker.check. The tests should now pass, as the newly generated output will match your newly added golden files. - Commit: Commit the changes to the tool's source code, the updated
tests.idl, and the new golden files together in your patch.