Automated Test Suite
Since version 4.3.0 the library ships an automated test suite, built with DUnitX, in the Test folder of the installation (and of the repository).
The suite is a console application for Delphi 13 (Win32 and Win64) and locks two kinds of behaviour:
- Regression tests for the defects fixed by the code reviews: every fix has a test that failed on the previous sources and passes on the current ones.
- Contract tests for the rendering and the style families: every Class/Appearance of every family assigns its colours, a solid border always has a colour, the Classic Disabled state visibly differs from Normal for every VCL style,
btRoundedbuttons are real pills, the notification badge keeps its shape whatever the border width of the button.
Running the tests
Test\run_tests.cmd [Win32|Win64] [Debug|Release] [BDS path]- Defaults:
Win64,Debug. The Debug configuration runs with range and overflow checking on, which is the point of running the tests at all. - The Delphi installation is taken from the
BDSenvironment variable or from the registry (Delphi 13, 12, 11, 10.4, newest first); pass the path as third argument to force one. - The script builds
Test\Projects\D13\StyledComponentsTests.dprojwith MSBuild, runs the executable and writes a NUnit XML report inTest\Bin\<Platform>\<Config>\dunitx-results.xml. Exit code0means all tests passed.
The project can also be opened and run from the IDE like any DUnitX console project.
What is covered
| Unit | Area |
|---|---|
StyledRenderTests | GDI+ shapes (pill radius), notification badge, style family registry and contracts (all families) |
StyledButtonTests | Assign between styled buttons, StyleFamily change, dialog keys (Enter/Esc with KeyPreview) |
StyledContainerTests | TStyledToolbar sizing inside BeginUpdate/EndUpdate, TStyledPanel ParentBackground with and without VCL styles, TStyledButtonGroup/TStyledCategoryButtons items shape |
StyledDialogTests | TStyledTaskDialog radio buttons |
StyledPerfTests | Performance benchmarks (see below) |
StyledTestUtils provides the shared helpers: off-screen painting of graphic and windowed controls, pixel probes with tolerance, a hidden host form, DFM streaming round-trip and the [AllFamilies] attribute that runs a test case once per registered style family.
Performance benchmarks
StyledPerfTests installs a pass-through memory manager that counts heap allocations and measures each scenario with TStopwatch: the numbers are reported in the test message and in the XML report, and a test fails only above an allocation ceiling (allocations are deterministic, times depend on the machine). Run them with the Release configuration for meaningful times.
Values measured on Delphi 13, Win32, per single paint, before and after the 4.3.0 optimizations:
| Scenario | 4.2.4 | 4.3.0 |
|---|---|---|
TStyledButton real WM_PAINT, double buffered | 21 allocations | 7 allocations |
| Classic button paint (VCL style re-resolved per paint) | 19 allocations | 11 allocations |
TStyledButtonGroup / TStyledCategoryButtons item with its own style | 27 allocations | 9 allocations |
TStyledBitBtn Kind=bkOK (PNG decoded per paint) | 38 allocations, ~950 µs | 14 allocations, ~230 µs |
TStyledBitBtn custom glyph (TImageList built per paint) | 37 allocations, ~560 µs | 11 allocations, ~150 µs |
| Command link button | 49 allocations, ~660 µs | 25 allocations, ~400 µs |
SVG-Colors unknown class name (EConvertError) | ~40 µs | ~4 µs |
For reference a plain VCL TButton painted the same way costs 0 allocations and about 30-45 µs; most of the remaining time of a styled button is the GDI+ drawing of the shape and of the text (about 20 µs each).
Notes
- The test project links its resource with the comctl32 v6 manifest on purpose: without it
StyleServices.EnabledisFalseand the whole VCL-style colour table of the Classic family is not registered, so those tests would pass vacuously. - The tests that need a custom VCL style load
Carbon.vsffrom the DelphiRedist\styles\vclfolder and restore the system style afterwards. Test\BinandTest\Libare build outputs and are not part of the installer.
