Commit: 5b6dde93e9d9551c616196a296aefafe0cd5d20c
Author: Jacques Lucke
Date:   Sat Apr 27 23:18:14 2019 +0200
Branches: functions
https://developer.blender.org/rB5b6dde93e9d9551c616196a296aefafe0cd5d20c

initial unit test for functions system

===================================================================

M       source/blender/functions/CMakeLists.txt
M       source/blender/functions/backends/tuple_call/tuple.hpp
M       source/blender/functions/backends/tuple_call/tuple_call.hpp
M       tests/gtests/CMakeLists.txt
A       tests/gtests/functions/CMakeLists.txt
A       tests/gtests/functions/functions_test.cc

===================================================================

diff --git a/source/blender/functions/CMakeLists.txt 
b/source/blender/functions/CMakeLists.txt
index d732d77274a..cc722a1e517 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -143,6 +143,7 @@ set(SRC
 )
 
 set(LIB
+  bf_blenlib
 )
 
 blender_add_lib(bf_functions "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/functions/backends/tuple_call/tuple.hpp 
b/source/blender/functions/backends/tuple_call/tuple.hpp
index 8df5d6ebe22..e0ca2c91be7 100644
--- a/source/blender/functions/backends/tuple_call/tuple.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple.hpp
@@ -403,6 +403,6 @@ inline uint TupleMeta::size_of_full_tuple() const
 } /* namespace FN */
 
 #define FN_TUPLE_STACK_ALLOC(name, meta_expr) \
-  SharedTupleMeta &name##_meta = (meta_expr); \
+  FN::SharedTupleMeta &name##_meta = (meta_expr); \
   void *name##_buffer = alloca(name##_meta->size_of_data_and_init()); \
-  Tuple name(name##_meta, name##_buffer);
+  FN::Tuple name(name##_meta, name##_buffer);
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.hpp 
b/source/blender/functions/backends/tuple_call/tuple_call.hpp
index f45fd4087be..38d68772e5f 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.hpp
@@ -33,7 +33,7 @@ class TupleCallBody : public TupleCallBodyBase {
  public:
   BLI_COMPOSITION_DECLARATION(TupleCallBody);
 
-  inline void call__setup_stack(Tuple &fn_in, Tuple &fn_out, ExecutionContext 
&ctx)
+  inline void call__setup_stack(Tuple &fn_in, Tuple &fn_out, ExecutionContext 
&ctx) const
   {
     TextStackFrame frame(this->owner()->name().c_str());
     ctx.stack().push(&frame);
@@ -44,13 +44,20 @@ class TupleCallBody : public TupleCallBodyBase {
   inline void call__setup_stack(Tuple &fn_in,
                                 Tuple &fn_out,
                                 ExecutionContext &ctx,
-                                StackFrame &extra_frame)
+                                StackFrame &extra_frame) const
   {
     ctx.stack().push(&extra_frame);
     this->call__setup_stack(fn_in, fn_out, ctx);
     ctx.stack().pop();
   }
 
+  inline void call__setup_execution_context(Tuple &fn_in, Tuple &fn_out) const
+  {
+    ExecutionStack stack;
+    ExecutionContext ctx(stack);
+    this->call__setup_stack(fn_in, fn_out, ctx);
+  }
+
   virtual void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx) const 
= 0;
 };
 
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 285b414e997..5541531d2d0 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -15,6 +15,7 @@ if(WITH_GTESTS)
   add_subdirectory(blenlib)
   add_subdirectory(guardedalloc)
   add_subdirectory(bmesh)
+  add_subdirectory(functions)
   if(WITH_ALEMBIC)
     add_subdirectory(alembic)
   endif()
diff --git a/tests/gtests/functions/CMakeLists.txt 
b/tests/gtests/functions/CMakeLists.txt
new file mode 100644
index 00000000000..a41144d7937
--- /dev/null
+++ b/tests/gtests/functions/CMakeLists.txt
@@ -0,0 +1,41 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2019, Blender Foundation
+# All rights reserved.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+  .
+  ..
+  ../../../source/blender/blenlib
+  ../../../source/blender/functions
+  ../../../intern/guardedalloc
+  ${LLVM_INCLUDE_DIRS}
+)
+
+set(LIB
+  bf_functions
+)
+
+include_directories(${INC})
+
+setup_libdirs()
+
+BLENDER_SRC_GTEST(functions "functions_test.cc" "${LIB}")
+
+
+setup_liblinks(functions_test)
diff --git a/tests/gtests/functions/functions_test.cc 
b/tests/gtests/functions/functions_test.cc
new file mode 100644
index 00000000000..d2b81531722
--- /dev/null
+++ b/tests/gtests/functions/functions_test.cc
@@ -0,0 +1,18 @@
+#include "testing/testing.h"
+#include "FN_all.hpp"
+
+using namespace FN;
+
+TEST(functions_impl, MultiplyFloats)
+{
+  auto fn = Functions::GET_FN_multiply_floats();
+  auto *body = fn->body<TupleCallBody>();
+  FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
+
+  fn_in.set<float>(0, 4);
+  fn_in.set<float>(1, 20);
+
+  body->call__setup_execution_context(fn_in, fn_out);
+
+  EXPECT_EQ(fn_out.get<float>(0), 80);
+}

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to