]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add calc inch to pixel and pixel to inch
authorBastian Dehn <hhaalo@arcor.de>
Fri, 21 Feb 2025 17:14:22 +0000 (18:14 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 6 Mar 2025 20:44:36 +0000 (21:44 +0100)
src/CMakeLists.txt
src/kds_s2000w_handler_opts_calc.c [new file with mode: 0644]
src/kds_s2000w_handler_opts_calc.h [new file with mode: 0644]
tests/CMakeLists.txt
tests/kds_s2000w_handler_opts_calc_tests.c [new file with mode: 0644]
tests/kds_s2000w_handler_opts_calc_tests.h [new file with mode: 0644]
tests/kds_s2000w_handler_opts_calc_tests_run.c [new file with mode: 0644]
tests/kds_s2000w_image_converter_tests_run.c

index aa2b61a29d081f34c8ff30d86626c0b55fe3c00f..6234e713ce5902fa61e5b4c816fa915923e16d93 100644 (file)
@@ -78,6 +78,7 @@ SET(SOURCES
        "kds_s2000w_net.c"
        "kds_s2000w_option_descriptors.c"
        "kds_s2000w_handler.c"
+       "kds_s2000w_handler_opts_calc.c"
        "kds_s2000w_handler_opts.c"
        "kds_s2000w_client.c"
        "kds_s2000w_debug.c"
diff --git a/src/kds_s2000w_handler_opts_calc.c b/src/kds_s2000w_handler_opts_calc.c
new file mode 100644 (file)
index 0000000..d5f31f9
--- /dev/null
@@ -0,0 +1,13 @@
+#include "kds_s2000w_handler_opts_calc.h"
+
+#define INCH_RESOLUTION 10
+
+uint32_t kds_s2000w_handler_opts_calc_inch_to_pixel(uint32_t dpi, uint32_t inch)
+{
+       return inch / INCH_RESOLUTION * dpi;
+}
+
+uint32_t kds_s2000w_handler_opts_calc_pixel_to_inch(uint32_t dpi, uint32_t pixel)
+{
+       return pixel / dpi * INCH_RESOLUTION;
+}
\ No newline at end of file
diff --git a/src/kds_s2000w_handler_opts_calc.h b/src/kds_s2000w_handler_opts_calc.h
new file mode 100644 (file)
index 0000000..a9d8fad
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef KDS_S20000W_HANDLER_OPTS_CALC_H
+#define KDS_S20000W_HANDLER_OPTS_CALC_H
+#include <stdint.h>
+
+uint32_t kds_s2000w_handler_opts_calc_inch_to_pixel(uint32_t dpi, uint32_t inch);
+uint32_t kds_s2000w_handler_opts_calc_pixel_to_inch(uint32_t dpi, uint32_t pixel);
+
+#endif
\ No newline at end of file
index 881243193fb4ef48f666c0317a49e93e340e5b9c..783849ff59d6f1262005fdfbe54fd48a64b77020 100644 (file)
@@ -4,6 +4,14 @@ FIND_PACKAGE(CMOCKA REQUIRED)
 
 MESSAGE(STATUS "find ${CMOCKA_LIBRARY}")
 
+ADD_EXECUTABLE("kds_s2000w_handler_opts_calc_tests_run"
+       "kds_s2000w_handler_opts_calc_tests_run.c"
+       "kds_s2000w_handler_opts_calc_tests.c")
+ADD_DEPENDENCIES("kds_s2000w_handler_opts_calc_tests_run" sane-kds_s2000w_net-static)
+TARGET_LINK_LIBRARIES("kds_s2000w_handler_opts_calc_tests_run"
+       ${CMOCKA_LIBRARY}
+       sane-kds_s2000w_net-static)
+
 ADD_EXECUTABLE("kds_s2000w_net_get_opt_tests_run"
        "kds_s2000w_net_get_opt_tests_run.c"
        "kds_s2000w_net_get_opt_tests.c"
@@ -69,6 +77,8 @@ TARGET_LINK_LIBRARIES("kds_s2000w_image_type_check_tests_run"
 INCLUDE(CTest)
 ENABLE_TESTING()
 
+ADD_TEST(NAME "kds_s2000w_handler_opts_calc_tests_run"
+       COMMAND "kds_s2000w_handler_opts_calc_tests_run")
 ADD_TEST(NAME "kds_s2000w_net_get_opt_tests_run"
        COMMAND "kds_s2000w_net_get_opt_tests_run")
 ADD_TEST(NAME "kds_s2000w_net_read_tests_run"
diff --git a/tests/kds_s2000w_handler_opts_calc_tests.c b/tests/kds_s2000w_handler_opts_calc_tests.c
new file mode 100644 (file)
index 0000000..a9aa26e
--- /dev/null
@@ -0,0 +1,21 @@
+#include "kds_s2000w_handler_opts_calc_tests.h"
+
+void kds_s2000w_handler_opts_calc_inch_to_pixel_test()
+{
+       uint32_t dpi = 300;
+       uint32_t inch = 10;
+
+       uint32_t pixel = kds_s2000w_handler_opts_calc_inch_to_pixel(dpi, inch);
+
+       assert_int_equal(pixel, 300);
+}
+
+void kds_s2000w_handler_opts_calc_pixel_to_inch_test()
+{
+       uint32_t dpi = 300;
+       uint32_t pixel = 300;
+
+       uint32_t inch = kds_s2000w_handler_opts_calc_pixel_to_inch(dpi, pixel);
+
+       assert_int_equal(inch, 10);
+}
\ No newline at end of file
diff --git a/tests/kds_s2000w_handler_opts_calc_tests.h b/tests/kds_s2000w_handler_opts_calc_tests.h
new file mode 100644 (file)
index 0000000..9a8fd70
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef KDS_S2000W_HANDLER_OPTS_CALC_TESTS_H
+#define KDS_S2000W_HANDLER_OPTS_CALC_TESTS_H
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "../src/kds_s2000w_handler_opts_calc.h"
+
+void kds_s2000w_handler_opts_calc_inch_to_pixel_test();
+void kds_s2000w_handler_opts_calc_pixel_to_inch_test();
+
+#endif
\ No newline at end of file
diff --git a/tests/kds_s2000w_handler_opts_calc_tests_run.c b/tests/kds_s2000w_handler_opts_calc_tests_run.c
new file mode 100644 (file)
index 0000000..db57ecd
--- /dev/null
@@ -0,0 +1,11 @@
+#include "kds_s2000w_handler_opts_calc_tests.h"
+
+int main()
+{
+       const struct CMUnitTest opts_calc_tests[] = {
+               cmocka_unit_test(kds_s2000w_handler_opts_calc_inch_to_pixel_test),
+               cmocka_unit_test(kds_s2000w_handler_opts_calc_pixel_to_inch_test)
+       };
+
+       return cmocka_run_group_tests(opts_calc_tests, NULL, NULL);
+}
\ No newline at end of file
index 048b3431927a22fd5f4c33a25b609817fd8d6fb6..b18cd1b0e581de2c7670c4e9f4570470cae9d3db 100644 (file)
@@ -1,5 +1,3 @@
-#include <stdlib.h>
-#include <string.h>
 #include "kds_s2000w_client_mock.h"
 #include "kds_s2000w_image_converter_tests.h"