#include "kds_s2000w_image_converter.h"
#include "kds_s2000w_debug.h"
-void kds_s2000w_convert_terminate()
-{
- debug_printf(ALL, "kds_s2000w_convert_terminate");
- MagickCoreTerminus();
-}
-
void kds_s2000w_convert_to_pnm_with_depth(blobdata* in,
blobdata* out,
int depth,
const char* extension = "tiff";
debug_printf(ALL, "kds_s2000w_convert_tiff_to_pnm");
kds_s2000w_convert_to_pnm_with_depth(in, out, -1, extension);
+}
+
+void kds_s2000w_metadata_from_image(blobdata* image, image_metadata* mdata)
+{
+ debug_printf(ALL, "kds_s2000w_metadata_from_image");
+ ExceptionInfo* exception = NULL;
+ Image* input_image = NULL;
+ ImageInfo* image_info = NULL;
+
+ exception = AcquireExceptionInfo();
+ image_info = CloneImageInfo(NULL);
+ sprintf(image_info->filename, "image.pnm");
+
+ input_image = BlobToImage(image_info, image->data, image->size , exception);
+
+ if (exception->severity != UndefinedException) {
+ fprintf(stderr, "%s\n", GetExceptionMessage(exception->error_number));
+ CatchException(exception);
+ }
+
+ mdata->width = input_image->columns;
+ mdata->height = input_image->rows;
+ mdata->depth = input_image->depth;
+
+ DestroyImageInfo(image_info);
+ DestroyImage(input_image);
+ DestroyExceptionInfo(exception);
}
\ No newline at end of file
void* data;
} blobdata;
-void kds_s2000w_convert_terminate();
+typedef struct {
+ int width;
+ int height;
+ int depth;
+} image_metadata;
void kds_s2000w_convert_jpg_to_pnm_with_depth(blobdata* in, blobdata* out, int depth);
void kds_s2000w_convert_tiff_to_pnm(blobdata* in, blobdata* out);
+void kds_s2000w_metadata_from_image(blobdata* image, image_metadata* mdata);
#endif
\ No newline at end of file
${CMOCKA_LIBRARY}
sane-kds_s2000w_net)
+ADD_EXECUTABLE("kds_s2000w_image_converter_tests_run"
+ "kds_s2000w_image_converter_tests_run.c"
+ "kds_s2000w_image_converter_tests.c"
+ "kds_s2000w_client_mock.c")
+ADD_DEPENDENCIES("kds_s2000w_image_converter_tests_run" sane-kds_s2000w_net)
+TARGET_LINK_LIBRARIES("kds_s2000w_image_converter_tests_run"
+ ${CMOCKA_LIBRARY}
+ sane-kds_s2000w_net)
+
INCLUDE(CTest)
ENABLE_TESTING()
ADD_TEST(NAME "kds_s2000w_net_get_opt_tests_run"
- COMMAND "./kds_s2000w_net_get_opt_tests_run")
+ COMMAND "kds_s2000w_net_get_opt_tests_run")
ADD_TEST(NAME "kds_s2000w_net_read_tests_run"
- COMMAND "./kds_s2000w_net_read_tests_run")
+ COMMAND "kds_s2000w_net_read_tests_run")
ADD_TEST(NAME "kds_s2000w_net_tests_run"
COMMAND "kds_s2000w_net_tests_run")
ADD_TEST(NAME "kds_s2000w_read_config_tests_run"
COMMAND "kds_s2000w_read_config_tests_run")
+ADD_TEST(NAME "kds_s2000w_converter_tests_run"
+ COMMAND "kds_s2000w_image_converter_tests_run")
ADD_CUSTOM_TARGET("runningtests"
ALL "ctest" "--verbose"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS "kds_s2000w_read_config_tests_run"
+ DEPENDS "kds_s2000w_net_get_opt_tests_run"
+ "kds_s2000w_net_read_tests_run"
"kds_s2000w_net_tests_run"
- "kds_s2000w_net_read_tests_run")
+ "kds_s2000w_read_config_tests_run"
+ "kds_s2000w_image_converter_tests_run")
ADD_CUSTOM_TARGET("generate_gcov_coverage"
ALL gcov ${CMAKE_BINARY_DIR}/src/CMakeFiles/sane-kds_s2000w_net.dir/*.c.o
--- /dev/null
+#include <stdlib.h>
+#include "../src/kds_s2000w_config.h"
+#include "../src/kds_s2000w_image_converter.h"
+#include "kds_s2000w_client_mock.h"
+#include "kds_s2000w_image_converter_tests.h"
+
+void __wrap_load_config(program_config* config, const char* config_stream)
+{
+ config->scanner_url = malloc(sizeof(char) * 28);
+ config->username = malloc(sizeof(char) * 4);
+
+ config->scanner_url = "https://scanner.example.com\0";
+ config->username = "Max\0";
+}
+
+void __wrap_kds_s2000w_convert_tiff_to_pnm(blobdata* in, blobdata* out)
+{
+ return;
+}
+
+void __wrap_wait_a_second()
+{
+ return;
+}
+
+
+void get_metadata_from_image_test()
+{
+ blobdata* image = malloc(sizeof(blobdata));
+ image->data = malloc(sizeof(char) * 17);
+ image->size = 17;
+ char* image_data = (char*) image->data;
+ image_data[0] = 0x50;
+ image_data[1] = 0x36;
+ image_data[2] = 0x0a;
+ image_data[3] = 0x32;
+ image_data[4] = 0x20;
+ image_data[5] = 0x31;
+ image_data[6] = 0x0a;
+ image_data[7] = 0x32;
+ image_data[8] = 0x35;
+ image_data[9] = 0x35;
+ image_data[10] = 0x0a;
+ for (int i = 11; i < 17; i++) {
+ image_data[i] = 0xff;
+ }
+ image_metadata* mdata = malloc(sizeof(image_metadata));
+ mdata->width = 0;
+ mdata->height = 0;
+ mdata->depth = 0;
+
+ kds_s2000w_metadata_from_image(image, mdata);
+
+ assert_int_equal(mdata->width, 2);
+ assert_int_equal(mdata->height, 1);
+ assert_int_equal(mdata->depth, 8);
+
+ free(image->data);
+ image->data = NULL;
+ free(image);
+ image = NULL;
+ free(mdata);
+ mdata = NULL;
+}
\ No newline at end of file
--- /dev/null
+#ifndef KDS_S2000W_IMAGE_CONVERTER_TESTS_H
+#define KDS_S2000W_IMAGE_CONVERTER_TESTS_H
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+void get_metadata_from_image_test();
+
+#endif
\ No newline at end of file
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include "kds_s2000w_client_mock.h"
+#include "kds_s2000w_image_converter_tests.h"
+
+int main()
+{
+ const struct CMUnitTest converter_tests[] = {
+ cmocka_unit_test(get_metadata_from_image_test)
+ };
+
+ return cmocka_run_group_tests(converter_tests, NULL, NULL);
+}
\ No newline at end of file