Remove the finalize() member function from Input.
[movit] / diffusion_effect_test.cpp
1 // Unit tests for DiffusionEffect.
2
3 #include <GL/glew.h>
4
5 #include "diffusion_effect.h"
6 #include "effect_chain.h"
7 #include "gtest/gtest.h"
8 #include "image_format.h"
9 #include "test_util.h"
10
11 TEST(DiffusionEffectTest, IdentityTransformDoesNothing) {
12         const int size = 4;
13
14         float data[size * size] = {
15                 0.0, 1.0, 0.0, 1.0,
16                 0.0, 1.0, 1.0, 0.0,
17                 0.0, 0.5, 1.0, 0.5,
18                 0.0, 0.0, 0.0, 0.0,
19         };
20         float out_data[size * size];
21
22         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
23         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
24         ASSERT_TRUE(diffusion_effect->set_float("radius", 0.0f));
25         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
26
27         expect_equal(data, out_data, size, size);
28 }
29
30 TEST(DiffusionEffectTest, FlattensOutWhitePyramid) {
31         const int size = 9;
32
33         float data[size * size] = {
34                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
35                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
38                 0.0, 0.0, 0.5, 0.7, 1.0, 0.7, 0.5, 0.0, 0.0,
39                 0.0, 0.0, 0.5, 0.7, 0.7, 0.7, 0.5, 0.0, 0.0,
40                 0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0,
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         };
44         float expected_data[size * size] = {
45                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
46                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
49                 0.0, 0.0, 0.4, 0.5, 0.6, 0.5, 0.4, 0.0, 0.0,
50                 0.0, 0.0, 0.4, 0.5, 0.5, 0.5, 0.4, 0.0, 0.0,
51                 0.0, 0.0, 0.4, 0.4, 0.4, 0.4, 0.4, 0.0, 0.0,
52                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
53                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
54         };
55         float out_data[size * size];
56
57         EffectChainTester tester(data, size, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
58         Effect *diffusion_effect = tester.get_chain()->add_effect(new DiffusionEffect());
59         ASSERT_TRUE(diffusion_effect->set_float("radius", 2.0f));
60         ASSERT_TRUE(diffusion_effect->set_float("blurred_mix_amount", 0.7f));
61         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
62
63         expect_equal(expected_data, out_data, size, size, 0.05f, 0.002);
64 }