Пример #1
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));
                }
            });
        }
Пример #2
0
            public void DisposeOfProperly()
            {
                int N = H5Base.nObjects;

                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    Assert.Equal(N + 2, H5Base.nObjects);  // +file +root

                    H5DataSet DSET = hf.Root["datasets/float2d"];

                    Assert.Equal(N + 3, H5Base.nObjects);  // +dataset

                    Assert.NotNull(DSET);

                    Assert.Equal(2, DSET.Rank);
                    Assert.Equal(Edge, DSET.Dims[0]);
                    Assert.Equal(Edge, DSET.Dims[1]);
                    Assert.Equal(Edge, DSET.MaxDims[0]);
                    Assert.Equal(Edge, DSET.MaxDims[1]);
                    Assert.Equal(Square, DSET.Length);
                    Assert.Equal(typeof(float), DSET.PrimitiveType);

                    // check, that the object count is stable..
                    Assert.Equal(N + 3, H5Base.nObjects);  // +/- 0

                    DSET.Dispose();

                    Assert.Equal(N + 2, H5Base.nObjects); // -dataset
                }
                Assert.Equal(N + 0, H5Base.nObjects);     // -root -file
            }
Пример #3
0
            public void InjectReadonly()
            {
                string path = Path.Combine(demodata, "test_inject_readonly.h5");

                if (!File.Exists(path))
                {
                    using (H5File hf = H5File.Open(path, "x"))
                    {
                        var dset = hf.Root.CreateDataset("existing", 1, new long[] { 1 }, typeof(int));
                        // make sure, the file is closed properly:
                        dset.Dispose();
                    }
                }

                // first try: readonly file mode..
                using (var hf = H5File.Open(path, "r"))
                {
                    using (ReadOnlyObject myo = new ReadOnlyObject(hf.Root))
                    {
                        // ..dataset has been skipped:
                        Assert.Null(myo.readonli);

                        Assert.NotNull(myo.existing);
                    }
                }
            }
Пример #4
0
        public void WriteToMapping()
        {
            using (TempH5FileContainer container = new TempH5FileContainer())
            {
                H5File hf = container.Content();
                Assert.True(hf.Root.IsWritable);

                MyNewObject myo = new MyNewObject(hf.Root);

                Assert.Throws <KeyNotFoundException>(() => myo.Attr["not_existing"]);

                Assert.NotNull(myo.Attr["please_create"]);
                Assert.NotNull(myo.Attr["dataset_attr"]);

                myo.Attr["dataset_attr"].Writes("foo");
                myo.Attr["please_create"].Write(3.14f);
                Assert.Throws <InvalidCastException>(() => myo.Attr["please_create"].Write(3.14));

                Assert.Equal("foo", myo.Attr["dataset_attr"].Reads());
                Assert.Equal(3.14f, myo.Attr["please_create"].Read <float>());
                Assert.Equal(3.14f, myo.Attr["please_create"].Read());

                myo.Dispose();
            }
        }
Пример #5
0
 public void Test_Link_Dont_Exist(string key)
 {
     using (H5File hf = H5File.Open(demodata + "test_link_exists.h5", mode: "r"))
     {
         Assert.False(H5Link.Exists(hf.ID, key));
     }
 }
Пример #6
0
            public void AttemptToWriteClosedFileFails()
            {
                string path = Path.GetTempFileName();

                H5File FILE = H5File.Open(path, mode: "w");

                // create some stuff..
                H5Group GROUP = FILE.Root.SubGroup("foo", create: true);

                GROUP.CreateDataset("bar", 1, new long[] { 7L }, typeof(byte));
                dset1d <byte> DSET = GROUP["bar"] as dset1d <byte>;

                Assert.NotNull(DSET);

                DSET[3] = 5;

                // close all H5Objects manually in this test-scenario:
                GROUP.Dispose();
                DSET.Dispose();
                FILE.Dispose();

                // the file.ID becomes the H5F.close() return value, which is often
                // (but not guaranteed to be) zero / non-negative:
                Assert.Equal((H5Ohm.hid_t) 0, FILE.ID);
                Assert.Equal((H5Ohm.hid_t) 0, FILE.Root.ID);
                Assert.Equal((H5Ohm.hid_t) 0, DSET.ID);
                Assert.Equal((H5Ohm.hid_t) 0, GROUP.ID);

                Assert.Throws <InvalidOperationException>(() => FILE.Root["foo/bar"]);
                Assert.Throws <InvalidOperationException>(() => DSET[5] = 3);
                Assert.Throws <InvalidOperationException>(() => GROUP["bar"]);
            }
