3 #include <gtest/gtest.h>
7 #include <system_error>
9 #include "testing/testing.h"
94 TEST(obj_exporter_utils, append_negative_frame_to_filename)
96 const char path_original[
FILE_MAX] =
"/my_file.obj";
97 const char path_truth[
FILE_MAX] =
"/my_file-123.obj";
98 const int frame = -123;
99 char path_with_frame[
FILE_MAX] = {0};
102 EXPECT_EQ_ARRAY(path_with_frame, path_truth,
BLI_strlen_utf8(path_truth));
105 TEST(obj_exporter_utils, append_positive_frame_to_filename)
107 const char path_original[
FILE_MAX] =
"/my_file.obj";
108 const char path_truth[
FILE_MAX] =
"/my_file123.obj";
109 const int frame = 123;
110 char path_with_frame[
FILE_MAX] = {0};
113 EXPECT_EQ_ARRAY(path_with_frame, path_truth,
BLI_strlen_utf8(path_truth));
122 res.assign((
const char *)
buffer, buffer_len);
144 const char *
const temp_file_path =
"output\xc4\x84\xd0\x96.OBJ";
150 const std::string out_filepath)
153 auto writer = std::make_unique<OBJWriter>(out_filepath.c_str(),
params);
156 catch (
const std::system_error &ex) {
157 std::cerr << ex.code().category().name() <<
": " << ex.what() <<
": " << ex.code().message()
168 std::string out_file_path = get_temp_obj_filename();
171 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
176 writer->write_header();
179 using namespace std::string_literals;
185 std::string out_file_path = get_temp_obj_filename();
188 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
193 writer->write_mtllib_name(
"/Users/blah.mtl");
194 writer->write_mtllib_name(
"\\C:\\blah.mtl");
197 ASSERT_EQ(
result,
"mtllib blah.mtl\nmtllib blah.mtl\n");
200 TEST(obj_exporter_writer, format_handler_buffer_chunking)
216 ASSERT_EQ(got_blocks, 7);
219 using namespace std::string_literals;
220 const char *expected = R
"(o abc
224 o 012345678901234567890123456789abcd
229 ASSERT_EQ(got_string, expected);
235 const size_t a_len =
a.size();
236 const size_t b_len =
b.size();
237 const size_t a_next =
a.find_first_of(
'\n');
238 const size_t b_next =
b.find_first_of(
'\n');
239 if (a_next == std::string::npos || b_next == std::string::npos) {
240 std::cout <<
"Couldn't find newline in one of args\n";
243 if (
a.compare(a_next, a_len - a_next,
b, b_next, b_len - b_next) != 0) {
244 for (
int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) {
245 if (
a[a_next + i] !=
b[b_next + i]) {
246 std::cout <<
"Difference found at pos " << a_next + i <<
" of a\n";
247 std::cout <<
"a: " <<
a.substr(a_next + i, 100) <<
" ...\n";
248 std::cout <<
"b: " <<
b.substr(b_next + i, 100) <<
" ... \n";
268 const std::string &golden_obj,
269 const std::string &golden_mtl,
281 std::string golden_file_path = blender::tests::flags_test_asset_dir() +
"/" + golden_obj;
289 printf(
"failing test output in %s\n", out_file_path.c_str());
291 ASSERT_TRUE(are_equal);
293 BLI_delete(out_file_path.c_str(),
false,
false);
295 if (!golden_mtl.empty()) {
298 std::string golden_mtl_file_path = blender::tests::flags_test_asset_dir() +
"/" + golden_mtl;
302 printf(
"failing test output in %s\n", out_mtl_file_path.c_str());
304 ASSERT_TRUE(are_equal);
306 BLI_delete(out_mtl_file_path.c_str(),
false,
false);
315 compare_obj_export_to_golden(
"io_tests/blend_geometry/all_tris.blend",
316 "io_tests/obj/all_tris.obj",
317 "io_tests/obj/all_tris.mtl",
326 compare_obj_export_to_golden(
327 "io_tests/blend_geometry/all_quads.blend",
"io_tests/obj/all_quads.obj",
"", _export.
params);
336 compare_obj_export_to_golden(
337 "io_tests/blend_geometry/fgons.blend",
"io_tests/obj/fgons.obj",
"", _export.
params);
346 compare_obj_export_to_golden(
347 "io_tests/blend_geometry/edges.blend",
"io_tests/obj/edges.obj",
"", _export.
params);
356 compare_obj_export_to_golden(
357 "io_tests/blend_geometry/vertices.blend",
"io_tests/obj/vertices.obj",
"", _export.
params);
364 compare_obj_export_to_golden(
"io_tests/blend_geometry/non_uniform_scale.blend",
365 "io_tests/obj/non_uniform_scale.obj",
377 compare_obj_export_to_golden(
378 "io_tests/blend_geometry/nurbs.blend",
"io_tests/obj/nurbs.obj",
"", _export.
params);
388 compare_obj_export_to_golden(
"io_tests/blend_geometry/nurbs_curves.blend",
389 "io_tests/obj/nurbs_curves.obj",
401 compare_obj_export_to_golden(
402 "io_tests/blend_geometry/nurbs.blend",
"io_tests/obj/nurbs_mesh.obj",
"", _export.
params);
412 compare_obj_export_to_golden(
"io_tests/blend_geometry/cube_all_data.blend",
413 "io_tests/obj/cube_all_data_triangulated.obj",
424 compare_obj_export_to_golden(
"io_tests/blend_geometry/cube_normal_edit.blend",
425 "io_tests/obj/cube_normal_edit.obj",
437 compare_obj_export_to_golden(
"io_tests/blend_geometry/cube_vertex_groups.blend",
438 "io_tests/obj/cube_vertex_groups.obj",
448 compare_obj_export_to_golden(
"io_tests/blend_geometry/cubes_positioned.blend",
449 "io_tests/obj/cubes_positioned.obj",
461 compare_obj_export_to_golden(
"io_tests/blend_geometry/cubes_vertex_colors.blend",
462 "io_tests/obj/cubes_vertex_colors.obj",
471 compare_obj_export_to_golden(
"io_tests/blend_geometry/cubes_with_textures.blend",
472 "io_tests/obj/cubes_with_textures.obj",
473 "io_tests/obj/cubes_with_textures.mtl",
481 compare_obj_export_to_golden(
"io_tests/blend_geometry/cubes_with_textures.blend",
482 "io_tests/obj/cubes_with_textures_rel.obj",
483 "io_tests/obj/cubes_with_textures_rel.mtl",
494 compare_obj_export_to_golden(
"io_tests/blend_geometry/suzanne_all_data.blend",
495 "io_tests/obj/suzanne_all_data.obj",
504 compare_obj_export_to_golden(
505 "io_tests/blend_scene/all_curves.blend",
"io_tests/obj/all_curves.obj",
"", _export.
params);
513 compare_obj_export_to_golden(
"io_tests/blend_scene/all_curves.blend",
514 "io_tests/obj/all_curves_as_nurbs.obj",
526 compare_obj_export_to_golden(
"io_tests/blend_scene/all_objects.blend",
527 "io_tests/obj/all_objects.obj",
528 "io_tests/obj/all_objects.mtl",
539 compare_obj_export_to_golden(
"io_tests/blend_scene/all_objects.blend",
540 "io_tests/obj/all_objects_mat_groups.obj",
541 "io_tests/obj/all_objects_mat_groups.mtl",
void BKE_tempdir_init(const char *userdir)
void BKE_tempdir_session_purge(void)
const char * BKE_tempdir_base(void)
const char * BKE_blender_version_string(void)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
File and directory operations.
void * BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size)
int BLI_delete(const char *file, bool dir, bool recursive) ATTR_NONNULL()
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
external readfile function prototypes.
@ PATH_REFERENCE_RELATIVE
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
struct Depsgraph * depsgraph
struct BlendFileData * bfile
std::unique_ptr< OBJWriter > init_writer(const OBJExportParams ¶ms, const std::string out_filepath)
std::string get_temp_obj_filename()
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)
const Depsgraph * depsgraph
void * BKE_tempdir_session
ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
static bool strings_equal_after_first_lines(const std::string &a, const std::string &b)
TEST_F(obj_exporter_test, 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
bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames)
static std::string read_temp_file_in_string(const std::string &file_path)
std::pair< Vector< std::unique_ptr< OBJMesh > >, Vector< std::unique_ptr< OBJCurve > > > filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_params)
void export_frame(Depsgraph *depsgraph, const OBJExportParams &export_params, const char *filepath)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
bool export_triangulated_mesh
bool export_curves_as_nurbs
bool export_material_groups
bool export_selected_objects
bool export_vertex_groups
ePathReferenceMode path_mode
bool export_smooth_groups