[Bf-blender-cvs] [57ae71dbf3b] soc-2020-io-performance: Exporter: start adding tests.

Ankit Meel noreply at git.blender.org
Wed Nov 11 15:37:50 CET 2020


Commit: 57ae71dbf3b438a6eb9332bcfb06670fd46ef060
Author: Ankit Meel
Date:   Wed Nov 11 19:56:28 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rB57ae71dbf3b438a6eb9332bcfb06670fd46ef060

Exporter: start adding tests.

Corresponds to file https://developer.blender.org/F9260238

It should be put in "io_tests/blend_scene/all_objects_2_92.blend"
directory.

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

M	source/blender/io/wavefront_obj/exporter/obj_exporter.cc
M	source/blender/io/wavefront_obj/exporter/obj_exporter.hh
M	source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc

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

diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
index 828943dddfb..fc416be1c98 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc
@@ -83,7 +83,7 @@ void OBJDepsgraph::update_for_newframe()
  *
  * \note Curves are also stored with Meshes if export settings specify so.
  */
-static std::pair<Vector<std::unique_ptr<OBJMesh>>, Vector<std::unique_ptr<OBJCurve>>>
+std::pair<Vector<std::unique_ptr<OBJMesh>>, Vector<std::unique_ptr<OBJCurve>>>
 find_exportable_objects(Depsgraph *depsgraph, const OBJExportParams &export_params)
 {
   Vector<std::unique_ptr<OBJMesh>> r_exportable_meshes;
@@ -224,9 +224,7 @@ static void export_frame(Depsgraph *depsgraph,
  *
  * \return Whether the filepath is in #FILE_MAX limits.
  */
-static bool append_frame_to_filename(const char *filepath,
-                                     const int frame,
-                                     char *r_filepath_with_frames)
+bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames)
 {
   BLI_strncpy(r_filepath_with_frames, filepath, FILE_MAX);
   BLI_path_extension_replace(r_filepath_with_frames, FILE_MAX, "");
diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.hh b/source/blender/io/wavefront_obj/exporter/obj_exporter.hh
index b1bcfdf3b69..d748dc16726 100644
--- a/source/blender/io/wavefront_obj/exporter/obj_exporter.hh
+++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.hh
@@ -25,6 +25,8 @@
 
 #include "BLI_utility_mixins.hh"
 
+#include "BLI_vector.hh"
+
 #include "IO_wavefront_obj.h"
 
 namespace blender::io::obj {
@@ -66,4 +68,11 @@ class OBJDepsgraph : NonMovable, NonCopyable {
 
 void exporter_main(bContext *C, const OBJExportParams &export_params);
 
+class OBJMesh;
+class OBJCurve;
+
+std::pair<Vector<std::unique_ptr<OBJMesh>>, Vector<std::unique_ptr<OBJCurve>>>
+find_exportable_objects(Depsgraph *depsgraph, const OBJExportParams &export_params);
+
+bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames);
 }  // namespace blender::io::obj
diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
index 3ca50e4f02f..db10eb88ed2 100644
--- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
+++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc
@@ -1 +1,127 @@
 /* Apache License, Version 2.0 */
+
+#include <gtest/gtest.h>
+#include <ios>
+
+#include "testing/testing.h"
+#include "tests/blendfile_loading_base_test.h"
+
+#include "BLI_float3.hh"
+#include "BLI_string_utf8.h"
+#include "BLI_vector.hh"
+
+#include "DEG_depsgraph.h"
+
+#include "IO_wavefront_obj.h"
+#include "obj_export_mesh.hh"
+#include "obj_export_nurbs.hh"
+#include "obj_exporter.hh"
+
+namespace blender::io::obj {
+
+class Export_OBJ : public BlendfileLoadingBaseTest {
+ public:
+  /**
+   * \param filepath: relative to "tests" directory.
+   */
+  bool load_file_and_depsgraph(const std::string &filepath,
+                               const eEvaluationMode eval_mode = DAG_EVAL_VIEWPORT)
+  {
+    if (!blendfile_load(filepath.c_str())) {
+      return false;
+    }
+    depsgraph_create(eval_mode);
+    return true;
+  }
+};
+
+struct OBJExportParamsDefault {
+  OBJExportParams params;
+  OBJExportParamsDefault()
+  {
+    params.filepath[0] = '\0';
+    params.export_animation = false;
+    params.start_frame = 0;
+    params.end_frame = 1;
+
+    params.forward_axis = OBJ_AXIS_NEGATIVE_Z_FORWARD;
+    params.up_axis = OBJ_AXIS_Y_UP;
+    params.scaling_factor = 1.f;
+
+    params.export_eval_mode = DAG_EVAL_VIEWPORT;
+    params.export_selected_objects = false;
+    params.export_uv = true;
+    params.export_normals = true;
+    params.export_materials = true;
+    params.export_triangulated_mesh = false;
+    params.export_curves_as_nurbs = false;
+
+    params.export_object_groups = false;
+    params.export_material_groups = false;
+    params.export_vertex_groups = false;
+    params.export_smooth_groups = true;
+    params.smooth_groups_bitflags = false;
+  }
+};
+
+const std::string all_objects_file = "io_tests/blend_scene/all_objects_2_92.blend";
+
+TEST_F(Export_OBJ, filter_objects_as_mesh)
+{
+  OBJExportParamsDefault _export;
+  if (!load_file_and_depsgraph(all_objects_file)) {
+    return;
+  }
+
+  auto [objmeshes, objcurves]{find_exportable_objects(depsgraph, _export.params)};
+  EXPECT_EQ(objmeshes.size(), 22);
+  EXPECT_EQ(objcurves.size(), 0);
+}
+
+TEST_F(Export_OBJ, filter_objects_as_curves)
+{
+  OBJExportParamsDefault _export;
+  if (!load_file_and_depsgraph(all_objects_file)) {
+    return;
+  }
+  _export.params.export_curves_as_nurbs = true;
+  auto [objmeshes, objcurves]{find_exportable_objects(depsgraph, _export.params)};
+  EXPECT_EQ(objmeshes.size(), 18);
+  EXPECT_EQ(objcurves.size(), 4);
+}
+
+TEST_F(Export_OBJ, filter_objects_selected)
+{
+  OBJExportParamsDefault _export;
+  if (!load_file_and_depsgraph(all_objects_file)) {
+    return;
+  }
+  _export.params.export_selected_objects = true;
+  _export.params.export_curves_as_nurbs = true;
+  auto [objmeshes, objcurves]{find_exportable_objects(depsgraph, _export.params)};
+  EXPECT_EQ(objmeshes.size(), 8);
+  EXPECT_EQ(objcurves.size(), 2);
+}
+
+TEST_F(Export_OBJ, append_negative_frame_to_filename)
+{
+  const char path_original[1024] = "/my_file.obj";
+  const char path_expected[1024] = "/my_file-123.obj";
+  const int frame = -123;
+  char path_with_frame[1024] = {0};
+  const bool ok = append_frame_to_filename(path_original, frame, path_with_frame);
+  EXPECT_TRUE(ok);
+  EXPECT_EQ_ARRAY(path_with_frame, path_expected, BLI_strlen_utf8(path_expected));
+}
+
+TEST_F(Export_OBJ, append_positive_frame_to_filename)
+{
+  const char path_original[1024] = "/my_file.obj";
+  const char path_expected[1024] = "/my_file123.obj";
+  const int frame = 123;
+  char path_with_frame[1024] = {0};
+  const bool ok = append_frame_to_filename(path_original, frame, path_with_frame);
+  EXPECT_TRUE(ok);
+  EXPECT_EQ_ARRAY(path_with_frame, path_expected, BLI_strlen_utf8(path_expected));
+}
+}  // namespace blender::io::obj



More information about the Bf-blender-cvs mailing list