Add more unit tests
This commit is contained in:
parent
fc25ac6fb3
commit
99991b0287
@ -53,6 +53,7 @@ const char* all_tests()
|
||||
UTEST_RUN(test_amf_write_doc_1_zip);
|
||||
UTEST_RUN(test_amf_write_doc_1_zip64);
|
||||
UTEST_RUN(test_amf_write_doc_1_zip64_file);
|
||||
UTEST_RUN(test_amf_write_doc_1_task_iface);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ const char* all_tests()
|
||||
UTEST_RUN(test_internal__fast_atof);
|
||||
UTEST_RUN(test_internal__locale_utils);
|
||||
UTEST_RUN(test_internal__error_check);
|
||||
UTEST_RUN(test_internal__itoa);
|
||||
UTEST_RUN(test_internal__ostringstream);
|
||||
UTEST_RUN(test_internal__safe_cast);
|
||||
UTEST_RUN(test_internal__stringstream);
|
||||
|
@ -45,30 +45,28 @@
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
struct __tamf__material
|
||||
{
|
||||
struct __tamf__material {
|
||||
double color[3];
|
||||
const char* name;
|
||||
};
|
||||
|
||||
struct __tamf__triangle
|
||||
{
|
||||
struct __tamf__triangle {
|
||||
uint32_t vertex[3];
|
||||
};
|
||||
|
||||
struct __tamf__mesh
|
||||
{
|
||||
struct __tamf__mesh {
|
||||
const struct gmio_vec3d* vec_vertex;
|
||||
uint32_t vertex_count;
|
||||
const struct __tamf__triangle* vec_triangle;
|
||||
uint32_t triangle_count;
|
||||
};
|
||||
|
||||
struct __tamf__document
|
||||
{
|
||||
struct __tamf__document {
|
||||
const struct __tamf__material* vec_material;
|
||||
uint32_t material_count;
|
||||
uint32_t instance_count;
|
||||
struct __tamf__mesh mesh;
|
||||
const struct gmio_amf_instance* vec_instance;
|
||||
};
|
||||
|
||||
static void __tamf__get_document_element(
|
||||
@ -101,12 +99,31 @@ static void __tamf__get_document_element(
|
||||
case GMIO_AMF_DOCUMENT_ELEMENT_TEXTURE:
|
||||
break;
|
||||
case GMIO_AMF_DOCUMENT_ELEMENT_CONSTELLATION:
|
||||
if (element_index == 0) {
|
||||
struct gmio_amf_constellation* ptr_constellation =
|
||||
(struct gmio_amf_constellation*)ptr_element;
|
||||
ptr_constellation->id = element_index;
|
||||
ptr_constellation->instance_count = doc->instance_count;
|
||||
ptr_constellation->metadata_count = 0;
|
||||
}
|
||||
break;
|
||||
case GMIO_AMF_DOCUMENT_ELEMENT_METADATA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void __tamf__get_constellation_instance(
|
||||
const void* cookie,
|
||||
uint32_t constellation_index,
|
||||
uint32_t instance_index,
|
||||
struct gmio_amf_instance* ptr_instance)
|
||||
{
|
||||
const struct __tamf__document* doc =
|
||||
(const struct __tamf__document*)cookie;
|
||||
if (constellation_index == 0)
|
||||
*ptr_instance = doc->vec_instance[instance_index];
|
||||
}
|
||||
|
||||
static void __tamf__get_object_mesh(
|
||||
const void* cookie,
|
||||
uint32_t object_index,
|
||||
@ -216,11 +233,21 @@ const struct __tamf__triangle __tamf__doc_1_triangles[] = {
|
||||
{ 3, 5, 2}
|
||||
};
|
||||
|
||||
const struct gmio_amf_instance __tamf__doc_1_instances[] = {
|
||||
{ 0, {0}, {0} },
|
||||
{ 1, {10, 0, 0}, { 45, 0, 0} },
|
||||
{ 2, {0, 10, 0}, { 0, 45, 0} },
|
||||
{ 3, {0, 0, 10}, { 0, 0, 45} },
|
||||
{ 4, {10, 10, 0}, { 45, 45, 0} },
|
||||
};
|
||||
|
||||
struct __tamf__document __tamf__create_doc_1()
|
||||
{
|
||||
struct __tamf__document doc = {0};
|
||||
doc.vec_material = __tamf__doc_1_materials;
|
||||
doc.vec_instance = __tamf__doc_1_instances;
|
||||
doc.material_count = GMIO_ARRAY_SIZE(__tamf__doc_1_materials);
|
||||
doc.instance_count = GMIO_ARRAY_SIZE(__tamf__doc_1_instances);
|
||||
doc.mesh.vec_vertex = __tamf__doc_1_vertices;
|
||||
doc.mesh.vertex_count = GMIO_ARRAY_SIZE(__tamf__doc_1_vertices);
|
||||
doc.mesh.vec_triangle = __tamf__doc_1_triangles;
|
||||
@ -235,6 +262,7 @@ struct gmio_amf_document __tamf_create_doc(
|
||||
doc.cookie = testdoc;
|
||||
doc.unit = GMIO_AMF_UNIT_MILLIMETER;
|
||||
doc.func_get_document_element = __tamf__get_document_element;
|
||||
doc.func_get_constellation_instance = __tamf__get_constellation_instance;
|
||||
doc.func_get_object_mesh = __tamf__get_object_mesh;
|
||||
doc.func_get_object_mesh_element = __tamf__get_object_mesh_element;
|
||||
doc.func_get_object_mesh_volume_triangle =
|
||||
@ -243,6 +271,7 @@ struct gmio_amf_document __tamf_create_doc(
|
||||
__tamf__get_document_element_metadata;
|
||||
doc.object_count = 1;
|
||||
doc.material_count = testdoc->material_count;
|
||||
doc.constellation_count = testdoc->instance_count > 0 ? 1 : 0;
|
||||
return doc;
|
||||
}
|
||||
|
||||
@ -450,3 +479,60 @@ static const char* test_amf_write_doc_1_zip64_file()
|
||||
UTEST_COMPARE_INT(error, GMIO_ERROR_OK);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct __tamf__task {
|
||||
intmax_t max_value;
|
||||
intmax_t current_value;
|
||||
intmax_t trigger_stop_value;
|
||||
bool progress_error;
|
||||
};
|
||||
|
||||
static bool __tamf__is_stop_requested(void* cookie)
|
||||
{
|
||||
struct __tamf__task* task = (struct __tamf__task*)cookie;
|
||||
return task->current_value >= task->trigger_stop_value;
|
||||
}
|
||||
|
||||
static void __tamf__handle_progress(
|
||||
void* cookie, intmax_t value, intmax_t max_value)
|
||||
{
|
||||
struct __tamf__task* task = (struct __tamf__task*)cookie;
|
||||
if (task->current_value > value)
|
||||
task->progress_error = true;
|
||||
task->current_value = value;
|
||||
task->max_value = max_value;
|
||||
}
|
||||
|
||||
static const char* test_amf_write_doc_1_task_iface()
|
||||
{
|
||||
static const size_t wbuffsize = 8192;
|
||||
struct gmio_rw_buffer wbuff = {0};
|
||||
wbuff.ptr = calloc(wbuffsize, 1);
|
||||
wbuff.len = wbuffsize;
|
||||
const struct __tamf__document testdoc = __tamf__create_doc_1();
|
||||
const struct gmio_amf_document doc = __tamf_create_doc(&testdoc);
|
||||
struct gmio_amf_write_options options = {0};
|
||||
struct __tamf__task task = {0};
|
||||
options.task_iface.cookie = &task;
|
||||
options.task_iface.func_handle_progress = __tamf__handle_progress;
|
||||
{
|
||||
const int error = __tamf__write_amf(&wbuff, &doc, &options);
|
||||
UTEST_COMPARE_INT(error, GMIO_ERROR_OK);
|
||||
UTEST_ASSERT(!task.progress_error);
|
||||
UTEST_COMPARE_INT(task.current_value, task.max_value);
|
||||
printf("\n-- Info: max_value=%d\n", task.max_value);
|
||||
}
|
||||
|
||||
uint8_t memblock[256] = {0};
|
||||
options.stream_memblock = gmio_memblock(&memblock, sizeof(memblock), NULL);
|
||||
task.trigger_stop_value = task.max_value / 2;
|
||||
options.task_iface.func_is_stop_requested = __tamf__is_stop_requested;
|
||||
{
|
||||
const int error = __tamf__write_amf(&wbuff, &doc, &options);
|
||||
UTEST_COMPARE_INT(error, GMIO_ERROR_TASK_STOPPED);
|
||||
UTEST_ASSERT(task.current_value < task.max_value);
|
||||
}
|
||||
|
||||
free(wbuff.ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "../src/gmio_core/internal/fast_atof.h"
|
||||
#include "../src/gmio_core/internal/file_utils.h"
|
||||
#include "../src/gmio_core/internal/helper_stream.h"
|
||||
#include "../src/gmio_core/internal/itoa.h"
|
||||
#include "../src/gmio_core/internal/locale_utils.h"
|
||||
#include "../src/gmio_core/internal/numeric_utils.h"
|
||||
#include "../src/gmio_core/internal/ostringstream.h"
|
||||
@ -848,19 +849,22 @@ static const char* test_internal__zip_utils()
|
||||
|
||||
static const char* test_internal__zlib_enumvalues()
|
||||
{
|
||||
struct __int_pair { int v1; int v2; };
|
||||
static const struct __int_pair enumConst[] = {
|
||||
/* enum gmio_zlib_compress_level */
|
||||
UTEST_COMPARE_INT(Z_BEST_SPEED, GMIO_ZLIB_COMPRESS_LEVEL_BEST_SPEED);
|
||||
UTEST_COMPARE_INT(Z_BEST_COMPRESSION, GMIO_ZLIB_COMPRESS_LEVEL_BEST_SIZE);
|
||||
UTEST_COMPARE_INT(0, GMIO_ZLIB_COMPRESS_LEVEL_DEFAULT);
|
||||
UTEST_COMPARE_INT(-1, GMIO_ZLIB_COMPRESS_LEVEL_NONE);
|
||||
|
||||
{ Z_BEST_SPEED, GMIO_ZLIB_COMPRESS_LEVEL_BEST_SPEED },
|
||||
{ Z_BEST_COMPRESSION, GMIO_ZLIB_COMPRESS_LEVEL_BEST_SIZE },
|
||||
{ 0, GMIO_ZLIB_COMPRESS_LEVEL_DEFAULT },
|
||||
{ -1, GMIO_ZLIB_COMPRESS_LEVEL_NONE },
|
||||
/* enum gmio_zlib_compress_strategy */
|
||||
UTEST_COMPARE_INT(Z_DEFAULT_STRATEGY, GMIO_ZLIB_COMPRESSION_STRATEGY_DEFAULT);
|
||||
UTEST_COMPARE_INT(Z_FILTERED, GMIO_ZLIB_COMPRESSION_STRATEGY_FILTERED);
|
||||
UTEST_COMPARE_INT(Z_HUFFMAN_ONLY, GMIO_ZLIB_COMPRESSION_STRATEGY_HUFFMAN_ONLY);
|
||||
UTEST_COMPARE_INT(Z_RLE, GMIO_ZLIB_COMPRESSION_STRATEGY_RLE);
|
||||
UTEST_COMPARE_INT(Z_FIXED, GMIO_ZLIB_COMPRESSION_STRATEGY_FIXED);
|
||||
|
||||
{ Z_DEFAULT_STRATEGY, GMIO_ZLIB_COMPRESSION_STRATEGY_DEFAULT },
|
||||
{ Z_FILTERED, GMIO_ZLIB_COMPRESSION_STRATEGY_FILTERED },
|
||||
{ Z_HUFFMAN_ONLY, GMIO_ZLIB_COMPRESSION_STRATEGY_HUFFMAN_ONLY },
|
||||
{ Z_RLE, GMIO_ZLIB_COMPRESSION_STRATEGY_RLE },
|
||||
{ Z_FIXED, GMIO_ZLIB_COMPRESSION_STRATEGY_FIXED }
|
||||
};
|
||||
for (size_t i = 0; i < GMIO_ARRAY_SIZE(enumConst); ++i)
|
||||
UTEST_COMPARE_INT(enumConst[i].v1, enumConst[i].v2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -897,3 +901,35 @@ static const char* test_internal__file_utils()
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* test_internal__itoa()
|
||||
{
|
||||
char buff[512] = {0};
|
||||
{
|
||||
gmio_u32toa(0, buff);
|
||||
UTEST_COMPARE_CSTR("0", buff);
|
||||
gmio_u32toa(100, buff);
|
||||
UTEST_COMPARE_CSTR("100", buff);
|
||||
gmio_u32toa(UINT32_MAX, buff);
|
||||
UTEST_COMPARE_CSTR("4294967295", buff);
|
||||
|
||||
memset(buff, 0, sizeof(buff));
|
||||
gmio_i32toa(0, buff);
|
||||
UTEST_COMPARE_CSTR("0", buff);
|
||||
gmio_i32toa(-100, buff);
|
||||
UTEST_COMPARE_CSTR("-100", buff);
|
||||
}
|
||||
#ifdef GMIO_HAVE_INT64_TYPE
|
||||
{
|
||||
uint64_t u64 = UINT32_MAX;
|
||||
u64 += UINT32_MAX;
|
||||
gmio_u64toa(u64, buff);
|
||||
UTEST_COMPARE_CSTR("8589934590", buff);
|
||||
|
||||
const int64_t i64 = -1 * u64;
|
||||
gmio_i64toa(i64, buff);
|
||||
UTEST_COMPARE_CSTR("-8589934590", buff);
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user