Skip to content

Commit

Permalink
Merge pull request #340 from raedma/master
Browse files Browse the repository at this point in the history
+ Fix and test for #338
  • Loading branch information
jamesmudd committed Jan 13, 2022
2 parents 5f9db74 + e4b4206 commit f601647
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 1 addition & 2 deletions jhdf/src/main/java/io/jhdf/dataset/DatasetReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import io.jhdf.object.datatype.DataType;
import io.jhdf.storage.HdfBackingStorage;

import java.lang.reflect.Array;
import java.nio.ByteBuffer;

Expand Down Expand Up @@ -63,7 +62,7 @@ public static Object readDataset(DataType type, ByteBuffer buffer, int[] dimensi

final Object data = type.fillData(buffer, dimensions, hdfBackingStorage);

if (isScalar) {
if (isScalar && data.getClass().isArray()) {
return Array.get(data, 0);
} else {
return data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of jHDF. A pure Java library for accessing HDF5 files.
*
* http://jhdf.io
*
* Copyright (c) 2022 James Mudd
*
* MIT License see 'LICENSE' file
*/
package io.jhdf.attribute;

import io.jhdf.HdfFile;
import static io.jhdf.TestUtils.loadTestHdfFile;
import io.jhdf.api.Attribute;
import io.jhdf.api.Node;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class CompoundScalarAttributeTest {

private static final String HDF5_TEST_FILE_NAME = "test_compound_scalar_attribute.hdf5";

private static HdfFile hdfFile;

@BeforeAll
static void setup() throws Exception {
hdfFile = loadTestHdfFile(HDF5_TEST_FILE_NAME);
}

@AfterAll
static void tearDown() {
hdfFile.close();
}

@Test
void testReadAttribute() {

Node node = hdfFile.getByPath("GROUP");
Attribute attribute = node.getAttribute("VERSION");

Object data = attribute.getData();

Map<String,int[]> dataImpl = (Map<String,int[]>)data;

String key = "myMajor";
assertTrue(dataImpl.containsKey(key));
assertEquals(1,dataImpl.get(key)[0]);

key = "myMinor";
assertTrue(dataImpl.containsKey(key));
assertEquals(0,dataImpl.get(key)[0]);

key = "myPatch";
assertTrue(dataImpl.containsKey(key));
assertEquals(0,dataImpl.get(key)[0]);
}
}
Binary file not shown.

0 comments on commit f601647

Please sign in to comment.