]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add type check tiff test with bool
authorBastian Dehn <hhaalo@arcor.de>
Sun, 9 Feb 2025 18:08:50 +0000 (19:08 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 9 Feb 2025 18:13:11 +0000 (19:13 +0100)
src/kds_s2000w_image_type_check.c
src/kds_s2000w_image_type_check.h
tests/CMakeLists.txt
tests/kds_s2000w_image_type_check_tests.c [new file with mode: 0644]
tests/kds_s2000w_image_type_check_tests.h [new file with mode: 0644]
tests/kds_s2000w_image_type_check_tests_run.c [new file with mode: 0644]

index f405ca652ba90c35055a182eee3f12873af8b9b5..95773e19d88eeb9072eb7946c62937cec5e634a5 100644 (file)
@@ -1,8 +1,9 @@
 #include <string.h>
+
 #include "kds_s2000w_debug.h"
 #include "kds_s2000w_image_type_check.h"
 
-uint8_t kds_s2000w_image_type_check_is_tiff(blobdata* image)
+bool kds_s2000w_image_type_check_is_tiff(blobdata* image)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_is_tiff");
 
@@ -11,7 +12,7 @@ uint8_t kds_s2000w_image_type_check_is_tiff(blobdata* image)
 
        char* image_data = (char*) image->data;
 
-       uint8_t result = image_data[0] == (char)0x49;
+       bool result = image_data[0] == (char)0x49;
        result = result && image_data[1] == (char)0x49;
        result = result && image_data[2] == (char)0x2A;
        result = result && image_data[3] == (char)0x00;
@@ -25,7 +26,7 @@ uint8_t kds_s2000w_image_type_check_is_tiff(blobdata* image)
        return result && image_data[3] == (char)0x2A;
 }
 
-uint8_t kds_s2000w_image_type_check_is_pnm(blobdata* image)
+bool kds_s2000w_image_type_check_is_pnm(blobdata* image)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_is_pnm");
 
@@ -39,7 +40,7 @@ uint8_t kds_s2000w_image_type_check_is_pnm(blobdata* image)
        return strncmp(image_data, "P4", 2) == 0;
 }
 
-uint8_t kds_s2000w_image_type_check_is_jpeg(blobdata* image)
+bool kds_s2000w_image_type_check_is_jpeg(blobdata* image)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_is_jpeg");
 
index d82665face07c267f4636ffe722e6b3e5c93ec13..5dfa852fa300f45c5b1d29cd81fbd27f44c4a265 100644 (file)
@@ -1,10 +1,11 @@
 #ifndef KDS_S2000W_IMAGE_TYPE_CHECK_H
 #define KDS_S2000W_IMAGE_TYPE_CHECK_H
 #include <stdint.h>
+#include <stdbool.h>
 #include "kds_s2000w_image_converter.h"
 
-uint8_t kds_s2000w_image_type_check_is_tiff(blobdata* image);
-uint8_t kds_s2000w_image_type_check_is_pnm(blobdata* image);
-uint8_t kds_s2000w_image_type_check_is_jpeg(blobdata* image);
+bool kds_s2000w_image_type_check_is_tiff(blobdata* image);
+bool kds_s2000w_image_type_check_is_pnm(blobdata* image);
+bool kds_s2000w_image_type_check_is_jpeg(blobdata* image);
 
 #endif
\ No newline at end of file
index 12d7748e3cf2138d1b6597479cd6c0bd0bbf46cf..881243193fb4ef48f666c0317a49e93e340e5b9c 100644 (file)
@@ -58,6 +58,14 @@ TARGET_LINK_LIBRARIES("kds_s2000w_option_descriptor_tests_run"
        ${CMOCKA_LIBRARY}
        sane-kds_s2000w_net-static)
 
+ADD_EXECUTABLE("kds_s2000w_image_type_check_tests_run"
+       "kds_s2000w_image_type_check_tests_run.c"
+       "kds_s2000w_image_type_check_tests.c")
+ADD_DEPENDENCIES("kds_s2000w_image_type_check_tests_run" sane-kds_s2000w_net-static)
+TARGET_LINK_LIBRARIES("kds_s2000w_image_type_check_tests_run"
+       ${CMOCKA_LIBRARY}
+       sane-kds_s2000w_net-static)
+
 INCLUDE(CTest)
 ENABLE_TESTING()
 
@@ -73,6 +81,8 @@ ADD_TEST(NAME "kds_s2000w_converter_tests_run"
        COMMAND "kds_s2000w_image_converter_tests_run")
 ADD_TEST(NAME "kds_s2000w_option_descriptor_tests_run"
        COMMAND "kds_s2000w_option_descriptor_tests_run")
+ADD_TEST(NAME "kds_s2000w_image_type_check_tests_run"
+       COMMAND "kds_s2000w_image_type_check_tests_run")
 
 ADD_CUSTOM_TARGET("runningtests"
        ALL "ctest" "--verbose"
diff --git a/tests/kds_s2000w_image_type_check_tests.c b/tests/kds_s2000w_image_type_check_tests.c
new file mode 100644 (file)
index 0000000..4b5e4fc
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include "kds_s2000w_image_type_check_tests.h"
+#include "../src/kds_s2000w_image_type_check.h"
+
+void kds_s2000w_image_type_check_is_tiff_true()
+{
+       blobdata* image = malloc(sizeof(blobdata));
+       image->data = malloc(sizeof(char) * 4);
+       char* imagedata = (char*) image->data;
+       imagedata[0] = 0x49;
+       imagedata[1] = 0x49;
+       imagedata[2] = 0x2A;
+       imagedata[3] = 0x00;
+       image->size = 4;
+
+       uint8_t result = kds_s2000w_image_type_check_is_tiff(image);
+
+       assert_true(result);
+
+       free(image->data);
+       image->data = NULL;
+       free(image);
+       image = NULL;
+}
+
+void kds_s2000w_image_type_check_is_tiff_false()
+{
+       blobdata* image = malloc(sizeof(blobdata));
+       image->size = 0;
+
+       uint8_t result = kds_s2000w_image_type_check_is_tiff(image);
+
+       assert_false(result);
+
+       free(image);
+       image = NULL;
+}
\ No newline at end of file
diff --git a/tests/kds_s2000w_image_type_check_tests.h b/tests/kds_s2000w_image_type_check_tests.h
new file mode 100644 (file)
index 0000000..9cf4b9d
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef KDS_S2000W_IMAGE_TYPE_CHECK_TESTS
+#define KDS_S2000W_IMAGE_TYPE_CHECK_TESTS
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+void kds_s2000w_image_type_check_is_tiff_true();
+void kds_s2000w_image_type_check_is_tiff_false();
+
+#endif
\ No newline at end of file
diff --git a/tests/kds_s2000w_image_type_check_tests_run.c b/tests/kds_s2000w_image_type_check_tests_run.c
new file mode 100644 (file)
index 0000000..e96cb5f
--- /dev/null
@@ -0,0 +1,11 @@
+#include "kds_s2000w_image_type_check_tests.h"
+
+int main()
+{
+       const struct CMUnitTest type_check_tests[] = {
+               cmocka_unit_test(kds_s2000w_image_type_check_is_tiff_true),
+               cmocka_unit_test(kds_s2000w_image_type_check_is_tiff_false)
+       };
+
+       return cmocka_run_group_tests(type_check_tests, NULL, NULL);
+}
\ No newline at end of file