From 215dae7424c98292e17607db2bb08b0935ee5cfe Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 19 Aug 2016 20:39:05 +0200 Subject: test + fix errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libcoopgamma.py | 6 ++-- src/libcoopgamma_native.pyx.gpp | 34 ++++++++++++--------- src/test | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 17 deletions(-) diff --git a/src/libcoopgamma.py b/src/libcoopgamma.py index 7d561db..549d2b9 100644 --- a/src/libcoopgamma.py +++ b/src/libcoopgamma.py @@ -1004,10 +1004,10 @@ class Context: @param async:AsyncContext Slot for information about the request that is needed to identify and parse the response ''' - (successful, value) = libcoopgamma_native.libcoopgamma_native_get_gamma_send( + error = libcoopgamma_native.libcoopgamma_native_get_gamma_send( query, self.address, async.address) - if not successful: - raise ErrorReport.create_error(value) + if error != 0: + raise ErrorReport.create_error(error) def get_gamma_recv(self, async): ''' diff --git a/src/libcoopgamma_native.pyx.gpp b/src/libcoopgamma_native.pyx.gpp index 1597e0c..60d9f4a 100644 --- a/src/libcoopgamma_native.pyx.gpp +++ b/src/libcoopgamma_native.pyx.gpp @@ -1784,17 +1784,20 @@ def libcoopgamma_native_set_gamma_send(filtr, address : int, async : int): cdef libcoopgamma_filter_t flr crtc_bs = filtr.crtc.encode('utf-8') + bytes([0]) clss_bs = filtr.fclass.encode('utf-8') + bytes([0]) - flr.priority = (filtr.priority) + flr.priority = (0 if filtr.priority is None else filtr.priority) flr.lifespan = (filtr.lifespan) - flr.depth = (filtr.depth) + flr.depth = (0 if filtr.depth is None else filtr.depth) flr.fclass = NULL flr.crtc = NULL - flr.ramps.u_red_size = len(filtr.ramps.red) - flr.ramps.u_green_size = len(filtr.ramps.green) - flr.ramps.u_blue_size = len(filtr.ramps.blue) - flr.ramps.u_red = NULL + flr.ramps.u_red_size = len(filtr.ramps.red) if filtr.ramps is not None else 0 + flr.ramps.u_green_size = len(filtr.ramps.green) if filtr.ramps is not None else 0 + flr.ramps.u_blue_size = len(filtr.ramps.blue) if filtr.ramps is not None else 0 + flr.ramps.u_red = NULL + flr.ramps.u_green = NULL + flr.ramps.u_blue = NULL try: - libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) + if filtr.ramps is not None: + libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) flr.crtc = malloc(len(crtc_bs) * sizeof(char)) if flr.crtc is NULL: return int(errno) @@ -1857,17 +1860,20 @@ def libcoopgamma_native_set_gamma_sync(filtr, address : int): cdef bytes bs crtc_bs = filtr.crtc.encode('utf-8') + bytes([0]) clss_bs = filtr.fclass.encode('utf-8') + bytes([0]) - flr.priority = (filtr.priority) + flr.priority = (0 if filtr.priority is None else filtr.priority) flr.lifespan = (filtr.lifespan) - flr.depth = (filtr.depth) + flr.depth = (0 if filtr.depth is None else filtr.depth) flr.fclass = NULL flr.crtc = NULL - flr.ramps.u_red_size = len(filtr.ramps.red) - flr.ramps.u_green_size = len(filtr.ramps.green) - flr.ramps.u_blue_size = len(filtr.ramps.blue) - flr.ramps.u_red = NULL + flr.ramps.u_red_size = len(filtr.ramps.red) if filtr.ramps is not None else 0 + flr.ramps.u_green_size = len(filtr.ramps.green) if filtr.ramps is not None else 0 + flr.ramps.u_blue_size = len(filtr.ramps.blue) if filtr.ramps is not None else 0 + flr.ramps.u_red = NULL + flr.ramps.u_green = NULL + flr.ramps.u_blue = NULL try: - libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) + if filtr.ramps is not None: + libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) flr.crtc = malloc(len(crtc_bs) * sizeof(char)) if flr.crtc is NULL: return int(errno) diff --git a/src/test b/src/test index 8d5d5e9..3f97539 100755 --- a/src/test +++ b/src/test @@ -59,6 +59,7 @@ if len(sys.argv) == 1: else: g = eval(sys.argv[1]) g.attach() + pass print('\033[1m%s:\033[m' % 'CRTC:s') crtcs = g.get_crtcs_sync() @@ -106,6 +107,7 @@ for i, fltr in enumerate(table.filters): for y in zip(rr, gr, br): print(fmt % y) print() +table_nc = table table = g.get_gamma_sync(cg.FilterQuery(crtc = crtc, coalesce = True)) print('\033[1m%s:\033[m' % 'Filter table') @@ -124,6 +126,7 @@ for fltr in table.filters: for y in zip(rr, gr, br): print(fmt % y) print() +table_c = table fltr = cg.Filter(0, crtc, 'pylibcoopgamma::test::test', cg.Lifespan.UNTIL_DEATH, table.depth, cg.Ramps(table.red_size, table.green_size, table.blue_size)) @@ -219,5 +222,68 @@ if info.gamut is not None: if info2.gamut.white.y_raw != info.gamut.white.y_raw or info2.gamut.white.y != info.gamut.white.y: sys.exit(4) +try: + g.set_gamma_send(cg.Filter(crtc = crtc, fclass = 'pylibcoopgamma::test::test', + lifespan = cg.Lifespan.REMOVE), async) +except OSError as e: + flush(e) +if g.synchronise([async]) != 0: + sys.exit(1) +g.set_gamma_recv(async) + +try: + g.get_gamma_send(cg.FilterQuery(crtc = crtc, coalesce = False), async) +except OSError as e: + flush(e) +if g.synchronise([async]) != 0: + sys.exit(5) +table = g.get_gamma_recv(async) +if table.red_size != table_nc.red_size: + sys.exit(6) +if table.green_size != table_nc.green_size: + sys.exit(6) +if table.blue_size != table_nc.blue_size: + sys.exit(6) +if table.depth != table_nc.depth: + sys.exit(6) +if len(table.filters) != len(table_nc.filters): + sys.exit(6) +for i, (fltr1, fltr2) in enumerate(zip(table.filters, table_nc.filters)): + if fltr1.priority != fltr2.priority: + sys.exit(6) + if fltr1.fclass != fltr2.fclass: + sys.exit(6) + if fltr1.ramps.red != fltr2.ramps.red: + sys.exit(6) + if fltr1.ramps.green != fltr2.ramps.green: + sys.exit(6) + if fltr1.ramps.blue != fltr2.ramps.blue: + sys.exit(6) + +try: + g.get_gamma_send(cg.FilterQuery(crtc = crtc, coalesce = True), async) +except OSError as e: + flush(e) +if g.synchronise([async]) != 0: + sys.exit(7) +table = g.get_gamma_recv(async) +if table.red_size != table_c.red_size: + sys.exit(8) +if table.green_size != table_c.green_size: + sys.exit(8) +if table.blue_size != table_c.blue_size: + sys.exit(8) +if table.depth != table_c.depth: + sys.exit(8) +if len(table.filters) != len(table_c.filters): + sys.exit(8) +for i, (fltr1, fltr2) in enumerate(zip(table.filters, table_c.filters)): + if fltr1.ramps.red != fltr2.ramps.red: + sys.exit(8) + if fltr1.ramps.green != fltr2.ramps.green: + sys.exit(8) + if fltr1.ramps.blue != fltr2.ramps.blue: + sys.exit(8) + del g -- cgit v1.2.3-70-g09d2