Testing framework refactoring and move, new tests.mk
[gfxprim.git] / tests / core / GP_Common.test.c
blob0fe2b1f249e3ea6edfed14527705ccb72ef11a1d
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include "GP_Tests.h"
25 #include <GP_Common.h>
26 #include <unistd.h>
29 * Demo ("testing" ;-) tests for GP_Common.h
32 GP_SUITE(GP_Common)
34 GP_TEST(min_max)
36 fail_unless(GP_MIN(-1.5, 2) == -1.5);
37 fail_unless(GP_MAX(4294967295ULL, 1ULL) == 4294967295ULL);
38 int x=0, y=0;
39 fail_unless(GP_MAX(x++, ++y) == 1);
40 fail_unless(x == 1 && y == 1);
42 GP_ENDTEST
44 GP_TEST(get_bits)
46 fail_unless(GP_GET_BITS(15, 7, 0x12345678ULL) == 0x68);
47 fail_unless(GP_GET_BITS(0, 0, 0x12345678ULL) == 0);
48 fail_unless(GP_GET_BITS(16, 16, 0x1234) == 0);
49 fail_unless(GP_GET_BITS(1, 32, 0x12345678ULL) == 0x091A2B3CULL);
51 GP_ENDTEST
53 GP_TEST(set_bits)
55 uint32_t x = 0x89ABC;
56 uint16_t *y = (uint16_t*) &x;
57 GP_CLEAR_BITS(3, 4, x);
58 fail_unless(x == 0x89A84);
59 GP_SET_BITS_OR(10, x, 0x0000000);
60 fail_unless(x == 0x89A84);
61 GP_SET_BITS(24, 18, x, 0x42F1);
62 fail_unless(x == 0xF1089A84);
63 /* Check that only uint16_t is affected */
64 GP_SET_BITS(0, 24, *y, 0x100F000LL);
65 # if __BYTE_ORDER == __BIG_ENDIAN
66 fail_unless(x == 0xF108F000);
67 # else
68 fail_unless(x == 0x100F9A84);
69 # endif
71 GP_ENDTEST
73 GP_TEST(abort_check_assert, "loop_start=0, loop_end=9, expect_signal=6")
75 /* Prevent output during testing */
76 # ifdef stderr
77 # undef stderr
78 # endif
79 # define stderr stdin
80 if (_i==0) GP_ABORT();
81 if (_i==1) GP_ABORT("MSG");
82 if (_i==2) GP_ABORT("FORMAT %d", _i);
83 if (_i==3) GP_ASSERT(1==0);
84 if (_i==4) GP_ASSERT(1==0, "MSG");
85 if (_i==5) GP_ASSERT(1==0, "FORMAT %d", _i);
86 if (_i==6) GP_CHECK(1==0);
87 if (_i==7) GP_CHECK(1==0, "MSG");
88 if (_i==8) GP_CHECK(1==0, "FORMAT %d", _i);
90 GP_ENDTEST
92 GP_TEST(assert_check_nop)
94 /* Also tests % in conditon */
95 GP_ASSERT(7 % 3 == 1);
96 GP_ASSERT(7 % 3 == 1, "MSG");
97 GP_CHECK(7 % 3 == 1);
98 GP_CHECK(7 % 3 == 1, "MSG");
100 GP_ENDTEST