1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* Force assertions, even on release builds. */
35 int main(int argc
, char **argv
)
37 const unsigned int width
= 16, height
= 16;
38 const unsigned int mc_types
[2] = {XVMC_MOCOMP
| XVMC_MPEG_2
, XVMC_IDCT
| XVMC_MPEG_2
};
43 unsigned int is_overlay
, intra_unsigned
;
45 XvMCContext context
= {0};
47 display
= XOpenDisplay(NULL
);
54 XVMC_CHROMA_FORMAT_420
,
63 XCloseDisplay(display
);
64 fprintf(stderr
, "Error, unable to find a good port.\n");
70 Atom xv_colorkey
= XInternAtom(display
, "XV_COLORKEY", 0);
71 XvGetPortAttribute(display
, port_num
, xv_colorkey
, &colorkey
);
74 /* Test NULL context */
75 /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
76 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
, XVMC_DIRECT
, NULL
) == XvMCBadContext
);
77 /* Test invalid port */
78 /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
79 assert(XvMCCreateContext(display
, -1, surface_type_id
, width
, height
, XVMC_DIRECT
, &context
) == XvBadPort
);
80 /* Test invalid surface */
81 assert(XvMCCreateContext(display
, port_num
, -1, width
, height
, XVMC_DIRECT
, &context
) == BadMatch
);
82 /* Test invalid flags */
83 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
, -1, &context
) == BadValue
);
85 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, 16384, height
, XVMC_DIRECT
, &context
) == BadValue
);
86 /* Test huge height */
87 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, 16384, XVMC_DIRECT
, &context
) == BadValue
);
88 /* Test huge width & height */
89 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, 16384, 16384, XVMC_DIRECT
, &context
) == BadValue
);
90 /* Test valid params */
91 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
, XVMC_DIRECT
, &context
) == Success
);
92 /* Test context id assigned */
93 assert(context
.context_id
!= 0);
94 /* Test surface type id assigned and correct */
95 assert(context
.surface_type_id
== surface_type_id
);
96 /* Test width & height assigned and correct */
97 assert(context
.width
== width
&& context
.height
== height
);
98 /* Test port assigned and correct */
99 assert(context
.port
== port_num
);
100 /* Test flags assigned and correct */
101 assert(context
.flags
== XVMC_DIRECT
);
102 /* Test NULL context */
103 assert(XvMCDestroyContext(display
, NULL
) == XvMCBadContext
);
104 /* Test valid params */
105 assert(XvMCDestroyContext(display
, &context
) == Success
);
106 /* Test awkward but valid width */
107 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
+ 1, height
, XVMC_DIRECT
, &context
) == Success
);
108 assert(context
.width
>= width
+ 1);
109 assert(XvMCDestroyContext(display
, &context
) == Success
);
110 /* Test awkward but valid height */
111 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
, height
+ 1, XVMC_DIRECT
, &context
) == Success
);
112 assert(context
.height
>= height
+ 1);
113 assert(XvMCDestroyContext(display
, &context
) == Success
);
114 /* Test awkward but valid width & height */
115 assert(XvMCCreateContext(display
, port_num
, surface_type_id
, width
+ 1, height
+ 1, XVMC_DIRECT
, &context
) == Success
);
116 assert(context
.width
>= width
+ 1 && context
.height
>= height
+ 1);
117 assert(XvMCDestroyContext(display
, &context
) == Success
);
119 XvUngrabPort(display
, port_num
, CurrentTime
);
120 XCloseDisplay(display
);