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
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-04 01:00:25 +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"
|
2016-01-21 23:11:45 +08:00
|
|
|
#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"
|
2015-12-04 01:00:25 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2016-02-12 18:55:39 +08:00
|
|
|
#include <string.h>
|
2015-12-04 01:00:25 +08:00
|
|
|
|
2016-06-16 16:29:27 +08:00
|
|
|
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;
|
2016-02-03 18:43:52 +08:00
|
|
|
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;
|
2015-12-04 01:00:25 +08:00
|
|
|
|
2016-02-03 18:43:52 +08:00
|
|
|
infos.stla_solidname = stla_solid_name;
|
|
|
|
infos.stla_solidname_maxlen = sizeof(stla_solid_name) - 1;
|
2016-07-13 17:46:28 +08:00
|
|
|
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);
|
2016-01-21 23:11:45 +08:00
|
|
|
}
|
|
|
|
else {
|
2016-01-29 19:47:01 +08:00
|
|
|
UTEST_COMPARE_INT(GMIO_STL_ERROR_UNKNOWN_FORMAT, error);
|
2016-01-21 23:11:45 +08:00
|
|
|
}
|
|
|
|
|
2016-03-11 00:55:01 +08:00
|
|
|
if (testcase->format == GMIO_STL_FORMAT_ASCII) {
|
2016-02-03 18:43:52 +08:00
|
|
|
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;
|
2016-02-03 18:43:52 +08:00
|
|
|
#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));
|
2016-02-03 18:43:52 +08:00
|
|
|
}
|
|
|
|
else {
|
2016-02-01 23:53:45 +08:00
|
|
|
UTEST_COMPARE_INT(expected_size, infos.size);
|
2016-02-03 18:43:52 +08:00
|
|
|
}
|
2014-02-13 19:02:40 +08:00
|
|
|
|
2016-01-21 23:11:45 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:29:27 +08:00
|
|
|
static const char* test_stl_infos()
|
2016-01-21 23:11:45 +08:00
|
|
|
{
|
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()) {
|
2016-06-16 16:29:27 +08:00
|
|
|
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);
|
2016-01-21 23:11:45 +08:00
|
|
|
return error;
|
2016-03-11 00:55:01 +08:00
|
|
|
}
|
|
|
|
++testcase;
|
2016-01-21 23:11:45 +08:00
|
|
|
}
|
2015-12-04 01:00:25 +08:00
|
|
|
return NULL;
|
|
|
|
}
|