131 lines
3.2 KiB
C++
131 lines
3.2 KiB
C++
#include <archives/binary.hpp>
|
|
#include <CUnit/Basic.h>
|
|
#include "../image.h"
|
|
#include "../streamingview.hpp"
|
|
#include "../util.h"
|
|
#include <cwalk.h>
|
|
#ifdef __cplusplus
|
|
#include <iostream>
|
|
#endif // __cplusplus
|
|
|
|
#define STRLEN 2048
|
|
|
|
FILE *imageHandle = NULL;
|
|
char frame1Path[STRLEN];
|
|
|
|
#define HERE __FILE__
|
|
|
|
int setUp(void)
|
|
{
|
|
char framesDir[STRLEN];
|
|
size_t length;
|
|
cwk_path_get_dirname(HERE, &length); // archimedes_mobile_lib/src/tests
|
|
cwk_path_join(HERE, "../../../assets/test/frames", framesDir, STRLEN);
|
|
cwk_path_join(framesDir, "0001.png", frame1Path, STRLEN);
|
|
printf("Opening file %s\n", frame1Path);
|
|
return 0;
|
|
}
|
|
|
|
int tearDown(void)
|
|
{
|
|
if (imageHandle)
|
|
{
|
|
fclose(imageHandle);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void test_create_frame(void)
|
|
{
|
|
imageHandle = fopen(frame1Path, "rw+");
|
|
const Frame *f = new_frame_from_handle(
|
|
imageHandle,
|
|
768,
|
|
768,
|
|
64);
|
|
CU_ASSERT_PTR_NOT_NULL(f->stream);
|
|
CU_ASSERT(f->w == 768);
|
|
}
|
|
|
|
void test_frame_from_data(void)
|
|
{
|
|
uint8_t *contents = NULL;
|
|
size_t len = read_file(frame1Path, &contents);
|
|
const Frame *f = new_frame_from_data(contents, len, 768, 768, 64);
|
|
CU_ASSERT_PTR_NOT_NULL(f->stream);
|
|
CU_ASSERT(f->w == 768);
|
|
}
|
|
|
|
void test_archimedes_get_data(void)
|
|
{
|
|
imageHandle = fopen(frame1Path, "rw+");
|
|
const Frame *f = new_frame_from_handle(
|
|
imageHandle,
|
|
768,
|
|
768,
|
|
64);
|
|
|
|
unsigned char *image_data = NULL;
|
|
size_t image_data_len = 0;
|
|
ImageResult *result = archimedes_get_image_data(f);
|
|
CU_ASSERT_FALSE(result->error);
|
|
CU_ASSERT_PTR_NOT_NULL(result->data);
|
|
CU_ASSERT_TRUE(result->data_len > 0);
|
|
}
|
|
|
|
void test_archimedes_streamed_view(void)
|
|
{
|
|
return ;
|
|
imageHandle = fopen(frame1Path, "rw+");
|
|
Frame *f = new_frame_from_handle(
|
|
imageHandle,
|
|
768,
|
|
768,
|
|
64);
|
|
|
|
const libdart_openmvg::StreamingView view(f);
|
|
|
|
std::stringbuf buffer; // empty stringbuf
|
|
|
|
std::ostream os(&buffer); // associate stream buffer to stream
|
|
std::istream is(&buffer); // associate stream buffer to stream
|
|
|
|
cereal::BinaryInputArchive inArchive(is);
|
|
cereal::BinaryOutputArchive outArchive(os);
|
|
|
|
// view.save(outArchive);
|
|
view.load(inArchive);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
CU_pSuite pSuite = NULL;
|
|
|
|
/* initialize the CUnit test registry */
|
|
if (CUE_SUCCESS != CU_initialize_registry())
|
|
return CU_get_error();
|
|
|
|
/* add a suite to the registry */
|
|
pSuite = CU_add_suite("ImageSuite", setUp, tearDown);
|
|
if (NULL == pSuite)
|
|
{
|
|
CU_cleanup_registry();
|
|
return CU_get_error();
|
|
}
|
|
|
|
/* add the tests to the suite */
|
|
if ((NULL == CU_add_test(pSuite, "frame can be created", test_create_frame)) ||
|
|
(NULL == CU_add_test(pSuite, "frame can be created from data", test_frame_from_data)) ||
|
|
(NULL == CU_add_test(pSuite, "data can be retrieved from frame", test_archimedes_get_data)) ||
|
|
(NULL == CU_add_test(pSuite, "Streaming view can read & write data", test_archimedes_streamed_view)))
|
|
{
|
|
CU_cleanup_registry();
|
|
return CU_get_error();
|
|
}
|
|
|
|
/* Run all tests using the CUnit Basic interface */
|
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
|
CU_basic_run_tests();
|
|
CU_cleanup_registry();
|
|
return CU_get_error();
|
|
} |