Beispiel #1
0
/*-------------------------------------------------------------------------
 * Function:	test_value_dsnt_exist
 *
 * Purpose:	Create an enumeration datatype with "gaps in values"
 *              and then request a name of non-existing value within
 *              an existing range by calling H5Tenum_nameof function.
 *              Function should fail instead of succeeding and returning
 *              a name of one of the existing values.
 *              Request a value by supplying non-existing name by calling
 *              H5Tenum_nameof function. Function should fail.
 *
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Elena Pourmal
 *              Wednesday, June 7, 2002
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_value_dsnt_exist(void)
{

    hid_t       datatype_id=(-1);  /* identifiers */
    int val;
    char nam[100];
    size_t size = 100;
    TESTING("for non-existing name and value");
    /* Turn off error reporting since we expect failure in this test */

    if (H5Eset_auto(NULL, NULL) < 0) goto error;
    if ((datatype_id = H5Tenum_create(H5T_NATIVE_INT))< 0) goto error;

    /* These calls should fail, since no memebrs exist yet */
    if (H5Tenum_valueof(datatype_id, "SAX", &val) >= 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;
}
Beispiel #2
0
//--------------------------------------------------------------------------
// Function:	EnumType::valueOf
///\brief	Retrieves the value corresponding to a member of this
///		enumeration datatype, given the member's name.
///\param	name  -  IN: Name of the queried member
///\param	value - OUT: Pointer to the retrieved value
///\exception	H5::DataTypeIException
// Programmer	Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void EnumType::valueOf( const char* name, void *value ) const
{
   // Calls C routine H5Tenum_valueof to get the enum datatype value
   herr_t ret_value = H5Tenum_valueof( id, name, value );
   if( ret_value < 0 )
   {
      throw DataTypeIException("EnumType::valueOf", "H5Tenum_valueof failed");
   }
}
Beispiel #3
0
/*
 * test_enum
 * Test that enumerated datatypes can have UTF-8 member names.
 */
void test_enum(hid_t UNUSED fid, const char * string)
{
  /* Define an enumerated type */
  typedef enum {
    E1_RED,
    E1_GREEN,
    E1_BLUE,
    E1_WHITE
  } c_e1;
  /* Variable declarations */
  c_e1 val;
  herr_t ret;
  hid_t type_id;
  char readbuf[MAX_STRING_LENGTH];

  /* Create an enumerated datatype in HDF5 with a UTF-8 member name*/
  type_id = H5Tcreate(H5T_ENUM, sizeof(c_e1));
  CHECK(type_id, FAIL, "H5Tcreate");
  val = E1_RED;
  ret = H5Tenum_insert(type_id, "RED", &val);
  CHECK(ret, FAIL, "H5Tenum_insert");
  val = E1_GREEN;
  ret = H5Tenum_insert(type_id, "GREEN", &val);
  CHECK(ret, FAIL, "H5Tenum_insert");
  val = E1_BLUE;
  ret = H5Tenum_insert(type_id, "BLUE", &val);
  CHECK(ret, FAIL, "H5Tenum_insert");
  val = E1_WHITE;
  ret = H5Tenum_insert(type_id, string, &val);
  CHECK(ret, FAIL, "H5Tenum_insert");

  /* Ensure that UTF-8 member name gives the right value and vice versa. */
  ret = H5Tenum_valueof(type_id, string, &val);
  CHECK(ret, FAIL, "H5Tenum_valueof");
  VERIFY(val, E1_WHITE, "H5Tenum_valueof");
  ret = H5Tenum_nameof(type_id, &val, readbuf, (size_t)MAX_STRING_LENGTH);
  CHECK(ret, FAIL, "H5Tenum_nameof");
  ret = strcmp(readbuf, string);
  VERIFY(ret, 0, "strcmp");

  /* Close the datatype */
  ret = H5Tclose(type_id);
  CHECK(ret, FAIL, "H5Tclose");
}
Beispiel #4
0
/*-------------------------------------------------------------------------
* subroutine for test_text_dtype(): test_enums().
*-------------------------------------------------------------------------
*/
static int test_enums(void)
{
    hid_t   dtype;
    size_t  size = 16;
    char    name1[16];
    int     value1 = 7;
    const char    *name2 = "WHITE";
    int     value2;
    H5T_class_t type_class;
    char*   dt_str;
    size_t  str_len;
    H5T_order_t native_order = H5Tget_order(H5T_NATIVE_INT);

    TESTING3("        text for enum types");

    if((dtype = H5LTtext_to_dtype("H5T_ENUM { H5T_STD_I32LE; \"RED\" 5; \"GREEN\" 6; \"BLUE\" 7; \"WHITE\" 8; }", H5LT_DDL))<0)
        goto out;

    if((type_class = H5Tget_class(dtype))<0)
        goto out;
    if(type_class != H5T_ENUM)
        goto out;

    /* Convert the variable before using it */
    if(!H5Tequal(H5T_STD_I32LE, H5T_NATIVE_INT)) {
        if(H5Tconvert(H5T_NATIVE_INT, H5T_STD_I32LE, 1, &value1, NULL, H5P_DEFAULT) < 0)
            goto out;
    }

    if(H5Tenum_nameof(dtype, &value1, name1, size)<0)
        goto out;
    if(strcmp(name1, "BLUE"))
        goto out;

    if(H5Tenum_valueof(dtype, name2, &value2)<0)
        goto out;

    /* Convert the variable before comparing it */
    if(!H5Tequal(H5T_STD_I32LE, H5T_NATIVE_INT)) {
        if(H5Tconvert(H5T_NATIVE_INT, H5T_STD_I32LE, 1, &value2, NULL, H5P_DEFAULT) < 0)
            goto out;
    }

    if(value2 != 8)
        goto out;

    if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
        goto out;
    dt_str = (char*)calloc(str_len, sizeof(char));
    if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0)
        goto out;
    if(strcmp(dt_str, "H5T_ENUM {\n      H5T_STD_I32LE;\n      \"RED\"              5;\n      \"GREEN\"            6;\n      \"BLUE\"             7;\n      \"WHITE\"            8;\n   }")) {

        printf("dt=\n%s\n", dt_str);
        goto out;
    }

    free(dt_str);

    if(H5Tclose(dtype)<0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}