Blender  V3.3
COM_BufferArea_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. */
3 
4 #include "testing/testing.h"
5 
6 #include "COM_BufferArea.h"
7 
9 
10 static rcti create_rect(int width, int height)
11 {
12  rcti rect;
13  BLI_rcti_init(&rect, 0, width, 0, height);
14  return rect;
15 }
16 
17 static rcti create_rect(int width, int height, int offset)
18 {
19  rcti rect;
21  return rect;
22 }
23 
24 TEST(BufferArea, BufferConstructor)
25 {
26  const int width = 2;
27  const int height = 3;
28  BufferArea<float> area(nullptr, width, height, 4);
29  EXPECT_EQ(area.width(), width);
30  EXPECT_EQ(area.height(), height);
31  rcti rect = create_rect(width, height);
32  EXPECT_TRUE(BLI_rcti_compare(&area.get_rect(), &rect));
33 }
34 
35 TEST(BufferArea, AreaConstructor)
36 {
37  const int buf_width = 5;
38  const int area_width = 1;
39  const int area_height = 3;
40  rcti area_rect = create_rect(area_width, area_height, 1);
41  BufferArea<float> area(nullptr, buf_width, area_rect, 4);
42  EXPECT_EQ(area.width(), area_width);
43  EXPECT_EQ(area.height(), area_height);
44  EXPECT_TRUE(BLI_rcti_compare(&area.get_rect(), &area_rect));
45 }
46 
47 static void fill_buffer_with_indexes(float *buf, int buf_len)
48 {
49  for (int i = 0; i < buf_len; i++) {
50  buf[i] = i;
51  }
52 }
53 
55 {
56  int elems_count = 0;
57  for (float *elem : area) {
58  EXPECT_EQ(elem, buffer);
59  elems_count++;
60  }
61  EXPECT_EQ(elems_count, 1);
62 }
63 
65  float *buf, int buf_width, int buf_len, int num_channels, BufferArea<float> area)
66 {
67  fill_buffer_with_indexes(buf, buf_len);
68  rcti rect = area.get_rect();
69  int x = rect.xmin;
70  int y = rect.ymin;
71  for (float *elem : area) {
72  for (int ch = 0; ch < num_channels; ch++) {
73  const int buf_index = y * buf_width * num_channels + x * num_channels + ch;
74  EXPECT_NEAR(elem[ch], buf_index, FLT_EPSILON);
75  }
76  x++;
77  if (x == rect.xmax) {
78  y++;
79  x = rect.xmin;
80  }
81  }
82  EXPECT_EQ(x, rect.xmin);
83  EXPECT_EQ(y, rect.ymax);
84 }
85 
86 TEST(BufferArea, SingleElemBufferIteration)
87 {
88  const int buf_width = 4;
89  const int buf_height = 5;
90  const int area_width = 2;
91  const int area_height = 3;
92  const int num_channels = 4;
93  const int stride = 0;
94  float buf[num_channels];
95  {
96  BufferArea area(buf, buf_width, buf_height, stride);
98  }
99  {
100  rcti area_rect = create_rect(area_width, area_height, 1);
101  BufferArea area(buf, buf_width, area_rect, stride);
103  }
104 }
105 
106 TEST(BufferArea, FullBufferIteration)
107 {
108  const int buf_width = 4;
109  const int area_width = 2;
110  const int area_height = 3;
111  const int buf_height = (area_height + 1);
112  const int num_channels = 4;
113  const int buf_len = buf_height * buf_width * num_channels;
114  float buf[buf_len];
115  {
116  BufferArea area(buf, buf_width, buf_height, num_channels);
117  test_full_buffer_iteration(buf, buf_width, buf_len, num_channels, area);
118  }
119  {
120  rcti area_rect = create_rect(area_width, area_height, 1);
121  BufferArea area(buf, buf_width, area_rect, num_channels);
122  test_full_buffer_iteration(buf, buf_width, buf_len, num_channels, area);
123  }
124 }
125 
126 } // namespace blender::compositor::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
bool BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
static void test_single_elem_iteration(float *buffer, BufferArea< float > area)
static rcti create_rect(int width, int height)
static void fill_buffer_with_indexes(float *buf, int buf_len)
static void test_full_buffer_iteration(float *buf, int buf_width, int buf_len, int num_channels, BufferArea< float > area)
TEST(BufferArea, BufferConstructor)
static void area(int d1, int d2, int e1, int e2, float weights[2])
int ymin
Definition: DNA_vec_types.h:64
int ymax
Definition: DNA_vec_types.h:64
int xmin
Definition: DNA_vec_types.h:63
int xmax
Definition: DNA_vec_types.h:63