Merge branch 'develop' of https://github.com/fougue/gmio into develop

This commit is contained in:
Hugues Delorme 2017-01-09 12:18:34 +01:00
commit fe6858a0b9
3 changed files with 22 additions and 28 deletions

View File

@ -161,7 +161,7 @@ size_t gmio_zip_read_local_file_header(
int *ptr_error) int *ptr_error)
{ {
uint8_t buff[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER]; uint8_t buff[GMIO_ZIP_SIZE_LOCAL_FILE_HEADER];
uint8_t* buffit = buff; const uint8_t* buffit = buff;
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff)); const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff))) if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
@ -251,7 +251,7 @@ size_t gmio_zip_read_central_directory_header(
int *ptr_error) int *ptr_error)
{ {
uint8_t buff[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER]; uint8_t buff[GMIO_ZIP_SIZE_CENTRAL_DIRECTORY_HEADER];
uint8_t* buffit = buff; const uint8_t* buffit = buff;
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff)); const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff))) if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
@ -311,7 +311,7 @@ size_t gmio_zip_read_end_of_central_directory_record(
int *ptr_error) int *ptr_error)
{ {
uint8_t buff[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD]; uint8_t buff[GMIO_ZIP_SIZE_END_OF_CENTRAL_DIRECTORY_RECORD];
uint8_t* buffit = buff; const uint8_t* buffit = buff;
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff)); const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff))) if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
@ -404,7 +404,7 @@ size_t gmio_zip_read_data_descriptor(
int* ptr_error) int* ptr_error)
{ {
uint8_t buff[GMIO_ZIP_SIZE_DATA_DESCRIPTOR]; uint8_t buff[GMIO_ZIP_SIZE_DATA_DESCRIPTOR];
uint8_t* buffit = buff; const uint8_t* buffit = buff;
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff)); const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff))) if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))
@ -427,7 +427,7 @@ size_t gmio_zip64_read_data_descriptor(
{ {
#ifdef GMIO_HAVE_INT64_TYPE #ifdef GMIO_HAVE_INT64_TYPE
uint8_t buff[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR]; uint8_t buff[GMIO_ZIP64_SIZE_DATA_DESCRIPTOR];
uint8_t* buffit = buff; const uint8_t* buffit = buff;
const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff)); const size_t read_len = gmio_stream_read_bytes(stream, buff, sizeof(buff));
if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff))) if (!gmio_zip_read_checkhelper(stream, read_len, sizeof(buff)))

View File

@ -246,7 +246,7 @@ struct gmio_zip_write_result {
size_t written_len; size_t written_len;
}; };
enum { GMIO_ZIP_UTILS_ERROR_TAG = 0xAA000000 }; enum { GMIO_ZIP_UTILS_ERROR_TAG = 0x00AA0000 };
enum gmio_zip_utils_error { enum gmio_zip_utils_error {
GMIO_ZIP_UTILS_ERROR_BAD_MAGIC = GMIO_ZIP_UTILS_ERROR_TAG + 0x01 GMIO_ZIP_UTILS_ERROR_BAD_MAGIC = GMIO_ZIP_UTILS_ERROR_TAG + 0x01
}; };

View File

