diff options
author | Elena Pourmal <epourmal@hdfgroup.org> | 2002-06-11 19:28:50 (GMT) |
---|---|---|
committer | Elena Pourmal <epourmal@hdfgroup.org> | 2002-06-11 19:28:50 (GMT) |
commit | 29227e0a1dc37c0d1560ef6d058375b50b3f0610 (patch) | |
tree | 8ff2e69dec5343d3ec5dffa5ff254d9fd21086ba /test | |
parent | f19971bb05462c45b442181a6a282c21fcc1041f (diff) | |
download | hdf5-29227e0a1dc37c0d1560ef6d058375b50b3f0610.zip hdf5-29227e0a1dc37c0d1560ef6d058375b50b3f0610.tar.gz hdf5-29227e0a1dc37c0d1560ef6d058375b50b3f0610.tar.bz2 |
[svn-r5594]
Purpose:
Bug fix #774
Description:
Added a test for the H5Tenum_nameof and H5Tenum_valueof functions.
Values that do not exists in the enumeration type are supplied to
the functions; functions should fail instead of succeeding.
Platforms tested:
Solaris 2.7 and Linux 2.2.18
Diffstat (limited to 'test')
-rw-r--r-- | test/enum.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/enum.c b/test/enum.c index 089fd30..464db00 100644 --- a/test/enum.c +++ b/test/enum.c @@ -349,6 +349,89 @@ test_tr2(hid_t file) /*------------------------------------------------------------------------- + * 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() +{ + + hid_t datatype_id; /* identifiers */ + herr_t status; + 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; +} + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: @@ -383,6 +466,7 @@ main(void) nerrors += test_noconv(file); nerrors += test_tr1(file); nerrors += test_tr2(file); + nerrors += test_value_dsnt_exist(); H5Fclose(file); |