U. Artie Eoff | d690175 | 2012-09-28 06:39:31 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include <assert.h> |
| 24 | |
| 25 | #include "test-runner.h" |
| 26 | |
| 27 | TEST(surface_to_from_global) |
| 28 | { |
| 29 | struct weston_surface *surface; |
| 30 | GLfloat x, y; |
| 31 | wl_fixed_t fx, fy; |
| 32 | int32_t ix, iy; |
| 33 | |
| 34 | surface = weston_surface_create(compositor); |
| 35 | weston_surface_configure(surface, 5, 10, 50, 50); |
| 36 | weston_surface_update_transform(surface); |
| 37 | |
| 38 | weston_surface_to_global_float(surface, 33, 22, &x, &y); |
| 39 | assert(x == 38 && y == 32); |
| 40 | |
| 41 | weston_surface_to_global_float(surface, -8, -2, &x, &y); |
| 42 | assert(x == -3 && y == 8); |
| 43 | |
| 44 | weston_surface_to_global_fixed(surface, wl_fixed_from_int(12), |
| 45 | wl_fixed_from_int(5), &fx, &fy); |
| 46 | assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15)); |
| 47 | |
| 48 | weston_surface_from_global_float(surface, 38, 32, &x, &y); |
| 49 | assert(x == 33 && y == 22); |
| 50 | |
| 51 | weston_surface_from_global_float(surface, 42, 5, &x, &y); |
| 52 | assert(x == 37 && y == -5); |
| 53 | |
| 54 | weston_surface_from_global_fixed(surface, wl_fixed_from_int(21), |
| 55 | wl_fixed_from_int(100), &fx, &fy); |
| 56 | assert(fx = wl_fixed_from_int(16) && fy == wl_fixed_from_int(90)); |
| 57 | |
| 58 | weston_surface_from_global(surface, 0, 0, &ix, &iy); |
| 59 | assert(ix == -5 && iy == -10); |
| 60 | |
| 61 | weston_surface_from_global(surface, 5, 10, &ix, &iy); |
| 62 | assert(ix == 0 && iy == 0); |
| 63 | |
| 64 | wl_display_terminate(compositor->wl_display); |
| 65 | } |