]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add tset get metadata from image
authorBastian Dehn <hhaalo@arcor.de>
Wed, 1 May 2024 11:30:31 +0000 (13:30 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 1 May 2024 11:30:31 +0000 (13:30 +0200)
src/kds_s2000w_image_converter.c
src/kds_s2000w_image_converter.h
tests/CMakeLists.txt
tests/kds_s2000w_image_converter_tests.c [new file with mode: 0644]
tests/kds_s2000w_image_converter_tests.h [new file with mode: 0644]
tests/kds_s2000w_image_converter_tests_run.c [new file with mode: 0644]

index ea4c37512ad0f390791d92d2253bd9c25dbf6607..0e01a1f2746d0d104c5d6da62b141b805386ad1a 100644 (file)
@@ -7,12 +7,6 @@
 #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,
@@ -72,4 +66,31 @@ void kds_s2000w_convert_tiff_to_pnm(blobdata* in, blobdata* out)
        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
index 3ab8b3df47070c4adee1bda570d6d0017194a887..01b47b6915ee9ed4b84e84df772ca90f35ff6699 100644 (file)
@@ -6,8 +6,13 @@ typedef struct {
        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
index 945e2a799ed6cfb0a0169e7ad3c88742a243380d..27576f66ce41bdd9018ad5147af03546df5d85dc 100644 (file)
@@ -40,24 +40,37 @@ TARGET_LINK_LIBRARIES("kds_s2000w_read_config_tests_run"
        ${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
diff --git a/tests/kds_s2000w_image_converter_tests.c b/tests/kds_s2000w_image_converter_tests.c
new file mode 100644 (file)
index 0000000..f34de5a
--- /dev/null
@@ -0,0 +1,64 @@
+#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
diff --git a/tests/kds_s2000w_image_converter_tests.h b/tests/kds_s2000w_image_converter_tests.h
new file mode 100644 (file)
index 0000000..6522e3d
--- /dev/null
@@ -0,0 +1,11 @@
+#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
diff --git a/tests/kds_s2000w_image_converter_tests_run.c b/tests/kds_s2000w_image_converter_tests_run.c
new file mode 100644 (file)
index 0000000..048b343
--- /dev/null
@@ -0,0 +1,13 @@
+#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