Пример #7
0
            public void double2d_Arrays()
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    dset2d <double> DSET = hf.Root["datasets/double2d"] as dset2d <double>;

                    Assert.NotNull(DSET);
                    Assert.Equal(Square, DSET.Length);

                    Assert.Equal(new double[] { 0, 0, 4, 0, 0, 0, 0 }, DSET.Row(2));
                    Assert.Equal(new double[] { 0, 0, 0, 9, 0, 0, 0 }, DSET.Row(3));
                    Assert.Equal(new double[] { 0, 0, 0, 0, 0, 25, 0 }, DSET.Row(5));
                    Assert.Equal(new double[] { 0, 1, 4, 9, 16, 25, 36 }, DSET.Row(6));

                    Assert.Equal(new double[] { 0, 0, 4, 0, 0, 0, 4 }, DSET.Column(2));
                    Assert.Equal(new double[] { 0, 0, 0, 9, 0, 0, 9 }, DSET.Column(3));
                    Assert.Equal(new double[] { 0, 0, 0, 0, 0, 25, 25 }, DSET.Column(5));
                    Assert.Equal(new double[] { 0, 0, 0, 0, 0, 0, 36 }, DSET.Column(6));

                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(7));
                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(17));
                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Row(-1));

                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(7));
                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(17));
                    Assert.Throws <IndexOutOfRangeException>(() => DSET.Column(-1));
                }
            }
Пример #8
0
            public void ClosePreviouslyInitializedFile()
            {
                string path = Path.GetTempFileName();

                H5File FILE = H5File.Open(path, mode: "w");

                // initialize a test-object, which creates two datasets:
                var PIG = new GuineaPig(FILE.Root);

                Assert.True(PIG.stringset.ID > 0);
                Assert.True(PIG.byteset.ID > 0);

                // th test-object must be disposed of as this is not automatic:
                PIG.Dispose();

                FILE.Dispose();

                // trying to re-open is a surefire way to check if FILE was closed correctly:
                H5File FILE2 = H5File.Open(path, mode: "w");

                FILE2.Dispose();

                Assert.Equal((hid_t)0, PIG.stringset.ID);
                Assert.Equal((hid_t)0, PIG.byteset.ID);

                File.Delete(path);

                Assert.False(File.Exists(FILE.Path));
            }
Пример #9
0
            public void string2d_To2dArray()
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    string2d DSET = hf.Root["datasets/string2d"] as string2d;

                    Assert.NotNull(DSET);
                    Assert.Equal(5 * 5, DSET.Length);

                    var expect = new string[5, 5] {
                        { "foo", "", "", "", "", },
                        { "", "bar", "", "", "", },
                        { "", "", "zoom", "", "", },
                        { "", "", "", "grok", "", },
                        { "foo", "bar", "zoom", "grok", "yom" },
                    };

                    var actual = DSET.Values;

                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 5; j++)
                        {
                            Assert.Equal(expect[i, j], actual[i, j]);
                        }
                    }
                }
            }
