test(cpp): add tests for pure utilities#55
Conversation
Cover the engine-free utility units that compile directly into the Catch2 binary (no plugin DLL, no CommonLibSSE/D3D/ImGui runtime): - SphericalHarmonics: band-0/1 basis constants, Dot symmetry + 1/pi self-dot identity, Add/Scale algebra, Unproject of a DC-only SH. - PerfUtils: CalcFrameTime / CalcFPS guards, Mean/Median edge cases, QPC. - RestartSettings: UTIL_RESTART_FIELD offset/size, FindRestartField hit/miss/case-sensitivity/empty. - Input: device+key packing & 16-bit truncation, IsValid, equality/order, ToString/IsValidDevice, JSON round-trip (scalar + vector). Adds test_prelude.h (force-included) to supply the float2/3/4 = DirectX::SimpleMath aliases the plugin PCH normally provides, and links DirectXTK + magic_enum to the test target. FileSystem was reclassified out of Tier 1: SanitizeFileName calls Util::IEquals, which is defined in Format.cpp (includes Globals.h), so the TU can't compile standalone. It moves to the Tier-2 follow-up. 139 assertions / 39 cases pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 35 minutes and 48 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
No actionable suggestions for changed features. |
There was a problem hiding this comment.
Pull request overview
Adds the first batch ("Tier-1") of Catch2 unit tests for pure-utility code that does not depend on the plugin DLL, CommonLibSSE, D3D, or ImGui. A small force-included prelude supplies the float2/3/4 SimpleMath aliases that the plugin PCH normally provides, so headers like SphericalHarmonics.h compile inside the standalone test binary.
Changes:
- New Catch2 test suites for
SphericalHarmonics,PerfUtils,RestartSettings, andInput(combo packing, validation, equality/ordering, JSON round-trip). - New
test_prelude.hforce-included intocpp_teststo provide the SimpleMathfloatN/float4x4aliases without dragging in the engine PCH. tests/cpp/CMakeLists.txtregisters the new sources, force-includes the prelude, addsdirectxtk+magic_enumdependencies, and compilesUtils/SphericalHarmonics.cppdirectly into the test binary.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cpp/test_sphericalharmonics.cpp | Band-0/1 basis constants, Dot symmetry, Add/Scale algebra, DC-only Unproject. |
| tests/cpp/test_perfutils.cpp | CalcFrameTime/CalcFPS guards, Mean/Median edge cases, QPC monotonicity. |
| tests/cpp/test_restartsettings.cpp | UTIL_RESTART_FIELD offset/size and FindRestartField hit/miss/case-sensitivity/empty-span. |
| tests/cpp/test_input.cpp | Device+key packing, 16-bit key truncation, IsValid, ordering, ToString/IsValidDevice, JSON round-trip. |
| tests/cpp/test_prelude.h | Force-included aliases (float2/3/4, float4x4) for SimpleMath types. |
| tests/cpp/CMakeLists.txt | Registers new sources, prelude force-include, DirectXTK + magic_enum deps. |
|
✅ A pre-release build is available for this PR: |
The constructor required std::is_standard_layout_v<SettingsT>, but that rejects Settings carrying a std::string (std::string is not standard-layout under MSVC's STL) -- which broke cpp_tests' SettingsWithString deep-copy case on the VS2026/MSVC 14.50 toolchain (CI's older windows-2025 STL happened to accept it). The requirement is overly strict: detail::MemberOffset uses layout-agnostic pointer subtraction, and offsetof in UTIL_RESTART_FIELD is conditionally-supported on non-standard-layout types (MSVC computes correct offsets for the scalar registered fields). Reject only polymorphic types, where a vtable makes member offsets genuinely unstable. Runtime behavior unchanged; this only relaxes a compile-time guard. cpp_tests now builds and passes locally on MSVC 14.50 (161 assertions). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
13b55da to
6a5743e
Compare
Move InverseSquareLighting's radius/attenuation constants and the CalculateRadius / GetAttenuation / SmoothStep math into a new pure header (Features/InverseSquareLighting/RadiusMath.h, namespace ISLMath). The functions take only plain floats, so the header compiles standalone into the cpp_tests binary with no game/RE runtime. The class's static methods now delegate to it -- call sites (incl. LightEditor) are unchanged. Adds test_isl_radiusmath.cpp (13 assertions): SmoothStep ramp/clamp, CalculateRadius closed-form + shadow/override branches + NaN->1 guard, GetAttenuation peak/vanish/monotonic. Validated: cpp suite + plugin build. Phase 2 (Tier 2) of the cpp-test expansion; follows #55. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move InverseSquareLighting's radius/attenuation constants and the CalculateRadius / GetAttenuation / SmoothStep math into a new pure header (Features/InverseSquareLighting/RadiusMath.h, namespace ISLMath). The functions take only plain floats, so the header compiles standalone into the cpp_tests binary with no game/RE runtime. The class's static methods now delegate to it -- call sites (incl. LightEditor) are unchanged. Adds test_isl_radiusmath.cpp (13 assertions): SmoothStep ramp/clamp, CalculateRadius closed-form + shadow/override branches + NaN->1 guard, GetAttenuation peak/vanish/monotonic. Validated: cpp suite + plugin build. Phase 2 (Tier 2) of the cpp-test expansion; follows #55. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
First batch of the cpp-test expansion — the Tier-1 units that are directly unit-testable (compile straight into the Catch2 binary, no plugin DLL / CommonLibSSE / D3D / ImGui runtime). Tier-2 (extraction-required units like FormulaHelper, ISL math, LLF clamp) is a planned fast-follow.
New suites (139 new assertions; 161 total with the existing Subrect + BootSnapshot suites)
Dotsymmetry + the1/πunit-direction self-dot identity,Add/Scalealgebra,Unprojectof a DC-only SH.CalcFrameTime/CalcFPSguards,Mean/Median(empty/odd/even/unsorted), QPC clock monotonicity.UTIL_RESTART_FIELDoffset/size,FindRestartFieldhit/miss/case-sensitivity/empty-span.IsValid, equality/ordering,ToString/IsValidDevice, JSON round-trip (scalar + vector).Harness changes
test_prelude.h(force-included via/FI) supplies thefloat2/3/4 = DirectX::SimpleMath::*aliases the plugin PCH normally provides, soSphericalHarmonics.cppcompiles without dragging in the RE/SKSE PCH.Local-build fix (BootSnapshot)
cpp_testsdidn't build on the VS2026 / MSVC 14.50 toolchain:test_bootsnapshot'sSettingsWithString(astd::stringmember) trippedBootSnapshot'sis_standard_layoutstatic-assert, becausestd::stringisn't standard-layout under MSVC's current STL. (CI'swindows-2025/older STL accepted it, so the gate stayed green and earlier incremental builds masked it via a stale.obj.)The assert was overly strict —
detail::MemberOffsetuses layout-agnostic pointer subtraction andoffsetofis conditionally-supported (MSVC computes correct offsets for the scalar registered fields). Relaxed it to reject only polymorphic Settings (genuinely unstable offsets). Runtime behavior unchanged; compile-time guard only.cpp_testsnow builds and passes locally on MSVC 14.50.Scope notes
SanitizeFileNamecallsUtil::IEquals, declared inFormat.hbut defined inFormat.cpp(which#includesGlobals.h), soFileSystem.cppcan't compile standalone. Moves to the Tier-2 follow-up onceIEqualsis decoupled.Input::MatchesKeyboardCombois intentionally not tested — it reads live key state viaGetAsyncKeyState.Validation
Full suite builds and passes locally (MSVC 14.50) and is gated in CI (
windows-2025): 161 assertions / 43 cases.