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