@ -151,7 +151,6 @@ static const char* test_stlb_header_write()
const char* filepath = "temp/solid.stlb"; const char* filepath = "temp/solid.stlb";
struct gmio_stlb_header header = {0}; struct gmio_stlb_header header = {0};
const char* header_str = "temp/solid.stlb generated with gmio library"; const char* header_str = "temp/solid.stlb generated with gmio library";
int error = GMIO_ERROR_OK;
{ {
FILE* outfile = fopen(filepath, "wb"); FILE* outfile = fopen(filepath, "wb");
@ -159,7 +158,7 @@ static const char* test_stlb_header_write()
memcpy(&header, memcpy(&header,
header_str, header_str,
GMIO_MIN(GMIO_STLB_HEADER_SIZE, strlen(header_str))); GMIO_MIN(GMIO_STLB_HEADER_SIZE, strlen(header_str)));
error = gmio_stlb_header_write( const int error = gmio_stlb_header_write(
&stream, GMIO_ENDIANNESS_LITTLE, &header, 0); &stream, GMIO_ENDIANNESS_LITTLE, &header, 0);
fclose(outfile); fclose(outfile);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
@ -168,7 +167,7 @@ static const char* test_stlb_header_write()
{ {
struct gmio_stl_data data = {0}; struct gmio_stl_data data = {0};
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data); struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(filepath, &creator, NULL); const int error = gmio_stl_read_file(filepath, &creator, NULL);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header)); UTEST_ASSERT(gmio_stlb_header_equal(&header, &data.header));
UTEST_COMPARE_UINT(0, data.tri_array.count); UTEST_COMPARE_UINT(0, data.tri_array.count);
@ -192,12 +191,11 @@ static const char* test_stlb_write()
const char* model_fpath_out = "temp/solid.le_stlb"; const char* model_fpath_out = "temp/solid.le_stlb";
const char* model_fpath_out_be = "temp/solid.be_stlb"; const char* model_fpath_out_be = "temp/solid.be_stlb";
struct gmio_stl_data data = {0}; struct gmio_stl_data data = {0};
int error = GMIO_ERROR_OK;
/* Read input model file */ /* Read input model file */
{ {
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data); struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_fpath, &creator, NULL); const int error = gmio_stl_read_file(model_fpath, &creator, NULL);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
} }
@ -208,13 +206,14 @@ static const char* test_stlb_write()
const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data); const struct gmio_stl_mesh mesh = gmio_stl_data_mesh(&data);
struct gmio_stl_write_options opts = {0}; struct gmio_stl_write_options opts = {0};
opts.stlb_header = data.header; opts.stlb_header = data.header;
error = gmio_stl_write_file( int error = gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_LE, model_fpath_out, &mesh, &opts); GMIO_STL_FORMAT_BINARY_LE, model_fpath_out, &mesh, &opts);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
/* Big-endian version */ /* Big-endian version */
error = gmio_stl_write_file( error = gmio_stl_write_file(
GMIO_STL_FORMAT_BINARY_BE, model_fpath_out_be, &mesh, &opts); GMIO_STL_FORMAT_BINARY_BE, model_fpath_out_be, &mesh, &opts);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
} }
/* Check input and output models are equal */ /* Check input and output models are equal */
@ -251,7 +250,7 @@ static const char* test_stlb_write()
{ {
struct gmio_stl_data data_be = {0}; struct gmio_stl_data data_be = {0};
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data_be); struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data_be);
error = gmio_stl_read_file(model_fpath_out_be, &creator, NULL); const int error = gmio_stl_read_file(model_fpath_out_be, &creator, NULL);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header)); UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header));
UTEST_COMPARE_UINT(data.tri_array.count, data_be.tri_array.count); UTEST_COMPARE_UINT(data.tri_array.count, data_be.tri_array.count);
@ -273,12 +272,11 @@ static const char* test_stla_write()
const char* model_filepath_out = "temp/solid.stla"; const char* model_filepath_out = "temp/solid.stla";
struct gmio_stl_data data = {0}; /* TODO: fix memory leak on error */ struct gmio_stl_data data = {0}; /* TODO: fix memory leak on error */
char header_str[GMIO_STLB_HEADER_SIZE + 1] = {0}; char header_str[GMIO_STLB_HEADER_SIZE + 1] = {0};
int error = GMIO_ERROR_OK;
/* Read input model file */ /* Read input model file */
{ {
struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data); struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data);
error = gmio_stl_read_file(model_filepath, &creator, NULL); const int error = gmio_stl_read_file(model_filepath, &creator, NULL);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
} }
@ -290,7 +288,7 @@ static const char* test_stla_write()
opts.stla_solid_name = header_str; opts.stla_solid_name = header_str;
opts.stla_float32_prec = 7; opts.stla_float32_prec = 7;
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE; opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_LOWERCASE;
error = gmio_stl_write_file( const int error = gmio_stl_write_file(
GMIO_STL_FORMAT_ASCII, model_filepath_out, &mesh, &opts); GMIO_STL_FORMAT_ASCII, model_filepath_out, &mesh, &opts);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
} }
@ -301,18 +299,17 @@ static const char* test_stla_write()
struct gmio_stl_data data_stla = {0}; struct gmio_stl_data data_stla = {0};
struct gmio_stl_mesh_creator creator = struct gmio_stl_mesh_creator creator =
gmio_stl_data_mesh_creator(&data_stla); gmio_stl_data_mesh_creator(&data_stla);
size_t i = 0;
gmio_cstr_copy( gmio_cstr_copy(
trim_header_str, trim_header_str,
sizeof(trim_header_str), sizeof(trim_header_str),
header_str, header_str,
sizeof(header_str)); sizeof(header_str));
gmio_string_trim_from_end(trim_header_str, sizeof(header_str)); gmio_string_trim_from_end(trim_header_str, sizeof(header_str));
error = gmio_stl_read_file(model_filepath_out, &creator, NULL); const int error = gmio_stl_read_file(model_filepath_out, &creator, NULL);
UTEST_COMPARE_INT(GMIO_ERROR_OK, error); UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
UTEST_COMPARE_UINT(data.tri_array.count, data_stla.tri_array.count); UTEST_COMPARE_UINT(data.tri_array.count, data_stla.tri_array.count);
UTEST_COMPARE_CSTR(trim_header_str, data_stla.solid_name); UTEST_COMPARE_CSTR(trim_header_str, data_stla.solid_name);
for (i = 0; i < data.tri_array.count; ++i) { for (size_t i = 0; i < data.tri_array.count; ++i) {
const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i]; const struct gmio_stl_triangle* lhs = &data.tri_array.ptr[i];
const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i]; const struct gmio_stl_triangle* rhs = &data_stla.tri_array.ptr[i];
const bool tri_equal = gmio_stl_triangle_equal(lhs, rhs, 5); const bool tri_equal = gmio_stl_triangle_equal(lhs, rhs, 5);
@ -369,7 +366,7 @@ static const char* test_stla_lc_numeric()
int error[4] = {0}; int error[4] = {0};
gmio_lc_numeric_save(); gmio_lc_numeric_save();
setlocale(LC_NUMERIC, ""); setlocale(LC_NUMERIC, ""); /* "" -> environment's default locale */
if (!gmio_lc_numeric_is_C()) { if (!gmio_lc_numeric_is_C()) {
struct gmio_stl_read_options read_opts = {0}; struct gmio_stl_read_options read_opts = {0};
struct gmio_stl_write_options write_opts = {0}; struct gmio_stl_write_options write_opts = {0};
@ -381,17 +378,14 @@ static const char* test_stla_lc_numeric()
error[2] = gmio_stla_read(&null_stream, &null_meshcreator, &read_opts); error[2] = gmio_stla_read(&null_stream, &null_meshcreator, &read_opts);
error[3] = gmio_stl_write( error[3] = gmio_stl_write(
GMIO_STL_FORMAT_ASCII, &null_stream, &null_mesh, &write_opts); GMIO_STL_FORMAT_ASCII, &null_stream, &null_mesh, &write_opts);
} for (size_t i = 0; i < GMIO_ARRAY_SIZE(error); ++i) {
else {
fprintf(stderr, "\nskip: default locale is NULL or already C/POSIX");
}
gmio_lc_numeric_restore();
{
size_t i = 0;
for (; i < GMIO_ARRAY_SIZE(error); ++i) {
UTEST_COMPARE_INT(GMIO_ERROR_BAD_LC_NUMERIC, error[i]); UTEST_COMPARE_INT(GMIO_ERROR_BAD_LC_NUMERIC, error[i]);
} }
} }
else {
fprintf(stderr, "\nskip: default locale is NULL or already C/POSIX\n");
}
gmio_lc_numeric_restore();
return NULL; return NULL;
} }