Merge branch 'gallium-0.1' of ssh://ymanton@git.freedesktop.org/git/nouveau/mesa...
[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 /* Note: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
44 /* Note: Nvidia binary driver segfaults on NULL context, halts with debug output on bad port */
45
46 /* Test NULL context */
47 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
48 /* Test invalid port */
49 assert(XvMCCreateContext(display, port_num + 1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
50 /* Test invalid surface */
51 assert(XvMCCreateContext(display, port_num, surface_type_id + 1, width, height, XVMC_DIRECT, &context) == BadMatch);
52 /* Test invalid flags */
53 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
54 /* Test huge width */
55 assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
56 /* Test huge height */
57 assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
58 /* Test huge width & height */
59 assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
60 /* Test valid params */
61 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
62 /* Test context id assigned */
63 assert(context.context_id != 0);
64 /* Test surface type id assigned and correct */
65 assert(context.surface_type_id == surface_type_id);
66 /* Test width & height assigned and correct */
67 assert(context.width == width && context.height == height);
68 /* Test port assigned and correct */
69 assert(context.port == port_num);
70 /* Test flags assigned and correct */
71 assert(context.flags == XVMC_DIRECT);
72 /* Test NULL context */
73 assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
74 /* Test valid params */
75 assert(XvMCDestroyContext(display, &context) == Success);
76 /* Test awkward but valid width */
77 assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
78 assert(context.width >= width + 1);
79 assert(XvMCDestroyContext(display, &context) == Success);
80 /* Test awkward but valid height */
81 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
82 assert(context.height >= height + 1);
83 assert(XvMCDestroyContext(display, &context) == Success);
84 /* Test awkward but valid width & height */
85 assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
86 assert(context.width >= width + 1 && context.height >= height + 1);
87 assert(XvMCDestroyContext(display, &context) == Success);
88
89 XvUngrabPort(display, port_num, CurrentTime);
90 XCloseDisplay(display);
91
92 return 0;
93 }
94