5#include <gtest/gtest.h>
11#include "testing/testing.h"
97TEST(obj_exporter_utils, append_negative_frame_to_filename)
101 const int frame = -12;
102 char path_with_frame[
FILE_MAX] = {0};
105 EXPECT_STREQ(path_with_frame, path_truth);
108TEST(obj_exporter_utils, append_positive_frame_to_filename)
112 const int frame = 12;
113 char path_with_frame[
FILE_MAX] = {0};
116 EXPECT_STREQ(path_with_frame, path_truth);
119TEST(obj_exporter_utils, append_large_positive_frame_to_filename)
123 const int frame = 1234567;
124 char path_with_frame[
FILE_MAX] = {0};
127 EXPECT_STREQ(path_with_frame, path_truth);
135 if (buffer !=
nullptr) {
136 res.assign((
const char *)buffer, buffer_len);
158 const char *
const temp_file_path =
"output\xc4\x84\xd0\x96.OBJ";
164 const std::string &out_filepath)
167 auto writer = std::make_unique<OBJWriter>(out_filepath.c_str(),
params);
170 catch (
const std::system_error &ex) {
171 std::cerr << ex.code().category().name() <<
": " << ex.what() <<
": " << ex.code().message()
182 std::string out_file_path = get_temp_obj_filename();
185 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
190 writer->write_header();
193 using namespace std::string_literals;
199 std::string out_file_path = get_temp_obj_filename();
202 std::unique_ptr<OBJWriter> writer = init_writer(_export.
params, out_file_path);
207 writer->write_mtllib_name(
"/Users/blah.mtl");
208 writer->write_mtllib_name(
"\\C:\\blah.mtl");
211 ASSERT_EQ(result,
"mtllib blah.mtl\nmtllib blah.mtl\n");
214TEST(obj_exporter_writer, format_handler_buffer_chunking)
230 ASSERT_EQ(got_blocks, 7);
233 using namespace std::string_literals;
234 const char *expected = R
"(o abc
238o 012345678901234567890123456789abcd
243 ASSERT_EQ(got_string, expected);
249 const size_t a_len = a.size();
250 const size_t b_len =
b.size();
251 const size_t a_next = a.find_first_of(
'\n');
252 const size_t b_next =
b.find_first_of(
'\n');
253 if (a_next == std::string::npos || b_next == std::string::npos) {
254 std::cout <<
"Couldn't find newline in one of args\n";
257 if (a.compare(a_next, a_len - a_next,
b, b_next, b_len - b_next) != 0) {
258 for (
int i = 0; i < a_len - a_next && i < b_len - b_next; ++i) {
259 if (a[a_next + i] !=
b[b_next + i]) {
260 std::cout <<
"Difference found at pos " << a_next + i <<
" of a\n";
261 std::cout <<
"a: " << a.substr(a_next + i, 100) <<
" ...\n";
262 std::cout <<
"b: " <<
b.substr(b_next + i, 100) <<
" ... \n";
282 const std::string &golden_obj,
283 const std::string &golden_mtl,
295 std::string golden_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR + golden_obj;
297 golden_file_path.c_str(),
params.file_base_for_tests,
sizeof(
params.file_base_for_tests));
304 printf(
"failing test output in %s\n", out_file_path.c_str());
306 ASSERT_TRUE(are_equal);
308 BLI_delete(out_file_path.c_str(),
false,
false);
310 if (!golden_mtl.empty()) {
313 std::string golden_mtl_file_path = blender::tests::flags_test_asset_dir() +
SEP_STR +
318 printf(
"failing test output in %s\n", out_mtl_file_path.c_str());
320 ASSERT_TRUE(are_equal);
322 BLI_delete(out_mtl_file_path.c_str(),
false,
false);
331 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_tris.blend",
342 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "all_quads.blend",
354 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "fgons.blend",
366 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "edges.blend",
378 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
379 "cube_loose_edges_verts.blend",
391 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "vertices.blend",
401 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
402 "non_uniform_scale.blend",
415 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
428 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs_curves.blend",
441 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "nurbs.blend",
454 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "cube_all_data.blend",
455 "io_tests" SEP_STR "obj" SEP_STR "cube_all_data_triangulated.obj",
466 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
467 "cube_normal_edit.blend",
480 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
481 "cube_vertex_groups.blend",
492 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
493 "cubes_positioned.blend",
506 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
507 "cubes_vertex_colors.blend",
517 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
518 "cubes_with_textures.blend",
528 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
529 "cubes_with_textures.blend",
542 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR
543 "suzanne_all_data.blend",
553 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
564 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_curves.blend",
577 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
590 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_scene" SEP_STR "all_objects.blend",
601 compare_obj_export_to_golden(
"io_tests" SEP_STR "blend_geometry" SEP_STR "materials_pbr.blend",
613 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
#define STRNCPY(dst, src)
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
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()
local_group_size(16, 16) .push_constant(Type b
const Depsgraph * depsgraph
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)
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)
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)
bool export_triangulated_mesh
bool export_curves_as_nurbs
bool export_material_groups
bool export_selected_objects
bool export_vertex_groups
bool export_pbr_extensions
ePathReferenceMode path_mode
bool export_smooth_groups
void * BKE_tempdir_session