Пример #10
0
            public void float2d_To2dArray()
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    dset2d <float> DSET = hf.Root["datasets/float2d"] as dset2d <float>;

                    Assert.NotNull(DSET);
                    Assert.Equal(Square, DSET.Length);

                    var expect = new float[7, 7] {
                        { 0, 0, 0, 0, 0, 0, 0 },
                        { 0, 1, 0, 0, 0, 0, 0 },
                        { 0, 0, 4, 0, 0, 0, 0 },
                        { 0, 0, 0, 9, 0, 0, 0 },
                        { 0, 0, 0, 0, 16, 0, 0 },
                        { 0, 0, 0, 0, 0, 25, 0 },
                        { 0, 1, 4, 9, 16, 25, 36 },
                    };

                    var actual = DSET.Values;

                    for (int i = 0; i < 7; i++)
                    {
                        for (int j = 0; j < 7; j++)
                        {
                            Assert.Equal(expect[i, j], actual[i, j]);
                        }
                    }
                }
            }
Пример #11
0
            public void CanAccessAbsolutePaths()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    using (H5Group GRP = hf.Root.CreateGroup("foo"))
                    {
                        H5Group SUBGRP = GRP.SubGroup("bar", create: true);
                        SUBGRP.Dispose();

                        Assert.True(H5Link.Exists(hf.ID, "/foo/"));
                        Assert.True(H5Link.Exists(hf.ID, "/foo/bar/"));

                        SUBGRP = hf.Root.SubGroup("/foo");
                        Assert.NotNull(GRP);
                        SUBGRP.Dispose();

                        SUBGRP = hf.Root.SubGroup("/foo/bar");
                        Assert.NotNull(GRP);
                        SUBGRP.Dispose();

                        SUBGRP = hf.Root.SubGroup("foo/bar");
                        Assert.NotNull(SUBGRP);
                        SUBGRP.Dispose();
                    }
                }
            }
Пример #12
0
        public void CanDefilterBZip2()
        {
            // # Works only with Linux! On Windows, deflate is used instead.
            // import numpy
            // import tables


            // fileName = 'bzip2.h5'
            // shape = (1000,)
            // atom = tables.Int32Atom()
            // filters = tables.Filters(complevel=9, complib='bzip2')

            // with tables.open_file(fileName, 'w') as f:
            //     dataset = f.create_carray(f.root, 'bzip2', atom, shape, filters=filters)
            //     dataset[:] = list(range(0, 1000))

            // Arrange
            var filePath = "./testfiles/bzip2.h5";
            var expected = Enumerable.Range(0, 1000).ToArray();

            H5Filter.Register(identifier: (H5FilterID)307, name: "bzip2", filterFunc: BZip2Helper.FilterFunc);

            // Act
            using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var dataset = root.Dataset("bzip2");
            var actual  = dataset.Read <int>();

            // Assert
            Assert.True(actual.SequenceEqual(expected));
        }
Пример #13
0
            public void Elements()
            {
                using (H5File hf = H5File.Open(testfile, mode: "r"))
                {
                    using (dset1d <int> DSET = hf.Root["datasets/int1d"] as dset1d <int>)
                    {
                        Assert.NotNull(DSET);

                        var actual = DSET.Elements().ToArray();

                        var expected = new int[] { 0, 1, 2, 3, 4, 5, 6 };

                        Assert.Equal(expected, actual);
                    }

                    using (dset2d <int> DSET = hf.Root["datasets/int2d"] as dset2d <int>)
                    {
                        Assert.NotNull(DSET);

                        var actual = DSET.Elements().Skip(5 * 7 + 4).Take(7).ToArray();

                        var expected = new int[7] {
                            0, 25, 0, 0, 1, 4, 9
                        };

                        Assert.Equal(expected, actual);
                    }
                }
            }
Пример #14
0
            public void DeleteSubGroup()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    Assert.False(H5Link.Exists(hf.ID, "foo"));
                    Assert.False(H5Link.Exists(hf.ID, "bar"));

                    using (hf.Root.CreateGroup("foo"))
                    {
                    }
                    using (hf.Root.CreateGroup("bar"))
                    {
                    }

                    Assert.True(H5Link.Exists(hf.ID, "foo"));
                    Assert.True(H5Link.Exists(hf.ID, "bar"));

                    hf.Root.DeleteGroup("bar");

                    Assert.True(H5Link.Exists(hf.ID, "foo"));
                    Assert.False(H5Link.Exists(hf.ID, "bar"));

                    hf.Root.DeleteGroup("foo");

                    Assert.False(H5Link.Exists(hf.ID, "foo"));
                    Assert.False(H5Link.Exists(hf.ID, "bar"));
                }
            }
