Add some more simple tests to EffectChainTest.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Oct 2012 23:34:11 +0000 (01:34 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Oct 2012 23:34:11 +0000 (01:34 +0200)
effect_chain_test.cpp

index c8fd946..a85fb36 100644 (file)
@@ -1,8 +1,10 @@
 // Unit tests for EffectChain.
+//
+// Note that this also contains the tests for some of the simpler effects.
 
 #include "effect_chain.h"
 #include "flat_input.h"
-#include "sandbox_effect.h"
+#include "mirror_effect.h"
 #include "opengl.h"
 #include "gtest/gtest.h"
 
@@ -96,6 +98,26 @@ void expect_equal(const float *ref, const float *result, unsigned width, unsigne
        }
 }
 
+TEST(EffectChainTest, EmptyChain) {
+       float data[] = {
+               0.0f, 0.25f, 0.3f,
+               0.75f, 1.0f, 1.0f,
+       };
+       float out_data[6];
+       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 3, 2);
+}
+
+// An effect that does nothing.
+class IdentityEffect : public Effect {
+public:
+       IdentityEffect() {}
+       virtual std::string effect_type_id() const { return "IdentityEffect"; }
+       std::string output_fragment_shader() { return read_file("identity.frag"); }
+};
+
 TEST(EffectChainTest, Identity) {
        float data[] = {
                0.0f, 0.25f, 0.3f,
@@ -103,7 +125,47 @@ TEST(EffectChainTest, Identity) {
        };
        float out_data[6];
        EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new IdentityEffect());
        tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(data, out_data, 3, 2);
 }
+
+// An effect that does nothing, but requests texture bounce.
+class BouncingIdentityEffect : public Effect {
+public:
+       BouncingIdentityEffect() {}
+       virtual std::string effect_type_id() const { return "IdentityEffect"; }
+       std::string output_fragment_shader() { return read_file("identity.frag"); }
+       bool needs_texture_bounce() const { return true; }
+};
+
+TEST(EffectChainTest, TextureBouncePreservesIdentity) {
+       float data[] = {
+               0.0f, 0.25f, 0.3f,
+               0.75f, 1.0f, 1.0f,
+       };
+       float out_data[6];
+       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new BouncingIdentityEffect());
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(data, out_data, 3, 2);
+}
+
+TEST(MirrorTest, BasicTest) {
+       float data[] = {
+               0.0f, 0.25f, 0.3f,
+               0.75f, 1.0f, 1.0f,
+       };
+       float expected_data[6] = {
+               0.3f, 0.25f, 0.0f,
+               1.0f, 1.0f, 0.75f,
+       };
+       float out_data[6];
+       EffectChainTester tester(data, 3, 2, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new MirrorEffect());
+       tester.run(out_data, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 3, 2);
+}