1 /* 2 * v4l-test: Test environment for Video For Linux Two API 3 * 4 * 16 Jun 2009 0.1 First release 5 * 6 * Written by Mrton Nmeth <nm127 (at) freemail.hu> 7 * Released under GPL 8 */ 9 10 #include <stdio.h> 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #include <fcntl.h> 14 #include <unistd.h> 15 #include <sys/ioctl.h> 16 #include <errno.h> 17 #include <string.h> 18 19 #include <linux/videodev2.h> 20 #include <linux/errno.h> 21 22 #include <CUnit/CUnit.h> 23 24 #include "v4l2_test.h" 25 #include "dev_video.h" 26 #include "video_limits.h" 27 #include "v4l2_validator.h" 28 #include "v4l2_foreach.h" 29 30 #include "test_VIDIOC_JPEGCOMP.h" 31 32 static int valid_jpeg_markers(__u32 jpeg_markers) 33 { 34 int valid = 0; 35 36 if ((jpeg_markers & ~(V4L2_JPEG_MARKER_DHT | 37 V4L2_JPEG_MARKER_DQT | 38 V4L2_JPEG_MARKER_DRI | 39 V4L2_JPEG_MARKER_COM | V4L2_JPEG_MARKER_APP)) 40 == 0) { 41 valid = 1; 42 } else { 43 valid = 0; 44 } 45 return valid; 46 } 47 48 void test_VIDIOC_G_JPEGCOMP() 49 { 50 struct v4l2_jpegcompression jpegcomp; 51 int ret_get, errno_get; 52 53 memset(&jpegcomp, 0xff, sizeof(jpegcomp)); 54 ret_get = ioctl(get_video_fd(), VIDIOC_G_JPEGCOMP, &jpegcomp); 55 errno_get = errno; 56 57 dprintf("\tVIDIOC_G_JPEGCOMP, ret_get=%i, errno_get=%i\n", ret_get, 58 errno_get); 59 60 if (ret_get == 0) { 61 CU_ASSERT_EQUAL(ret_get, 0); 62 63 //CU_ASSERT_EQUAL(jpegcomp.quality, ???); 64 //CU_ASSERT_EQUAL(jpegcomp.APPn, ???); 65 CU_ASSERT(0 <= jpegcomp.APP_len); 66 CU_ASSERT(jpegcomp.APP_len <= (int)sizeof(jpegcomp.APP_data)); 67 //CU_ASSERT_EQUAL(jpegcomp.APP_data, ???); 68 CU_ASSERT(0 <= jpegcomp.COM_len); 69 CU_ASSERT(jpegcomp.COM_len <= (int)sizeof(jpegcomp.COM_data)); 70 //CU_ASSERT_EQUAL(jpegcomp.COM_data, ???); 71 CU_ASSERT(valid_jpeg_markers(jpegcomp.jpeg_markers)); 72 73 dprintf("\tjpegcomp = { .quality=%i, " 74 ".APPn=%i, " 75 ".APP_len=%i, " 76 ".APP_data=..., " 77 ".COM_len=%i, " 78 ".COM_data=..., " 79 ".jpeg_markers=0x%x ", 80 jpegcomp.quality, jpegcomp.APPn, jpegcomp.APP_len, 81 //jpegcomp.APP_data, 82 jpegcomp.COM_len, 83 //jpegcomp.COM_data, 84 jpegcomp.jpeg_markers); 85 86 } else { 87 CU_ASSERT_EQUAL(ret_get, -1); 88 CU_ASSERT_EQUAL(errno_get, EINVAL); 89 } 90 91 } 92 93 void test_VIDIOC_G_JPEGCOMP_NULL() 94 { 95 struct v4l2_jpegcompression jpegcomp; 96 int ret_get, errno_get; 97 int ret_null, errno_null; 98 99 memset(&jpegcomp, 0, sizeof(jpegcomp)); 100 ret_get = ioctl(get_video_fd(), VIDIOC_G_JPEGCOMP, &jpegcomp); 101 errno_get = errno; 102 103 dprintf("\tVIDIOC_G_JPEGCOMP, ret_get=%i, errno_get=%i\n", ret_get, 104 errno_get); 105 106 ret_null = ioctl(get_video_fd(), VIDIOC_G_JPEGCOMP, NULL); 107 errno_null = errno; 108 109 dprintf("\tVIDIOC_G_JPEGCOMP, ret_null=%i, errno_null=%i\n", ret_null, 110 errno_null); 111 112 if (ret_get == 0) { 113 CU_ASSERT_EQUAL(ret_get, 0); 114 CU_ASSERT_EQUAL(ret_null, -1); 115 CU_ASSERT_EQUAL(errno_null, EFAULT); 116 } else { 117 CU_ASSERT_EQUAL(ret_get, -1); 118 CU_ASSERT_EQUAL(errno_get, EINVAL); 119 CU_ASSERT_EQUAL(ret_null, -1); 120 CU_ASSERT_EQUAL(errno_null, EINVAL); 121 } 122 123 } 124