#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");
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;
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");
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");
#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
${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()
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"
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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