]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test for pnm pixmap check
authorBastian Dehn <hhaalo@arcor.de>
Mon, 8 Dec 2025 20:03:44 +0000 (21:03 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 8 Dec 2025 20:05:52 +0000 (21:05 +0100)
src/kds_s2000w_image_type_check.c
tests/kds_s2000w_image_type_check_tests.c

index 3793972a4ff5b04871705242de282c7f46cb15b4..a6a396ca7f508f44c4cdb0c6657e4f788d30d805 100644 (file)
@@ -4,7 +4,7 @@
 bool kds_s2000w_image_type_check_is_tiff(const blobdata_t* image)
 {
        if (image->size < 4)
-               return 0;
+               return false;
 
        const char* image_data = (const char*) image->data;
        bool result = image_data[0] == (char)0x49;
@@ -16,21 +16,19 @@ bool kds_s2000w_image_type_check_is_tiff(const blobdata_t* image)
 bool kds_s2000w_image_type_check_is_pnm(const blobdata_t* image)
 {
        if (image->size < 2)
-               return 0;
+               return false;
 
        const char* image_data = (const char*) image->data;
-       if (strncmp(image_data, "P6", 2) == 0)
-               return 1;
-
-       return strncmp(image_data, "P4", 2) == 0;
+       return strncmp(image_data, "P4", 2) == 0
+               || (strncmp(image_data, "P6", 2) == 0);
 }
 
 bool kds_s2000w_image_type_check_is_jpeg(const blobdata_t* image)
 {
        if (image->size < 2)
-               return 0;
+               return false;
 
        const char* image_data = (const char*) image->data;
-       uint8_t result = image_data[0] == (char)0xff;
+       bool result = image_data[0] == (char)0xff;
        return result && image_data[1] == (char)0xd8;
 }
\ No newline at end of file
index b64b626577194f9e1307dea42a8ea0bca6f0756b..ed260645da3befc49d784502c04ce32e6234798d 100644 (file)
@@ -78,6 +78,32 @@ void kds_s2000w_image_type_check_is_pnm_true_test()
        image = NULL;
 }
 
+void kds_s2000w_image_type_check_is_pnm_pixmap_true_test()
+{
+       blobdata_t* image = malloc(sizeof(blobdata_t));
+       if (image == NULL)
+               return;
+       image->size = 2;
+       image->data = malloc(sizeof(char) * image->size);
+       if (image->data == NULL) {
+               free(image);
+               image = NULL;
+               return;
+       }
+       char* imagedata = (char*) image->data;
+       imagedata[0] = 'P';
+       imagedata[1] = '4';
+
+       bool result = kds_s2000w_image_type_check_is_pnm(image);
+
+       assert_true(result);
+
+       free(image->data);
+       image->data = NULL;
+       free(image);
+       image = NULL;
+}
+
 void kds_s2000w_image_type_check_is_pnm_false_test()
 {
        blobdata_t* image = malloc(sizeof(blobdata_t));
@@ -140,6 +166,7 @@ int main()
                cmocka_unit_test(kds_s2000w_image_type_check_is_tiff_true_test),
                cmocka_unit_test(kds_s2000w_image_type_check_is_tiff_false_test),
                cmocka_unit_test(kds_s2000w_image_type_check_is_pnm_true_test),
+               cmocka_unit_test(kds_s2000w_image_type_check_is_pnm_pixmap_true_test),
                cmocka_unit_test(kds_s2000w_image_type_check_is_pnm_false_test),
                cmocka_unit_test(kds_s2000w_image_type_check_is_jpeg_true_test),
                cmocka_unit_test(kds_s2000w_image_type_check_is_jpeg_false_test),