gmio/tests/test_stl_infos.c

115 lines
4.2 KiB
C
Raw Normal View History

2015-03-03 00:38:33 +08:00
/****************************************************************************
2017-01-27 01:05:12 +08:00
** Copyright (c) 2017, Fougue Ltd. <http://www.fougue.pro>
2016-07-05 18:46:22 +08:00
** All rights reserved.
2015-03-03 00:38:33 +08:00
**
2016-07-05 18:46:22 +08:00
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
2015-03-03 00:38:33 +08:00
**
2016-07-05 18:46:22 +08:00
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
**
** 2. Redistributions in binary form must reproduce the above
** copyright notice, this list of conditions and the following
** disclaimer in the documentation and/or other materials provided
** with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2015-03-03 00:38:33 +08:00
****************************************************************************/
#include "utest_assert.h"
2016-03-11 00:55:01 +08:00
#include "stl_testcases.h"
2015-12-10 01:51:03 +08:00
#include "../src/gmio_core/error.h"
#include "../src/gmio_stl/stl_error.h"
2015-12-10 01:51:03 +08:00
#include "../src/gmio_stl/stl_infos.h"
2016-09-21 15:03:39 +08:00
#include "../src/gmio_core/internal/helper_stream.h"
#include <stdio.h>
2016-02-12 18:55:39 +08:00
#include <string.h>
static const char* __tstl__test_stl_infos(
const struct stl_read_testcase* testcase)
2013-03-06 18:49:53 +08:00
{
2016-03-11 00:55:01 +08:00
FILE* file = fopen(testcase->filepath, "rb");
gmio_streamsize_t expected_size = testcase->expected_size;
char stla_solid_name[512] = {0};
2016-01-29 19:47:01 +08:00
struct gmio_stl_infos infos = {0};
struct gmio_stream stream = gmio_stream_stdio(file);
2015-12-10 01:51:03 +08:00
int error = GMIO_ERROR_OK;
infos.stla_solidname = stla_solid_name;
infos.stla_solidname_maxlen = sizeof(stla_solid_name) - 1;
error = gmio_stl_infos_probe(&infos, &stream, GMIO_STL_INFO_FLAG_ALL, NULL);
2016-03-11 00:55:01 +08:00
if (testcase->expected_size == -1)
expected_size = gmio_stream_size(&stream);
fclose(file);
if (testcase->format != GMIO_STL_FORMAT_UNKNOWN) {
2016-01-29 19:47:01 +08:00
UTEST_COMPARE_INT(GMIO_ERROR_OK, error);
}
else {
2016-01-29 19:47:01 +08:00
UTEST_COMPARE_INT(GMIO_STL_ERROR_UNKNOWN_FORMAT, error);
}
2016-03-11 00:55:01 +08:00
if (testcase->format == GMIO_STL_FORMAT_ASCII) {
const size_t name_len = strlen(stla_solid_name);
2016-03-03 01:05:19 +08:00
const gmio_streamsize_t name_len_ssize = name_len;
#if 0
printf("expected_size=%d "
"name_len=%d "
"infos.size=%d "
"infos.solid_name=%s\n",
expected_size, name_len, infos.size, infos.stla_solidname);
#endif
2016-03-03 01:05:19 +08:00
UTEST_ASSERT((expected_size - name_len_ssize) <= infos.size);
UTEST_ASSERT(infos.size <= (expected_size + name_len_ssize));
}
else {
UTEST_COMPARE_INT(expected_size, infos.size);
}
return NULL;
}
static const char* test_stl_infos()
{
2016-03-11 00:55:01 +08:00
const struct stl_read_testcase* testcase = stl_read_testcases_ptr();
while (testcase != stl_read_testcases_ptr_end()) {
const char* error = __tstl__test_stl_infos(testcase);
2016-03-11 00:55:01 +08:00
if (error != NULL) {
fprintf(stderr,
"\ntest_stl_infos()\n"
" filepath : %s\n"
" error : %s\n",
testcase->filepath, error);
return error;
2016-03-11 00:55:01 +08:00
}
++testcase;
}
return NULL;
}
static const char* test_stl_infos_github8()
{
const char* filepath = "models/solid_empty.stla";
struct gmio_stl_infos infos = {0};
infos.stla_solidname_maxlen = 512;
const int error = gmio_stl_infos_probe_file(
&infos, filepath, GMIO_STL_INFO_FLAG_ALL, NULL);
UTEST_COMPARE_INT(error, GMIO_STL_ERROR_INFO_NULL_SOLIDNAME);
return NULL;
}