Пример #15
0
            public void CreateSubGroup()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    Assert.False(H5Link.Exists(hf.ID, "foo"));
                    Assert.Throws <KeyNotFoundException>(() => hf.Root.SubGroup("foo"));

                    using (var GRP = hf.Root.CreateGroup("foo"))
                    {
                        Assert.True(H5Link.Exists(hf.ID, "foo"));
                        using (hf.Root.SubGroup("foo"))
                        {
                        }  // dispose immediately

                        Assert.False(H5Link.Exists(hf.ID, "bar"));
                        Assert.Throws <KeyNotFoundException>(() => hf.Root.SubGroup("bar"));

                        // create on-the-fly..
                        using (hf.Root.SubGroup("bar", create: true))
                        {
                        }
                        Assert.True(H5Link.Exists(hf.ID, "bar"));
                    }
                }
            }
Пример #16
0
        public void ComplexDatatypeCreate()
        {
            var points = new NamedPoint[10];
            for (int i = 0; i < 10; i++)
            {
                var p = new NamedPoint {point = {x = i*2, y = i*3}};
                var name = Encoding.ASCII.GetBytes(i.ToString());
                unsafe
                {
                    Marshal.Copy(name, 0, (IntPtr)p.name, name.Length);
                }
                points[i] = p;
            }

            using (var file = new H5File(TEST_FILE))
            {
                var stringType = file.CreateDatatype("STRING", H5T.H5TClass.STRING, 40);
                var pointType = file.CreateDatatype("POINT",
                                                    new[] {"x", "y"},
                                                    new[]
                                                        {
                                                            new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                            new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                        });

                var type = file.CreateDatatype("NAMED_POINT",
                                                new[] {"name", "point"},
                                                new[] {stringType, pointType});

                var dataset = file.AddDataset("points", type, points);
                Assert.AreEqual(points, dataset.GetData<NamedPoint>());
            }
        }
Пример #17
0
        public void CanReadDataset_CompactTestFile()
        {
            TestUtils.RunForAllVersions(version =>
            {
                // Arrange
                var filePath = "testfiles/h5ex_d_compact.h5";
                var expected = new int[4, 7];

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        expected[i, j] = i * j - j;
                    }
                }

                // Act
                using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                var parent     = root;
                var dataset    = parent.Dataset("DS1");
                var actual     = dataset.Read <int>();

                // Assert
                Assert.True(actual.SequenceEqual(expected.Cast <int>()));
            });
        }
Пример #18
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));
        }
Пример #19
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();
            });
        }
Пример #20
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);
                }
            });
        }
        public void CanReadWrappedFiles()
        {
            // Arrange
            var filePath = "testfiles/secret.mat";

            // Act
            using var root = H5File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, deleteOnClose: true);
            var children = root.Children.ToList();
        }
Пример #22
0
            public void OpenNonExistingFails()
            {
                string path = Path.Combine(demodata, "aeroiyu359hnfna.soie");

                Assert.False(File.Exists(path));

                Assert.Throws <FileNotFoundException>(() => H5File.Open(path, mode: "r"));
                Assert.Throws <FileNotFoundException>(() => H5File.Open(path, mode: "r+"));
            }
Пример #23
0
            public void CreateDatasetFails()
            {
                using (var container = new TempH5FileContainer(filemode: "r"))
                {
                    H5File hf = container.Content();

                    Assert.Throws <InvalidOperationException>(() => hf.Root.CreateDataset("zoom", 2, new long[] { 3, 4 }, typeof(float)));
                }
            }
Пример #24
0
        public void CanReadWrappedFiles()
        {
            // Arrange
            var filePath = "testfiles/secret.mat";

            // Act
            using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
            var children = root.Children.ToList();
        }
