|
From: <sv...@va...> - 2009-02-23 04:17:04
|
Author: njn
Date: 2009-02-23 04:16:56 +0000 (Mon, 23 Feb 2009)
New Revision: 9235
Log:
Merged part of r9234 (unit_libcbase improvements) from the DARWIN branch.
Modified:
trunk/memcheck/tests/unit_libcbase.c
Modified: trunk/memcheck/tests/unit_libcbase.c
===================================================================
--- trunk/memcheck/tests/unit_libcbase.c 2009-02-23 04:14:34 UTC (rev 9234)
+++ trunk/memcheck/tests/unit_libcbase.c 2009-02-23 04:16:56 UTC (rev 9235)
@@ -6,38 +6,40 @@
#include "coregrind/m_libcbase.c"
+#define CHECK(x) \
+ if (!x) { fprintf(stderr, "failure: %s:%d\n", __FILE__, __LINE__); }
void test_isXYZ(void)
{
- assert( VG_(isspace)(' ') );
- assert( VG_(isspace)('\n') );
- assert( VG_(isspace)('\t') );
- assert( ! VG_(isspace)('3') );
- assert( ! VG_(isspace)('x') );
+ CHECK( VG_(isspace)(' ') );
+ CHECK( VG_(isspace)('\n') );
+ CHECK( VG_(isspace)('\t') );
+ CHECK( ! VG_(isspace)('3') );
+ CHECK( ! VG_(isspace)('x') );
- assert( VG_(isdigit)('0') );
- assert( VG_(isdigit)('1') );
- assert( VG_(isdigit)('5') );
- assert( VG_(isdigit)('9') );
- assert( ! VG_(isdigit)('a') );
- assert( ! VG_(isdigit)('!') );
+ CHECK( VG_(isdigit)('0') );
+ CHECK( VG_(isdigit)('1') );
+ CHECK( VG_(isdigit)('5') );
+ CHECK( VG_(isdigit)('9') );
+ CHECK( ! VG_(isdigit)('a') );
+ CHECK( ! VG_(isdigit)('!') );
}
void test_is_XYZ_digit()
{
Long x;
- assert( is_dec_digit('0', &x) && 0 == x );
- assert( is_dec_digit('1', &x) && 1 == x );
- assert( is_dec_digit('9', &x) && 9 == x );
+ CHECK( is_dec_digit('0', &x) && 0 == x );
+ CHECK( is_dec_digit('1', &x) && 1 == x );
+ CHECK( is_dec_digit('9', &x) && 9 == x );
- assert( is_hex_digit('0', &x) && 0 == x );
- assert( is_hex_digit('1', &x) && 1 == x );
- assert( is_hex_digit('9', &x) && 9 == x );
- assert( is_hex_digit('a', &x) && 10 == x );
- assert( is_hex_digit('f', &x) && 15 == x );
- assert( is_hex_digit('A', &x) && 10 == x );
- assert( is_hex_digit('F', &x) && 15 == x );
+ CHECK( is_hex_digit('0', &x) && 0 == x );
+ CHECK( is_hex_digit('1', &x) && 1 == x );
+ CHECK( is_hex_digit('9', &x) && 9 == x );
+ CHECK( is_hex_digit('a', &x) && 10 == x );
+ CHECK( is_hex_digit('f', &x) && 15 == x );
+ CHECK( is_hex_digit('A', &x) && 10 == x );
+ CHECK( is_hex_digit('F', &x) && 15 == x );
}
void test_strtoll(void)
@@ -90,8 +92,8 @@
long long res2 = strtoll (a[i].str, &endptr2, 10);
//printf("res1 = %lld, *endptr1 = '%c'\n", res1, *endptr1);
//printf("res2 = %lld, *endptr2 = '%c'\n", res2, *endptr2);
- assert(a[i].res == res1 && a[i].endptr_val == *endptr1);
- assert(res2 == res1 && *endptr2 == *endptr1);
+ CHECK(a[i].res == res1 && a[i].endptr_val == *endptr1);
+ CHECK(res2 == res1 && *endptr2 == *endptr1);
}
}
@@ -145,60 +147,13 @@
long long res2 = strtoll (a[i].str, &endptr2, 16);
//printf(" res1 = %lld, *endptr1 = '%c'\n", res1, *endptr1);
//printf(" res2 = %lld, *endptr2 = '%c'\n", res2, *endptr2);
- assert(a[i].res == res1 && a[i].endptr_val == *endptr1);
- assert(res2 == res1 && *endptr2 == *endptr1);
+ CHECK(a[i].res == res1 && a[i].endptr_val == *endptr1);
+ CHECK(res2 == res1 && *endptr2 == *endptr1);
}
}
- // VG_(strtod)()
- {
- StrtollInputs a[] = {
- // If there's no number at the head of the string, return 0, and
- // make 'endptr' point to the start of the string.
- { str : "", res : 0, endptr_val : '\0' },
- { str : " \n\t", res : 0, endptr_val : ' ' },
- { str : "one", res : 0, endptr_val : 'o' },
- { str : "\ntwo", res : 0, endptr_val : '\n' },
- // Successful conversion. Leading whitespace is ignored. A single
- // '-' or '+' is accepted. "0X" and "0x" are also allowed at the
- // front, but if no digits follow, just the "0" is converted.
- { str : "0", res : 0, endptr_val : '\0' },
- { str : "0", res : 0, endptr_val : '\0' },
- { str : "+0", res : 0, endptr_val : '\0' },
- { str : "-0", res : 0, endptr_val : '\0' },
- { str : "1", res : 1, endptr_val : '\0' },
- { str : "+1", res : 1, endptr_val : '\0' },
- { str : "-1", res : -1, endptr_val : '\0' },
- { str : "1a", res : 26, endptr_val : '\0' },
- { str : "-5F7", res : -1527, endptr_val : '\0' },
- { str : "0x1234567", res : 19088743, endptr_val : '\0' },
- { str : "007", res : 7, endptr_val : '\0' },
- { str : "0X00ABCD", res : 43981, endptr_val : '\0' },
- { str : " +AbC", res : 2748, endptr_val : '\0' },
- { str : " -0xAbC", res : -2748, endptr_val : '\0' },
- { str : " -0xxx", res : 0, endptr_val : 'x' },
- { str : "\n\t\r\v -56", res : -86, endptr_val : '\0' },
- { str : "123xyz", res : 291, endptr_val : 'x' },
- { str : " -123defghi", res : -1195503, endptr_val : 'g' },
-
- // Whitespace after the +/- is not allowed; conversion fails.
- { str : "+ 1", res : 0, endptr_val : '+' },
- { str : "-\n0x1", res : 0, endptr_val : '-' },
- };
-
- // Nb: We test the results against strtoll() as well.
- int i;
- for (i = 0; i < (sizeof(a) / sizeof(StrtollInputs)); i++) {
- Char* endptr1;
- char* endptr2;
- Long res1 = VG_(strtoll16)(a[i].str, &endptr1);
- long long res2 = strtoll (a[i].str, &endptr2, 16);
- //printf(" res1 = %lld, *endptr1 = '%c'\n", res1, *endptr1);
- //printf(" res2 = %lld, *endptr2 = '%c'\n", res2, *endptr2);
- assert(a[i].res == res1 && a[i].endptr_val == *endptr1);
- assert(res2 == res1 && *endptr2 == *endptr1);
- }
- }
+ // VG_(strtod)()
+ // XXX: todo
}
int main(void)
|