summaryrefslogtreecommitdiff
path: root/src/tests/test_demo_effects.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_demo_effects.cc')
-rw-r--r--src/tests/test_demo_effects.cc108
1 files changed, 55 insertions, 53 deletions
diff --git a/src/tests/test_demo_effects.cc b/src/tests/test_demo_effects.cc
index ec1d68c..3c40bc5 100644
--- a/src/tests/test_demo_effects.cc
+++ b/src/tests/test_demo_effects.cc
@@ -1,23 +1,31 @@
// This file is part of the 64k demo project.
// It tests all demo effect classes for basic construction and initialization.
-// Validates that every effect can be instantiated and initialized without crashes.
+// Validates that every effect can be instantiated and initialized without
+// crashes.
//
// MAINTENANCE REQUIREMENT: When adding a new effect to demo_effects.h:
-// 1. Add it to the appropriate test list (post_process_effects or scene_effects)
+// 1. Add it to the appropriate test list (post_process_effects or
+// scene_effects)
// 2. Update EXPECTED_POST_PROCESS_COUNT or EXPECTED_SCENE_COUNT below
// 3. Run test to verify: ./build/test_demo_effects
-// 4. If the effect requires Renderer3D, add it to requires_3d check in test_scene_effects()
+// 4. If the effect requires Renderer3D, add it to requires_3d check in
+// test_scene_effects()
-#if !defined(STRIP_ALL) // Test code only - zero size impact on final binary
+#if !defined(STRIP_ALL) // Test code only - zero size impact on final binary
// Expected effect counts - UPDATE THESE when adding new effects!
-static constexpr int EXPECTED_POST_PROCESS_COUNT = 8; // FlashEffect, PassthroughEffect, GaussianBlurEffect, ChromaAberrationEffect, DistortEffect, SolarizeEffect, FadeEffect, ThemeModulationEffect
-static constexpr int EXPECTED_SCENE_COUNT = 6; // HeptagonEffect, ParticlesEffect, ParticleSprayEffect, MovingEllipseEffect, FlashCubeEffect, Hybrid3DEffect
+static constexpr int EXPECTED_POST_PROCESS_COUNT =
+ 8; // FlashEffect, PassthroughEffect, GaussianBlurEffect,
+ // ChromaAberrationEffect, DistortEffect, SolarizeEffect, FadeEffect,
+ // ThemeModulationEffect
+static constexpr int EXPECTED_SCENE_COUNT =
+ 6; // HeptagonEffect, ParticlesEffect, ParticleSprayEffect,
+ // MovingEllipseEffect, FlashCubeEffect, Hybrid3DEffect
#include "effect_test_helpers.h"
-#include "webgpu_test_fixture.h"
#include "gpu/demo_effects.h"
#include "gpu/effect.h"
+#include "webgpu_test_fixture.h"
#include <cassert>
#include <cstdio>
#include <cstring>
@@ -26,10 +34,8 @@ static constexpr int EXPECTED_SCENE_COUNT = 6; // HeptagonEffect, ParticlesEffe
// Helper: Test effect construction and initialization
// Returns: 0=failed, 1=passed, 2=skipped (requires full 3D setup)
-static int test_effect_smoke(const char* name,
- std::shared_ptr<Effect> effect,
- MainSequence* main_seq,
- bool requires_3d = false) {
+static int test_effect_smoke(const char* name, std::shared_ptr<Effect> effect,
+ MainSequence* main_seq, bool requires_3d = false) {
fprintf(stdout, " Testing %s...\n", name);
// Check construction
@@ -53,7 +59,7 @@ static int test_effect_smoke(const char* name,
// These will fail in init_test() environment - skip them gracefully
if (requires_3d) {
fprintf(stdout, " ⚠ Skipped (requires full 3D pipeline setup)\n");
- return 2; // Skipped
+ return 2; // Skipped
}
seq->init(main_seq);
@@ -65,7 +71,7 @@ static int test_effect_smoke(const char* name,
}
fprintf(stdout, " ✓ %s construction and initialization OK\n", name);
- return 1; // Passed
+ return 1; // Passed
}
// Test 1: Post-process effects
@@ -83,24 +89,17 @@ static void test_post_process_effects() {
// Test each post-process effect
std::vector<std::pair<const char*, std::shared_ptr<Effect>>> effects = {
- {"FlashEffect",
- std::make_shared<FlashEffect>(fixture.ctx())},
- {"PassthroughEffect",
- std::make_shared<PassthroughEffect>(fixture.ctx())},
+ {"FlashEffect", std::make_shared<FlashEffect>(fixture.ctx())},
+ {"PassthroughEffect", std::make_shared<PassthroughEffect>(fixture.ctx())},
{"GaussianBlurEffect",
std::make_shared<GaussianBlurEffect>(fixture.ctx())},
{"ChromaAberrationEffect",
- std::make_shared<ChromaAberrationEffect>(
- fixture.ctx())},
- {"DistortEffect",
- std::make_shared<DistortEffect>(fixture.ctx())},
- {"SolarizeEffect",
- std::make_shared<SolarizeEffect>(fixture.ctx())},
- {"FadeEffect",
- std::make_shared<FadeEffect>(fixture.ctx())},
+ std::make_shared<ChromaAberrationEffect>(fixture.ctx())},
+ {"DistortEffect", std::make_shared<DistortEffect>(fixture.ctx())},
+ {"SolarizeEffect", std::make_shared<SolarizeEffect>(fixture.ctx())},
+ {"FadeEffect", std::make_shared<FadeEffect>(fixture.ctx())},
{"ThemeModulationEffect",
- std::make_shared<ThemeModulationEffect>(
- fixture.ctx())},
+ std::make_shared<ThemeModulationEffect>(fixture.ctx())},
};
int passed = 0;
@@ -121,10 +120,15 @@ static void test_post_process_effects() {
// Validation: Ensure test coverage matches expected count
const int tested_count = static_cast<int>(effects.size());
if (tested_count != EXPECTED_POST_PROCESS_COUNT) {
- fprintf(stderr, " ✗ COVERAGE ERROR: Expected %d post-process effects, but only tested %d!\n",
+ fprintf(stderr,
+ " ✗ COVERAGE ERROR: Expected %d post-process effects, but only "
+ "tested %d!\n",
EXPECTED_POST_PROCESS_COUNT, tested_count);
- fprintf(stderr, " ✗ Did you add a new post-process effect without updating the test?\n");
- fprintf(stderr, " ✗ Update EXPECTED_POST_PROCESS_COUNT in test_demo_effects.cc\n");
+ fprintf(stderr,
+ " ✗ Did you add a new post-process effect without updating the "
+ "test?\n");
+ fprintf(stderr,
+ " ✗ Update EXPECTED_POST_PROCESS_COUNT in test_demo_effects.cc\n");
assert(false && "Post-process effect count mismatch - update test!");
}
}
@@ -144,18 +148,14 @@ static void test_scene_effects() {
// Test each scene effect
std::vector<std::pair<const char*, std::shared_ptr<Effect>>> effects = {
- {"HeptagonEffect",
- std::make_shared<HeptagonEffect>(fixture.ctx())},
- {"ParticlesEffect",
- std::make_shared<ParticlesEffect>(fixture.ctx())},
+ {"HeptagonEffect", std::make_shared<HeptagonEffect>(fixture.ctx())},
+ {"ParticlesEffect", std::make_shared<ParticlesEffect>(fixture.ctx())},
{"ParticleSprayEffect",
std::make_shared<ParticleSprayEffect>(fixture.ctx())},
{"MovingEllipseEffect",
std::make_shared<MovingEllipseEffect>(fixture.ctx())},
- {"FlashCubeEffect",
- std::make_shared<FlashCubeEffect>(fixture.ctx())},
- {"Hybrid3DEffect",
- std::make_shared<Hybrid3DEffect>(fixture.ctx())},
+ {"FlashCubeEffect", std::make_shared<FlashCubeEffect>(fixture.ctx())},
+ {"Hybrid3DEffect", std::make_shared<Hybrid3DEffect>(fixture.ctx())},
};
int passed = 0;
@@ -183,10 +183,14 @@ static void test_scene_effects() {
// Validation: Ensure test coverage matches expected count
const int tested_count = static_cast<int>(effects.size());
if (tested_count != EXPECTED_SCENE_COUNT) {
- fprintf(stderr, " ✗ COVERAGE ERROR: Expected %d scene effects, but only tested %d!\n",
- EXPECTED_SCENE_COUNT, tested_count);
- fprintf(stderr, " ✗ Did you add a new scene effect without updating the test?\n");
- fprintf(stderr, " ✗ Update EXPECTED_SCENE_COUNT in test_demo_effects.cc\n");
+ fprintf(
+ stderr,
+ " ✗ COVERAGE ERROR: Expected %d scene effects, but only tested %d!\n",
+ EXPECTED_SCENE_COUNT, tested_count);
+ fprintf(stderr,
+ " ✗ Did you add a new scene effect without updating the test?\n");
+ fprintf(stderr,
+ " ✗ Update EXPECTED_SCENE_COUNT in test_demo_effects.cc\n");
assert(false && "Scene effect count mismatch - update test!");
}
}
@@ -202,21 +206,19 @@ static void test_effect_type_classification() {
}
// Post-process effects should return true
- auto flash = std::make_shared<FlashEffect>(
- fixture.ctx());
+ auto flash = std::make_shared<FlashEffect>(fixture.ctx());
assert(flash->is_post_process() && "FlashEffect should be post-process");
- auto blur = std::make_shared<GaussianBlurEffect>(
- fixture.ctx());
- assert(blur->is_post_process() && "GaussianBlurEffect should be post-process");
+ auto blur = std::make_shared<GaussianBlurEffect>(fixture.ctx());
+ assert(blur->is_post_process() &&
+ "GaussianBlurEffect should be post-process");
// Scene effects should return false
- auto heptagon = std::make_shared<HeptagonEffect>(
- fixture.ctx());
- assert(!heptagon->is_post_process() && "HeptagonEffect should NOT be post-process");
+ auto heptagon = std::make_shared<HeptagonEffect>(fixture.ctx());
+ assert(!heptagon->is_post_process() &&
+ "HeptagonEffect should NOT be post-process");
- auto particles = std::make_shared<ParticlesEffect>(
- fixture.ctx());
+ auto particles = std::make_shared<ParticlesEffect>(fixture.ctx());
assert(!particles->is_post_process() &&
"ParticlesEffect should NOT be post-process");
@@ -234,4 +236,4 @@ int main() {
return 0;
}
-#endif /* !defined(STRIP_ALL) */
+#endif /* !defined(STRIP_ALL) */