source: mainline/uspace/lib/gfx/test/coord.c@ 7b882c1f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7b882c1f was 7b882c1f, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Need some vector operations

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2019 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <gfx/coord.h>
30#include <pcut/pcut.h>
31
32PCUT_INIT;
33
34PCUT_TEST_SUITE(coord);
35
36extern void gfx_coord2_add(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
37extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
38extern void gfx_rect_translate(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *);
39
40/** gfx_coord2_add should add two coordinate vectors */
41PCUT_TEST(coord2_add)
42{
43 gfx_coord2_t a, b;
44 gfx_coord2_t d;
45
46 a.x = 10;
47 a.y = 11;
48 b.x = 20;
49 b.y = 22;
50
51 gfx_coord2_add(&a, &b, &d);
52
53 PCUT_ASSERT_EQUALS(a.x + b.x, d.x);
54 PCUT_ASSERT_EQUALS(a.y + b.y, d.y);
55}
56
57/** gfx_coord2_subtract should subtract two coordinate vectors */
58PCUT_TEST(coord2_subtract)
59{
60 gfx_coord2_t a, b;
61 gfx_coord2_t d;
62
63 a.x = 10;
64 a.y = 11;
65 b.x = 20;
66 b.y = 22;
67
68 gfx_coord2_subtract(&a, &b, &d);
69
70 PCUT_ASSERT_EQUALS(a.x - b.x, d.x);
71 PCUT_ASSERT_EQUALS(a.y - b.y, d.y);
72}
73
74/** gfx_rect_translate should translate rectangle */
75PCUT_TEST(rect_translate)
76{
77 gfx_coord2_t offs;
78 gfx_rect_t srect;
79 gfx_rect_t drect;
80
81 offs.x = 5;
82 offs.y = 6;
83
84 srect.p0.x = 10;
85 srect.p0.y = 11;
86 srect.p1.x = 20;
87 srect.p1.y = 22;
88
89 gfx_rect_translate(&offs, &srect, &drect);
90
91 PCUT_ASSERT_EQUALS(offs.x + srect.p0.x, drect.p0.x);
92 PCUT_ASSERT_EQUALS(offs.y + srect.p0.y, drect.p0.y);
93 PCUT_ASSERT_EQUALS(offs.x + srect.p1.x, drect.p1.x);
94 PCUT_ASSERT_EQUALS(offs.y + srect.p1.y, drect.p1.y);
95}
96
97PCUT_EXPORT(coord);
Note: See TracBrowser for help on using the repository browser.