tests: add test_core
This commit is contained in:
parent
f052c09053
commit
edff3f77f8
@ -37,6 +37,11 @@ add_executable(
|
|||||||
add_executable(
|
add_executable(
|
||||||
test_platform EXCLUDE_FROM_ALL test_platform.c)
|
test_platform EXCLUDE_FROM_ALL test_platform.c)
|
||||||
|
|
||||||
|
# test_core
|
||||||
|
add_executable(
|
||||||
|
test_core EXCLUDE_FROM_ALL test_core.c)
|
||||||
|
target_link_libraries(test_core gmio)
|
||||||
|
|
||||||
# test_stl
|
# test_stl
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/models
|
||||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
@ -61,10 +66,12 @@ endif()
|
|||||||
# Declare tests
|
# Declare tests
|
||||||
add_test(test_internal test_internal)
|
add_test(test_internal test_internal)
|
||||||
add_test(test_platform test_platform)
|
add_test(test_platform test_platform)
|
||||||
|
add_test(test_core test_core)
|
||||||
add_test(test_stl test_stl)
|
add_test(test_stl test_stl)
|
||||||
|
|
||||||
add_dependencies(
|
add_dependencies(
|
||||||
check
|
check
|
||||||
test_internal
|
test_internal
|
||||||
test_platform
|
test_platform
|
||||||
|
test_core
|
||||||
test_stl)
|
test_stl)
|
||||||
|
117
tests/test_core.c
Normal file
117
tests/test_core.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
** 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_lib.h"
|
||||||
|
|
||||||
|
#include "../src/gmio_core/buffer.h"
|
||||||
|
#include "../src/gmio_core/endian.h"
|
||||||
|
#include "../src/gmio_core/error.h"
|
||||||
|
#include "../src/gmio_core/stream.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static gmio_buffer_t buffer_ctor()
|
||||||
|
{
|
||||||
|
return gmio_buffer_calloc(4, 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* test_core__buffer()
|
||||||
|
{
|
||||||
|
/* gmio_buffer_calloc() */
|
||||||
|
{
|
||||||
|
const size_t obj_count = 4;
|
||||||
|
const size_t obj_size = 256;
|
||||||
|
const size_t buff_size = obj_count * obj_size;
|
||||||
|
const uint8_t zero_buff[4 * 256] = { 0 };
|
||||||
|
gmio_buffer_t buff = gmio_buffer_calloc(obj_count, obj_size);
|
||||||
|
UTEST_ASSERT(buff.ptr != NULL);
|
||||||
|
UTEST_ASSERT(buff.size == buff_size);
|
||||||
|
UTEST_ASSERT(memcmp(buff.ptr, &zero_buff[0], buff_size) == 0);
|
||||||
|
UTEST_ASSERT(buff.func_deallocate == &free);
|
||||||
|
gmio_buffer_deallocate(&buff);
|
||||||
|
}
|
||||||
|
/* gmio_buffer_malloc() */
|
||||||
|
{
|
||||||
|
const size_t buff_size = 2 * 1024; /* 2KB */
|
||||||
|
gmio_buffer_t buff = gmio_buffer_malloc(buff_size);
|
||||||
|
UTEST_ASSERT(buff.ptr != NULL);
|
||||||
|
UTEST_ASSERT(buff.size == buff_size);
|
||||||
|
UTEST_ASSERT(buff.func_deallocate == &free);
|
||||||
|
gmio_buffer_deallocate(&buff);
|
||||||
|
}
|
||||||
|
/* gmio_buffer_realloc() */
|
||||||
|
{
|
||||||
|
const size_t buff_size = 1024; /* 1KB */
|
||||||
|
gmio_buffer_t buff = gmio_buffer_malloc(buff_size);
|
||||||
|
buff = gmio_buffer_realloc(buff.ptr, 2 * buff_size);
|
||||||
|
UTEST_ASSERT(buff.ptr != NULL);
|
||||||
|
UTEST_ASSERT(buff.size == (2 * buff_size));
|
||||||
|
UTEST_ASSERT(buff.func_deallocate == &free);
|
||||||
|
gmio_buffer_deallocate(&buff);
|
||||||
|
}
|
||||||
|
/* default ctor */
|
||||||
|
{
|
||||||
|
UTEST_ASSERT(gmio_buffer_default_constructor() != NULL);
|
||||||
|
gmio_buffer_set_default_constructor(&buffer_ctor);
|
||||||
|
UTEST_ASSERT(gmio_buffer_default_constructor() == &buffer_ctor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* test_core__endian()
|
||||||
|
{
|
||||||
|
UTEST_ASSERT(gmio_host_endianness() == GMIO_ENDIANNESS_HOST);
|
||||||
|
UTEST_ASSERT(GMIO_ENDIANNESS_LITTLE != GMIO_ENDIANNESS_BIG);
|
||||||
|
UTEST_ASSERT(GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_LITTLE
|
||||||
|
|| GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_BIG);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* test_core__error()
|
||||||
|
{
|
||||||
|
UTEST_ASSERT(gmio_no_error(GMIO_ERROR_OK));
|
||||||
|
UTEST_ASSERT(!gmio_error(GMIO_ERROR_OK));
|
||||||
|
|
||||||
|
UTEST_ASSERT(!gmio_no_error(GMIO_ERROR_UNKNOWN));
|
||||||
|
UTEST_ASSERT(gmio_error(GMIO_ERROR_UNKNOWN));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* test_core__stream()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
const gmio_stream_t null_stream = gmio_stream_null();
|
||||||
|
const uint8_t null_bytes[sizeof(gmio_stream_t)] = { 0 };
|
||||||
|
UTEST_ASSERT(memcmp(&null_stream, &null_bytes, sizeof(gmio_stream_t))
|
||||||
|
== 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* all_tests()
|
||||||
|
{
|
||||||
|
UTEST_SUITE_START();
|
||||||
|
UTEST_RUN(test_core__buffer);
|
||||||
|
UTEST_RUN(test_core__endian);
|
||||||
|
UTEST_RUN(test_core__error);
|
||||||
|
UTEST_RUN(test_core__stream);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
UTEST_MAIN(all_tests)
|
Loading…
Reference in New Issue
Block a user