Пример #25
0
        public TempH5FileContainer(string filemode = "w")
        {
            string temp_path = System.IO.Path.GetTempFileName();

            hf = H5File.Open(temp_path, mode: "w");
            // close..
            hf.Dispose();
            // ..to reopen:
            hf = H5File.Open(temp_path, mode: filemode);
        }
Пример #26
0
            public void NonexistingLookupFails()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    Assert.Throws <KeyNotFoundException>(() => hf.Root["zoom"]);
                    Assert.Throws <KeyNotFoundException>(() => hf.Root["foo/bar"]);
                }
            }
Пример #27
0
 static void Main(string[] args)
 {
     using (var hf = H5File.Open("example.h5", "w"))
     {
         using (new MyObject(hf.Root))
         {
             // ... work, work, work ...
         }
     }
 }
Пример #28
0
            public void CreateGroupFails()
            {
                using (var container = new TempH5FileContainer(filemode: "r"))
                {
                    H5File hf = container.Content();

                    Assert.Throws <InvalidOperationException>(() => hf.Root.SubGroup("foo", create: true));

                    Assert.Throws <InvalidOperationException>(() => hf.Root.CreateGroup("bar"));
                }
            }
Пример #29
0
            public void InitObjectFails()
            {
                using (var container = new TempH5FileContainer(filemode: "r"))
                {
                    H5File hf = container.Content();

                    Assert.False(hf.Root.IsWritable);

                    Assert.Throws <InvalidOperationException>(() => new GuineaPig(hf.Root));
                }
            }
Пример #30
0
            public void LocateDatasetWith2DProperties(string key)
            {
                using (H5File hf = H5File.Open(demodata + "test_link_exists.h5", mode: "r"))
                {
                    H5DataSet dset = hf.Root[key];

                    Assert.Equal(2, dset.Rank);
                    Assert.Equal(49L, dset.Length);
                    Assert.Equal(new long[] { 7, 7 }, dset.Dims);
                }
            }
Пример #31
0
            public void CannotCreateMultipleGroups()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    Assert.False(H5Link.Exists(hf.ID, "grok/"));
                    Assert.False(H5Link.Exists(hf.ID, "grok/fitz"));

                    Assert.Throws <InvalidOperationException>(() => hf.Root.CreateGroup("grok/fitz"));
                }
            }
Пример #32
0
        public void NestsGroups()
        {
            using (var file = new H5File(TEST_FILE))
            {
                file.AddGroup("out").AddGroup("mid").AddGroup("in");

                Assert.AreEqual(1, file.Groups.Count());
                var o = file.Groups.First();
                Assert.AreEqual("out", o.Name);
                Assert.AreEqual(1, o.Groups.Count());
                var m = o.Groups.First();
                Assert.AreEqual("mid", m.Name);
                Assert.AreEqual(1, m.Groups.Count());
                var i = m.Groups.First();
                Assert.AreEqual("in", i.Name);
                Assert.AreEqual(0, i.Groups.Count());
            }
        }
Пример #33
0
 internal H5Datatype(H5File file, string path)
     : base(file, path)
 {
 }
Пример #34
0
 internal H5Attribute(H5File file, string path, string name)
     : base(file, path)
 {
     _name = name;
 }
Пример #35
0
 protected H5Object(H5File file, string path)
 {
     File = file;
     Path = path;
 }
Пример #36
0
 internal H5Link(H5File file, string path)
     : base(file, path)
 {
 }
Пример #37
0
 public void ShouldAddEmptyStringAttribute()
 {
     using (var file = new H5File(TEST_FILE))
     {
         file.Attributes["attr"] = "";
         Assert.AreEqual("", file.Attributes["attr"].GetValue());
     }
 }
Пример #38
0
        public void ShouldDeleteGroup()
        {
            using (var file = new H5File(TEST_FILE))
            {
                var group = file.AddGroup("group");
                group.Delete();
                Assert.AreEqual(0, file.Groups.Count());
            }

            using (var file = new H5File(TEST_FILE))
            {
                Assert.AreEqual(0, file.Groups.Count());
            }
        }
