Add an assert to expect_equal() to make sure people send in reasonable widths and...
[movit] / diffusion_effect_test.cpp
1 // Unit tests for DiffusionEffect.
2
3 #include "test_util.h"
4 #include "gtest/gtest.h"
5 #include "diffusion_effect.h"
6
7 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
8         const int size = 4;
9
10         float data[size * size] = {
11                 0.0, 1.0, 0.0, 1.0,
12                 0.0, 1.0, 1.0, 0.0,
13                 0.0, 0.5, 1.0, 0.5,
14                 0.0, 0.0, 0.0, 0.0,
15         };
16         float out_data[size * size];
17
18         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
19         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
20         ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
21         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
22
23         expect_equal(data, out_data, size, size);
24 }
25
26 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
27         const int size = 9;
28
29         float data[size * size] = {
30                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
31                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
32                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
33                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
34                 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
35                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
36                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
37                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
38                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
39         };
40         float expected_data[size * size] = {
41                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
42                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
43                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
44                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
45                 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
46                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
47                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
48                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
49                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
50         };
51         float out_data[size * size];
52
53         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
54         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
55         ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
56         ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
57         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
58
59         expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
60 }