diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-04 17:34:43 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-04 17:34:43 +0000 |
commit | 31871d0d1ea28fbd8ccdfe08747393770c78797a (patch) | |
tree | ba0957fc2fce864f69f9709ad8aebb36cebf58c8 /tests/tstrtoc.c | |
parent | dd15486f885a3fc86a412a68f9afca6dc019f098 (diff) | |
download | mpc-31871d0d1ea28fbd8ccdfe08747393770c78797a.tar.gz |
src/strtoc.c: Check if nptr is NULL.
tests/strtoc.dat: Add invalid values for the base parameter.
tests/tstrtoc.c: Add a check for null pointer and empty string.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@437 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests/tstrtoc.c')
-rw-r--r-- | tests/tstrtoc.c | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/tstrtoc.c b/tests/tstrtoc.c index 2bec657..8f9c66d 100644 --- a/tests/tstrtoc.c +++ b/tests/tstrtoc.c @@ -55,8 +55,6 @@ static const char *rnd_mode[] = "undefined", "undefined", }; -static char file_name[] = "strtoc.dat"; - static void read_int (FILE *fp, int *nread, const char *name) { @@ -141,8 +139,8 @@ read_string (FILE *fp, char **buffer_ptr, size_t buffer_length, const char *name exit (1); } -int -main (void) +static void +check_file (const char* file_name) { FILE *fp; @@ -254,6 +252,44 @@ main (void) if (rstr != NULL) free (rstr); free (pathname); +} + +static void +check_null (void) +{ + int inex; + char *end; + mpc_t z; + + mpc_init2 (z, 53); + + inex = mpc_strtoc (z, NULL, &end, 10, MPC_RNDNN); + if (end != NULL || inex != 0 || mpfr_nan_p (MPC_RE (z)) == 0 + || mpfr_nan_p (MPC_IM (z)) == 0) + { + printf ("Error: mpc_strtoc(z, NULL) with an NULL pointer should fail" + " and the z value should be set to NaN +I*NaN\ngot "); + OUT (z); + exit (1); + } + + inex = mpc_strtoc (z, "", &end, 10, MPC_RNDNN); + if (inex != 0 || mpfr_nan_p (MPC_RE (z)) == 0 + || mpfr_nan_p (MPC_IM (z)) == 0) + { + printf ("Error: mpc_strtoc(z, "") with an empty string should fail" + " and the z value should be set to NaN +I*NaN\ngot "); + OUT (z); + exit (1); + } + mpc_clear (z); +} + +int +main (void) +{ + check_null (); + check_file ("strtoc.dat"); return 0; } |