Add a test for GammaExpansionEffect. Not done yet.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 20:17:49 +0000 (22:17 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 20:17:49 +0000 (22:17 +0200)
Makefile
gamma_expansion_effect_test.cpp [new file with mode: 0644]

index aaa9896..3e497f5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,12 +2,12 @@ GTEST_DIR = /usr/src/gtest
 
 CC=gcc
 CXX=g++
-CXXFLAGS=-Wall -g -I$(GTEST_DIR)/include $(shell pkg-config --cflags eigen3 )
-LDFLAGS=-lSDL -lSDL_image -lGL -lrt -lpthread
+CXXFLAGS=-Wall -g -I$(GTEST_DIR)/include $(shell pkg-config --cflags eigen3 ) -fprofile-arcs -ftest-coverage
+LDFLAGS=-lSDL -lSDL_image -lGL -lrt -lpthread -fprofile-arcs -ftest-coverage
 RANLIB=ranlib
 
 DEMO_OBJS=demo.o
-TESTS=effect_chain_test mix_effect_test
+TESTS=effect_chain_test mix_effect_test gamma_expansion_effect_test
 
 # Core.
 LIB_OBJS=util.o widgets.o effect.o effect_chain.o
@@ -50,6 +50,8 @@ effect_chain_test: effect_chain_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
 mix_effect_test: mix_effect_test.o $(TEST_OBJS) libmovit.a
        $(CXX) -o $@ $^ $(LDFLAGS)
+gamma_expansion_effect_test: gamma_expansion_effect_test.o $(TEST_OBJS) libmovit.a
+       $(CXX) -o $@ $^ $(LDFLAGS)
 
 OBJS=$(DEMO_OBJS) $(LIB_OBJS) $(TEST_OBJS) $(TESTS:=.o)
 
diff --git a/gamma_expansion_effect_test.cpp b/gamma_expansion_effect_test.cpp
new file mode 100644 (file)
index 0000000..0fd9a71
--- /dev/null
@@ -0,0 +1,35 @@
+// Unit tests for GammaExpansionEffect.
+
+#include "test_util.h"
+#include "gtest/gtest.h"
+#include "gamma_expansion_effect.h"
+
+TEST(GammaExpansionEffectTest, sRGB_KeyValues) {
+       float data[] = {
+               0.0f, 1.0f,
+               0.040f, 0.041f,  // On either side of the discontinuity.
+       };
+       float expected_data[] = {
+               0.0f, 1.0f,
+               0.00309f, 0.00317f, 
+       };
+       float out_data[4];
+       EffectChainTester tester(data, 2, 2, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 2, 2);
+}
+
+TEST(GammaExpansionEffectTest, sRGB_RampAlwaysIncreases) {
+       float data[256], out_data[256];
+       for (unsigned i = 0; i < 256; ++i) {
+               data[i] = i / 255.0f;
+       }
+       EffectChainTester tester(data, 256, 1, COLORSPACE_sRGB, GAMMA_sRGB);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       for (unsigned i = 1; i < 256; ++i) {
+               EXPECT_GT(out_data[i], out_data[i - 1])
+                  << "No increase between " << i-1 << " and " << i;
+       }
+}