Stop %'s in GP_ASSERT() from breaking printf format
[gfxprim.git] / core / tests / GP_Comon.test.c
blobe99cf3db7345f2e8b73eff4fced5fe5d57a11304
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>
28 * Demo ("testing" ;-) tests for GP_Common.h
31 GP_SUITE(GP_Common)
33 GP_TEST(min_max)
35 fail_unless(GP_MIN(-1.5, 2) == -1.5);
36 fail_unless(GP_MAX(4294967295ULL, 1ULL) == 4294967295ULL);
37 int x=0, y=0;
38 fail_unless(GP_MAX(x++, ++y) == 1);
39 fail_unless(x == 1 && y == 1);
41 GP_ENDTEST
43 GP_TEST(get_bits)
45 fail_unless(GP_GET_BITS(15, 7, 0x12345678ULL) == 0x68);
46 fail_unless(GP_GET_BITS(0, 0, 0x12345678ULL) == 0);
47 fail_unless(GP_GET_BITS(16, 16, 0x1234) == 0);
48 fail_unless(GP_GET_BITS(1, 32, 0x12345678ULL) == 0x091A2B3CULL);
50 GP_ENDTEST
52 GP_TEST(set_bits)
54 uint32_t x = 0x89ABC;
55 uint16_t *y = (uint16_t*) &x;
56 GP_CLEAR_BITS(3, 4, x);
57 fail_unless(x == 0x89A84);
58 GP_SET_BITS_OR(10, x, 0x0000000);
59 fail_unless(x == 0x89A84);
60 GP_SET_BITS(24, 18, x, 0x42F1);
61 fail_unless(x == 0xF1089A84);
62 /* Check that only uint16_t is affected */
63 GP_SET_BITS(0, 24, *y, 0x100F000LL);
64 fail_unless(x == 0xF108F000);
66 GP_ENDTEST
68 GP_TEST(abort_check_assert, "loop_start=0, loop_end=9, expect_exit=1")
70 if (_i==0) GP_ABORT();
71 if (_i==1) GP_ABORT("MSG");
72 if (_i==2) GP_ABORT("FORMAT %d", _i);
73 if (_i==3) GP_ASSERT(1==0);
74 if (_i==4) GP_ASSERT(1==0, "MSG");
75 if (_i==5) GP_ASSERT(1==0, "FORMAT %d", _i);
76 if (_i==6) GP_CHECK(1==0);
77 if (_i==7) GP_CHECK(1==0, "MSG");
78 if (_i==8) GP_CHECK(1==0, "FORMAT %d", _i);
80 GP_ENDTEST
82 GP_TEST(assert_check_nop)
84 /* Also tests % in conditon */
85 GP_ASSERT(7 % 3 == 1);
86 GP_ASSERT(7 % 3 == 1, "MSG");
87 GP_CHECK(7 % 3 == 1);
88 GP_CHECK(7 % 3 == 1, "MSG");
90 GP_ENDTEST