summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2012-05-22 21:36:45 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2012-05-22 21:36:45 (GMT)
commitb904ca7ec369149f858495860795fd7afcba8670 (patch)
treea3d592fedf3dca2fd90c1f50e1c262d0d86fc493 /tools
parent2f8b5057c1613f02e3ba24aa2511734e5ea836bd (diff)
downloadhdf5-b904ca7ec369149f858495860795fd7afcba8670.zip
hdf5-b904ca7ec369149f858495860795fd7afcba8670.tar.gz
hdf5-b904ca7ec369149f858495860795fd7afcba8670.tar.bz2
[svn-r22391] HDFFV-7999: h5dump did not display H5T_DSET_UTF8.
Changed if/else block to switch like in h5ls, and distinguished between ERROR and UNKNOWN. Reviewed by JKM Tested: local linux
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/CMakeLists.txt7
-rw-r--r--tools/h5dump/h5dumpgentest.c50
-rw-r--r--tools/h5dump/testh5dump.sh.in5
-rw-r--r--tools/lib/h5tools_dump.c73
-rw-r--r--tools/testfiles/charsets.ddl27
-rw-r--r--tools/testfiles/charsets.h5bin0 -> 8288 bytes
6 files changed, 150 insertions, 12 deletions
diff --git a/tools/h5dump/CMakeLists.txt b/tools/h5dump/CMakeLists.txt
index a6e452d..ad19ba4 100644
--- a/tools/h5dump/CMakeLists.txt
+++ b/tools/h5dump/CMakeLists.txt
@@ -43,6 +43,7 @@ IF (BUILD_TESTING)
# Copy all the HDF5 files from the test directory into the source directory
# --------------------------------------------------------------------
SET (HDF5_REFERENCE_FILES
+ charsets.ddl
file_space.ddl
filter_fail.ddl
packedbits.ddl
@@ -239,6 +240,7 @@ IF (BUILD_TESTING)
tvlstr.h5.xml
)
SET (HDF5_REFERENCE_TEST_FILES
+ charsets.h5
file_space.h5
filter_fail.h5
packedbits.h5
@@ -676,6 +678,8 @@ IF (BUILD_TESTING)
COMMAND ${CMAKE_COMMAND}
-E remove
h5dump-help.out
+ charsets.out
+ charsets.out.err
file_space.out
file_space.out.err
filter_fail.out
@@ -1060,6 +1064,9 @@ IF (BUILD_TESTING)
# test printing characters in ASCII instead of decimal
ADD_H5_TEST (tchar1 0 --enable-error-stack -r tchar.h5)
+ # test datatypes in ASCII and UTF8
+ ADD_H5_TEST (charsets 0 --enable-error-stack charsets.h5)
+
# rev. 2004
# tests for super block
ADD_H5_TEST (tboot1 0 --enable-error-stack -H -B -d dset tfcontents1.h5)
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index b28f3de..4fab379 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -97,6 +97,7 @@
#define FILE65 "file_space.h5"
#define FILE66 "packedbits.h5"
#define FILE67 "zerodim.h5"
+#define FILE68 "charsets.h5"
@@ -7132,6 +7133,54 @@ gent_packedbits(void)
}
/*-------------------------------------------------------------------------
+ * Function: gent_charsets
+ *
+ * Purpose: Generate a file to be used in the character set test
+ * Contains:
+ * 1) a ascii datatype
+ * 2) a utf8 datatype
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+gent_charsets(void)
+{
+ hid_t fid, did, sid;
+ herr_t status;
+ hsize_t dim[] = {1}; /* Dataspace dimensions */
+ typedef struct CharSetInfo {
+ const char *ascii_p_;
+ const char *utf8_p_;
+ } CharSetInfo;
+
+ sid = H5Screate_simple( 1, dim, NULL );
+ fid = H5Fcreate( FILE68, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
+
+ hid_t charset_dtid = H5Tcreate( H5T_COMPOUND, sizeof( CharSetInfo ) );
+
+ hid_t ascii_dtid = H5Tcreate( H5T_STRING, H5T_VARIABLE );
+ status = H5Tset_cset( ascii_dtid, H5T_CSET_ASCII );
+ H5Tinsert( charset_dtid, "ascii", HOFFSET(CharSetInfo, ascii_p_ ), ascii_dtid );
+
+ hid_t utf8_dtid = H5Tcreate( H5T_STRING, H5T_VARIABLE );
+ status = H5Tset_cset( utf8_dtid, H5T_CSET_UTF8 );
+ H5Tinsert( charset_dtid, "utf8", HOFFSET( CharSetInfo, utf8_p_ ), utf8_dtid );
+
+ did = H5Dcreate2( fid, "CharSets", charset_dtid, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
+
+ const char * writeData[] = { "ascii", "utf8", };
+ status = H5Dwrite( did, charset_dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, writeData );
+
+ H5Tclose( charset_dtid );
+ H5Tclose( ascii_dtid );
+ H5Tclose( utf8_dtid );
+ H5Sclose( sid );
+ H5Dclose( did );
+ H5Fclose( fid );
+}
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
*-------------------------------------------------------------------------
@@ -7207,6 +7256,7 @@ int main(void)
gent_extlinks();
gent_fs_strategy_threshold();
gent_packedbits();
+ gent_charsets();
return 0;
}
diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in
index 5441e25..016b4f1 100644
--- a/tools/h5dump/testh5dump.sh.in
+++ b/tools/h5dump/testh5dump.sh.in
@@ -75,6 +75,7 @@ test -d $TESTDIR || mkdir $TESTDIR
# Comment '#' without space can be used.
# --------------------------------------------------------------------
LIST_HDF5_TEST_FILES="
+$SRC_H5DUMP_TESTFILES/charsets.h5
$SRC_H5DUMP_TESTFILES/file_space.h5
$SRC_H5DUMP_TESTFILES/filter_fail.h5
$SRC_H5DUMP_TESTFILES/packedbits.h5
@@ -161,6 +162,7 @@ $SRC_H5DUMP_TESTFILES/tvms.h5
"
LIST_OTHER_TEST_FILES="
+$SRC_H5DUMP_TESTFILES/charsets.ddl
$SRC_H5DUMP_TESTFILES/file_space.ddl
$SRC_H5DUMP_TESTFILES/filter_fail.ddl
$SRC_H5DUMP_TESTFILES/packedbits.ddl
@@ -691,6 +693,9 @@ TOOLTEST tno-subset.ddl --no-compact-subset -d "AHFINDERDIRECT::ah_centroid_t[0]
# test printing characters in ASCII instead of decimal
TOOLTEST tchar1.ddl --enable-error-stack -r tchar.h5
+# test datatypes in ASCII and UTF8
+TOOLTEST charsets.ddl --enable-error-stack charsets.h5
+
# rev. 2004
# tests for super block
diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c
index 194e85e..20c1c8f 100644
--- a/tools/lib/h5tools_dump.c
+++ b/tools/lib/h5tools_dump.c
@@ -2119,14 +2119,38 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_
h5tools_str_reset(buffer);
h5tools_str_append(buffer, "%s ", STRPAD);
- if (str_pad == H5T_STR_NULLTERM)
- h5tools_str_append(buffer, "H5T_STR_NULLTERM;");
- else if (str_pad == H5T_STR_NULLPAD)
- h5tools_str_append(buffer, "H5T_STR_NULLPAD;");
- else if (str_pad == H5T_STR_SPACEPAD)
- h5tools_str_append(buffer, "H5T_STR_SPACEPAD;");
- else
- h5tools_str_append(buffer, "H5T_STR_ERROR;");
+ switch (str_pad) {
+ case H5T_STR_NULLTERM:
+ h5tools_str_append(buffer, "H5T_STR_NULLTERM;");
+ break;
+ case H5T_STR_NULLPAD:
+ h5tools_str_append(buffer, "H5T_STR_NULLPAD;");
+ break;
+ case H5T_STR_SPACEPAD:
+ h5tools_str_append(buffer, "H5T_STR_SPACEPAD;");
+ break;
+ case H5T_STR_RESERVED_3:
+ case H5T_STR_RESERVED_4:
+ case H5T_STR_RESERVED_5:
+ case H5T_STR_RESERVED_6:
+ case H5T_STR_RESERVED_7:
+ case H5T_STR_RESERVED_8:
+ case H5T_STR_RESERVED_9:
+ case H5T_STR_RESERVED_10:
+ case H5T_STR_RESERVED_11:
+ case H5T_STR_RESERVED_12:
+ case H5T_STR_RESERVED_13:
+ case H5T_STR_RESERVED_14:
+ case H5T_STR_RESERVED_15:
+ h5tools_str_append(buffer, "H5T_STR_UNKNOWN;");
+ break;
+ case H5T_STR_ERROR:
+ h5tools_str_append(buffer, "H5T_STR_ERROR;");
+ break;
+ default:
+ h5tools_str_append(buffer, "ERROR;");
+ break;
+ }
h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0);
ctx->need_prefix = TRUE;
@@ -2136,10 +2160,35 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_
h5tools_str_append(buffer, "%s ", CSET);
- if (cset == H5T_CSET_ASCII)
- h5tools_str_append(buffer, "H5T_CSET_ASCII;");
- else
- h5tools_str_append(buffer, "unknown_cset;");
+ switch (cset) {
+ case H5T_CSET_ASCII:
+ h5tools_str_append(buffer, "H5T_CSET_ASCII;");
+ break;
+ case H5T_CSET_UTF8:
+ h5tools_str_append(buffer, "H5T_CSET_UTF8;");
+ break;
+ case H5T_CSET_RESERVED_2:
+ case H5T_CSET_RESERVED_3:
+ case H5T_CSET_RESERVED_4:
+ case H5T_CSET_RESERVED_5:
+ case H5T_CSET_RESERVED_6:
+ case H5T_CSET_RESERVED_7:
+ case H5T_CSET_RESERVED_8:
+ case H5T_CSET_RESERVED_9:
+ case H5T_CSET_RESERVED_10:
+ case H5T_CSET_RESERVED_11:
+ case H5T_CSET_RESERVED_12:
+ case H5T_CSET_RESERVED_13:
+ case H5T_CSET_RESERVED_14:
+ case H5T_CSET_RESERVED_15:
+ h5tools_str_append(buffer, "H5T_CSET_UNKNOWN;");
+ case H5T_CSET_ERROR:
+ h5tools_str_append(buffer, "H5T_CSET_ERROR;");
+ break;
+ default:
+ h5tools_str_append(buffer, "ERROR;");
+ break;
+ }
h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0);
ctx->need_prefix = TRUE;
diff --git a/tools/testfiles/charsets.ddl b/tools/testfiles/charsets.ddl
new file mode 100644
index 0000000..c2301fb
--- /dev/null
+++ b/tools/testfiles/charsets.ddl
@@ -0,0 +1,27 @@
+HDF5 "charsets.h5" {
+GROUP "/" {
+ DATASET "CharSets" {
+ DATATYPE H5T_COMPOUND {
+ H5T_STRING {
+ STRSIZE H5T_VARIABLE;
+ STRPAD H5T_STR_NULLTERM;
+ CSET H5T_CSET_ASCII;
+ CTYPE H5T_C_S1;
+ } "ascii";
+ H5T_STRING {
+ STRSIZE H5T_VARIABLE;
+ STRPAD H5T_STR_NULLTERM;
+ CSET H5T_CSET_UTF8;
+ CTYPE H5T_C_S1;
+ } "utf8";
+ }
+ DATASPACE SIMPLE { ( 1 ) / ( 1 ) }
+ DATA {
+ (0): {
+ "ascii",
+ "utf8"
+ }
+ }
+ }
+}
+}
diff --git a/tools/testfiles/charsets.h5 b/tools/testfiles/charsets.h5
new file mode 100644
index 0000000..2b9e735
--- /dev/null
+++ b/tools/testfiles/charsets.h5
Binary files differ