Add a unit test for DiffusionEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 11:45:29 +0000 (13:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Oct 2012 11:45:29 +0000 (13:45 +0200)
Makefile
diffusion_effect_test.cpp [new file with mode: 0644]

index 12bd209..3747597 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ TESTS += saturation_effect_test
 TESTS += deconvolution_sharpen_effect_test
 TESTS += blur_effect_test
 TESTS += unsharp_mask_effect_test
+TESTS += diffusion_effect_test
 
 # Core.
 LIB_OBJS=util.o widgets.o effect.o effect_chain.o
@@ -79,6 +80,8 @@ blur_effect_test: blur_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
 unsharp_mask_effect_test: unsharp_mask_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
+diffusion_effect_test: diffusion_effect_test.o $(TEST_OBJS) libmovit.a
+       $(CXX) -o $@ $^ $(LDFLAGS)
 
 OBJS=$(DEMO_OBJS) $(LIB_OBJS) $(TEST_OBJS) $(TESTS:=.o)
 
diff --git a/diffusion_effect_test.cpp b/diffusion_effect_test.cpp
new file mode 100644 (file)
index 0000000..446a51f
--- /dev/null
@@ -0,0 +1,60 @@
+// Unit tests for DiffusionEffect.
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "diffusion_effect.h"
+
+TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
+       const int size = 4;
+
+       float data[size * size] = {
+               0.0, 1.0, 0.0, 1.0,
+               0.0, 1.0, 1.0, 0.0,
+               0.0, 0.5, 1.0, 0.5,
+               0.0, 0.0, 0.0, 0.0,
+       };
+       float out_data[size * size];
+
+       EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
+       ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, size, size);
+}
+
+TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
+       const int size = 9;
+
+       float data[size * size] = {
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
+               0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
+               0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
+               0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
+               0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+       };
+       float expected_data[size * size] = {
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
+               0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
+               0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
+               0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
+               0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+               0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+       };
+       float out_data[size * size];
+
+       EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
+       ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
+       ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
+}