3
qUn                 @   s   d Z ddlZddlZddlZejdZddlZddlmZmZm	Z	m
Z
 ddlmZmZmZ ejdd Zd	d
 Zdd Zdd Zdd Zejje dk dddd Zejje dk dddd ZdS )z

    cairocffi.test_xcb
    ~~~~~~~~~~~~~~~~~~

    Test suite for cairocffi.xcb.

    :copyright: Copyright 2014 by Simon Sapin
    :license: BSD, see LICENSE for details.

    Nxcffib)ConfigWindowCW	EventMaskGC   )Context
XCBSurfacecairo_versionc                s@   t jjd}|r(tj|  fdd}n
tjd | j|  S )zs
    Fixture that will setup and take down a xcffib.Connection object running on
    a display spawned by xvfb
    ZDISPLAYc                  s    j   d S )N)Z
disconnect )connr   R/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/cairocffi/test_xcb.pyteardown_conn$   s    zxcb_conn.<locals>.teardown_connz$DISPLAY environment variable not set)osenvirongetr   connectpytestskipZaddfinalizer)requestZdisplayr   r   )r   r   xcb_conn   s    


r   c             C   sB   | j j| j }x.|jD ]$}x|jD ]}|j|jkr"|S q"W qW dS )zBFind the xcffib.xproto.VISUALTYPE corresponding to the root visualN)setuprootspref_screenZallowed_depthsZvisualsZ	visual_idroot_visual)r   default_screenivr   r   r   find_root_visual-   s
    r   c             C   s^   | j  }| jj| j }| jj|j||jdd||dtj	j
j|jtjtjB |jtjtjB g |S )z<Creates a window of the given dimensions and returns the XIDr   )generate_idr   r   r   coreZCreateWindow
root_depthrootr   xprotoZWindowClassZInputOutputr   r   Z	BackPixelr   black_pixelZExposureZStructureNotify)r   widthheightwidr   r   r   r   create_window6   s    

r(   c             C   s0   | j  }| jj| j }| jj|j|||| |S )z<Creates a window of the given dimensions and returns the XID)r   r   r   r   r    ZCreatePixmapr!   )r   r'   r%   r&   pixmapr   r   r   r   create_pixmapL   s    r*   c             C   s>   | j  }| jj| j }| jj||jtjtj	B |j
|jg |S )z!Creates a simple graphics context)r   r   r   r   r    ZCreateGCr"   r   Z
ForegroundZ
Backgroundr$   Zwhite_pixel)r   gcr   r   r   r   	create_gcZ   s    

r,   i+  zCairo version too low)reasonc          
   C   s   d}d}t | ||}t| |||}t| }t| }t| ||||}|sJtt|}|jddd |j  | j	j
| | j  tj }	x6tj |	d k r| j }
t|
tjjrP qW tjd | j	j|||dddd||	 | j  x|
r| j }
qW d S )N
   r   zNever received ExposeEventr   )r(   r*   r,   r   r	   AssertionErrorr   set_source_rgbpaintr    	MapWindowflushtimewait_for_event
isinstancer   r#   ExposeEventr   failZCopyAreapoll_for_event)r   r%   r&   r'   r)   r+   r   surfacectxstarteventr   r   r   test_xcb_pixmapk   s:    
r>   c       	      C   s  d}d}t | ||}| jj| | j  tj }x6tj |d k r\| j }t|tjj	r2P q2W t
jd t| }t| ||||}|stt|}|jddd |j  | j  | jj|tjtjB tjB tjB dd|d |d g | j  tj }xltj |d k rT| j }t|tjjr|jd| ks0t|jd| ksDt|j}|j}P qW t
jd |j|| t|}|jddd |j  | j  x|r| j }qW d S )Nr.   zNever received ExposeEventr         z#Never received ConfigureNotifyEvent)r(   r    r2   r3   r4   r5   r6   r   r#   r7   r   r8   r   r	   r/   r   r0   r1   ZConfigureWindowr   XYZWidthZHeightZConfigureNotifyEventr%   r&   Zset_sizer9   )	r   r%   r&   r'   r<   r=   r   r:   r;   r   r   r   test_xcb_window   sR    

rC   )__doc__r   r4   r   Zimportorskipr   Zxcffib.xprotor   r   r   r    r   r	   r
   Zfixturer   r   r(   r*   r,   ZmarkZxfailr>   rC   r   r   r   r   <module>   s    
	2