/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * Programmer: Robb Matzke * Tuesday, December 22, 1998 */ #include "h5test.h" #define CPTR(VAR,CONST) ((VAR)=(CONST),&(VAR)) const char *FILENAME[] = { "enum1", NULL }; typedef enum { E1_RED, E1_GREEN, E1_BLUE, E1_WHITE, E1_BLACK } c_e1; /*------------------------------------------------------------------------- * Function: test_named * * Purpose: Create an enumeration data type and store it in the file. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Wednesday, December 23, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int test_named(hid_t file) { hid_t type=-1, cwg=-1; c_e1 val; signed char val8; TESTING("named enumeration types"); if ((cwg=H5Gcreate(file, "test_named", 0))<0) goto error; /* A native integer */ if ((type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error; if (H5Tenum_insert(type, "RED", CPTR(val, E1_RED ))<0) goto error; if (H5Tenum_insert(type, "GREEN", CPTR(val, E1_GREEN))<0) goto error; if (H5Tenum_insert(type, "BLUE", CPTR(val, E1_BLUE ))<0) goto error; if (H5Tenum_insert(type, "WHITE", CPTR(val, E1_WHITE))<0) goto error; if (H5Tenum_insert(type, "BLACK", CPTR(val, E1_BLACK))<0) goto error; if (H5Tcommit(cwg, "e1_a", type)<0) goto error; if (H5Tclose(type)<0) goto error; /* A smaller type */ if ((type = H5Tcreate(H5T_ENUM, 1))<0) goto error; if (H5Tenum_insert(type, "RED", CPTR(val8, E1_RED ))<0) goto error; if (H5Tenum_insert(type, "GREEN", CPTR(val8, E1_GREEN))<0) goto error; if (H5Tenum_insert(type, "BLUE", CPTR(val8, E1_BLUE ))<0) goto error; if (H5Tenum_insert(type, "WHITE", CPTR(val8, E1_WHITE))<0) goto error; if (H5Tenum_insert(type, "BLACK", CPTR(val8, E1_BLACK))<0) goto error; if (H5Tcommit(cwg, "e1_b", type)<0) goto error; if (H5Tclose(type)<0) goto error; /* A non-native type */ if (H5T_ORDER_BE==H5Tget_order(H5T_NATIVE_INT)) { if ((type = H5Tenum_create(H5T_STD_U8LE))<0) goto error; } else { if ((type = H5Tenum_create(H5T_STD_U8BE))<0) goto error; } if (H5Tenum_insert(type, "RED", CPTR(val8, E1_RED ))<0) goto error; if (H5Tenum_insert(type, "GREEN", CPTR(val8, E1_GREEN))<0) goto error; if (H5Tenum_insert(type, "BLUE", CPTR(val8, E1_BLUE ))<0) goto error; if (H5Tenum_insert(type, "WHITE", CPTR(val8, E1_WHITE))<0) goto error; if (H5Tenum_insert(type, "BLACK", CPTR(val8, E1_BLACK))<0) goto error; if (H5Tcommit(cwg, "e1_c", type)<0) goto error; if (H5Tclose(type)<0) goto error; if (H5Gclose(cwg)<0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Tclose(type); H5Gclose(cwg); } H5E_END_TRY; return 1; } /*------------------------------------------------------------------------- * Function: test_noconv * * Purpose: Tests creation of datasets when no conversion is present. * * Return: Success: 0 * * Failure: number of errors * * Programmer: Robb Matzke * Monday, January 4, 1999 * * Modifications: * *------------------------------------------------------------------------- */ static int test_noconv(hid_t file) { hid_t cwg=-1, type=-1, space=-1, dset=-1; c_e1 val; static c_e1 data1[]={E1_RED, E1_GREEN, E1_BLUE, E1_GREEN, E1_WHITE, E1_WHITE, E1_BLACK, E1_GREEN, E1_BLUE, E1_RED, E1_RED, E1_BLUE, E1_GREEN, E1_BLACK, E1_WHITE, E1_RED, E1_WHITE, E1_GREEN, E1_GREEN, E1_BLUE}; c_e1 data2[NELMTS(data1)]; hsize_t i, ds_size[1]={NELMTS(data1)}; TESTING("no-conversion datasets"); if ((cwg=H5Gcreate(file, "test_noconv", 0))<0) goto error; if ((type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error; if (H5Tenum_insert(type, "RED", CPTR(val, E1_RED ))<0) goto error; if (H5Tenum_insert(type, "GREEN", CPTR(val, E1_GREEN))<0) goto error; if (H5Tenum_insert(type, "BLUE", CPTR(val, E1_BLUE ))<0) goto error; if (H5Tenum_insert(type, "WHITE", CPTR(val, E1_WHITE))<0) goto error; if (H5Tenum_insert(type, "BLACK", CPTR(val, E1_BLACK))<0) goto error; if ((space=H5Screate_simple(1, ds_size, NULL))<0) goto error; if ((dset=H5Dcreate(cwg, "color_table", type, space, H5P_DEFAULT))<0) goto error; if (H5Dwrite(dset, type, space, space, H5P_DEFAULT, data1)<0) goto error; if (H5Dread(dset, type, space, space, H5P_DEFAULT, data2)<0) goto error; for (i=0; i= 0) goto error; val = 3; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; val = 2; if (H5Tenum_insert(datatype_id, "TWO", (int *)&val) < 0) goto error; val = 6; if (H5Tenum_insert(datatype_id, "SIX", (int *)&val) < 0) goto error; val = 10; if (H5Tenum_insert(datatype_id, "TEN", (int *)&val) < 0) goto error; /* This call should fail since we did not create a member with value = 3*/ val = 3; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we did not create a member with value = 11*/ val = 11; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we did not create a member with value = 0*/ val = 0; if (H5Tenum_nameof(datatype_id, &val, nam, size) >= 0) goto error; /* This call should fail since we do not have SAX name in the type */ if (H5Tenum_valueof(datatype_id, "SAX", &val) >= 0) goto error; /* This call should fail since we do not have TEEN name in the type */ if (H5Tenum_valueof(datatype_id, "TEEN", &val) >= 0) goto error; /* This call should fail since we do not have A name in the type */ if (H5Tenum_valueof(datatype_id, "A", &val) >= 0) goto error; if (H5Tclose(datatype_id) < 0) goto error; PASSED(); return 0; error: H5E_BEGIN_TRY { H5Tclose(datatype_id); } H5E_END_TRY; return 1; } /*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Tuesday, December 22, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl=-1, file=-1; char name[1024]; int nerrors=0; h5_reset(); fapl = h5_fileaccess(); /* Create the file */ h5_fixname(FILENAME[0], fapl, name, sizeof name); if ((file=H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) goto error; /* Tests */ nerrors += test_named(file); nerrors += test_noconv(file); nerrors += test_tr1(file); nerrors += test_tr2(file); nerrors += test_value_dsnt_exist(); H5Fclose(file); if (nerrors) goto error; puts("All enum tests passed."); h5_cleanup(FILENAME, fapl); return 0; error: puts("*** ENUM TESTS FAILED ***"); return 1; }