3 // Copyright (C) 2006 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program 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
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #define ENSC_TESTSUITE
24 #include "lib_internal/util.h"
25 #include "lib_internal/coreassert.h"
27 #define TEST_TMPL(FUNC, TYPE, STR, VAL, STRICT) \
29 TYPE exp = (TYPE)(VAL)!=(TYPE)BAD ? (VAL) : 0; \
30 bool val = (TYPE)(VAL)==(TYPE)BAD ? false : true; \
32 bool rc = FUNC((STR), &tmp, (STRICT)); \
33 char const * const UNUSED STR_FUNC = #FUNC; \
34 char const * const UNUSED STR_VAL = #VAL; \
35 char const * const UNUSED STR_STRICT = #STRICT; \
37 rc = FUNC((STR), 0, (STRICT)); \
39 if (val) assert(tmp == exp); \
42 #define TESTS(STR, VAL, STRICT) \
43 TEST_TMPL(isNumber, signed long, STR, VAL, STRICT)
45 #define TESTU(STR, VAL, STRICT) \
46 TEST_TMPL(isNumberUnsigned, unsigned long, STR, VAL, STRICT)
48 #define TEST(STR, VALS0, VALS1, VALU0, VALU1) \
49 TESTS(STR, VALS0, true); \
50 TESTS(STR, VALS1, false); \
51 TESTU(STR, VALU0, true); \
52 TESTU(STR, VALU1, false);
55 #define BAD 0xdeadbeaf
59 TEST( "0", 0, 0, 0, 0);
60 TEST( "1", 1, 1, 1, 1);
61 TEST("-1", -1, -1, BAD, BAD);
62 TEST( "1k", BAD, 1000, BAD, 1000);
63 //TEST("-1k", BAD, -1000, BAD, BAD);
64 TEST( "1K", BAD, 1024, BAD, 1024);
65 //TEST("-1K", BAD, -1024, BAD, BAD);
66 TEST( "1m", BAD, 1000000, BAD, 1000000);
67 //TEST("-1m", BAD, -1000000, BAD, BAD);
68 TEST( "1M", BAD, 1048576, BAD, 1048576);
69 //TEST("-1M", BAD, -1048576, BAD, BAD);
71 TEST( "010", 8, 8, 8, 8);
72 TEST( "010k", BAD, 8000, BAD, 8000);
73 TEST("-010", -8, -8, BAD, BAD);
74 //TEST("-010k", BAD, 8000, BAD, BAD);
76 TEST( "0x10", 16, 16, 16, 16);
77 TEST( "0x10k", BAD, 16000, BAD, 16000);
78 TEST("-0x10", -16, -16, BAD, BAD);
79 //TEST("-0x10k", BAD, -16000, BAD, BAD);