C++ tools and synthetic data
The C++ tools give engineers a small command-line view of MLT tiles, while the synthetic data system creates controlled tiles for decoder and encoder checks. Together they connect the library described in C++ tile library with the shared tile fixtures and the codec flow described in C++ codec pipeline.
Tooling role
The tooling turns binary tile data into a form that engineers can inspect and compare. The synthetic system supplies small, known inputs so that changes in tile behavior can be checked without relying only on large real-world tiles.
Tile inspection
JSON output
The mlt-cpp-json command reads one MLT tile and writes a JSON representation to standard output. With no tile coordinate, the result is a flat feature collection that keeps the tile's raw coordinate space and adds the layer name and extent to each feature's properties; this form matches the synthetic expected files. cpp/…/mlt-json.cpp• L33-67, cpp/…/synthetic-geojson.hpp• L6-11
The command can also receive z, x, and y tile coordinates. In that mode it writes GeoJSON with geographic coordinates, which makes a tile suitable for inspection in tools that understand GeoJSON. cpp/…/mlt-json.cpp• L34-49, cpp/…/mlt-json.cpp• L58-67
References: cpp/…/mlt-json.cpp• L33-67 cpp/…/synthetic-geojson.hpp• L6-11
Synthetic GeoJSON shape
The synthetic GeoJSON form is a logical view of a decoded tile rather than a source-data format. It preserves feature geometry, properties, and optional IDs, while recording layer context in _layer and _extent; this lets tests compare meaning without depending on the exact byte layout. cpp/…/synthetic-geojson.cpp• L74-93
The view covers the supported point, line, polygon, and multi-geometry families. It keeps coordinates in tile space so that a fixture can test geometry behavior directly and consistently across encoders. cpp/…/synthetic-geojson.cpp• L16-68
References: cpp/…/synthetic-geojson.cpp• L16-68 cpp/…/synthetic-geojson.cpp• L74-93
Synthetic fixture system
Fixture purpose
Synthetic fixtures are small MLT tiles paired with expected logical JSON. Their purpose is cross-language conformance: a decoder should produce the same logical result from a fixture regardless of which implementation wrote the tile. test/…/README.md• L1-11
The C++ generator builds inputs that cover the main tile dimensions without tying the checks to production data. The set includes geometry forms, feature IDs, property values, extents, mixed geometry, and alternate encoding choices. cpp/…/test_synthetic.cpp• L130-172, cpp/…/synthetic_mlt_generator.hpp• L297-404, cpp/…/synthetic_mlt_generator.hpp• L633-654, cpp/…/synthetic_mlt_generator.hpp• L899-945
References: test/…/README.md• L1-16 cpp/…/test_synthetic.cpp• L130-172 cpp/…/synthetic_mlt_generator.hpp• L297-404 cpp/…/synthetic_mlt_generator.hpp• L633-654 cpp/…/synthetic_mlt_generator.hpp• L899-945
Fixture validation
The C++ synthetic test discovers fixture tiles, maps fixture names to generators, and checks the generated result against the stored tile. It prefers byte equality because that catches changes in the encoded form. When byte equality is not stable for a case, it decodes both tiles and compares their logical JSON instead. cpp/…/test_synthetic.cpp• L177-237
The test also reports gaps between stored fixtures and registered generators. A missing generator is visible as an unchecked fixture, while a generated case with no matching fixture is a test failure. This keeps the fixture set and its C++ input model from drifting apart. cpp/…/test_synthetic.cpp• L240-299
References: cpp/…/test_synthetic.cpp• L177-237 cpp/…/test_synthetic.cpp• L240-299
Cross-language fixture use
The shared fixture directory is the common contract for the language implementations. The C++ command-line test runs the decoder against active fixtures and compares its JSON output with the expected content; unsupported fixture groups are marked separately instead of being treated as valid coverage. cpp/…/synthetic.test.ts• L12-40
The fixture layout distinguishes common cases from implementation-specific encoding cases. Add a common case to the shared version directory when Java can encode it; keep language-specific encoding behavior in its dedicated fixture group. test/…/README.md• L13-16
References: cpp/…/synthetic.test.ts• L12-40 test/…/README.md• L1-16
Robustness inputs
Robustness tests use small stored tiles as seeds for invalid input checks. The test mutates tile bytes and also builds malformed tile structures to confirm that decoding rejects bad data with a controlled runtime error instead of crashing or consuming unbounded memory. cpp/…/test_robustness.cpp• L1-7, cpp/…/test_robustness.cpp• L104-232, cpp/…/test_robustness.cpp• L602-639
This validation complements synthetic fixtures. Synthetic fixtures describe valid tile meaning, while robustness inputs probe how the decoder handles broken lengths, offsets, indexes, nesting, and compressed streams. The checks can run with AddressSanitizer and UndefinedBehaviorSanitizer to expose unsafe memory access. cpp/…/test_robustness.cpp• L1-7, cpp/…/test_robustness.cpp• L236-598
References: cpp/…/test_robustness.cpp• L1-7 cpp/…/test_robustness.cpp• L104-232 cpp/…/test_robustness.cpp• L236-598 cpp/…/test_robustness.cpp• L602-639
Inspection and validation flow
The normal path starts with a binary tile and ends with either a human-readable view or a semantic comparison against a known result. The command-line tool supports the first path, while the synthetic tests use the second path.
The diagram shows how the same decoded tile can serve interactive inspection and fixture validation.
flowchart LR
A[MLT tile] --> B[mlt-cpp-json]
B --> C[Raw tile-space JSON]
B --> D[Coordinate-aware GeoJSON]
A --> E[Synthetic fixture test]
F[Generated test input] --> E
E --> G[Byte comparison]
E --> H[Decoded logical JSON comparison]
I[Fixture tiles] --> J[Robustness test]
J --> K[Controlled rejection]
The command is built with the C++ tool target, while the synthetic checks are part of the C++ test target and can also invoke the command through the TypeScript test harness. cpp/CMakeLists.txt• L25-28, cpp/CMakeLists.txt• L205-212, cpp/…/CMakeLists.txt• L1-4, cpp/…/CMakeLists.txt• L1-27
Change checklist
When these files or sections are changed, remember to consider these:
- When the JSON shape changes, update the synthetic expected representation and every comparison path that consumes it.
- When a new fixture is added, register its C++ generator and confirm that its name matches the stored
.mltstem. - When a fixture uses an encoding whose bytes can vary, preserve the semantic comparison exception rather than weakening all fixture checks.
- When CLI output or arguments change, check both raw tile-space output and coordinate-aware GeoJSON output.
- When a fixture group changes, confirm that the cross-language harness still classifies supported and skipped groups correctly.
- When decoder limits or invalid-input handling changes, review the malformed tile and mutated-fixture checks for both controlled errors and bounded resource use.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A fixture has no registered C++ generator | The fixture is skipped by the generator comparison and loses C++ input coverage | The coverage test lists unchecked fixtures for review. cpp/…/test_synthetic.cpp• L245-299 |
| A generator has no matching fixture file | The generated case cannot verify a stored contract | The coverage test fails when generated names are missing from the fixture directory. cpp/…/test_synthetic.cpp• L269-297 |
| A semantic-only case is forced into byte equality | Valid output can fail because some encoding choices do not have stable bytes | The test records an explicit exception and still compares decoded JSON. cpp/…/test_synthetic.cpp• L101-116, cpp/…/test_synthetic.cpp• L215-231 |
| Tile coordinates are omitted when geographic GeoJSON is expected | The command emits raw tile-space coordinates instead | Pass z, x, and y to select coordinate-aware output. cpp/…/mlt-json.cpp• L34-49, cpp/…/mlt-json.cpp• L61-67 |
| Malformed lengths, offsets, indexes, or nesting reach the decoder without rejection | The decoder can throw the wrong error or risk unsafe access and excessive allocation | The robustness suite checks controlled std::runtime_error failures and runs mutated fixture bytes through the decoder. cpp/…/test_robustness.cpp• L1-7, cpp/…/test_robustness.cpp• L104-232, cpp/…/test_robustness.cpp• L602-639 |
Key files
| File | Why to read it |
|---|---|
| cpp/…/mlt-json.cpp | Defines the command-line inspection modes and their output choice. |
| cpp/…/synthetic-geojson.cpp | Defines the shared logical GeoJSON view used by synthetic checks. |
| cpp/…/synthetic_mlt_generator.hpp | Shows how controlled tile inputs cover geometry, IDs, properties, and encoding variants. |
| cpp/…/test_synthetic.cpp | Shows how generated tiles and stored fixtures are matched and compared. |
| cpp/…/synthetic.test.ts | Shows the command-line decoder check against shared synthetic expectations. |
| test/…/README.md | Defines the purpose and placement rules for cross-language fixtures. |
| cpp/…/test_robustness.cpp | Shows how malformed and mutated tiles test safe decoder failure. |
| cpp/CMakeLists.txt | Shows when the C++ tools and tests are included in a build. |