# Path: tests/test_xcb.py
# def xcbtest(*protos):
#     def wrapper(fun):
#         @wraps(fun)
#         def wrapper(self):
#             from tilenol.xcb import Proto, Connection
#             from zorro import Hub
#             err = []
#             hub = Hub()
#             def real_test():
#                 pr = Proto()
#                 for i in protos:
#                     pr.load_xml(i)
#                 conn = Connection(pr)
#                 fun(self, conn)
#             @hub.run
#             def test():
#                 try:
#                     real_test()
#                 except Exception as e:
#                     err.append(e)
#             if err:
#                 raise err[0]
#         return wrapper
#     return wrapper


import unittest
import cairo
from .test_xcb import xcbtest
        from tilenol.xcb.core import Core, Rectangle


class TestConn(unittest.TestCase):

    @xcbtest('xproto')
    def testPicture(self, conn):
        core = Core(conn)
        img = cairo.ImageSurface(cairo.FORMAT_ARGB32, 128, 128)
        ctx = cairo.Context(img)
        ctx.set_source_rgb(1, 0, 0)
        ctx.move_to(64, 0)
        ctx.line_to(128, 128)
        ctx.line_to(0, 128)
        ctx.fill()
        conn.connection()
        win = core.create_toplevel(
            bounds=Rectangle(10, 10, 100, 100),
            border=1,
            klass=core.WindowClass.InputOutput,
            params={
                core.CW.BackPixel: conn.init_data['roots'][0]['white_pixel'],
                core.CW.EventMask:
                    core.EventMask.Exposure | core.EventMask.KeyPress,
                })
        core.raw.MapWindow(window=win)
        for ev in conn.get_events():
            if ev.__class__.__name__ == 'ExposeEvent' and ev.window == win:
                break

# Path: tests/test_xcb.py
# def xcbtest(*protos):
#     def wrapper(fun):
#         @wraps(fun)
#         def wrapper(self):
#             from tilenol.xcb import Proto, Connection
#             from zorro import Hub
#             err = []
#             hub = Hub()
#             def real_test():
#                 pr = Proto()
#                 for i in protos:
#                     pr.load_xml(i)
#                 conn = Connection(pr)
#                 fun(self, conn)
#             @hub.run
#             def test():
#                 try:
#                     real_test()
#                 except Exception as e:
#                     err.append(e)
#             if err:
#                 raise err[0]
#         return wrapper
#     return wrapper


# Path: tests/test_cairo.py
import unittest
import cairo
from .test_xcb import xcbtest
        from tilenol.xcb.core import Core, Rectangle



class TestConn(unittest.TestCase):

    @xcbtest('xproto')
    def testPicture(self, conn):
        core = Core(conn)
        img = cairo.ImageSurface(cairo.FORMAT_ARGB32, 128, 128)
        ctx = cairo.Context(img)
        ctx.set_source_rgb(1, 0, 0)
        ctx.move_to(64, 0)
        ctx.line_to(128, 128)
        ctx.line_to(0, 128)
        ctx.fill()
        conn.connection()
        win = core.create_toplevel(
            bounds=Rectangle(10, 10, 100, 100),
            border=1,
            klass=core.WindowClass.InputOutput,
            params={
                core.CW.BackPixel: conn.init_data['roots'][0]['white_pixel'],
                core.CW.EventMask:
                    core.EventMask.Exposure | core.EventMask.KeyPress,
                })
        core.raw.MapWindow(window=win)
        for ev in conn.get_events():
            if ev.__class__.__name__ == 'ExposeEvent' and ev.window == win:
                break

        gc = conn.new_xid()