test lib at c level.

This commit is contained in:
Jordan
2024-03-11 18:09:11 -07:00
parent 29483913d6
commit 330c72acbb
12 changed files with 236 additions and 23 deletions
+39 -7
View File
@@ -2,6 +2,9 @@
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)
project(archimedes_mobile_lib_library VERSION 0.0.1 LANGUAGES CXX)
enable_language(CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
function(dump_cmake_variables)
@@ -27,7 +30,6 @@ function(dump_cmake_variables)
endforeach()
endfunction()
project(archimedes_mobile_lib_library VERSION 0.0.1 LANGUAGES CXX)
set (OPENMVG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/src)
set (FFMPEG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../ffmpeg_install/include)
@@ -37,17 +39,17 @@ find_package(
REQUIRED
)
find_package(JPEG REQUIRED)
find_package(TIFF REQUIRED)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extlib/cwalk)
set(PNG_SHARED ON CACHE BOOL "" FORCE)
set(PNG_STATIC OFF CACHE BOOL "" FORCE)
set(PNG_EXECUTABLES OFF CACHE BOOL "" FORCE) # we only want lib
set(PNG_TESTS OFF CACHE BOOL "" FORCE) # we only want lib
set(SKIP_INSTALL_ALL OFF CACHE BOOL "" FORCE) # we only want lib
# find_package(PNG
# REQUIRED
# HINTS "../"
# )
add_definitions(${PNG_DEFINITIONS})
add_library(archimedes_mobile_lib SHARED
@@ -55,12 +57,15 @@ add_library(archimedes_mobile_lib SHARED
)
dump_cmake_variables("^png")
# dump_cmake_variables("")
message("LIBRARIES:" ${OpenMVG_LIBRARIES})
target_link_libraries(
archimedes_mobile_lib
cwalk
jpeg
tiff
${CMAKE_CURRENT_SOURCE_DIR}/../../libpng/_install/lib/libpng16.so
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_image.a
${OPENMVG_LIBRARIES}
@@ -78,7 +83,34 @@ set_target_properties(archimedes_mobile_lib
PUBLIC_HEADER image.h
OUTPUT_NAME "archimedes_mobile_lib"
)
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bstatic")
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bdynamic")
add_executable(
test_image
${CMAKE_CURRENT_SOURCE_DIR}/tests/test_image.cxx
)
target_link_libraries(
test_image
cunit
cwalk
archimedes_mobile_lib
${CMAKE_CURRENT_SOURCE_DIR}/../../libpng/_install/lib/libpng16.so
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_image.a
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_features.a
${OPENMVG_LIBRARIES}
)
set_target_properties(test_image
PROPERTIES
LINKER_LANGUAGE CXX
)
add_test (
NAME test_image
COMMAND test_image
)
target_compile_definitions(archimedes_mobile_lib PUBLIC DART_SHARED_LIB)
+1
Submodule src/extlib/cwalk added at f418404bf3
+1 -1
View File
@@ -17,7 +17,7 @@ const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
FILE *make_buffer(const uint8_t *data, const size_t data_len)
{
FILE *file = fmemopen((char *)data, data_len, "r+");
FILE *file = fmemopen((void *) data, data_len, "r+");
if (file == NULL)
{
+13 -1
View File
@@ -13,7 +13,14 @@
#include <stdint.h>
#include <png.h>
extern "C" auto png_sig_cm = png_sig_cmp;
#if defined(__cplusplus)
extern "C" {
auto png_sig_cm = png_sig_cmp;
}
#endif // __cplusplus
typedef struct _Frame
{
@@ -23,6 +30,11 @@ typedef struct _Frame
int depth;
} Frame;
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
const Frame *new_frame_from_handle(FILE *, int, int, int);
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
+126
View File
@@ -0,0 +1,126 @@
#include <CUnit/Basic.h>
#include "image.h"
#include <cwalk.h>
#define STRLEN 2048
FILE *imageHandle = NULL;
char frame1Path[STRLEN];
/*
* Read the contents of a file into an array
* path: path to the file
* contents: array we'll write to that contains the contents of the file.
*/
size_t read_file(const char *path, uint8_t **contents) {
FILE *file = fopen(path, "rb");
if (file == NULL) {
printf("Error: Unable to open file.\n");
return 0;
}
// Determine the file size
fseek(file, 0, SEEK_END);
size_t file_size = ftell(file);
rewind(file);
// Allocate memory for the contents array
*contents = (uint8_t *) malloc(file_size);
if (*contents == NULL) {
printf("Error: Unable to allocate memory.\n");
fclose(file);
return 0;
}
// Read the file contents into the array
fread(*contents, 1, file_size, file);
fclose(file);
return file_size;
}
int setUp(void)
{
char framesDir[STRLEN];
char *here = __FILE__;
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;
archimedes_get_image_data(f, image_data);
CU_ASSERT_PTR_NOT_NULL(image_data);
}
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)))
{
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();
}