• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include "config.h"
27 
28 #include <assert.h>
29 #include <stdint.h>
30 
31 #include <libweston/libweston.h>
32 #include "libweston-internal.h"
33 #include "compositor/weston.h"
34 #include "weston-test-runner.h"
35 #include "weston-test-fixture-compositor.h"
36 
37 static enum test_result_code
fixture_setup(struct weston_test_harness * harness)38 fixture_setup(struct weston_test_harness *harness)
39 {
40 	struct compositor_setup setup;
41 
42 	compositor_setup_defaults(&setup);
43 
44 	return weston_test_harness_execute_as_plugin(harness, &setup);
45 }
46 DECLARE_FIXTURE_SETUP(fixture_setup);
47 
PLUGIN_TEST(surface_to_from_global)48 PLUGIN_TEST(surface_to_from_global)
49 {
50 	/* struct weston_compositor *compositor; */
51 	struct weston_surface *surface;
52 	struct weston_view *view;
53 	float x, y;
54 	wl_fixed_t fx, fy;
55 	int32_t ix, iy;
56 
57 	surface = weston_surface_create(compositor);
58 	assert(surface);
59 	view = weston_view_create(surface);
60 	assert(view);
61 	surface->width = 50;
62 	surface->height = 50;
63 	weston_view_set_position(view, 5, 10);
64 	weston_view_update_transform(view);
65 
66 	weston_view_to_global_float(view, 33, 22, &x, &y);
67 	assert(x == 38 && y == 32);
68 
69 	weston_view_to_global_float(view, -8, -2, &x, &y);
70 	assert(x == -3 && y == 8);
71 
72 	weston_view_to_global_fixed(view, wl_fixed_from_int(12),
73 				       wl_fixed_from_int(5), &fx, &fy);
74 	assert(fx == wl_fixed_from_int(17) && fy == wl_fixed_from_int(15));
75 
76 	weston_view_from_global_float(view, 38, 32, &x, &y);
77 	assert(x == 33 && y == 22);
78 
79 	weston_view_from_global_float(view, 42, 5, &x, &y);
80 	assert(x == 37 && y == -5);
81 
82 	weston_view_from_global_fixed(view, wl_fixed_from_int(21),
83 					 wl_fixed_from_int(100), &fx, &fy);
84 	assert(fx == wl_fixed_from_int(16) && fy == wl_fixed_from_int(90));
85 
86 	weston_view_from_global(view, 0, 0, &ix, &iy);
87 	assert(ix == -5 && iy == -10);
88 
89 	weston_view_from_global(view, 5, 10, &ix, &iy);
90 	assert(ix == 0 && iy == 0);
91 }
92