Пример #39
0
        public void ShouldExtendChunkDataset()
        {
            using (var file = new H5File(TEST_FILE))
            {
                var type = file.CreateDatatype("POINT",
                                               new[] { "x", "y" },
                                               new[]
                                                   {
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                   });

                var dataset = file.AddDataset("points", type, new long[] {0}, new long[] {-1}, new long[] {64});

                var points = new[] {new Point {x = 1, y = 2}};

                // Dataset not yet extended
                dataset.SetData(points);
                Assert.AreEqual(0, dataset.GetData<Point>().Count());

                dataset.Extend(new long[] {1});
                dataset.SetData(points);
                Assert.AreEqual(1, dataset.GetData<Point>().Count());
                Assert.AreEqual(points, dataset.GetData<Point>());
            }
        }
Пример #40
0
 public void PropertyShouldReturnSameObject()
 {
     using (var file = new H5File(TEST_FILE))
     {
         var g1 = file.AddGroup("group");
         var g2 = file.Groups.First();
         var g3 = file.Groups.First();
         Assert.IsTrue(g1 == g2 && g2 == g3);
     }
 }
Пример #41
0
 public void ObjectsWithSamePathShouldBeEqual()
 {
     using (var file = new H5File(TEST_FILE))
     {
         var group = file.AddGroup("group");
         Assert.AreEqual(group, file.Groups.First());
     }
 }
Пример #42
0
        public void SimpleGroupCreateFind()
        {
            using (var file = new H5File(TEST_FILE))
            {
                file.AddGroup("simple");
            }

            using (var file = new H5File(TEST_FILE))
            {
                Assert.AreEqual(1, file.Groups.Count());

                var group = file.Groups.First();
                Assert.AreEqual("simple", group.Name);
                Assert.AreEqual(0, group.Groups.Count());
            }
        }
Пример #43
0
        public void ShouldOverwriteAttribute()
        {
            using (var file = new H5File(TEST_FILE))
            {
                file.Attributes["attr"] = "banana";
                file.Attributes["attr"] = 123;

                var attr = file.Attributes.First();
                Assert.AreEqual("attr", attr.Name);
                Assert.AreEqual(123, attr.GetValue());
            }
        }
Пример #44
0
        public void SimpleDatatypeCreateFind()
        {
            var points = new Point[10];
            for (int i = 0; i < points.Length; i++)
            {
                points[i].x = i;
                points[i].y = i*3;
            }

            using (var file = new H5File(TEST_FILE))
            {
                var type = file.CreateDatatype("POINT",
                                               new[] {"x", "y"},
                                               new[]
                                                   {
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                   });

                var dataset = file.AddDataset("points", type, points);
            }

            using (var file = new H5File(TEST_FILE))
            {
                Assert.AreEqual(1, file.Datasets.Count());

                var dataset = file.Datasets.First();
                var actual = dataset.GetData<Point>();
                Assert.AreEqual(points, actual);
            }
        }
Пример #45
0
        public void SimpleAttributeCreateFind()
        {
            var attributes = new Dictionary<string, object>()
                {
                    {"attr1", "hello world!"},
                    {"attr2", 15.6},
                    {"attr3", new[] {3, 2, 1}}
                };

            using (var file = new H5File(TEST_FILE))
            {
                var group = file.AddGroup("simple");

                foreach (var kv in attributes)
                {
                    group.Attributes[kv.Key] = new H5Attribute(kv.Value);
                }
            }

            using (var file = new H5File(TEST_FILE))
            {
                Assert.AreEqual(1, file.Groups.Count());

                var group = file.Groups.First();
                var actual = group.Attributes.ToDictionary(a => a.Name, a => a.GetValue());

                Assert.AreEqual(attributes, actual);
            }
        }
Пример #46
0
        public void ShouldRemoveAttribute()
        {
            using (var file = new H5File(TEST_FILE))
            {
                file.Attributes["attr"] = "wowow";
                file.Attributes.Remove("attr");

                Assert.AreEqual(0, file.Attributes.Count());
            }
        }