1 // Unit tests for FlatInput.
4 #include "gtest/gtest.h"
5 #include "flat_input.h"
7 TEST(FlatInput, SimpleGrayscale) {
16 float expected_data[4 * size] = {
22 float out_data[4 * size];
24 EffectChainTester tester(data, 1, size, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
25 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
27 expect_equal(expected_data, out_data, 4, size);
30 TEST(FlatInput, RGB) {
33 float data[3 * size] = {
40 float expected_data[4 * size] = {
47 float out_data[4 * size];
49 EffectChainTester tester(data, 1, size, FORMAT_RGB, COLORSPACE_sRGB, GAMMA_LINEAR);
50 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
52 expect_equal(expected_data, out_data, 4, size);
55 TEST(FlatInput, RGBA) {
58 float data[4 * size] = {
65 float expected_data[4 * size] = {
72 float out_data[4 * size];
74 EffectChainTester tester(data, 1, size, FORMAT_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
75 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
77 expect_equal(expected_data, out_data, 4, size);
80 TEST(FlatInput, BGR) {
83 float data[3 * size] = {
90 float expected_data[4 * size] = {
97 float out_data[4 * size];
99 EffectChainTester tester(data, 1, size, FORMAT_BGR, COLORSPACE_sRGB, GAMMA_LINEAR);
100 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
102 expect_equal(expected_data, out_data, 4, size);
105 TEST(FlatInput, BGRA) {
108 float data[4 * size] = {
115 float expected_data[4 * size] = {
122 float out_data[4 * size];
124 EffectChainTester tester(data, 1, size, FORMAT_BGRA, COLORSPACE_sRGB, GAMMA_LINEAR);
125 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
127 expect_equal(expected_data, out_data, 4, size);
130 TEST(FlatInput, Pitch) {
133 const int height = 4;
135 float data[pitch * height] = {
141 float expected_data[4 * width * height] = {
142 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
143 0.5, 0.5, 0.5, 1.0, 0.5, 0.5, 0.5, 1.0,
144 0.7, 0.7, 0.7, 1.0, 0.2, 0.2, 0.2, 1.0,
145 1.0, 1.0, 1.0, 1.0, 0.6, 0.6, 0.6, 1.0,
147 float out_data[4 * width * height];
149 EffectChainTester tester(NULL, width, height);
152 format.color_space = COLORSPACE_sRGB;
153 format.gamma_curve = GAMMA_LINEAR;
155 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
156 input->set_pitch(pitch);
157 input->set_pixel_data(data);
158 tester.get_chain()->add_input(input);
160 tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_LINEAR);
161 expect_equal(expected_data, out_data, 4 * width, height);
164 TEST(FlatInput, UpdatedData) {
166 const int height = 4;
168 float data[width * height] = {
174 float out_data[width * height];
176 EffectChainTester tester(NULL, width, height);
179 format.color_space = COLORSPACE_sRGB;
180 format.gamma_curve = GAMMA_LINEAR;
182 FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
183 input->set_pixel_data(data);
184 tester.get_chain()->add_input(input);
186 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
187 expect_equal(data, out_data, width, height);
190 input->invalidate_pixel_data();
192 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
193 expect_equal(data, out_data, width, height);