/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_compounds(). *------------------------------------------------------------------------- */ static int test_compounds(void) { hid_t dtype; int nmembs; char *memb_name = NULL; H5T_class_t memb_class; H5T_class_t type_class; char* dt_str; size_t str_len; TESTING3(" text for compound types"); if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I16BE \"one_field\" : 2; H5T_STD_U8LE \"two_field\" : 6; }", H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_COMPOUND) goto out; if((nmembs = H5Tget_nmembers(dtype))<0) goto out; if(nmembs != 2) 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_COMPOUND {\n H5T_STD_I16BE \"one_field\" : 2;\n H5T_STD_U8LE \"two_field\" : 6;\n }")) { printf("dt=\n%s\n", dt_str); goto out; } free(dt_str); if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_COMPOUND { H5T_STD_I32BE \"i32_field\"; H5T_STD_I16BE \"i16_field\"; H5T_COMPOUND { H5T_STD_I16BE \"sec_field\"; H5T_COMPOUND { H5T_STD_I32BE \"thd_field\"; } \"grandchild\"; } \"child_compound\"; H5T_STD_I8BE \"i8_field\"; }", H5LT_DDL))<0) goto out; if((memb_name = H5Tget_member_name(dtype, 1)) == NULL) goto out; if(strcmp(memb_name, "i16_field")) goto out; free(memb_name); if((memb_class = H5Tget_member_class(dtype, 2))<0) goto out; if(memb_class != H5T_COMPOUND) goto out; PASSED(); return 0; out: H5_FAILED(); return -1; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_arrays(). *------------------------------------------------------------------------- */ static int test_arrays(void) { hid_t dtype; int ndims; hsize_t dims[3]; H5T_class_t type_class; char* dt_str; size_t str_len; TESTING3(" text for array types"); if((dtype = H5LTtext_to_dtype("H5T_ARRAY { [5][7][13] H5T_ARRAY { [17][19] H5T_COMPOUND { H5T_STD_I8BE \"arr_compound_1\"; H5T_STD_I32BE \"arr_compound_2\"; } } }", H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_ARRAY) goto out; if((ndims = H5Tget_array_ndims(dtype))<0) goto out; if(ndims != 3) goto out; if(H5Tget_array_dims2(dtype, dims) < 0) goto out; if(dims[0] != 5 || dims[1] != 7 || dims[2] != 13) 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_ARRAY {\n [5][7][13] H5T_ARRAY {\n [17][19] H5T_COMPOUND {\n H5T_STD_I8BE \"arr_compound_1\" : 0;\n H5T_STD_I32BE \"arr_compound_2\" : 1;\n }\n }\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; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_variables(). *------------------------------------------------------------------------- */ static int test_variables(void) { hid_t dtype; H5T_class_t type_class; char* dt_str; size_t str_len; TESTING3(" text for variable types"); if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_NATIVE_CHAR }\n", H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_VLEN) goto out; if(H5Tis_variable_str(dtype)) goto out; if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_VLEN { H5T_STD_I32BE } }", H5LT_DDL))<0) goto out; if(H5Tis_variable_str(dtype)) 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_VLEN {\n H5T_VLEN {\n H5T_STD_I32BE\n }\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; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_fps(). *------------------------------------------------------------------------- */ static int test_fps(void) { hid_t dtype; char* dt_str; size_t str_len; TESTING3(" text for floating-point types"); if((dtype = H5LTtext_to_dtype("H5T_NATIVE_LDOUBLE\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_NATIVE_LDOUBLE)) goto out; if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_IEEE_F32BE\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_IEEE_F32BE)) 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_IEEE_F32BE")) goto out; free(dt_str); if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_IEEE_F64LE\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_IEEE_F64LE)) goto out; if(H5Tclose(dtype)<0) goto out; PASSED(); return 0; out: H5_FAILED(); return -1; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_integers(). *------------------------------------------------------------------------- */ static int test_integers(void) { hid_t dtype; char* dt_str; size_t str_len; TESTING3("\n text for integer types"); if((dtype = H5LTtext_to_dtype("H5T_NATIVE_INT\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_NATIVE_INT)) goto out; if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_STD_I8BE\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_STD_I8BE)) 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_STD_I8BE")) goto out; free(dt_str); if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_STD_U16LE\n", H5LT_DDL))<0) goto out; if(!H5Tequal(dtype, H5T_STD_U16LE)) goto out; if(H5Tclose(dtype)<0) goto out; PASSED(); return 0; out: H5_FAILED(); return -1; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_opaques(). *------------------------------------------------------------------------- */ static int test_opaques(void) { hid_t dtype; size_t opq_size; H5T_class_t type_class; char* dt_str; size_t str_len; TESTING3(" text for opaque types"); if((dtype = H5LTtext_to_dtype("H5T_OPAQUE { OPQ_SIZE 19; OPQ_TAG \"This is a tag for opaque type\"; }", H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_OPAQUE) goto out; if((opq_size = H5Tget_size(dtype)) == 0) goto out; if(opq_size != 19) 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_OPAQUE {\n OPQ_SIZE 19;\n OPQ_TAG \"This is a tag for opaque type\";\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; }
/*------------------------------------------------------------------------- * 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; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_strings(). *------------------------------------------------------------------------- */ static int test_strings(void) { hid_t dtype; size_t str_size; H5T_str_t str_pad; H5T_cset_t str_cset; H5T_class_t type_class; char* dt_str; size_t str_len; TESTING3(" text for string types"); if((dtype = H5LTtext_to_dtype("H5T_STRING { STRSIZE 13; STRPAD H5T_STR_NULLTERM; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; }", H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_STRING) goto out; str_size = H5Tget_size(dtype); if(str_size != 13) goto out; str_pad = H5Tget_strpad(dtype); if(str_pad != H5T_STR_NULLTERM) goto out; str_cset = H5Tget_cset(dtype); if(str_cset != H5T_CSET_ASCII) 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_STRING {\n STRSIZE 13;\n STRPAD H5T_STR_NULLTERM;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }")) { printf("dt=\n%s\n", dt_str); goto out; } free(dt_str); if(H5Tclose(dtype)<0) goto out; if((dtype = H5LTtext_to_dtype("H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_NULLPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; }", H5LT_DDL))<0) goto out; if(!H5Tis_variable_str(dtype)) goto out; str_pad = H5Tget_strpad(dtype); if(str_pad != H5T_STR_NULLPAD) goto out; str_cset = H5Tget_cset(dtype); if(str_cset != H5T_CSET_ASCII) 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_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\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; }
/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_compound_bug(). Test case for * issue 7701. *------------------------------------------------------------------------- */ static int test_compound_bug(void) { hid_t dtype; H5T_class_t type_class; int nmembs; char* memb_name = NULL; char* dt_str; size_t str_len; char text[] = "H5T_COMPOUND { H5T_STD_I32LE \"state_________________________________________________________________________________\"; H5T_STD_I32LE \"desc_________________________________________________________________________________________\"; H5T_VLEN { H5T_COMPOUND { H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" 1; \"TWO\" 2; \"THREE\" 3; } \"type____\"; H5T_STD_I32LE \"sub_______________________________________________________________________________________________________________\"; H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; } \"sub_desc\"; H5T_STD_I32LE \"final___________________________________________________________________________________________________\"; } } \"sub\"; }"; char text2[] = "H5T_COMPOUND {\n" " H5T_STD_I16LE \"state___________________________" "__________________________________________________" "____\" : 0;\n" " H5T_STD_I16LE \"desc____________________________" "__________________________________________________" "___________\" : 2;\n" " H5T_VLEN { H5T_COMPOUND {\n" " H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" " "1; \"TWO\" 2; \"THREE\" 3; } \"type____\" : 0;\n" " H5T_STD_I32LE \"sub___________________________" "__________________________________________________" "__________________________________1\" : 4;\n" " H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_" "STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1;" " } \"sub_desc\" : 8;\n" " H5T_STD_I32LE \"final_________________________" "__________________________________________________" "________________________\" : 16;\n" " } } \"sub\" : 8;\n" "}\n"; TESTING3(" text for compound type of bug fix"); if((dtype = H5LTtext_to_dtype(text, H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_COMPOUND) goto out; if((memb_name = H5Tget_member_name(dtype, 2)) == NULL) goto out; if(strcmp(memb_name, "sub")) goto out; free(memb_name); 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; free(dt_str); if(H5Tclose(dtype)<0) goto out; /* Test similar datatype in another format */ if((dtype = H5LTtext_to_dtype(text2, H5LT_DDL))<0) goto out; if((type_class = H5Tget_class(dtype))<0) goto out; if(type_class != H5T_COMPOUND) goto out; if((nmembs = H5Tget_nmembers(dtype))<0) goto out; if(nmembs != 3) goto out; if((memb_name = H5Tget_member_name(dtype, 1)) == NULL) goto out; if(strcmp(memb_name, "desc_________________________________________________________________________________________")) goto out; free(memb_name); 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; free(dt_str); if(H5Tclose(dtype)<0) goto out; PASSED(); return 0; out: H5_FAILED(); return -1; }