Пример #1
0
        public void CanUnshuffleGeneric <T>(T dummy, int length)
            where T : unmanaged
        {
            // Arrange
            var version = H5F.libver_t.LATEST;

            var bytesOfType = Unsafe.SizeOf <T>();
            var expected    = Enumerable.Range(0, length * bytesOfType)
                              .Select(value => unchecked ((byte)value)).ToArray();

            var filePath = TestUtils.PrepareTestFile(version, fileId =>
                                                     TestUtils.AddFilteredDataset_Shuffle(fileId, bytesOfType: bytesOfType, length, expected));

            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var parent          = root.Group("filtered");
            var dataset         = parent.Dataset($"shuffle_{bytesOfType}");
            var actual_shuffled = dataset.Read <byte>(null, skipShuffle: true);

            // Act
            var actual = new byte[actual_shuffled.Length];

            ShuffleGeneric.Unshuffle(bytesOfType, actual_shuffled, actual);

            // Assert
            Assert.True(actual.AsSpan().SequenceEqual(expected));
        }
Пример #2
0
        public void CanReadDataset_Chunked_Legacy()
        {
            var versions = new H5F.libver_t[]
            {
                H5F.libver_t.EARLIEST,
                H5F.libver_t.V18
            };

            TestUtils.RunForVersions(versions, version =>
            {
                foreach (var withShuffle in new bool[] { false, true })
                {
                    // Arrange
                    var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddChunkedDataset_Legacy(fileId, withShuffle));

                    // Act
                    using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                    var parent     = root.Group("chunked");
                    var dataset    = parent.Dataset("chunked");
                    var actual     = dataset.Read <int>();

                    // Assert
                    Assert.True(actual.SequenceEqual(TestData.MediumData));
                }
            });
        }
Пример #3
0
        public void CanReadAttribute_Reference_Object()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddObjectReference(fileId, ContainerType.Attribute));

                // Act
                using var root           = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute_references = root.Group("reference").Attribute("object_reference");
                var references           = attribute_references.Read <H5ObjectReference>();

                var dereferenced = references
                                   .Select(reference => root.Get(reference))
                                   .ToArray();

                // Assert
                for (int i = 0; i < TestData.NumericalData.Count; i++)
                {
                    var dataset     = (H5Dataset)dereferenced[i];
                    var expected    = (Array)TestData.NumericalData[i][1];
                    var elementType = expected.GetType().GetElementType();

                    var method  = typeof(TestUtils).GetMethod(nameof(TestUtils.ReadAndCompare), BindingFlags.Public | BindingFlags.Static);
                    var generic = method.MakeGenericMethod(elementType);
                    var result  = (bool)generic.Invoke(null, new object[] { dataset, expected });

                    Assert.True(result);
                }
            });
        }
Пример #4
0
        public void CanReadDataset_Reference_Region()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddRegionReference(fileId, ContainerType.Dataset));

                // Act
                using var root         = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var dataset_references = root.Group("reference").Dataset("region_reference");
                var references         = dataset_references.Read <H5RegionReference>();

                var reference = references[0];
                root.Context.Reader.Seek((long)reference.CollectionAddress, SeekOrigin.Begin);

                // H5Rint.c (H5R__get_region)
#warning use more structs?
                var globalHeapId = new GlobalHeapId(root.Context.Superblock)
                {
                    CollectionAddress = reference.CollectionAddress,
                    ObjectIndex       = reference.ObjectIndex
                };

                var globalHeapCollection = globalHeapId.Collection;
                var globalHeapObject     = globalHeapCollection.GlobalHeapObjects[(int)globalHeapId.ObjectIndex - 1];
                var localReader          = new H5BinaryReader(new MemoryStream(globalHeapObject.ObjectData));
                var address   = root.Context.Superblock.ReadOffset(localReader);
                var selection = new DataspaceSelection(localReader);

                throw new NotImplementedException();
            });
        }
Пример #5
0
        public void CanReadWrappedFiles()
        {
            // Arrange
            var filePath = "testfiles/secret.mat";

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var children = root.Children.ToList();
        }
Пример #6
0
        public void GetsH5UnresolvedLinkForDanglingLinks()
        {
            // Arrange
            var filePath = TestUtils.PrepareTestFile(H5F.libver_t.LATEST, fileId => TestUtils.AddExternalFileLink(fileId, "not-existing.h5"));

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var link = root.Get("/links/external_link") as H5UnresolvedLink;

            // Assert
            Assert.NotNull(link);
            Assert.Equal("Unable to open external file 'not-existing.h5'.", link.Reason.Message);
        }
