Add a unit test for SaturationEffect.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 22:02:18 +0000 (00:02 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 22:02:18 +0000 (00:02 +0200)
Makefile
saturation_effect_test.cpp [new file with mode: 0644]

index 454dded..012a0e6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ LDFLAGS += -fprofile-arcs -ftest-coverage
 endif
 
 DEMO_OBJS=demo.o
-TESTS=effect_chain_test mix_effect_test gamma_expansion_effect_test gamma_compression_effect_test
+TESTS=effect_chain_test mix_effect_test gamma_expansion_effect_test gamma_compression_effect_test saturation_effect_test
 
 # Core.
 LIB_OBJS=util.o widgets.o effect.o effect_chain.o
@@ -59,6 +59,8 @@ gamma_expansion_effect_test: gamma_expansion_effect_test.o $(TEST_OBJS) libmovit
        $(CXX) -o $@ $^ $(LDFLAGS)
 gamma_compression_effect_test: gamma_compression_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
+saturation_effect_test: saturation_effect_test.o $(TEST_OBJS) libmovit.a
+       $(CXX) -o $@ $^ $(LDFLAGS)
 
 OBJS=$(DEMO_OBJS) $(LIB_OBJS) $(TEST_OBJS) $(TESTS:=.o)
 
diff --git a/saturation_effect_test.cpp b/saturation_effect_test.cpp
new file mode 100644 (file)
index 0000000..f6213c2
--- /dev/null
@@ -0,0 +1,64 @@
+// Unit tests for SaturationEffect.
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "saturation_effect.h"
+
+TEST(SaturationEffectTest, SaturationOneIsPassThrough) {
+       float data[] = {
+               1.0f, 0.5f, 0.75f, 0.6f,
+       };
+       float out_data[4];
+       EffectChainTester tester(data, 1, 1, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
+       ASSERT_TRUE(saturation_effect->set_float("saturation", 1.0f));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 1, 1);
+}
+
+TEST(SaturationEffectTest, SaturationZeroRemovesColorButPreservesAlpha) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               1.0f, 0.0f, 0.0f, 1.0f,
+               0.0f, 1.0f, 0.0f, 0.7f,
+               0.0f, 0.0f, 1.0f, 1.0f,
+       };
+       float expected_data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               0.2126f, 0.2126f, 0.2126f, 1.0f,
+               0.7152f, 0.7152f, 0.7152f, 0.7f,
+               0.0722f, 0.0722f, 0.0722f, 1.0f,
+       };
+
+       float out_data[5 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
+       ASSERT_TRUE(saturation_effect->set_float("saturation", 0.0f));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 5);
+}
+
+TEST(SaturationEffectTest, DoubleSaturation) {
+       float data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               0.3f, 0.1f, 0.1f, 1.0f,
+       };
+       float expected_data[] = {
+               0.0f, 0.0f, 0.0f, 1.0f,
+               0.5f, 0.5f, 0.5f, 0.3f,
+               0.4570f, 0.0575f, 0.0575f, 1.0f,
+       };
+
+       float out_data[3 * 4];
+       EffectChainTester tester(data, 5, 1, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+       Effect *saturation_effect = tester.get_chain()->add_effect(new SaturationEffect());
+       ASSERT_TRUE(saturation_effect->set_float("saturation", 2.0f));
+       tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 3);
+}