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;
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
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));
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),