Пример #7
0
        public void CanCheckAttribute_ExistsUTF8()
        {
            // Arrange
            var version  = H5F.libver_t.LATEST;
            var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddMass(fileId, ContainerType.Attribute));

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var parent = root.Group("mass_attributes");
            var actual = parent.AttributeExists("字形碼 / 字形码, Zìxíngmǎ");

            // Assert
            Assert.True(actual);
        }
Пример #8
0
        public void CanOpenGroup(string path, string expected)
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddSomeLinks(fileId));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var group      = root.Group(path);

                // Assert
                Assert.Equal(expected, group.Name);
            });
        }
Пример #9
0
        public void CanDefilterMultiple()
        {
            // Arrange
            var version  = H5F.libver_t.LATEST;
            var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddFilteredDataset_Multi(fileId));

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var parent  = root.Group("filtered");
            var dataset = parent.Dataset("multi");
            var actual  = dataset.Read <int>();

            // Assert
            Assert.True(actual.SequenceEqual(TestData.MediumData));
        }
Пример #10
0
        public void CanFollowLinks()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddLinks(fileId));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);

                var dataset_hard_1 = root.Dataset("links/hard_link_1/dataset");
                var dataset_hard_2 = root.Dataset("links/hard_link_2/dataset");
                var dataset_soft_2 = root.Dataset("links/soft_link_2/dataset");
                var dataset_direct = root.Dataset("links/dataset");
            });
        }
Пример #11
0
        public void CanCheckAttribute_ExistsMass(string attributeName, bool expected)
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddMass(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var parent     = root.Group("mass_attributes");
                var actual     = parent.AttributeExists(attributeName);

                // Assert
                Assert.Equal(expected, actual);
            });
        }
Пример #12
0
        public void CanReadDataset_NonNullableStruct()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, (Action <long>)(fileId => TestUtils.AddStruct(fileId, ContainerType.Dataset)));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var dataset    = root.Dataset("/struct/nonnullable");
                var actual     = dataset.Read <TestStructL1>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.NonNullableStructData));
            });
        }
Пример #13
0
        public void CanReadDataset_Numerical <T>(string name, T[] expected) where T : unmanaged
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, (Action <long>)(fileId => TestUtils.AddNumerical(fileId, ContainerType.Dataset)));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var dataset    = root.Dataset($"/numerical/{name}");
                var actual     = dataset.Read <T>();

                // Assert
                Assert.True(actual.SequenceEqual(expected));
            });
        }
Пример #14
0
        public void ThrowsForNestedNullableStruct()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, (Action <long>)(fileId => TestUtils.AddStruct((long)fileId, ContainerType.Dataset)));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var dataset    = root.Dataset($"/struct/nullable");
                var exception  = Assert.Throws <Exception>(() => dataset.ReadCompound <TestStructStringL1>());

                // Assert
                Assert.Contains("Nested nullable fields are not supported.", exception.Message);
            });
        }
Пример #15
0
        public void CanReadDataset_Opaque()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, (Action <long>)(fileId => TestUtils.AddOpaque(fileId, ContainerType.Dataset)));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var dataset    = root.Group("opaque").Dataset("opaque");
                var actual     = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.SmallData));
            });
        }
Пример #16
0
        public void CanReadAttribute_NonNullableStruct()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddStruct(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("struct").Attribute("nonnullable");
                var actual     = attribute.Read <TestStructL1>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.NonNullableStructData));
            });
        }
Пример #17
0
        public void CanReadAttribute_Huge()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddHuge(fileId, ContainerType.Attribute, version));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var parent     = root.Group("huge");
                var attribute  = parent.Attributes.First();
                var actual     = attribute.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.HugeData[0..actual.Length]));
            });
Пример #18
0
        public void CanReadAttribute_Dataspace_Null()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddDataspaceNull(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("dataspace").Attribute("null");
                var actual     = attribute.Read <double>();

                // Assert
                Assert.True(actual.Length == 0);
            });
        }
Пример #19
0
        public void ThrowsForNestedNullableStruct()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddStruct(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("struct").Attribute("nullable");
                var exception  = Assert.Throws <Exception>(() => attribute.ReadCompound <TestStructStringL1>());

                // Assert
                Assert.Contains("Nested nullable fields are not supported.", exception.Message);
            });
        }
