tests: add new test test_stl
This commit is contained in:
parent
3508eaa236
commit
0f4789d710
@ -256,12 +256,35 @@ enable_testing()
|
||||
set(CMAKE_CTEST_COMMAND ctest -V)
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
|
||||
|
||||
add_executable(test_internal EXCLUDE_FROM_ALL tests/stream_buffer.c
|
||||
tests/utils.c
|
||||
tests/test_internal.c
|
||||
src/gmio_core/stream.c
|
||||
src/gmio_core/internal/string_parse.c)
|
||||
add_executable(test_platform EXCLUDE_FROM_ALL tests/test_platform.c)
|
||||
add_executable(
|
||||
test_internal
|
||||
EXCLUDE_FROM_ALL
|
||||
tests/stream_buffer.c
|
||||
tests/utils.c
|
||||
tests/test_internal.c
|
||||
src/gmio_core/stream.c
|
||||
src/gmio_core/internal/string_parse.c)
|
||||
|
||||
add_executable(
|
||||
test_platform EXCLUDE_FROM_ALL tests/test_platform.c)
|
||||
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests/models
|
||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||
add_executable(
|
||||
test_stl
|
||||
EXCLUDE_FROM_ALL
|
||||
tests/test_stl_io.c
|
||||
src/gmio_core/buffer.c
|
||||
src/gmio_core/stream.c
|
||||
src/gmio_core/internal/string_parse.c
|
||||
src/gmio_stl/stl_format.c
|
||||
src/gmio_stl/stl_io.c
|
||||
src/gmio_stl/stla_read.c
|
||||
src/gmio_stl/stlb_read.c
|
||||
src/gmio_stl/internal/stl_rw_common.c
|
||||
src/gmio_stl/internal/stla_write.c
|
||||
src/gmio_stl/internal/stlb_byte_swap.c
|
||||
src/gmio_stl/internal/stlb_write.c)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
target_link_libraries(test_internal m) # -lm
|
||||
@ -269,6 +292,10 @@ endif()
|
||||
|
||||
add_test(test_internal test_internal)
|
||||
add_test(test_platform test_platform)
|
||||
add_test(test_stl test_stl)
|
||||
|
||||
add_dependencies(check test_internal
|
||||
test_platform)
|
||||
add_dependencies(
|
||||
check
|
||||
test_internal
|
||||
test_platform
|
||||
test_stl)
|
||||
|
0
tests/models/file_empty
Normal file
0
tests/models/file_empty
Normal file
10
tests/models/solid_4vertex.stla
Normal file
10
tests/models/solid_4vertex.stla
Normal file
@ -0,0 +1,10 @@
|
||||
solid
|
||||
facet normal 0 0 1
|
||||
outer loop
|
||||
vertex 0 0 0
|
||||
vertex 10 0 0
|
||||
vertex 5 10 0
|
||||
vertex 0 0 0
|
||||
endloop
|
||||
endfacet
|
||||
endsolid
|
2
tests/models/solid_anonymous_empty.stla
Normal file
2
tests/models/solid_anonymous_empty.stla
Normal file
@ -0,0 +1,2 @@
|
||||
solid
|
||||
endsolid
|
2
tests/models/solid_empty.stla
Normal file
2
tests/models/solid_empty.stla
Normal file
@ -0,0 +1,2 @@
|
||||
solid emptysolid
|
||||
endsolid
|
BIN
tests/models/solid_empty.stlb
Normal file
BIN
tests/models/solid_empty.stlb
Normal file
Binary file not shown.
9
tests/models/solid_lack_z.stla
Normal file
9
tests/models/solid_lack_z.stla
Normal file
@ -0,0 +1,9 @@
|
||||
solid
|
||||
facet normal 0 0 1
|
||||
outer loop
|
||||
vertex 0 0
|
||||
vertex 10 0 0
|
||||
vertex 5 10 0
|
||||
endloop
|
||||
endfacet
|
||||
endsolid
|
BIN
tests/models/solid_one_facet.le_stlb
Normal file
BIN
tests/models/solid_one_facet.le_stlb
Normal file
Binary file not shown.
9
tests/models/solid_one_facet.stla
Normal file
9
tests/models/solid_one_facet.stla
Normal file
@ -0,0 +1,9 @@
|
||||
solid
|
||||
facet normal 0 0 1
|
||||
outer loop
|
||||
vertex 0 0 0
|
||||
vertex 10 0 0
|
||||
vertex 5 10 0
|
||||
endloop
|
||||
endfacet
|
||||
endsolid
|
9
tests/models/solid_one_facet_uppercase.stla
Normal file
9
tests/models/solid_one_facet_uppercase.stla
Normal file
@ -0,0 +1,9 @@
|
||||
SOLID
|
||||
FACET NORMAL 0 0 1
|
||||
OUTER LOOP
|
||||
VERTEX 0 0 0
|
||||
VERTEX 10 0 0
|
||||
VERTEX 5 10 0
|
||||
ENDLOOP
|
||||
ENDFACET
|
||||
ENDSOLID
|
133
tests/test_stl_io.c
Normal file
133
tests/test_stl_io.c
Normal file
@ -0,0 +1,133 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** gmio
|
||||
** Copyright Fougue (2 Mar. 2015)
|
||||
** contact@fougsys.fr
|
||||
**
|
||||
** This software is a reusable library whose purpose is to provide complete
|
||||
** I/O support for various CAD file formats (eg. STL)
|
||||
**
|
||||
** This software is governed by the CeCILL-B license under French law and
|
||||
** abiding by the rules of distribution of free software. You can use,
|
||||
** modify and/ or redistribute the software under the terms of the CeCILL-B
|
||||
** license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html".
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "utest_lib.h"
|
||||
|
||||
#include "../src/gmio_core/error.h"
|
||||
#include "../src/gmio_stl/stl_error.h"
|
||||
#include "../src/gmio_stl/stl_io.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
static void add_triangle(
|
||||
void* cookie, uint32_t tri_id, const gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
}
|
||||
|
||||
struct filepath_errorcode
|
||||
{
|
||||
const char* filepath;
|
||||
int errorcode;
|
||||
};
|
||||
typedef struct filepath_errorcode filepath_errorcode_t;
|
||||
|
||||
const char* test_stl_read()
|
||||
{
|
||||
const filepath_errorcode_t expected[] = {
|
||||
{ "tests/models/file_empty", GMIO_STL_ERROR_UNKNOWN_FORMAT },
|
||||
{ "tests/models/solid_4vertex.stla", GMIO_STL_ERROR_PARSING },
|
||||
{ "tests/models/solid_anonymous_empty.stla", GMIO_ERROR_OK },
|
||||
{ "tests/models/solid_empty.stla", GMIO_ERROR_OK },
|
||||
{ "tests/models/solid_empty.stlb", GMIO_ERROR_OK },
|
||||
{ "tests/models/solid_lack_z.stla", GMIO_STL_ERROR_PARSING },
|
||||
{ "tests/models/solid_one_facet.stla", GMIO_ERROR_OK },
|
||||
{ "tests/models/solid_one_facet.le_stlb", GMIO_ERROR_OK },
|
||||
{ "tests/models/solid_one_facet_uppercase.stla", GMIO_ERROR_OK }
|
||||
};
|
||||
const size_t expected_count =
|
||||
sizeof(expected) / sizeof(filepath_errorcode_t);
|
||||
gmio_stl_mesh_creator_t meshc = {0};
|
||||
|
||||
meshc.add_triangle_func = &add_triangle;
|
||||
|
||||
for (size_t i = 0; i < expected_count; ++i) {
|
||||
const int err = gmio_stl_read_file(expected[i].filepath, &meshc, NULL);
|
||||
if (err != expected[i].errorcode) {
|
||||
printf("\nfilepath : %s\n"
|
||||
"expected error : 0x%x\n"
|
||||
"actual error : 0x%x\n",
|
||||
expected[i].filepath,
|
||||
expected[i].errorcode,
|
||||
err);
|
||||
}
|
||||
UTEST_ASSERT(err == expected[i].errorcode);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct stl_triangle_array
|
||||
{
|
||||
gmio_stl_triangle_t* ptr;
|
||||
uint32_t count;
|
||||
};
|
||||
typedef struct stl_triangle_array stl_triangle_array_t;
|
||||
|
||||
void stl_triangle_array_get_triangle(
|
||||
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
|
||||
{
|
||||
const stl_triangle_array_t* array = (const stl_triangle_array_t*)cookie;
|
||||
*triangle = array->ptr[tri_id];
|
||||
}
|
||||
|
||||
void generate_stlb_tests_models()
|
||||
{
|
||||
{
|
||||
FILE* outfile = fopen("tests/models/solid_empty.stlb", "wb");
|
||||
gmio_stream_t stream = gmio_stream_stdio(outfile);
|
||||
gmio_stlb_write_header(&stream, GMIO_ENDIANNESS_LITTLE, NULL, 0);
|
||||
fclose(outfile);
|
||||
}
|
||||
|
||||
{
|
||||
gmio_stl_mesh_t mesh = {0};
|
||||
gmio_stl_triangle_t tri = {
|
||||
{ 0.f, 0.f, 1.f }, /* normal */
|
||||
{ 0.f, 0.f, 0.f }, /* v1 */
|
||||
{ 10.f, 0.f, 0.f }, /* v2 */
|
||||
{ 5.f, 10.f, 0.f }, /* v3 */
|
||||
0 /* attr */
|
||||
};
|
||||
stl_triangle_array_t tri_array;
|
||||
|
||||
tri_array.ptr = &tri;
|
||||
tri_array.count = 1;
|
||||
|
||||
mesh.cookie = &tri_array;
|
||||
mesh.triangle_count = tri_array.count;
|
||||
mesh.get_triangle_func = &stl_triangle_array_get_triangle;
|
||||
|
||||
gmio_stl_write_file(
|
||||
GMIO_STL_FORMAT_BINARY_LE,
|
||||
"tests/models/solid_one_facet.le_stlb",
|
||||
&mesh,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
const char* all_tests()
|
||||
{
|
||||
/*generate_stlb_tests_models();*/
|
||||
UTEST_SUITE_START();
|
||||
UTEST_RUN(test_stl_read);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UTEST_MAIN(all_tests)
|
Loading…
Reference in New Issue
Block a user