tests: add new tests for gmio_stlb_header functions

This commit is contained in:
Hugues Delorme 2016-01-26 11:50:29 +01:00
parent 5605934628
commit 5969cad14b
4 changed files with 89 additions and 1 deletions

View File

@ -47,7 +47,7 @@ struct gmio_stlb_header gmio_stlb_header_str(const char* str);
/*! Copies \p header into C string \p str
*
* It replaces non-printable bytes with \p replacement char.
* \p str must be at least \c GMIO_STLB_HEADER_SIZE long, a terminating null
* \p str must be at least \c GMIO_STLB_HEADER_SIZE+1 long, a terminating null
* character ('\0') is copied at position \c GMIO_STLB_HEADER_SIZE
*/
GMIO_LIBSTL_EXPORT

View File

@ -55,6 +55,7 @@ set(GMIO_TEST_STL_SRC
test_stl_internal.c
test_stl_io.c
test_stl_infos.c
test_stlb_header.c
core_utils.c
stl_utils.c)
if(GMIO_BUILD_SHARED_LIBS)

View File

@ -18,11 +18,15 @@
const char* test_stl_internal__rw_common();
const char* test_stl_infos();
const char* test_stl_read();
const char* test_stla_write();
const char* test_stlb_write_header();
const char* test_stlb_write();
const char* test_stlb_header_str();
const char* test_stlb_header_to_printable_str();
const char* all_tests()
{
UTEST_SUITE_START();
@ -34,6 +38,8 @@ const char* all_tests()
UTEST_RUN(test_stla_write);
UTEST_RUN(test_stlb_write_header);
UTEST_RUN(test_stlb_write);
UTEST_RUN(test_stlb_header_str);
UTEST_RUN(test_stlb_header_to_printable_str);
return NULL;
}

81
tests/test_stlb_header.c Normal file
View File

@ -0,0 +1,81 @@
/****************************************************************************
** gmio
** Copyright Fougue (2 Mar. 2015)
** contact@fougue.pro
**
** 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_assert.h"
#include "../src/gmio_stl/stlb_header.h"
#include <string.h>
const char* test_stlb_header_str()
{
const struct gmio_stlb_header null = {0};
{
const struct gmio_stlb_header h = gmio_stlb_header_str("");
UTEST_ASSERT(memcmp(&h, &null, GMIO_STLB_HEADER_SIZE) == 0);
}
{
const char cstr[] = "gmio by Fougue";
const struct gmio_stlb_header h = gmio_stlb_header_str(cstr);
UTEST_COMPARE_CSTR((const char*)h.data, cstr);
UTEST_ASSERT(memcmp(
&h.data[sizeof(cstr)],
&null.data[sizeof(cstr)],
GMIO_STLB_HEADER_SIZE - sizeof(cstr))
== 0);
}
{
const char cstr[] = { /* size = 104(26*4) */
"abcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"
};
const struct gmio_stlb_header h = gmio_stlb_header_str(cstr);
UTEST_ASSERT(strncmp((const char*)h.data, cstr, GMIO_STLB_HEADER_SIZE)
== 0);
}
return NULL;
}
const char* test_stlb_header_to_printable_str()
{
{
const struct gmio_stlb_header null = {0};
char cstr[GMIO_STLB_HEADER_SIZE+1];
gmio_stlb_header_to_printable_str(&null, cstr, 0);
UTEST_ASSERT(memcmp(&cstr, &null, GMIO_STLB_HEADER_SIZE) == 0);
UTEST_COMPARE_UINT(strlen(cstr), 0);
}
{
char cstr[GMIO_STLB_HEADER_SIZE+1];
const char cstr_ab[] = "abcdefghijklmnopqrstuvwxyz";
const char cstr_ab_after_cpy[] = "abcde?ghijklmnopqrstuvwxyz";
struct gmio_stlb_header h = gmio_stlb_header_str(cstr_ab);
h.data[5] = 7; /* Bell */
gmio_stlb_header_to_printable_str(&h, cstr, '?');
UTEST_ASSERT(strncmp(cstr_ab_after_cpy,
cstr,
sizeof(cstr_ab_after_cpy) - 1)
== 0);
}
return NULL;
}