hdf5/test/dtypes.c

697 lines
18 KiB
C
Raw Normal View History

/*
* Copyright (C) 1997 NCSA
* All rights reserved.
*
* Programmer: Robb Matzke <matzke@llnl.gov>
* Tuesday, December 9, 1997
*
* Purpose: Tests the data type interface (H5T)
*/
#include <hdf5.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <H5config.h>
#ifndef HAVE_ATTRIBUTE
# undef __attribute__
# define __attribute__(X) /*void*/
# define __unused__ /*void*/
#else
# define __unused__ __attribute__((unused))
#endif
#define FILE_NAME_1 "dtypes1.h5"
#define FILE_NAME_2 "dtypes2.h5"
typedef struct complex_t {
double re;
double im;
} complex_t;
/*-------------------------------------------------------------------------
* Function: cleanup
*
* Purpose: Removes test files
*
* Return: void
*
* Programmer: Robb Matzke
* Thursday, June 4, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
cleanup (void)
{
if (!getenv ("HDF5_NOCLEANUP")) {
remove (FILE_NAME_1);
remove (FILE_NAME_2);
}
}
/*-------------------------------------------------------------------------
* Function: display_error_cb
*
* Purpose: Displays the error stack after printing "*FAILED*".
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Wednesday, March 4, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
display_error_cb (void __unused__ *client_data)
{
puts ("*FAILED*");
H5Eprint (stdout);
return 0;
}
/*-------------------------------------------------------------------------
* Function: test_classes
*
* Purpose: Test type classes
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_classes(void)
{
H5T_class_t tcls;
printf("%-70s", "Testing H5Tget_class()");
if ((tcls=H5Tget_class(H5T_NATIVE_INT))<0) goto error;
if (H5T_INTEGER!=tcls) {
puts("*FAILED*");
puts(" Invalid type class for H5T_NATIVE_INT");
goto error;
}
if ((tcls=H5Tget_class(H5T_NATIVE_DOUBLE))<0) goto error;
if (H5T_FLOAT!=tcls) {
puts("*FAILED*");
puts(" Invalid type class for H5T_NATIVE_DOUBLE");
goto error;
}
puts(" PASSED");
return 0;
error:
return -1;
}
/*-------------------------------------------------------------------------
* Function: test_copy
*
* Purpose: Are we able to copy a data type?
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_copy(void)
{
[svn-r303] Changes since 19980228 ---------------------- ./html/Dataspaces.html ./html/Errors.html ./html/Files.html ./html/H5.api.html ./html/review1.html ./src/H5private.h ./src/H5public.h ./test/dsets.c ./test/dtypes.c Removed all the types like `int32' and `intn' into private headers since they violate the naming scheme and pollute application name space. Besides, our test files only use them in a handful of places and it's probably useless to export them to the app. The app is always written in terms of standard numeric types or its own numeric types and probably never in terms of HDF5 numeric types. If it were, then the user would have to copy from their type to hdf5 type for almost every hdf5 API function call! Same goes for return values. I also removed SUCCEED/FAIL from the API since apps should be checking against zero anyway. if (FAIL==(space=H5Screate_simple(...))) /*wrong*/ if ((space=H5Fcreate_simple(...)<0)) /*right*/ ./src/H5.c Changed arguments of H5version() from `uintn' to `unsigned'. ./src/H5Tpublic.h ./src/H5T.c Changed return type of H5Tget_nmembers() from `intn' to `int' ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h Changed `H5Asearch_func_t' to `H5A_search_func_t' and moved its definition from the public to the private header file. ./html/H5.format.html Documented changes made to the external file list (H5O_EFL) message. ./src/H5D.c ./src/H5Dprivate.h ./src/H5E.c ./src/H5Epublic.h ./src/H5O.c ./src/H5Oefl.c ./src/H5Oprivate.h ./src/H5P.c ./src/H5Ppublic.h Added partial support for external raw data files. HDF5 can now describe external raw data files by listing the file names, offsets, and size for a dataset. However, we will restrict a dataset to be stored "contiguously" when the external file list is viewed as a single address space. The current implementation is unable to read/write to external files--that will come later this week as will documentation. For now, take a look at ./test/external.c, particularly the calls to H5Pset_external(). ./test/Makefile.in ./test/external.c [NEW] ./MANIFEST Added tests for external storage. Note: the read test is supposed to fail at this point since reading external datasets is not implemented yet. There is no write test. ./src/H5S.c ./src/H5Sprivate.h ./src/H5Ssimp.c Added H5S_get_npoints_max() to return the maximum possible number of data points in a data space. Added an extra argument to H5S_get_dims() which returns the maximum dims. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h ./src/H5M.c [DEPRICATED] ./src/H5Mpublic.h [DEPRICATED] Changed `template' to `property list' in lots of places. ./src/H5Osdspace.c Removed an extra `\n' from a print statement. ./src/H5S_public.h Changed H5S_UNLIMITED to the maximum size_t value. ./test/extend.c "Extendable" is spelled "extendible". ./src/H5Farray.c ./src/H5V.c ./src/H5Vprivate.h ./test/hyperslab.c Strides are now type ssize_t instead of int. These have nothing to do with the sample granularity arguments for hyperslabs, which are also called "strides" in the code. ./test/tstab.c Changed assumptions about default address and length sizes.
1998-03-05 00:20:23 +08:00
hid_t a_copy;
printf("%-70s", "Testing H5Tcopy()");
if ((a_copy = H5Tcopy(H5T_NATIVE_SHORT)) < 0) goto error;
if (H5Tclose(a_copy) < 0) goto error;
[svn-r303] Changes since 19980228 ---------------------- ./html/Dataspaces.html ./html/Errors.html ./html/Files.html ./html/H5.api.html ./html/review1.html ./src/H5private.h ./src/H5public.h ./test/dsets.c ./test/dtypes.c Removed all the types like `int32' and `intn' into private headers since they violate the naming scheme and pollute application name space. Besides, our test files only use them in a handful of places and it's probably useless to export them to the app. The app is always written in terms of standard numeric types or its own numeric types and probably never in terms of HDF5 numeric types. If it were, then the user would have to copy from their type to hdf5 type for almost every hdf5 API function call! Same goes for return values. I also removed SUCCEED/FAIL from the API since apps should be checking against zero anyway. if (FAIL==(space=H5Screate_simple(...))) /*wrong*/ if ((space=H5Fcreate_simple(...)<0)) /*right*/ ./src/H5.c Changed arguments of H5version() from `uintn' to `unsigned'. ./src/H5Tpublic.h ./src/H5T.c Changed return type of H5Tget_nmembers() from `intn' to `int' ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h Changed `H5Asearch_func_t' to `H5A_search_func_t' and moved its definition from the public to the private header file. ./html/H5.format.html Documented changes made to the external file list (H5O_EFL) message. ./src/H5D.c ./src/H5Dprivate.h ./src/H5E.c ./src/H5Epublic.h ./src/H5O.c ./src/H5Oefl.c ./src/H5Oprivate.h ./src/H5P.c ./src/H5Ppublic.h Added partial support for external raw data files. HDF5 can now describe external raw data files by listing the file names, offsets, and size for a dataset. However, we will restrict a dataset to be stored "contiguously" when the external file list is viewed as a single address space. The current implementation is unable to read/write to external files--that will come later this week as will documentation. For now, take a look at ./test/external.c, particularly the calls to H5Pset_external(). ./test/Makefile.in ./test/external.c [NEW] ./MANIFEST Added tests for external storage. Note: the read test is supposed to fail at this point since reading external datasets is not implemented yet. There is no write test. ./src/H5S.c ./src/H5Sprivate.h ./src/H5Ssimp.c Added H5S_get_npoints_max() to return the maximum possible number of data points in a data space. Added an extra argument to H5S_get_dims() which returns the maximum dims. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h ./src/H5M.c [DEPRICATED] ./src/H5Mpublic.h [DEPRICATED] Changed `template' to `property list' in lots of places. ./src/H5Osdspace.c Removed an extra `\n' from a print statement. ./src/H5S_public.h Changed H5S_UNLIMITED to the maximum size_t value. ./test/extend.c "Extendable" is spelled "extendible". ./src/H5Farray.c ./src/H5V.c ./src/H5Vprivate.h ./test/hyperslab.c Strides are now type ssize_t instead of int. These have nothing to do with the sample granularity arguments for hyperslabs, which are also called "strides" in the code. ./test/tstab.c Changed assumptions about default address and length sizes.
1998-03-05 00:20:23 +08:00
/* We should not be able to close a built-in byte */
H5E_BEGIN_TRY {
if (H5Tclose (H5T_NATIVE_CHAR)>=0) {
puts ("*FAILED*");
puts (" Should not be able to close a predefined type!");
goto error;
}
} H5E_END_TRY;
[svn-r303] Changes since 19980228 ---------------------- ./html/Dataspaces.html ./html/Errors.html ./html/Files.html ./html/H5.api.html ./html/review1.html ./src/H5private.h ./src/H5public.h ./test/dsets.c ./test/dtypes.c Removed all the types like `int32' and `intn' into private headers since they violate the naming scheme and pollute application name space. Besides, our test files only use them in a handful of places and it's probably useless to export them to the app. The app is always written in terms of standard numeric types or its own numeric types and probably never in terms of HDF5 numeric types. If it were, then the user would have to copy from their type to hdf5 type for almost every hdf5 API function call! Same goes for return values. I also removed SUCCEED/FAIL from the API since apps should be checking against zero anyway. if (FAIL==(space=H5Screate_simple(...))) /*wrong*/ if ((space=H5Fcreate_simple(...)<0)) /*right*/ ./src/H5.c Changed arguments of H5version() from `uintn' to `unsigned'. ./src/H5Tpublic.h ./src/H5T.c Changed return type of H5Tget_nmembers() from `intn' to `int' ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h Changed `H5Asearch_func_t' to `H5A_search_func_t' and moved its definition from the public to the private header file. ./html/H5.format.html Documented changes made to the external file list (H5O_EFL) message. ./src/H5D.c ./src/H5Dprivate.h ./src/H5E.c ./src/H5Epublic.h ./src/H5O.c ./src/H5Oefl.c ./src/H5Oprivate.h ./src/H5P.c ./src/H5Ppublic.h Added partial support for external raw data files. HDF5 can now describe external raw data files by listing the file names, offsets, and size for a dataset. However, we will restrict a dataset to be stored "contiguously" when the external file list is viewed as a single address space. The current implementation is unable to read/write to external files--that will come later this week as will documentation. For now, take a look at ./test/external.c, particularly the calls to H5Pset_external(). ./test/Makefile.in ./test/external.c [NEW] ./MANIFEST Added tests for external storage. Note: the read test is supposed to fail at this point since reading external datasets is not implemented yet. There is no write test. ./src/H5S.c ./src/H5Sprivate.h ./src/H5Ssimp.c Added H5S_get_npoints_max() to return the maximum possible number of data points in a data space. Added an extra argument to H5S_get_dims() which returns the maximum dims. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h ./src/H5M.c [DEPRICATED] ./src/H5Mpublic.h [DEPRICATED] Changed `template' to `property list' in lots of places. ./src/H5Osdspace.c Removed an extra `\n' from a print statement. ./src/H5S_public.h Changed H5S_UNLIMITED to the maximum size_t value. ./test/extend.c "Extendable" is spelled "extendible". ./src/H5Farray.c ./src/H5V.c ./src/H5Vprivate.h ./test/hyperslab.c Strides are now type ssize_t instead of int. These have nothing to do with the sample granularity arguments for hyperslabs, which are also called "strides" in the code. ./test/tstab.c Changed assumptions about default address and length sizes.
1998-03-05 00:20:23 +08:00
puts(" PASSED");
return 0;
error:
return -1;
}
/*-------------------------------------------------------------------------
* Function: test_compound
*
* Purpose: Tests various things about compound data types.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Wednesday, January 7, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_compound(void)
{
complex_t tmp;
hid_t complex_id;
printf("%-70s", "Testing compound data types");
/* Create the empty type */
if ((complex_id = H5Tcreate(H5T_COMPOUND, sizeof tmp))<0) goto error;
[svn-r303] Changes since 19980228 ---------------------- ./html/Dataspaces.html ./html/Errors.html ./html/Files.html ./html/H5.api.html ./html/review1.html ./src/H5private.h ./src/H5public.h ./test/dsets.c ./test/dtypes.c Removed all the types like `int32' and `intn' into private headers since they violate the naming scheme and pollute application name space. Besides, our test files only use them in a handful of places and it's probably useless to export them to the app. The app is always written in terms of standard numeric types or its own numeric types and probably never in terms of HDF5 numeric types. If it were, then the user would have to copy from their type to hdf5 type for almost every hdf5 API function call! Same goes for return values. I also removed SUCCEED/FAIL from the API since apps should be checking against zero anyway. if (FAIL==(space=H5Screate_simple(...))) /*wrong*/ if ((space=H5Fcreate_simple(...)<0)) /*right*/ ./src/H5.c Changed arguments of H5version() from `uintn' to `unsigned'. ./src/H5Tpublic.h ./src/H5T.c Changed return type of H5Tget_nmembers() from `intn' to `int' ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h Changed `H5Asearch_func_t' to `H5A_search_func_t' and moved its definition from the public to the private header file. ./html/H5.format.html Documented changes made to the external file list (H5O_EFL) message. ./src/H5D.c ./src/H5Dprivate.h ./src/H5E.c ./src/H5Epublic.h ./src/H5O.c ./src/H5Oefl.c ./src/H5Oprivate.h ./src/H5P.c ./src/H5Ppublic.h Added partial support for external raw data files. HDF5 can now describe external raw data files by listing the file names, offsets, and size for a dataset. However, we will restrict a dataset to be stored "contiguously" when the external file list is viewed as a single address space. The current implementation is unable to read/write to external files--that will come later this week as will documentation. For now, take a look at ./test/external.c, particularly the calls to H5Pset_external(). ./test/Makefile.in ./test/external.c [NEW] ./MANIFEST Added tests for external storage. Note: the read test is supposed to fail at this point since reading external datasets is not implemented yet. There is no write test. ./src/H5S.c ./src/H5Sprivate.h ./src/H5Ssimp.c Added H5S_get_npoints_max() to return the maximum possible number of data points in a data space. Added an extra argument to H5S_get_dims() which returns the maximum dims. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h ./src/H5M.c [DEPRICATED] ./src/H5Mpublic.h [DEPRICATED] Changed `template' to `property list' in lots of places. ./src/H5Osdspace.c Removed an extra `\n' from a print statement. ./src/H5S_public.h Changed H5S_UNLIMITED to the maximum size_t value. ./test/extend.c "Extendable" is spelled "extendible". ./src/H5Farray.c ./src/H5V.c ./src/H5Vprivate.h ./test/hyperslab.c Strides are now type ssize_t instead of int. These have nothing to do with the sample granularity arguments for hyperslabs, which are also called "strides" in the code. ./test/tstab.c Changed assumptions about default address and length sizes.
1998-03-05 00:20:23 +08:00
/* Add a couple fields */
if (H5Tinsert(complex_id, "real", HOFFSET(complex_t, re),
H5T_NATIVE_DOUBLE)<0) goto error;
if (H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im),
H5T_NATIVE_DOUBLE)<0) goto error;
if (H5Tclose (complex_id)<0) goto error;
puts(" PASSED");
return 0;
error:
return -1;
}
/*-------------------------------------------------------------------------
* Function: test_transient
*
* Purpose: Tests transient data types.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Thursday, June 4, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_transient (void)
{
static hsize_t ds_size[2] = {10, 20};
[svn-r429] Changes since 19980616 ---------------------- ./html/tracing.html NEW This entire update is to make it possible for the library to print the name, arguments, and return value of every API call without requiring any extra work from developers or app programmers. This file describes how this all works. ./configure.in Added the `--enable-tracing' switch. If you use it then the library will include code to print API function names, argument names and values, and function return values. However, you must then turn on the tracing by setting the HDF5_TRACE environment variable to a file descriptor number. The default is `--disable-tracing' since enabling it causes a slight increase in library size and a slowdown resulting from an extra function call for each API function call (I couldn't even measure the slowdown :-) ./bin/trace NEW A perl script that synchronizes the H5TRACE() macro calls in the *.c files with the function return type and formal argument names and types. If you use GNU make and gcc then this will be done automatically, otherwise just invoke this script with the names of one or more .c files. You could do it by hand to, but encoding argument types is a little tricky at first. ./config/commence.in Added the $(TRACE) macro, which defaults to the no-op. Added -D_POSIX_SOURCE to the compiler command line. ./src/Makefile.in Override the default for $(TRACE). ./config/depend.in Automatically calls $(TRACE) to synchronize the H5TRACE() macros in any source file that changed. As with makefile dependencies, one way to force synchronization of all files is to remove the `.depend' file. ./MANIFEST Added new files. ./src/H5Eprivate.h Modified HRETURN_ERROR() and HRETURN() for tracing. ./src/H5.c ./src/H5private.h This is where the real tracing work really happens, in H5_trace(). ./src/H5A.c ./src/H5D.c ./src/H5G.c ./src/H5P.c ./src/H5S.c ./src/H5Z.c Added H5TRACE() calls to all API functions. You don't really need these changes if you don't want to merge your stuff because they can be generated automatically by going to the hdf5/src directory and saying ../bin/trace *.c ./src/H5T.c Added H5TRACE() calls. Other stuff below. ./src/H5E.c ./src/H5Epublic.h Added H5TRACE() calls. Created a type H5E_auto_t for the `func' argument of H5Eset_auto() and H5Eget_auto() to make those arguments easier to parse for tracing. It should also make it clearer for users that don't know how to read complicated ANSI data types. ./src/H5F.c Added H5TRACE() calls. Changed a couple `uintn' argument types in API functions to `unsigned int' since `uintn' part of the API. Changed a few "can't" and "cant" error messages to "unable to". ./src/H5Ipublic.h Removed H5_DIRECTORY from the H5I_group_t enum. It wasn't used anywhere. ./src/H5Tconv.c Removed an unused label. ./src/H5Fistore.c ./src/H5Oattr.c ./src/H5Odtype.c ./src/H5T.c ./test/dsets.c ./test/dtypes.c Fixed a warning about a variable possibly used before it's initialized. Added __unused__ to turn off some unused argument warnings that pop up when debugging is turned off and optimizations are turned on.
1998-06-18 04:46:29 +08:00
hid_t file=-1, type=-1, space=-1, dset=-1, t2=-1;
printf ("%-70s", "Testing transient data types");
if ((file=H5Fcreate (FILE_NAME_1, H5F_ACC_TRUNC|H5F_ACC_DEBUG,
H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
space = H5Screate_simple (2, ds_size, ds_size);
/* Predefined types cannot be modified or closed */
H5E_BEGIN_TRY {
if (H5Tset_precision (H5T_NATIVE_INT, 256)>=0) {
puts ("*FAILED*");
puts (" Predefined types should not be modifiable!");
goto error;
}
if (H5Tclose (H5T_NATIVE_INT)>=0) {
puts ("*FAILED*");
puts (" Predefined types should not be closable!");
goto error;
}
} H5E_END_TRY;
/* Copying a predefined type results in a modifiable copy */
if ((type=H5Tcopy (H5T_NATIVE_INT))<0) goto error;
if (H5Tset_precision (type, 256)<0) goto error;
/* It should not be possible to create an attribute for a transient type */
H5E_BEGIN_TRY {
if (H5Acreate (type, "attr1", H5T_NATIVE_INT, space, H5P_DEFAULT)>=0) {
puts ("*FAILED*");
puts (" Attributes should not be allowed for transient types!");
goto error;
}
} H5E_END_TRY;
/* Create a dataset from a transient data type */
if (H5Tclose (type)<0) goto error;
if ((type = H5Tcopy (H5T_NATIVE_INT))<0) goto error;
if ((dset=H5Dcreate (file, "dset1", type, space, H5P_DEFAULT))<0) {
goto error;
}
/* The type returned from a dataset should not be modifiable */
if ((t2 = H5Dget_type (dset))<0) goto error;
H5E_BEGIN_TRY {
if (H5Tset_precision (t2, 256)>=0) {
puts ("*FAILED*");
puts (" Dataset data types should not be modifiable!");
goto error;
}
} H5E_END_TRY;
if (H5Tclose (t2)<0) goto error;
/*
* Close the dataset and reopen it, testing that it's type is still
* read-only.
*/
if (H5Dclose (dset)<0) goto error;
if ((dset=H5Dopen (file, "dset1"))<0) goto error;
if ((t2 = H5Dget_type (dset))<0) goto error;
H5E_BEGIN_TRY {
if (H5Tset_precision (t2, 256)>=0) {
puts ("*FAILED*");
puts (" Dataset data types should not be modifiable!");
goto error;
}
} H5E_END_TRY;
if (H5Tclose (t2)<0) goto error;
/*
* Get the dataset data type by applying H5Tcopy() to the dataset. The
* result should be modifiable.
*/
if ((t2=H5Tcopy (dset))<0) goto error;
if (H5Tset_precision (t2, 256)<0) goto error;
if (H5Tclose (t2)<0) goto error;
H5Dclose (dset);
H5Fclose (file);
H5Tclose (type);
H5Sclose (space);
puts (" PASSED");
return 0;
error:
H5E_BEGIN_TRY {
H5Tclose (t2);
H5Tclose (type);
H5Sclose (space);
H5Dclose (dset);
H5Fclose (file);
} H5E_END_TRY;
return -1;
}
/*-------------------------------------------------------------------------
* Function: test_named
*
* Purpose: Tests named data types.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Monday, June 1, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_named (void)
{
[svn-r429] Changes since 19980616 ---------------------- ./html/tracing.html NEW This entire update is to make it possible for the library to print the name, arguments, and return value of every API call without requiring any extra work from developers or app programmers. This file describes how this all works. ./configure.in Added the `--enable-tracing' switch. If you use it then the library will include code to print API function names, argument names and values, and function return values. However, you must then turn on the tracing by setting the HDF5_TRACE environment variable to a file descriptor number. The default is `--disable-tracing' since enabling it causes a slight increase in library size and a slowdown resulting from an extra function call for each API function call (I couldn't even measure the slowdown :-) ./bin/trace NEW A perl script that synchronizes the H5TRACE() macro calls in the *.c files with the function return type and formal argument names and types. If you use GNU make and gcc then this will be done automatically, otherwise just invoke this script with the names of one or more .c files. You could do it by hand to, but encoding argument types is a little tricky at first. ./config/commence.in Added the $(TRACE) macro, which defaults to the no-op. Added -D_POSIX_SOURCE to the compiler command line. ./src/Makefile.in Override the default for $(TRACE). ./config/depend.in Automatically calls $(TRACE) to synchronize the H5TRACE() macros in any source file that changed. As with makefile dependencies, one way to force synchronization of all files is to remove the `.depend' file. ./MANIFEST Added new files. ./src/H5Eprivate.h Modified HRETURN_ERROR() and HRETURN() for tracing. ./src/H5.c ./src/H5private.h This is where the real tracing work really happens, in H5_trace(). ./src/H5A.c ./src/H5D.c ./src/H5G.c ./src/H5P.c ./src/H5S.c ./src/H5Z.c Added H5TRACE() calls to all API functions. You don't really need these changes if you don't want to merge your stuff because they can be generated automatically by going to the hdf5/src directory and saying ../bin/trace *.c ./src/H5T.c Added H5TRACE() calls. Other stuff below. ./src/H5E.c ./src/H5Epublic.h Added H5TRACE() calls. Created a type H5E_auto_t for the `func' argument of H5Eset_auto() and H5Eget_auto() to make those arguments easier to parse for tracing. It should also make it clearer for users that don't know how to read complicated ANSI data types. ./src/H5F.c Added H5TRACE() calls. Changed a couple `uintn' argument types in API functions to `unsigned int' since `uintn' part of the API. Changed a few "can't" and "cant" error messages to "unable to". ./src/H5Ipublic.h Removed H5_DIRECTORY from the H5I_group_t enum. It wasn't used anywhere. ./src/H5Tconv.c Removed an unused label. ./src/H5Fistore.c ./src/H5Oattr.c ./src/H5Odtype.c ./src/H5T.c ./test/dsets.c ./test/dtypes.c Fixed a warning about a variable possibly used before it's initialized. Added __unused__ to turn off some unused argument warnings that pop up when debugging is turned off and optimizations are turned on.
1998-06-18 04:46:29 +08:00
hid_t file=-1, type=-1, space=-1, dset=-1, t2=-1, attr1=-1;
herr_t status;
static hsize_t ds_size[2] = {10, 20};
printf ("%-70s", "Testing named data types");
if ((file=H5Fcreate (FILE_NAME_2, H5F_ACC_TRUNC|H5F_ACC_DEBUG,
H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
space = H5Screate_simple (2, ds_size, ds_size);
/* Predefined types cannot be committed */
H5E_BEGIN_TRY {
if (H5Tcommit (file, "test_named_1 (should not exist)",
H5T_NATIVE_INT)>=0) {
puts ("*FAILED*");
puts (" Predefined types should not be committable!");
goto error;
}
} H5E_END_TRY;
/* Copy a predefined data type and commit the copy */
if ((type = H5Tcopy (H5T_NATIVE_INT))<0) goto error;
if (H5Tcommit (file, "native-int", type)<0) goto error;
if ((status=H5Tcommitted (type))<0) goto error;
if (0==status) {
puts ("*FAILED*");
puts (" H5Tcommitted() returned false!");
goto error;
}
/* We should not be able to modify a type after it has been committed. */
H5E_BEGIN_TRY {
if (H5Tset_precision (type, 256)>=0) {
puts ("*FAILED*");
puts (" Committed type is not constant!");
goto error;
}
} H5E_END_TRY;
/* We should not be able to re-commit a committed type */
H5E_BEGIN_TRY {
if (H5Tcommit (file, "test_named_2 (should not exist)", type)>=0) {
puts ("*FAILED*");
puts (" Committed types should not be recommitted!");
goto error;
}
} H5E_END_TRY;
/* It should be possible to define an attribute for the named type */
if ((attr1=H5Acreate (type, "attr1", H5T_NATIVE_INT, space,
H5P_DEFAULT))<0) goto error;
if (H5Aclose (attr1)<0) goto error;
/*
* Copying a committed type should result in a transient type which is
* not locked.
*/
if ((t2 = H5Tcopy (type))<0) goto error;
if ((status=H5Tcommitted (t2))<0) goto error;
if (status) {
puts ("*FAILED*");
puts (" Copying a named type should result in a transient type!");
goto error;
}
if (H5Tset_precision (t2, 256)<0) goto error;
if (H5Tclose (t2)<0) goto error;
/*
* Close the committed type and reopen it. It should return a named type.
*/
if (H5Tclose (type)<0) goto error;
if ((type=H5Topen (file, "native-int"))<0) goto error;
if ((status=H5Tcommitted (type))<0) goto error;
if (!status) {
puts ("*FAILED*");
puts (" Opened named types should be named types!");
goto error;
}
/* Create a dataset that uses the named type */
if ((dset = H5Dcreate (file, "dset1", type, space, H5P_DEFAULT))<0) {
goto error;
}
/* Get the dataset's data type and make sure it's a named type */
if ((t2 = H5Dget_type (dset))<0) goto error;
if ((status=H5Tcommitted (t2))<0) goto error;
if (!status) {
puts ("*FAILED*");
puts (" Dataset type should be a named type!");
goto error;
}
/* Close the dataset, then close its type, then reopen the dataset */
if (H5Dclose (dset)<0) goto error;
if (H5Tclose (t2)<0) goto error;
if ((dset = H5Dopen (file, "dset1"))<0) goto error;
/* Get the dataset's type and make sure it's named */
if ((t2 = H5Dget_type (dset))<0) goto error;
if ((status=H5Tcommitted (t2))<0) goto error;
if (!status) {
puts ("*FAILED*");
puts (" Dataset type should be a named type!");
goto error;
}
/*
* Close the dataset and create another with the type returned from the
* first dataset.
*/
if (H5Dclose (dset)<0) goto error;
if ((dset=H5Dcreate (file, "dset2", t2, space, H5P_DEFAULT))<0) {
goto error;
}
/* Reopen the second dataset and make sure the type is shared */
if (H5Tclose (t2)<0) goto error;
if (H5Dclose (dset)<0) goto error;
if ((dset = H5Dopen (file, "dset2"))<0) goto error;
if ((t2 = H5Dget_type (dset))<0) goto error;
if ((status=H5Tcommitted (t2))<0) goto error;
if (!status) {
puts ("*FAILED*");
puts (" Dataset type should be a named type!");
goto error;
}
if (H5Tclose (t2)<0) goto error;
/*
* Get the dataset data type by applying H5Tcopy() to the dataset. The
* result should be modifiable.
*/
if ((t2=H5Tcopy (dset))<0) goto error;
if (H5Tset_precision (t2, 256)<0) goto error;
if (H5Tclose (t2)<0) goto error;
/* Clean up */
if (H5Dclose (dset)<0) goto error;
if (H5Tclose (type)<0) goto error;
if (H5Sclose (space)<0) goto error;
if (H5Fclose (file)<0) goto error;
puts (" PASSED");
return 0;
error:
H5E_BEGIN_TRY {
H5Tclose (t2);
H5Tclose (type);
H5Sclose (space);
H5Dclose (dset);
H5Fclose (file);
} H5E_END_TRY;
return -1;
}
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
/*-------------------------------------------------------------------------
* Function: test_conv_num
*
* Purpose: Test atomic number conversions.
*
* Return: Success:
*
* Failure:
*
* Programmer: Robb Matzke
* Wednesday, June 10, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_conv_num (void)
{
const size_t ntests=100;
const size_t nelmts=2000;
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
size_t i, j;
void *buf=NULL, *saved=NULL;
unsigned char byte[4];
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
/*---------------------------------------------------------------------
* 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;
}
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
/* (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);
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
/* Allocate buffers */
buf = malloc (nelmts*8);
saved = malloc (nelmts*8);
for (i=0; i<ntests; i++) {
/* Start with NATIVE_INT */
for (j=0; j<nelmts; j++) ((int*)buf)[j] = rand();
memcpy (saved, buf, nelmts*sizeof(int));
/* Convert there and back */
if (H5Tconvert (H5T_NATIVE_INT, H5T_IEEE_S64LE, nelmts, buf,
NULL)<0) goto error;
if (H5Tconvert (H5T_IEEE_S64LE, H5T_NATIVE_INT, nelmts, buf,
NULL)<0) goto error;
/* Check results */
for (j=0; j<nelmts; j++) {
if (((int*)buf)[j]!=((int*)saved)[j]) {
puts ("*FAILED*");
printf (" Test %lu, elmt %lu, got %d instead of %d\n",
(unsigned long)i, (unsigned long)j,
((int*)buf)[j], ((int*)saved)[j]);
goto error;
}
}
}
puts (" PASSED");
free (buf);
free (saved);
return 0;
error:
if (buf) free (buf);
if (saved) free (saved);
return -1;
}
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Test the data type interface.
*
* Return: Success:
*
* Failure:
*
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
int
main(void)
{
int nerrors = 0;
/* Set the error handler */
H5Eset_auto (display_error_cb, NULL);
/* Do the tests */
nerrors += test_classes()<0 ? 1 : 0;
nerrors += test_copy()<0 ? 1 : 0;
nerrors += test_compound()<0 ? 1 : 0;
nerrors += test_transient ()<0 ? 1 : 0;
nerrors += test_named ()<0 ? 1 : 0;
[svn-r425] Changes since 19980610 ---------------------- THIS CHECKIN IS FOR QUINCEY -- NOT EVERYTHING WORKS (but it compiles) MOST OF THE CHANGES ARE FOR BETTER TYPE CONVERSION IN THE NEXT ALPHA ./MANIFEST ./src/H5Tbit.c NEW ./src/Makefile.in Bit vector operations (not done yet) ./configure.in Added -lm to the library list, needed by bit-vector operations and conversion functions. Removed vestiges of PARALLEL_SRC no longer used by the makefiles. Albert came up with a better way (that actually works :-) ./src/H5D.c No code changes. Split a couple of long lines, refilled a couple multi-line comments. ./src/H5T.c ./src/H5Tpublic.h Fixed a bug reported by Jim Reus regarding conversion of compound data types whose members require conversions which are satisfied by as-yet unregistered soft conversion functions. Added H5T_IEEE architecture, but the funny-looking integer types will be changed to H5T_BE_ and H5T_LE_ architectures with the type names changed to match the H5T_NATIVE_ integers. Added an H5Tconvert() but it hasn't been documented or tested yet. ./src/H5Tconv.c ./src/H5Tpkg.h Registered conversion functions integer->integer (a general case) and integer->float (for a specific case). The integer->integer conversion depends on the bitvector operations which aren't finished yet and the int->float conversion hasn't been retested since it was borrowed from AIO. Don't look at them yet, they're ugly :-) ./src/H5detect.c Fixed a typo which caused the msb_pad field of an atomic type to not be initialized. ./test/dtypes.c Added a test for number conversions but it's commented out until the conversion stuff is truly working.
1998-06-13 01:31:06 +08:00
nerrors += test_conv_num ()<0 ? 1 : 0;
if (nerrors) {
printf("***** %d DATA TYPE TEST%s FAILED! *****\n",
nerrors, 1 == nerrors ? "" : "S");
exit(1);
}
printf("All data type tests passed.\n");
cleanup ();
return 0;
}