Blender  V3.3
COM_NodeOperation_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 
7 
9 
11  public:
13  {
14  set_id(id);
16  set_width(2);
17  set_height(3);
18  }
19 };
20 
22  float constant_;
23 
24  public:
26  {
27  set_id(id);
29  set_width(2);
30  set_height(3);
31  constant_ = 1.0f;
32  }
33 
34  const float *get_constant_elem() override
35  {
36  return &constant_;
37  }
38 
39  void set_constant(float value)
40  {
41  constant_ = value;
42  }
43 };
44 
46  private:
47  int param1;
48  float param2;
49 
50  public:
52  {
57  param1 = 2;
58  param2 = 7.0f;
59 
60  get_input_socket(0)->set_link(input.get_output_socket());
61  }
62 
63  void set_param1(int value)
64  {
65  param1 = value;
66  }
67 
68  void hash_output_params() override
69  {
70  hash_params(param1, param2);
71  }
72 };
73 
77 {
78  if (h1 < h2) {
79  if (h3 < h1) {
80  EXPECT_TRUE(h3 < h2);
81  }
82  else if (h3 < h2) {
83  EXPECT_TRUE(h1 < h3);
84  }
85  else {
86  EXPECT_TRUE(h1 < h3);
87  EXPECT_TRUE(h2 < h3);
88  }
89  }
90  else {
91  EXPECT_TRUE(h2 < h1);
92  }
93 }
94 
95 TEST(NodeOperation, generate_hash)
96 {
97  /* Constant input. */
98  {
99  NonHashedConstantOperation input_op1(1);
100  input_op1.set_constant(1.0f);
101  EXPECT_EQ(input_op1.generate_hash(), std::nullopt);
102 
103  HashedOperation op1(input_op1, 6, 4);
104  std::optional<NodeOperationHash> hash1_opt = op1.generate_hash();
105  EXPECT_NE(hash1_opt, std::nullopt);
106  NodeOperationHash hash1 = *hash1_opt;
107 
108  NonHashedConstantOperation input_op2(1);
109  input_op2.set_constant(1.0f);
110  HashedOperation op2(input_op2, 6, 4);
111  NodeOperationHash hash2 = *op2.generate_hash();
112  EXPECT_EQ(hash1, hash2);
113 
114  input_op2.set_constant(3.0f);
115  hash2 = *op2.generate_hash();
116  EXPECT_NE(hash1, hash2);
117  }
118 
119  /* Non constant input. */
120  {
121  NonHashedOperation input_op(1);
122  EXPECT_EQ(input_op.generate_hash(), std::nullopt);
123 
124  HashedOperation op1(input_op, 6, 4);
125  HashedOperation op2(input_op, 6, 4);
126  NodeOperationHash hash1 = *op1.generate_hash();
127  NodeOperationHash hash2 = *op2.generate_hash();
128  EXPECT_EQ(hash1, hash2);
129  op1.set_param1(-1);
130  hash1 = *op1.generate_hash();
131  EXPECT_NE(hash1, hash2);
132 
133  HashedOperation op3(input_op, 11, 14);
134  NodeOperationHash hash3 = *op3.generate_hash();
135  EXPECT_NE(hash2, hash3);
136  EXPECT_NE(hash1, hash3);
137 
138  test_non_equal_hashes_compare(hash1, hash2, hash3);
139  test_non_equal_hashes_compare(hash3, hash2, hash1);
140  test_non_equal_hashes_compare(hash2, hash3, hash1);
141  test_non_equal_hashes_compare(hash3, hash1, hash2);
142 
143  NonHashedOperation input_op2(2);
144  HashedOperation op4(input_op2, 11, 14);
145  NodeOperationHash hash4 = *op4.generate_hash();
146  EXPECT_NE(hash3, hash4);
147 
148  input_op2.set_id(1);
149  hash4 = *op4.generate_hash();
150  EXPECT_EQ(hash3, hash4);
151  }
152 }
153 
154 } // namespace blender::compositor::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
_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 GLsizei width
void set_link(NodeOperationOutput *link)
NodeOperation contains calculation logic.
void add_output_socket(DataType datatype)
std::optional< NodeOperationHash > generate_hash()
NodeOperationInput * get_input_socket(unsigned int index)
void set_width(unsigned int width)
void set_height(unsigned int height)
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void hash_params(T1 param1, T2 param2)
HashedOperation(NodeOperation &input, int width, int height)
ccl_global KernelShaderEvalInput * input
TEST(BufferArea, BufferConstructor)
static void test_non_equal_hashes_compare(NodeOperationHash &h1, NodeOperationHash &h2, NodeOperationHash &h3)