5#include <gtest/gtest.h>
10#include "testing/testing.h"
70 params.export_curves_as_nurbs =
true;
83 params.export_selected_objects =
true;
84 params.export_curves_as_nurbs =
true;
90TEST(obj_exporter_utils, append_negative_frame_to_filename)
94 const int frame = -12;
95 char path_with_frame[
FILE_MAX] = {0};
98 EXPECT_STREQ(path_with_frame, path_truth);
101TEST(obj_exporter_utils, append_positive_frame_to_filename)
105 const int frame = 12;
106 char path_with_frame[
FILE_MAX] = {0};
109 EXPECT_STREQ(path_with_frame, path_truth);
112TEST(obj_exporter_utils, append_large_positive_frame_to_filename)
116 const int frame = 1234567;
117 char path_with_frame[
FILE_MAX] = {0};
120 EXPECT_STREQ(path_with_frame, path_truth);
128 if (buffer !=
nullptr) {
129 res.assign((
const char *)buffer, buffer_len);
151 const char *
const temp_file_path =
"output\xc4\x84\xd0\x96.OBJ";
157 const std::string &out_filepath)
160 auto writer = std::make_unique<OBJWriter>(out_filepath.c_str(),
params);
163 catch (
const std::system_error &ex) {
164 fprintf(stderr,
"[%s] %s\n", ex.code().category().name(), ex.what());
174 std::string out_file_path = get_temp_obj_filename();
177 std::unique_ptr<OBJWriter> writer = init_writer(
params, out_file_path);
182 writer->write_header();
185 using namespace std::string_literals;
191 std::string out_file_path = get_temp_obj_filename();
194 std::unique_ptr<OBJWriter> writer = init_writer(
params, out_file_path);
199 writer->write_mtllib_name(
"/Users/blah.mtl");
200 writer->write_mtllib_name(
"\\C:\\blah.mtl");
203 ASSERT_EQ(
result,
"mtllib blah.mtl\nmtllib blah.mtl\n");
206TEST(obj_exporter_writer, format_handler_buffer_chunking)
223 ASSERT_EQ(got_blocks, 6);
226 using namespace std::string_literals;
227 const char *expected = R
"(o abc
231o 012345678901234567890123456789abcd
236 ASSERT_EQ(got_string, expected);
242 const size_t a_len = a.size();
243 const size_t b_len =
b.size();
244 const size_t a_next = a.find_first_of(
'\n');
245 const size_t b_next =
b.find_first_of(
'\n');
246 if (a_next == std::string::npos) {
247 printf(
"No newline found in evaluated string\n");
250 if (b_next == std::string::npos) {
251 printf(
"No newline found in the golden string\n");
254 const size_t a_sublen = a_len - a_next;
255 const size_t b_sublen = b_len - b_next;
256 if (a_sublen != b_sublen) {
257 printf(
"Mismatching string length, evaluated contains %zu chars, while golden has %zu\n",
261 if (a.compare(a_next, a_sublen,
b, b_next, b_sublen) != 0) {
262 for (
int i = 0;
i < std::min(a_sublen, b_sublen); ++
i) {
263 if (a[a_next +
i] !=
b[b_next +
i]) {
264 printf(
"Difference found at pos %zu of a\n", a_next +
i);
265 printf(
"a: %s ...\n", a.substr(a_next +
i, 100).c_str());
266 printf(
"b: %s ...\n",
b.substr(b_next +
i, 100).c_str());
276class OBJExportRegressionTest :
public OBJExportTest {
286 const std::string &golden_obj,
287 const std::string &golden_mtl,
299 std::string golden_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR + golden_obj;
301 golden_file_path.c_str(),
params.file_base_for_tests,
sizeof(
params.file_base_for_tests));
308 printf(
"failed test for file: %s\n", golden_file_path.c_str());
310 printf(
"failing test output in %s\n", out_file_path.c_str());
313 ASSERT_TRUE(are_equal);
315 BLI_delete(out_file_path.c_str(),
false,
false);
317 if (!golden_mtl.empty()) {
320 std::string golden_mtl_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR +
325 printf(
"failed test for mtl file: %s\n", golden_mtl_file_path.c_str());
327 printf(
"failing test output in %s\n", out_mtl_file_path.c_str());
330 ASSERT_TRUE(are_equal);
332 BLI_delete(out_mtl_file_path.c_str(),
false,
false);
341 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_tris.blend",
347TEST_F(OBJExportRegressionTest, all_quads)
351 params.export_materials =
false;
352 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_quads.blend",
358TEST_F(OBJExportRegressionTest, fgons)
363 params.export_materials =
false;
364 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "fgons.blend",
370TEST_F(OBJExportRegressionTest, edges)
375 params.export_materials =
false;
376 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "edges.blend",
382TEST_F(OBJExportRegressionTest, vertices)
388 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
389 "cube_loose_edges_verts.blend",
395TEST_F(OBJExportRegressionTest, cube_loose_edges)
400 params.export_materials =
false;
401 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "vertices.blend",
407TEST_F(OBJExportRegressionTest, non_uniform_scale)
411 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
412 "non_uniform_scale.blend",
418TEST_F(OBJExportRegressionTest, nurbs_as_nurbs)
424 params.export_curves_as_nurbs =
true;
425 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
431TEST_F(OBJExportRegressionTest, nurbs_curves_as_nurbs)
437 params.export_curves_as_nurbs =
true;
438 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs_curves.blend",
444TEST_F(OBJExportRegressionTest, nurbs_as_mesh)
450 params.export_curves_as_nurbs =
false;
451 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
457TEST_F(OBJExportRegressionTest, cube_all_data_triangulated)
463 params.export_triangulated_mesh =
true;
464 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "cube_all_data.blend",
465 "io_tests" SEP_STR "obj" SEP_STR "cube_all_data_triangulated.obj",
470TEST_F(OBJExportRegressionTest, cube_normal_edit)
476 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
477 "cube_normal_edit.blend",
483TEST_F(OBJExportRegressionTest, cube_vertex_groups)
486 params.export_materials =
false;
487 params.export_normals =
false;
490 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
491 "cube_vertex_groups.blend",
497TEST_F(OBJExportRegressionTest, cubes_positioned)
500 params.export_materials =
false;
502 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
503 "cubes_positioned.blend",
509TEST_F(OBJExportRegressionTest, cubes_vertex_colors)
512 params.export_colors =
true;
513 params.export_normals =
false;
516 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
517 "cubes_vertex_colors.blend",
523TEST_F(OBJExportRegressionTest, cubes_with_textures_strip)
527 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
528 "cubes_with_textures.blend",
534TEST_F(OBJExportRegressionTest, cubes_with_textures_relative)
538 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
539 "cubes_with_textures.blend",
545TEST_F(OBJExportRegressionTest, suzanne_all_data)
550 params.export_materials =
false;
552 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
553 "suzanne_all_data.blend",
559TEST_F(OBJExportRegressionTest, all_curves)
562 params.export_materials =
false;
563 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
569TEST_F(OBJExportRegressionTest, all_curves_as_nurbs)
573 params.export_curves_as_nurbs =
true;
574 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
580TEST_F(OBJExportRegressionTest, all_objects)
586 params.export_colors =
true;
587 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
593TEST_F(OBJExportRegressionTest, all_objects_mat_groups)
599 params.export_material_groups =
true;
600 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
606TEST_F(OBJExportRegressionTest, materials_without_pbr)
611 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
617TEST_F(OBJExportRegressionTest, materials_pbr)
620 params.export_normals =
false;
622 params.export_pbr_extensions =
true;
623 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
void BKE_tempdir_init(const char *userdir)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void BKE_tempdir_session_purge()
const char * BKE_blender_version_string(void)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
char * STRNCPY(char(&dst)[N], const char *src)
external readfile function prototypes.
@ PATH_REFERENCE_RELATIVE
BPy_StructRNA * depsgraph
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
struct Depsgraph * depsgraph
struct BlendFileData * bfile
void compare_obj_export_to_golden(const std::string &blendfile, const std::string &golden_obj, const std::string &golden_mtl, OBJExportParams ¶ms)
bool load_file_and_depsgraph(const std::string &filepath, const eEvaluationMode eval_mode=DAG_EVAL_VIEWPORT)
std::unique_ptr< OBJWriter > init_writer(const OBJExportParams ¶ms, const std::string &out_filepath)
std::string get_temp_obj_filename()
void MEM_freeN(void *vmemh)
bool append_frame_to_filename(const char *filepath, const int frame, char r_filepath_with_frames[1024])
static bool strings_equal_after_first_lines(const std::string &a, const std::string &b)
std::pair< Vector< std::unique_ptr< OBJMesh > >, Vector< std::unique_ptr< IOBJCurve > > > filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_params)
TEST_F(OBJExportTest, filter_objects_curves_as_mesh)
TEST(obj_exporter_utils, append_negative_frame_to_filename)
constexpr bool save_failing_test_output
const std::string all_objects_file
static std::string read_temp_file_in_string(const std::string &file_path)
void export_frame(Depsgraph *depsgraph, const OBJExportParams &export_params, const char *filepath)
void * BKE_tempdir_session