5#include <gtest/gtest.h>
10#include "testing/testing.h"
91TEST(obj_exporter_utils, append_negative_frame_to_filename)
95 const int frame = -12;
96 char path_with_frame[
FILE_MAX] = {0};
99 EXPECT_STREQ(path_with_frame, path_truth);
102TEST(obj_exporter_utils, append_positive_frame_to_filename)
106 const int frame = 12;
107 char path_with_frame[
FILE_MAX] = {0};
110 EXPECT_STREQ(path_with_frame, path_truth);
113TEST(obj_exporter_utils, append_large_positive_frame_to_filename)
117 const int frame = 1234567;
118 char path_with_frame[
FILE_MAX] = {0};
121 EXPECT_STREQ(path_with_frame, path_truth);
129 if (buffer !=
nullptr) {
130 res.assign(buffer, buffer_len);
152 const char *
const temp_file_path =
"output\xc4\x84\xd0\x96.OBJ";
158 const std::string &out_filepath)
161 auto writer = std::make_unique<OBJWriter>(out_filepath.c_str(), params);
164 catch (
const std::system_error &ex) {
165 fprintf(stderr,
"[%s] %s\n", ex.code().category().name(), ex.what());
175 std::string out_file_path = get_temp_obj_filename();
178 std::unique_ptr<OBJWriter> writer = init_writer(params, out_file_path);
183 writer->write_header();
186 using namespace std::string_literals;
192 std::string out_file_path = get_temp_obj_filename();
195 std::unique_ptr<OBJWriter> writer = init_writer(params, out_file_path);
200 writer->write_mtllib_name(
"/Users/blah.mtl");
201 writer->write_mtllib_name(
"\\C:\\blah.mtl");
204 ASSERT_EQ(
result,
"mtllib blah.mtl\nmtllib blah.mtl\n");
207TEST(obj_exporter_writer, format_handler_buffer_chunking)
224 ASSERT_EQ(got_blocks, 6);
227 using namespace std::string_literals;
228 const char *expected = R
"(o abc
232o 012345678901234567890123456789abcd
237 ASSERT_EQ(got_string, expected);
243 const size_t a_len = a.size();
244 const size_t b_len =
b.size();
245 const size_t a_next = a.find_first_of(
'\n');
246 const size_t b_next =
b.find_first_of(
'\n');
247 if (a_next == std::string::npos) {
248 printf(
"No newline found in evaluated string\n");
251 if (b_next == std::string::npos) {
252 printf(
"No newline found in the golden string\n");
255 const size_t a_sublen = a_len - a_next;
256 const size_t b_sublen = b_len - b_next;
257 if (a_sublen != b_sublen) {
258 printf(
"Mismatching string length, evaluated contains %zu chars, while golden has %zu\n",
262 if (a.compare(a_next, a_sublen,
b, b_next, b_sublen) != 0) {
263 for (
int i = 0; i < std::min(a_sublen, b_sublen); ++i) {
264 if (a[a_next + i] !=
b[b_next + i]) {
265 printf(
"Difference found at pos %zu of a\n", a_next + i);
266 printf(
"a: %s ...\n", a.substr(a_next + i, 100).c_str());
267 printf(
"b: %s ...\n",
b.substr(b_next + i, 100).c_str());
277class OBJExportRegressionTest :
public OBJExportTest {
287 const std::string &golden_obj,
288 const std::string &golden_mtl,
300 std::string golden_file_path = tests::flags_test_asset_dir() +
SEP_STR + golden_obj;
309 printf(
"failed test for file: %s\n", golden_file_path.c_str());
311 printf(
"failing test output in %s\n", out_file_path.c_str());
314 ASSERT_TRUE(are_equal);
316 BLI_delete(out_file_path.c_str(),
false,
false);
318 if (!golden_mtl.empty()) {
321 std::string golden_mtl_file_path = tests::flags_test_asset_dir() +
SEP_STR + golden_mtl;
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)
352 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_quads.blend",
358TEST_F(OBJExportRegressionTest, fgons)
364 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "fgons.blend",
370TEST_F(OBJExportRegressionTest, edges)
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)
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)
425 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
431TEST_F(OBJExportRegressionTest, nurbs_curves_as_nurbs)
438 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs_curves.blend",
444TEST_F(OBJExportRegressionTest, nurbs_as_mesh)
451 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
457TEST_F(OBJExportRegressionTest, cube_all_data_triangulated)
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)
490 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
491 "cube_vertex_groups.blend",
497TEST_F(OBJExportRegressionTest, cubes_positioned)
502 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
503 "cubes_positioned.blend",
509TEST_F(OBJExportRegressionTest, cubes_vertex_colors)
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)
552 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
553 "suzanne_all_data.blend",
559TEST_F(OBJExportRegressionTest, all_curves)
563 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
569TEST_F(OBJExportRegressionTest, all_curves_as_nurbs)
574 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
580TEST_F(OBJExportRegressionTest, all_objects)
587 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
593TEST_F(OBJExportRegressionTest, all_objects_mat_groups)
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)
623 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
File and directory operations.
external readfile function prototypes.
struct Depsgraph * depsgraph
struct BlendFileData * bfile
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
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()
#define EXPECT_TRUE(result)
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)
bool append_frame_to_filename(const char *filepath, const int frame, char r_filepath_with_frames[FILE_MAX])
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)
TEST_F(AbstractHierarchyIteratorTest, ExportHierarchyTest)
void BKE_tempdir_session_purge()
char * STRNCPY(char(&dst)[N], const char *src)
const char * BKE_tempdir_session() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
char * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
const char * BKE_blender_version_string()
void BKE_tempdir_init(const char *userdir)
@ PATH_REFERENCE_RELATIVE
bool export_smooth_groups
bool export_selected_objects
bool export_pbr_extensions
bool export_material_groups
bool export_vertex_groups
ePathReferenceMode path_mode
bool export_curves_as_nurbs
const char * blen_filepath
char file_base_for_tests[FILE_MAX]
bool export_triangulated_mesh