protocol: wl_surface.frame needs wl_surface.commit
[profile/ivi/wayland.git] / tests / fixed-test.c
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <assert.h>
26 #include "wayland-private.h"
27 #include "test-runner.h"
28
29 TEST(fixed_double_conversions)
30 {
31         wl_fixed_t f;
32         double d;
33
34         d = 62.125;
35         f = wl_fixed_from_double(d);
36         fprintf(stderr, "double %lf to fixed %x\n", d, f);
37         assert(f == 0x3e20);
38
39         d = -1200.625;
40         f = wl_fixed_from_double(d);
41         fprintf(stderr, "double %lf to fixed %x\n", d, f);
42         assert(f == -0x4b0a0);
43
44         f = random();
45         d = wl_fixed_to_double(f);
46         fprintf(stderr, "fixed %x to double %lf\n", f, d);
47         assert(d == f / 256.0);
48
49         f = 0x012030;
50         d = wl_fixed_to_double(f);
51         fprintf(stderr, "fixed %x to double %lf\n", f, d);
52         assert(d == 288.1875);
53
54         f = 0x70000000;
55         d = wl_fixed_to_double(f);
56         fprintf(stderr, "fixed %x to double %lf\n", f, d);
57         assert(d == f / 256);
58
59         f = -0x012030;
60         d = wl_fixed_to_double(f);
61         fprintf(stderr, "fixed %x to double %lf\n", f, d);
62         assert(d == -288.1875);
63
64         f = 0x80000000;
65         d = wl_fixed_to_double(f);
66         fprintf(stderr, "fixed %x to double %lf\n", f, d);
67         assert(d == f / 256);
68 }
69
70 TEST(fixed_int_conversions)
71 {
72         wl_fixed_t f;
73         int i;
74
75         i = 62;
76         f = wl_fixed_from_int(i);
77         assert(f == 62 * 256);
78
79         i = -2080;
80         f = wl_fixed_from_int(i);
81         assert(f == -2080 * 256);
82
83         f = 0x277013;
84         i = wl_fixed_to_int(f);
85         assert(i == 0x2770);
86
87         f = -0x5044;
88         i = wl_fixed_to_int(f);
89         assert(i == -0x50);
90 }