// 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"
}
}
+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,
};
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);
+}