Blender V5.3
io_ply_importer_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023-2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "testing/testing.h"
6
7#include "BLI_path_utils.hh"
8
9#include "CLG_log.h"
10
11#include "ply_import.hh"
12#include "ply_import_buffer.hh"
13#include "ply_import_data.hh"
14
15namespace blender {
16
17static CLG_LogRef LOG = {"io.ply"};
18
19namespace io::ply {
20
21/* Extensive tests for PLY importing are in `io_ply_import_test.py`.
22 * The tests here are only for testing PLY reader buffer refill behavior,
23 * by using a very small buffer size on purpose. */
24
25TEST(ply_import, BufferRefillTest)
26{
27 std::string ply_path_a = tests::flags_test_asset_dir() +
28 SEP_STR "io_tests" SEP_STR "ply" SEP_STR + "ASCII_wireframe_cube.ply";
29 std::string ply_path_b = tests::flags_test_asset_dir() +
30 SEP_STR "io_tests" SEP_STR "ply" SEP_STR + "wireframe_cube.ply";
31
32 /* Use a small read buffer size to test buffer refilling behavior. */
33 constexpr size_t buffer_size = 50;
34 PlyReadBuffer infile_a(ply_path_a.c_str(), buffer_size);
35 PlyReadBuffer infile_b(ply_path_b.c_str(), buffer_size);
36 PlyHeader header_a, header_b;
37 const char *header_err_a = read_header(infile_a, header_a);
38 const char *header_err_b = read_header(infile_b, header_b);
39 if (header_err_a != nullptr || header_err_b != nullptr) {
40 CLOG_ERROR(&LOG, "Failed to read PLY header");
41 ADD_FAILURE();
42 return;
43 }
44 std::unique_ptr<PlyData> data_a = import_ply_data(infile_a, header_a);
45 std::unique_ptr<PlyData> data_b = import_ply_data(infile_b, header_b);
46 if (!data_a->error.empty() || !data_b->error.empty()) {
47 CLOG_ERROR(&LOG, "Failed to read PLY data");
48 ADD_FAILURE();
49 return;
50 }
51
52 /* Check whether the edges list matches expectations. */
53 std::pair<int, int> exp_edges[] = {{2, 0},
54 {0, 1},
55 {1, 3},
56 {3, 2},
57 {6, 2},
58 {3, 7},
59 {7, 6},
60 {4, 6},
61 {7, 5},
62 {5, 4},
63 {0, 4},
64 {5, 1}};
65 EXPECT_EQ_SPAN<std::pair<int, int>>(Span(exp_edges, 12), data_a->edges);
66 EXPECT_EQ_SPAN<std::pair<int, int>>(Span(exp_edges, 12), data_b->edges);
67}
68
69//@TODO: now we put vertex color attribute first, maybe put position first?
70//@TODO: test with vertex element having list properties
71//@TODO: test with edges starting with non-vertex index properties
72//@TODO: test various malformed headers
73//@TODO: UVs with: s,t; u,v; texture_u,texture_v; texture_s,texture_t (from miniply)
74//@TODO: colors with: r,g,b in addition to red,green,blue (from miniply)
75
76} // namespace io::ply
77} // namespace blender
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
constexpr Span()=default
std::unique_ptr< PlyData > import_ply_data(PlyReadBuffer &file, PlyHeader &header)
TEST(ply_import, BufferRefillTest)
const char * read_header(PlyReadBuffer &file, PlyHeader &r_header)
BMesh Iterators.
static CLG_LogRef LOG
Definition logging.cpp:12
#define SEP_STR
Definition unit.cc:41