X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Mon, 23 Feb 2004 15:34:52 -0500 Message-Id: <200402232034.i1NKYqrt024366@envy.delorie.com> From: DJ Delorie To: djgpp-workers AT delorie DOT com In-reply-to: <403A5F55.7E608910@yahoo.com> (message from CBFalconer on Mon, 23 Feb 2004 15:15:17 -0500) Subject: Re: strtoul bug (was Re: Fibonacci number) References: <4038E8CA DOT 6491815E AT virginia DOT edu> <4039DD96 DOT 3F36F3B7 AT yahoo DOT com> <200402231458 DOT i1NEwKwm020904 AT envy DOT delorie DOT com> <403A301C DOT E8F5FE65 AT yahoo DOT com> <200402231751 DOT i1NHp5lv022894 AT envy DOT delorie DOT com> <403A5F55 DOT 7E608910 AT yahoo DOT com> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk I'm thinking something table-driven would be better; no user input should be needed for a test case. How about a table like this? struct { char *input_string; int base; /* int expected_endp; /* index into string */ unsigned char expected_value[8]; int expected_errno; } tests[] = { { "0", 0, 1, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0 }, { "10x", 8, 2, { 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 0 }, /* etc */ { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 }, 0 } } We could have one table for each function (strtol, strtoul, strtoll, strtoull) and pass the table, function, and size of result (4 or 8) to a common "test this" function. The function should print nothing and exit(0) if they all pass, else print a diagnostic and exit(1) if any fail.