xref: /aosp_15_r20/external/harfbuzz_ng/test/shape/README.md (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1*2d1272b8SAndroid Build Coastguard WorkerAdding tests
2*2d1272b8SAndroid Build Coastguard Worker============
3*2d1272b8SAndroid Build Coastguard Worker
4*2d1272b8SAndroid Build Coastguard WorkerYou can test shaping of a unicode sequence against a font like this:
5*2d1272b8SAndroid Build Coastguard Worker```sh
6*2d1272b8SAndroid Build Coastguard Worker$ ./hb-unicode-encode 41 42 43 627 | ../../util/hb-shape font.ttf
7*2d1272b8SAndroid Build Coastguard Worker```
8*2d1272b8SAndroid Build Coastguard Workerassuming an in-tree build.  The 41 42 43 627 here is a sequence of
9*2d1272b8SAndroid Build Coastguard WorkerUnicode codepoints: U+0041,0042,0043,0627.  When you are happy with
10*2d1272b8SAndroid Build Coastguard Workerthe shape results, you can use the `record-test.sh` script to add
11*2d1272b8SAndroid Build Coastguard Workerthis to the test suite.  `record-test.sh` requires `pyftsubset` to
12*2d1272b8SAndroid Build Coastguard Workerbe installed.  You can get `pyftsubset` by installing
13*2d1272b8SAndroid Build Coastguard WorkerFontTools from <https://github.com/behdad/fonttools>.
14*2d1272b8SAndroid Build Coastguard Worker
15*2d1272b8SAndroid Build Coastguard WorkerTo use `record-test.sh`, just put it right before the `hb-shape` invocation:
16*2d1272b8SAndroid Build Coastguard Worker```sh
17*2d1272b8SAndroid Build Coastguard Worker$ ./hb-unicode-encode 41 42 43 627 | ./record-test.sh ../../util/hb-subset ../../util/hb-shape font.ttf
18*2d1272b8SAndroid Build Coastguard Worker```
19*2d1272b8SAndroid Build Coastguard Workerwhat this does is:
20*2d1272b8SAndroid Build Coastguard Worker  * Subset the font for the sequence of Unicode characters requested,
21*2d1272b8SAndroid Build Coastguard Worker  * Compare the `hb-shape` output of the original font versus the subset
22*2d1272b8SAndroid Build Coastguard Worker    font for the input sequence,
23*2d1272b8SAndroid Build Coastguard Worker  * If the outputs differ, perhaps it is because the font does not have
24*2d1272b8SAndroid Build Coastguard Worker    glyph names; it then compares the output of `hb-view` for both fonts.
25*2d1272b8SAndroid Build Coastguard Worker  * If the outputs differ, recording fails.  Otherwise, it will move the
26*2d1272b8SAndroid Build Coastguard Worker    subset font file into `data/in-house/fonts` and name it after its
27*2d1272b8SAndroid Build Coastguard Worker    hash, and print out the test case input, which you can then redirect
28*2d1272b8SAndroid Build Coastguard Worker    to an existing or new test file in `data/in-house/tests` using `-o`,
29*2d1272b8SAndroid Build Coastguard Worker    e.g.:
30*2d1272b8SAndroid Build Coastguard Worker```sh
31*2d1272b8SAndroid Build Coastguard Worker$ ./hb-unicode-encode 41 42 43 627 | ./record-test.sh -o data/in-house/tests/test-name.tests ../../util/hb-subset ../../util/hb-shape font.ttf
32*2d1272b8SAndroid Build Coastguard Worker```
33*2d1272b8SAndroid Build Coastguard Worker
34*2d1272b8SAndroid Build Coastguard WorkerIf you created a new test file, add it to `data/in-house/meson.build`
35*2d1272b8SAndroid Build Coastguard Workerso it is run.  Check that `make check` does indeed run it, and that the
36*2d1272b8SAndroid Build Coastguard Workertest passes.  When everything looks good, `git add` the new font as well
37*2d1272b8SAndroid Build Coastguard Workeras the new test file if you created any.  You can see what new files are
38*2d1272b8SAndroid Build Coastguard Workerthere by running `git status data/in-house`.  And commit!
39*2d1272b8SAndroid Build Coastguard Worker
40*2d1272b8SAndroid Build Coastguard Worker*Note!*  Please only add tests using Open Source fonts, preferably under
41*2d1272b8SAndroid Build Coastguard WorkerOFL or similar license.
42