Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / libXvMC / tests / test_context.c
1 #include <assert.h>
2 #include <error.h>
3 #include "testlib.h"
4
5 int main(int argc, char **argv)
6 {
7 const unsigned int width = 16, height = 16;
8 const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
9
10 Display *display;
11 XvPortID port_num;
12 int surface_type_id;
13 unsigned int is_overlay, intra_unsigned;
14 int colorkey;
15 XvMCContext context = {0};
16
17 display = XOpenDisplay(NULL);
18
19 if (!GetPort
20 (
21 display,
22 width,
23 height,
24 XVMC_CHROMA_FORMAT_420,
25 mc_types,
26 2,
27 &port_num,
28 &surface_type_id,
29 &is_overlay,
30 &intra_unsigned
31 ))
32 {
33 XCloseDisplay(display);
34 error(1, 0, "Error, unable to find a good port.\n");
35 }
36
37 if (is_overlay)
38 {
39 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
40 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
41 }
42
43 /* Test NULL context */
44 /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
45 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
46 /* Test invalid port */
47 /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
48 assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
49 /* Test invalid surface */
50 assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
51 /* Test invalid flags */
52 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
53 /* Test huge width */
54 assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
55 /* Test huge height */
56 assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
57 /* Test huge width & height */
58 assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
59 /* Test valid params */
60 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
61 /* Test context id assigned */
62 assert(context.context_id != 0);
63 /* Test surface type id assigned and correct */
64 assert(context.surface_type_id == surface_type_id);
65 /* Test width & height assigned and correct */
66 assert(context.width == width && context.height == height);
67 /* Test port assigned and correct */
68 assert(context.port == port_num);
69 /* Test flags assigned and correct */
70 assert(context.flags == XVMC_DIRECT);
71 /* Test NULL context */
72 assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
73 /* Test valid params */
74 assert(XvMCDestroyContext(display, &context) == Success);
75 /* Test awkward but valid width */
76 assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
77 assert(context.width >= width + 1);
78 assert(XvMCDestroyContext(display, &context) == Success);
79 /* Test awkward but valid height */
80 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
81 assert(context.height >= height + 1);
82 assert(XvMCDestroyContext(display, &context) == Success);
83 /* Test awkward but valid width & height */
84 assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
85 assert(context.width >= width + 1 && context.height >= height + 1);
86 assert(XvMCDestroyContext(display, &context) == Success);
87
88 XvUngrabPort(display, port_num, CurrentTime);
89 XCloseDisplay(display);
90
91 return 0;
92 }