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