diff options
Diffstat (limited to 'test/dtypes.c')
-rw-r--r-- | test/dtypes.c | 94 |
1 files changed, 89 insertions, 5 deletions
diff --git a/test/dtypes.c b/test/dtypes.c index e3d300f..a2f9a76 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -517,14 +517,100 @@ test_named (void) static herr_t test_conv_num (void) { - const size_t ntests=1; - const size_t nelmts=1; + const size_t ntests=100; + const size_t nelmts=2000; size_t i, j; void *buf=NULL, *saved=NULL; + unsigned char byte[4]; - printf ("%-70s", "Testing atomic number conversions"); + /*--------------------------------------------------------------------- + * Test some specific overflow/underflow cases. + *--------------------------------------------------------------------- + */ + printf ("%-70s", "Testing atomic number overflow conversions"); + fflush (stdout); + + /* (unsigned)0x80000000 -> (unsigned)0xffff */ + byte[0] = byte[1] = byte[2] = 0; + byte[3] = 0x80; + if (H5Tconvert (H5T_NATIVE_UINT32, H5T_NATIVE_UINT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0xff || byte[1]!=0xff) { + puts ("*FAILED*"); + puts (" (unsigned)0x80000000 -> (unsigned)0xffff"); + goto error; + } + + /* (unsigned)0xffffffff -> (signed)0x7fff */ + byte[0] = byte[1] = byte[2] = byte[3] = 0xff; + if (H5Tconvert (H5T_NATIVE_UINT32, H5T_NATIVE_INT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0xff || byte[1]!=0x7f) { + puts ("*FAILED*"); + puts (" (unsigned)0xffffffff -> (signed)0x7f"); + goto error; + } + /* (signed)0xffffffff -> (unsigned)0x0000 */ + byte[0] = byte[1] = byte[2] = byte[3] = 0xff; + if (H5Tconvert (H5T_NATIVE_INT32, H5T_NATIVE_UINT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0x00 || byte[1]!=0x00) { + puts ("*FAILED*"); + puts (" (signed)0xffffffff -> (unsigned)0x00"); + goto error; + } + + /* (signed)0x7fffffff -> (unsigned)0xffff */ + byte[0] = byte[1] = byte[2] = 0xff; + byte[3] = 0x7f; + if (H5Tconvert (H5T_NATIVE_INT32, H5T_NATIVE_UINT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0xff || byte[1]!=0xff) { + puts ("*FAILED*"); + puts (" (signed)0x7fffffff -> (unsigned)0xffff"); + goto error; + } + + /* (signed)0x7fffffff -> (signed)0x7fff */ + byte[0] = byte[1] = byte[2] = 0xff; + byte[3] = 0x7f; + if (H5Tconvert (H5T_NATIVE_INT32, H5T_NATIVE_INT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0xff || byte[1]!=0x7f) { + puts ("*FAILED*"); + puts (" (signed)0x7fffffff -> (signed)0x7fff"); + goto error; + } + + /* (signed)0xbfffffff -> (signed)0x8000 */ + byte[0] = byte[1] = byte[2] = 0xff; + byte[3] = 0xbf; + if (H5Tconvert (H5T_NATIVE_INT32, H5T_NATIVE_INT16, 1, byte, NULL)<0) { + goto error; + } + if (byte[0]!=0x00 || byte[1]!=0x80) { + puts ("*FAILED*"); + puts (" (signed)0xbfffffff -> (signed)0x8000"); + goto error; + } + + puts (" PASSED"); + + + /*----------------------------------------------------------------------- + * Test random cases. + *----------------------------------------------------------------------- + */ + printf ("%-70s", "Testing atomic number random conversions"); + fflush (stdout); + /* Allocate buffers */ buf = malloc (nelmts*8); saved = malloc (nelmts*8); @@ -597,9 +683,7 @@ main(void) nerrors += test_compound()<0 ? 1 : 0; nerrors += test_transient ()<0 ? 1 : 0; nerrors += test_named ()<0 ? 1 : 0; -#if 0 nerrors += test_conv_num ()<0 ? 1 : 0; -#endif if (nerrors) { printf("***** %d DATA TYPE TEST%s FAILED! *****\n", |