]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test suite check with test header bytes
authorBastian Dehn <hhaalo@arcor.de>
Sun, 11 Feb 2024 11:41:23 +0000 (12:41 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 11 Feb 2024 11:41:23 +0000 (12:41 +0100)
CMakeLists.txt
src/CMakeLists.txt [new file with mode: 0644]
tests/CMakeLists.txt [new file with mode: 0644]
tests/kds_s2000w_net_tests.c [new file with mode: 0644]
tests/runtests.c [new file with mode: 0644]
tools/CMakeLists.txt [new file with mode: 0644]

index bad10ae56891898d5b643f25f3e6f9839dd4d7e9..cf893185e95fb7cc99491a0fed9a1def86fec2e8 100644 (file)
@@ -2,26 +2,12 @@ cmake_minimum_required(VERSION 3.25.1)
 
 project("kds_s2000w_net" VERSION "0.0.1")
 
-find_library(SANE NAMES sane REQUIRED)
-find_package(CURL REQUIRED)
-find_package(JSON-C REQUIRED)
-find_package(ImageMagick COMPONENTS MagickCore REQUIRED)
+add_subdirectory(src)
+add_subdirectory(tools)
 
-add_library("sane-kds_s2000w_net"
-       SHARED
-       "src/kds_s2000w_net.c"
-       "src/kds_s2000w_option_descriptors.c"
-       "src/kds_s2000w_handler.c"
-       "src/kds_s2000w_handler_opts.c"
-       "src/kds_s2000w_client.c"
-       "src/kds_s2000w_image_converter.c")
-set_target_properties("sane-kds_s2000w_net" PROPERTIES VERSION 1)
-target_link_libraries("sane-kds_s2000w_net" json-c curl MagickCore-6.Q16 m)
+set(RUN_TESTS OFF CACHE BOOL "build and run tests")
 
-add_executable("convert"
-       "tools/convert.c"
-       "src/kds_s2000w_image_converter.c")
-target_link_libraries("convert" MagickCore-6.Q16)
+if(RUN_TESTS)
+       add_subdirectory(tests)
 
-install(TARGETS "sane-kds_s2000w_net"
-       DESTINATION "/usr/lib/x86_64-linux-gnu/sane")
\ No newline at end of file
+endif()
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6d40e8f
--- /dev/null
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.25.1)
+
+project("kds_s2000w_net" VERSION "0.0.1")
+
+find_library(SANE NAMES sane REQUIRED)
+find_package(CURL REQUIRED)
+find_package(JSON-C REQUIRED)
+find_package(ImageMagick COMPONENTS MagickCore REQUIRED)
+find_library(MATH NAMES m REQUIRED)
+
+add_library("sane-kds_s2000w_net"
+       SHARED
+       "kds_s2000w_net.c"
+       "kds_s2000w_option_descriptors.c"
+       "kds_s2000w_handler.c"
+       "kds_s2000w_handler_opts.c"
+       "kds_s2000w_client.c"
+       "kds_s2000w_image_converter.c")
+set_target_properties("sane-kds_s2000w_net" PROPERTIES VERSION 1)
+target_link_libraries("sane-kds_s2000w_net" json-c curl MagickCore-6.Q16 m)
+
+install(TARGETS "sane-kds_s2000w_net"
+       DESTINATION "/usr/lib/x86_64-linux-gnu/sane")
\ No newline at end of file
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..30eb376
--- /dev/null
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.25.1)
+
+find_library(CHECK NAMES check REQUIRED)
+find_library(SUBUNIT NAMES subunit REQUIRED)
+find_library(MATH NAMES m REQUIRED)
+
+add_executable("runtests"
+       "runtests.c"
+       "kds_s2000w_net_tests.c")
+add_dependencies("runtests" "sane-kds_s2000w_net")
+target_link_libraries("runtests" check subunit m sane-kds_s2000w_net)
+
+add_custom_target("runningtests" ALL "./runtests"
+       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+       DEPENDS "runtests")
\ No newline at end of file
diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c
new file mode 100644 (file)
index 0000000..a76de1f
--- /dev/null
@@ -0,0 +1,17 @@
+#include <check.h>
+int _sane_kds_s2000w_net_find_first_data_byte(const char* data);
+
+START_TEST(sane_kds_s2000w_net_find_first_data_byte_test)
+{
+       char data[] = {
+               0x50, 0x36, 0x0a, 0x31,
+               0x31, 0x35, 0x39, 0x20,
+               0x38, 0x32, 0x39, 0x0a,
+               0x32, 0x35, 0x35, 0x0a
+       };
+
+       int header_bytes = _sane_kds_s2000w_net_find_first_data_byte(data);
+
+       ck_assert_int_eq(header_bytes, 16);
+}
+END_TEST
\ No newline at end of file
diff --git a/tests/runtests.c b/tests/runtests.c
new file mode 100644 (file)
index 0000000..72bf4de
--- /dev/null
@@ -0,0 +1,31 @@
+#include <check.h>
+#include "kds_s2000w_net_tests.c"
+
+Suite* first_tests()
+{
+       Suite* suite = NULL;
+       TCase* tc_core = NULL;
+
+       suite = suite_create("first tests");
+
+       tc_core = tcase_create("core");
+       tcase_add_test(tc_core, sane_kds_s2000w_net_find_first_data_byte_test);
+
+       suite_add_tcase(suite, tc_core);
+
+       return suite;
+}
+
+int main()
+{
+       int failed = 0;
+       Suite* suite = first_tests();
+       SRunner* runner = srunner_create(suite);
+
+       srunner_run_all(runner, CK_NORMAL);
+       failed = srunner_ntests_failed(runner);
+       srunner_free(runner);
+       runner = NULL;
+
+       return failed == 0 ? 0 : 1;
+}
\ No newline at end of file
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1b2b869
--- /dev/null
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.25.1)
+
+find_package(ImageMagick COMPONENTS MagickCore REQUIRED)
+
+add_executable("convert"
+       "convert.c"
+       "../src/kds_s2000w_image_converter.c")
+target_link_libraries("convert" MagickCore-6.Q16)
\ No newline at end of file