Skip to content

Commit

Permalink
Improve tests validating file
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmudd committed Dec 13, 2024
1 parent 30b964d commit c8352b1
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion jhdf/src/test/java/io/jhdf/writing/StringWritingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ void writeReallyLongStrings() throws Exception {
}
}

// https://github.com/jamesmudd/jhdf/issues/656
@Test
@Order(5)
void writingNonAsciiStrings() throws Exception {
Path tempFile = Files.createTempFile(this.getClass().getSimpleName(), ".hdf5");
tempFile = Files.createTempFile(this.getClass().getSimpleName(), ".hdf5");
WritableHdfFile writableHdfFile = HdfFile.write(tempFile);

WritiableDataset dataset1 = writableHdfFile.putDataset("dataset1", "你好");
Expand All @@ -208,5 +210,37 @@ void writingNonAsciiStrings() throws Exception {
dataset3.putAttribute("attr", new String[][] {{"你好"}, {"世界"}});

writableHdfFile.close();

// Now read it back
try (HdfFile hdfFile = new HdfFile(tempFile)) {
Dataset dataset1Readback = hdfFile.getDatasetByPath("dataset1");
assertThat(dataset1Readback.getData()).isEqualTo("你好");
assertThat(dataset1Readback.getAttribute("attr").getData())
.isEqualTo("你好");

Dataset dataset2Readback = hdfFile.getDatasetByPath("dataset2");
assertThat(dataset2Readback.getData()).isEqualTo(new String[] {"你好"});
assertThat(dataset2Readback.getAttribute("attr").getData())
.isEqualTo(new String[] {"你好"});

Dataset dataset3Readback = hdfFile.getDatasetByPath("dataset3");
assertThat(dataset3Readback.getData()).isEqualTo(new String[][] {{"你好"}, {"世界"}});
assertThat(dataset3Readback.getAttribute("attr").getData())
.isEqualTo(new String[][] {{"你好"}, {"世界"}});
}
}

@Test
@Order(6)
@EnabledIfH5DumpAvailable
void readNonAsciiStringDatasetsWithH5Dump() throws Exception {
// Read with h5dump
HDF5FileXml hdf5FileXml = H5Dump.dumpAndParse(tempFile);

// Read with jhdf
try (HdfFile hdfFile = new HdfFile(tempFile)) {
// Compare
H5Dump.assetXmlAndHdfFileMatch(hdf5FileXml, hdfFile);
}
}
}

0 comments on commit c8352b1

Please sign in to comment.