• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  *  5 Apr 2009  0.3  Test case for NULL parameter reworked
5  * 28 Mar 2009  0.2  Clean up ret and errno variable names and dprintf() output
6  * 30 Jan 2009  0.1  First release
7  *
8  * Written by M�rton N�meth <nm127@freemail.hu>
9  * Released under GPL
10  */
11 
12 #include <stdio.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/ioctl.h>
18 #include <errno.h>
19 #include <string.h>
20 
21 #include <linux/videodev2.h>
22 #include <linux/errno.h>
23 
24 #include <CUnit/CUnit.h>
25 
26 #include "v4l2_test.h"
27 #include "dev_video.h"
28 #include "video_limits.h"
29 #include "v4l2_validator.h"
30 
31 #include "test_VIDIOC_QUERYSTD.h"
32 
test_VIDIOC_QUERYSTD()33 void test_VIDIOC_QUERYSTD()
34 {
35 	int ret_query, errno_query;
36 	v4l2_std_id id;
37 
38 	memset(&id, 0xff, sizeof(id));
39 
40 	ret_query = ioctl(get_video_fd(), VIDIOC_QUERYSTD, &id);
41 	errno_query = errno;
42 
43 	dprintf
44 	    ("\t%s:%u: VIDIOC_QUERYSTD, ret_query=%i, errno_query=%i, id=0x%llx\n",
45 	     __FILE__, __LINE__, ret_query, errno_query, id);
46 
47 	if (ret_query == 0) {
48 		CU_ASSERT_EQUAL(ret_query, 0);
49 		CU_ASSERT(id != 0);
50 		CU_ASSERT(valid_v4l2_std_id(id));
51 
52 	} else {
53 		/* if this ioctl is not supported, then errno shall be EINVAL */
54 		CU_ASSERT_EQUAL(ret_query, -1);
55 		CU_ASSERT_EQUAL(errno_query, EINVAL);
56 	}
57 
58 }
59 
test_VIDIOC_QUERYSTD_NULL()60 void test_VIDIOC_QUERYSTD_NULL()
61 {
62 	int ret_query, errno_query;
63 	int ret_null, errno_null;
64 	v4l2_std_id id;
65 
66 	memset(&id, 0, sizeof(id));
67 	ret_query = ioctl(get_video_fd(), VIDIOC_QUERYSTD, &id);
68 	errno_query = errno;
69 
70 	dprintf("\t%s:%u: VIDIOC_QUERYSTD: ret_query=%i, errno_query=%i\n",
71 		__FILE__, __LINE__, ret_query, errno_query);
72 
73 	ret_null = ioctl(get_video_fd(), VIDIOC_QUERYSTD, NULL);
74 	errno_null = errno;
75 
76 	dprintf("\t%s:%u: VIDIOC_G_TUNER: ret_null=%i, errno_null=%i\n",
77 		__FILE__, __LINE__, ret_null, errno_null);
78 
79 	/* check if VIDIOC_QUERYSTD is supported at all or not */
80 	if (ret_query == 0) {
81 		/* VIDIOC_QUERYSTD is supported, the parameter should be checked */
82 		CU_ASSERT_EQUAL(ret_query, 0);
83 		CU_ASSERT_EQUAL(ret_null, -1);
84 		CU_ASSERT_EQUAL(errno_null, EFAULT);
85 	} else {
86 		/* VIDIOC_QUERYSTD not supported at all, the parameter should not be evaluated */
87 		CU_ASSERT_EQUAL(ret_query, -1);
88 		CU_ASSERT_EQUAL(errno_query, EINVAL);
89 		CU_ASSERT_EQUAL(ret_null, -1);
90 		CU_ASSERT_EQUAL(errno_null, EINVAL);
91 
92 	}
93 }
94 
95 /* TODO: check for different input settings */
96