Пример #20
0
        public void CanReadAttribute_Dataspace_Scalar()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddDataspaceScalar(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("dataspace").Attribute("scalar");
                var actual     = attribute.Read <double>();

                // Assert
                Assert.True(actual.SequenceEqual(new double[] { -1.2234234e-3 }));
            });
        }
Пример #21
0
        public void CanReadAttribute_Opaque()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddOpaque(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("opaque").Attribute("opaque");
                var actual     = attribute.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.SmallData));
            });
        }
Пример #22
0
        public void CanReadAttribute_String(string name, string[] expected)
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddString(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute  = root.Group("string").Attribute(name);
                var actual     = attribute.ReadString();

                // Assert
                Assert.True(actual.SequenceEqual(expected));
            });
        }
Пример #23
0
        public void CanReadAttribute_Tiny()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddTiny(fileId, ContainerType.Attribute));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var parent     = root.Group("tiny");
                var attribute  = parent.Attributes.First();
                var actual     = attribute.Read <byte>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.TinyData));
            });
        }
Пример #24
0
        public void CanReadAttribute_Shared_Message()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddDataWithSharedDataType(fileId, ContainerType.Attribute));
                var expected = new string[] { "001", "11", "22", "33", "44", "55", "66", "77", "  ", "AA", "ZZ", "!!" };

                // Act
                using var root           = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var attribute_references = root.Group("shared_data_type").Attribute("shared_data_type");
                var actual = attribute_references.ReadString();

                // Assert
                Assert.True(actual.SequenceEqual(expected));
            });
        }
Пример #25
0
        public void CanReadDataset_Contiguous()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddContiguousDataset(fileId));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var parent     = root.Group("contiguous");
                var dataset    = parent.Dataset("contiguous");
                var actual     = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.HugeData));
            });
        }
Пример #26
0
        public void CanUnshuffleAvx2 <T>(T dummy, int length)
            where T : unmanaged
        {
            // Arrange
            var version = H5F.libver_t.LATEST;

            var bytesOfType = Unsafe.SizeOf <T>();
            var expected    = Enumerable.Range(0, length * bytesOfType)
                              .Select(value => unchecked ((byte)value)).ToArray();

            var filePath = TestUtils.PrepareTestFile(version, fileId =>
                                                     TestUtils.AddFilteredDataset_Shuffle(fileId, bytesOfType: bytesOfType, length, expected));

            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var parent          = root.Group("filtered");
            var dataset         = parent.Dataset($"shuffle_{bytesOfType}");
            var actual_shuffled = dataset.Read <byte>(default, skipShuffle: true);
Пример #27
0
        public void CanEnumerateLinksMass()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddMassLinks(fileId));
                var expected = 1000;

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var group      = root.Group("mass_links");

                // Assert
                var actual = group.Children.Count();
                Assert.Equal(expected, actual);
            });
        }
Пример #28
0
        public void CanReadDataset_ChunkedBTree2()
        {
            foreach (var withShuffle in new bool[] { false, true })
            {
                // Arrange
                var version  = H5F.libver_t.LATEST;
                var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddChunkedDataset_BTree2(fileId, withShuffle));

                // Act
                using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var parent  = root.Group("chunked");
                var dataset = parent.Dataset("chunked_btree2");
                var actual  = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(TestData.MediumData));
            }
        }
Пример #29
0
        public void CanReadDataset_Contiguous_With_FillValue_And_AllocationLate()
        {
            // Arrange
            var version   = H5F.libver_t.LATEST;
            var fillValue = 99;
            var filePath  = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddContiguousDatasetWithFillValueAndAllocationLate(fileId, fillValue));
            var expected  = Enumerable.Range(0, TestData.MediumData.Length)
                            .Select(value => fillValue)
                            .ToArray();

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var group   = root.Group("fillvalue");
            var dataset = group.Dataset($"{LayoutClass.Contiguous}");
            var actual  = dataset.Read <int>();

            // Assert
            Assert.Equal(expected, actual);
        }
Пример #30
0
        public void CanDerefenceWithCircularReferences()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath       = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddCircularReference(fileId));
                using var root     = H5File.OpenReadCore(filePath, deleteOnClose: true);
                var value          = root.Group("/circular/child/rainbow's end").Reference.Value;
                var groupReference = new H5ObjectReference()
                {
                    Value = value
                };

                // Act
                var group = root.Get(groupReference);

                // Assert
                Assert.Equal("rainbow's end", group.Name);
            });
        }