Skip to content

Commit

Permalink
Add test case for H5Tdecode1
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Jan 8, 2025
1 parent 30730d4 commit b1c6e2d
Showing 1 changed file with 73 additions and 18 deletions.
91 changes: 73 additions & 18 deletions test/dtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,10 +853,10 @@ test_compound_2(void)
{
struct st {
int a, b, c[4], d, e;
} *s_ptr;
} * s_ptr;
struct dt {
int e, d, c[4], b, a;
} *d_ptr;
} * d_ptr;

const size_t nelmts = NTESTELEM;
const hsize_t four = 4;
Expand Down Expand Up @@ -978,10 +978,10 @@ test_compound_3(void)
{
struct st {
int a, b, c[4], d, e;
} *s_ptr;
} * s_ptr;
struct dt {
int a, c[4], e;
} *d_ptr;
} * d_ptr;

const size_t nelmts = NTESTELEM;
const hsize_t four = 4;
Expand Down Expand Up @@ -1100,13 +1100,13 @@ test_compound_4(void)

struct st {
int a, b, c[4], d, e;
} *s_ptr;
} * s_ptr;
struct dt {
short b;
int a, c[4];
short d;
int e;
} *d_ptr;
} * d_ptr;

const size_t nelmts = NTESTELEM;
const hsize_t four = 4;
Expand Down Expand Up @@ -1328,11 +1328,11 @@ test_compound_6(void)
struct st {
short b;
short d;
} *s_ptr;
} * s_ptr;
struct dt {
long b;
long d;
} *d_ptr;
} * d_ptr;

const size_t nelmts = NTESTELEM;
unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
Expand Down Expand Up @@ -8926,7 +8926,7 @@ test_set_size_invalid(void)
*-------------------------------------------------------------------------
*/
static int
test_encode(void)
test_encode(bool use_old_decode_api)
{
struct cmpd {
int a;
Expand Down Expand Up @@ -8954,8 +8954,14 @@ test_encode(void)
unsigned char *vlstr_buf = NULL;
hid_t ret_id;
herr_t ret;
char test_msg[128];

TESTING("functions of encoding and decoding datatypes");
/* Silence unused parameter warning if built with no deprecated symbols */
(void)use_old_decode_api;

snprintf(test_msg, sizeof(test_msg), "%s functions of encoding and decoding datatypes",
use_old_decode_api ? "old" : "new");
TESTING(test_msg);

/* Create File */
h5_fixname(FILENAME[5], H5P_DEFAULT, filename, sizeof filename);
Expand Down Expand Up @@ -9059,7 +9065,12 @@ test_encode(void)
/* Try decoding an incorrect (empty) buffer (should fail) */
H5E_BEGIN_TRY
{
ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size);
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
ret_id = H5Tdecode1(cmpd_buf);
else
#endif
ret_id = H5Tdecode2(cmpd_buf, cmpd_buf_size);
}
H5E_END_TRY
if (ret_id != FAIL) {
Expand All @@ -9075,7 +9086,14 @@ test_encode(void)
}

/* Decode from the compound buffer and return an object handle */
if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0)
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid1 = H5Tdecode1(cmpd_buf);
else
#endif
decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size);

if (decoded_tid1 < 0)
FAIL_PUTS_ERROR("Can't decode compound type\n");

/* Verify that the datatype was copied exactly */
Expand Down Expand Up @@ -9114,7 +9132,14 @@ test_encode(void)
}

/* Decode from the enumerate buffer and return an object handle */
if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) {
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid2 = H5Tdecode1(enum_buf);
else
#endif
decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size);

if (decoded_tid2 < 0) {
H5_FAILED();
printf("Can't decode enumerate type\n");
goto error;
Expand Down Expand Up @@ -9156,7 +9181,14 @@ test_encode(void)
}

/* Decode from the VL string buffer and return an object handle */
if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) {
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid3 = H5Tdecode1(vlstr_buf);
else
#endif
decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size);

if (decoded_tid3 < 0) {
H5_FAILED();
printf("Can't decode VL string type\n");
goto error;
Expand Down Expand Up @@ -9264,7 +9296,14 @@ test_encode(void)
}

/* Decode from the compound buffer and return an object handle */
if ((decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size)) < 0)
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid1 = H5Tdecode1(cmpd_buf);
else
#endif
decoded_tid1 = H5Tdecode2(cmpd_buf, cmpd_buf_size);

if (decoded_tid1 < 0)
FAIL_PUTS_ERROR("Can't decode compound type\n");

/* Verify that the datatype was copied exactly */
Expand Down Expand Up @@ -9303,7 +9342,14 @@ test_encode(void)
}

/* Decode from the enumerate buffer and return an object handle */
if ((decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size)) < 0) {
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid2 = H5Tdecode1(enum_buf);
else
#endif
decoded_tid2 = H5Tdecode2(enum_buf, enum_buf_size);

if (decoded_tid2 < 0) {
H5_FAILED();
printf("Can't decode enumerate type\n");
goto error;
Expand Down Expand Up @@ -9345,11 +9391,19 @@ test_encode(void)
}

/* Decode from the VL string buffer and return an object handle */
if ((decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size)) < 0) {
#ifndef H5_NO_DEPRECATED_SYMBOLS
if (use_old_decode_api)
decoded_tid3 = H5Tdecode1(vlstr_buf);
else
#endif
decoded_tid3 = H5Tdecode2(vlstr_buf, vlstr_buf_size);

if (decoded_tid3 < 0) {
H5_FAILED();
printf("Can't decode VL string type\n");
goto error;
}

free(vlstr_buf);

/* Verify that the datatype was copied exactly */
Expand Down Expand Up @@ -12825,7 +12879,7 @@ main(void)
nerrors += test_set_fields_offset();
nerrors += test_transient(fapl);
nerrors += test_named(fapl);
nerrors += test_encode();
nerrors += test_encode(false);
nerrors += test_latest();
nerrors += test_int_float_except();
nerrors += test_named_indirect_reopen(fapl);
Expand All @@ -12836,6 +12890,7 @@ main(void)
nerrors += test_enum_member_order();
nerrors += test_str_create();
#ifndef H5_NO_DEPRECATED_SYMBOLS
nerrors += test_encode(true);
nerrors += test_deprec(fapl);
#endif /* H5_NO_DEPRECATED_SYMBOLS */

Expand Down

0 comments on commit b1c6e2d

Please sign in to comment.