Example #1
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"));
                }
            }
Example #2
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"));
                    }
                }
            }
Example #3
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();
            }
        }
Example #4
0
            public void ResizeDatasetChecksBounds(long[] new_dims)
            {
                using (var container = new TempH5FileContainer())
                {
                    H5Group ROOT = container.Content().Root;

                    int rank    = 2;
                    var dims    = new long[] { 2, 3 };
                    var maxdims = new long[] { 5, 6 };

                    using (H5DataSet DSET = ROOT.CreateDataset("resizable", rank, dims, typeof(double), maxdims))
                    {
                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        if (H5Library.LibVersion == "1.8.12")
                        {
                            Assert.NotEqual(maxdims, DSET.MaxDims);
                            Assert.Equal(dims, DSET.MaxDims);
                            Assert.Throws <NotImplementedException>(() => DSET.Resize(maxdims));
                        }
                        else
                        {
                            Assert.Throws <IndexOutOfRangeException>(() => DSET.Resize(new_dims));
                        }
                    }
                }
            }
Example #5
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();
                    }
                }
            }
Example #6
0
            public void ResizeDataset(long[] max_dims, long[] new_dims)
            {
                using (var container = new TempH5FileContainer())
                {
                    H5Group ROOT = container.Content().Root;

                    int rank = max_dims.Length;
                    var dims = new long[rank];
                    dims.Fill(1L);

                    using (H5DataSet DSET = ROOT.CreateDataset("resizable", rank, dims, typeof(double), max_dims))
                    {
                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        if (H5Library.LibVersion == "1.8.12")
                        {
                            Assert.NotEqual(max_dims, DSET.MaxDims);
                            Assert.Equal(dims, DSET.MaxDims);
                            Assert.Throws <NotImplementedException>(() => DSET.Resize(max_dims));
                        }
                        else
                        {
                            DSET.Resize(new_dims);

                            Assert.Equal(new_dims, DSET.Dims);
                        }
                    }
                }
            }
Example #7
0
                public void double1d()
                {
                    using (var container = new TempH5FileContainer())
                    {
                        H5Group ROOT = container.Content().Root;

                        int rank = 1;
                        var dims = new long[] { 3 };
                        using (dset1d <double> DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(double)) as dset1d <double>)
                        {
                            Assert.NotNull(DSET);
                            Assert.Equal(dims, DSET.Dims);

                            DSET[0] = 3.14;
                            DSET[1] = 3.14;
                            DSET[2] = 3.14;

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = 3.14);

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = 3.14);
                        }
                    }
                }
Example #8
0
                public void float1d()
                {
                    using (var Container = new TempH5FileContainer())
                    {
                        var hf = Container.Content();

                        var dims = new long[] { 7L };

                        dset1d <float> DSET = hf.Root.CreateDataset("tempdata", 1, dims, typeof(float)) as dset1d <float>;

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        var expect = new float[7] {
                            1, 0, 2, 9, 5, 3, 1
                        };

                        DSET.Values = expect;

                        var actual = DSET.Values;

                        Assert.Equal(expect, actual);

                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1]);
                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[9]);

                        DSET.Dispose();
                    }
                }
Example #9
0
                public void string1d()
                {
                    using (var Container = new TempH5FileContainer())
                    {
                        var hf = Container.Content();

                        var dims = new long[] { 3L };

                        string1d DSET = hf.Root.CreateDataset("tempdata", 1, dims, typeof(string)) as string1d;

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        var expect = new string[3] {
                            "foo", "bar", "zoom"
                        };

                        DSET.Values = expect;

                        var actual = DSET.Values;

                        Assert.Equal(expect, actual);

                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[1]);
                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[9]);

                        DSET.Dispose();
                    }
                }
Example #10
0
                public void string1d()
                {
                    using (var container = new TempH5FileContainer())
                    {
                        H5Group ROOT = container.Content().Root;

                        int rank = 1;
                        var dims = new long[] { 3 };

                        using (string1d DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(string)) as string1d)
                        {
                            Assert.NotNull(DSET);
                            Assert.Equal(dims, DSET.Dims);

                            DSET[0] = "foo";
                            DSET[1] = "bar";
                            DSET[2] = "yom";

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = "grok");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = "grok");
                        }
                    }
                }
Example #11
0
            public void CreateChunkedDataset()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5Group ROOT = container.Content().Root;

                    int rank    = 2;
                    var dims    = new long[] { 2, 3 };
                    var maxdims = new long[] { 5, 6 };

                    var trace = new StringWriter();
                    //TextWriterTraceListener listener = new TextWriterTraceListener(trace);
                    //Trace.Listeners.Add(listener);

                    using (var DSET = ROOT.CreateDataset("chunked", rank, dims, typeof(int), maxdims))
                    {
                        // chunking is not available in hdf5 v1.8.12 and we want to know about it:
                        //if (H5Library.LibVersion == "1.8.12")
                        //    Assert.Contains("WARNING", trace.ToString());
                        //Trace.Listeners.Remove(listener);

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);
                    }
                }
            }
Example #12
0
            public void ResizeUnlimited(long[] new_dims)
            {
                using (var container = new TempH5FileContainer())
                {
                    H5Group ROOT = container.Content().Root;

                    int rank    = 2;
                    var dims    = new long[] { 2, 3 };
                    var maxdims = new long[] { -1, -1 };

                    using (var DSET = ROOT.CreateDataset("resizable", rank, dims, typeof(double), maxdims) as dset2d <double>)
                    {
                        Assert.NotNull(DSET);

                        Assert.Equal(dims, DSET.Dims);

                        if (H5Library.LibVersion == "1.8.12")
                        {
                            Assert.Throws <NotImplementedException>(() => DSET.Resize(new long[] { 6, 9 }));
                        }
                        else
                        {
                            DSET.Resize(new_dims);
                            Assert.Equal(new_dims, DSET.Dims);
                        }
                    }
                }
            }
Example #13
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)));
                }
            }
Example #14
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"]);
                }
            }
Example #15
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));
                }
            }
Example #16
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"));
                }
            }
Example #17
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"));
                }
            }
Example #18
0
            public void FindsAllSubgroups()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

#if DEBUG
                    int nObjectsInitially = H5Base.nObjects;
#endif

                    H5Group SUT = hf.Root;

                    var testnames = new List <string>
                    {
                        "foo",
                        "bar",
                        "zoom",
                        "grok",
                    };
                    // create a group hierarchy..
                    foreach (string name in testnames)
                    {
                        using (var subgroup = SUT.CreateGroup(name))
                        {
                            using (subgroup.CreateGroup("tarnkappenzwerg"))
                            {
                                // just create and dispose..
                            }
                        }
                    }
                    // ..as well as some confusion..
                    using (SUT.CreateDataset("tarnkappenbomber", 1, new long[] { 7 }, typeof(float)))
                    {
                    }

                    var actual = SUT.SubGroups().Select(g => g.Name);

                    // a) check for set equality..
                    var testnames_sorted = new SortedSet <string>(testnames);

                    Assert.True(testnames_sorted.SetEquals(actual));

                    // b) check the default behaviour of sorting the SubGroups() alphabetically..
                    Assert.Equal(testnames_sorted.ToList(), actual);

                    // c) check that all allocated SubGroups() have been disposed of properly..
#if DEBUG
                    Assert.Equal(nObjectsInitially, H5Base.nObjects);
#endif
                }
            }
Example #19
0
            public void TestBasicInjection()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    using (MyObject myo = new MyObject(hf.Root))
                    {
                        Assert.NotNull(myo.intset);
                        Assert.NotNull(myo.longset);
                        Assert.NotNull(myo.byteset);
                        Assert.NotNull(myo.stringset);
                        Assert.NotNull(myo.doubleset);
                        Assert.NotNull(myo.floatset);
                        Assert.NotNull(myo.Privateset);
                        Assert.NotNull(myo.doubleset3);

                        Assert.Equal(1, myo.intset.Rank);
                        Assert.Equal(1, myo.longset.Rank);
                        Assert.Equal(1, myo.byteset.Rank);
                        Assert.Equal(1, myo.stringset.Rank);
                        Assert.Equal(2, myo.doubleset.Rank);
                        Assert.Equal(2, myo.floatset.Rank);
                        Assert.Equal(1, myo.Privateset.Rank);
                        Assert.Equal(3, myo.doubleset3.Rank);

                        Assert.Equal(1L, myo.intset.Length);
                        Assert.Equal(1L, myo.longset.Length);
                        Assert.Equal(1L, myo.byteset.Length);
                        Assert.Equal(1L, myo.stringset.Length);
                        Assert.Equal(1L, myo.doubleset.Length);
                        Assert.Equal(1L, myo.floatset.Length);
                        Assert.Equal(1L, myo.Privateset.Length);
                        Assert.Equal(1L, myo.doubleset3.Length);

                        Assert.Equal(typeof(int), myo.intset.PrimitiveType);
                        Assert.Equal(typeof(long), myo.longset.PrimitiveType);
                        Assert.Equal(typeof(byte), myo.byteset.PrimitiveType);
                        Assert.Equal(typeof(string), myo.stringset.PrimitiveType);
                        Assert.Equal(typeof(double), myo.doubleset.PrimitiveType);
                        Assert.Equal(typeof(float), myo.floatset.PrimitiveType);
                        Assert.Equal(typeof(float), myo.Privateset.PrimitiveType);
                        Assert.Equal(typeof(double), myo.doubleset3.PrimitiveType);
                    }
                }
            }
Example #20
0
                public void string2d()
                {
                    using (var container = new TempH5FileContainer())
                    {
                        H5Group ROOT = container.Content().Root;

                        int rank = 2;
                        var dims = new long[] { 3, 2 };

                        using (string2d DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(string)) as string2d)
                        {
                            Assert.NotNull(DSET);
                            Assert.Equal(dims, DSET.Dims);

                            DSET[0, 0] = "foo";
                            DSET[2, 1] = "bar";
                            DSET[1]    = new string[] { "zoom", "grok" };

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3] = "foo");

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = new string[] { "foo", "bar" });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = new string[] { "foo", "bar" });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[0] = new string[] { "foo", "bar", "zoom" });
                        }
                    }
                }
Example #21
0
                public void double2d()
                {
                    using (var container = new TempH5FileContainer())
                    {
                        H5Group ROOT = container.Content().Root;

                        int rank = 2;
                        var dims = new long[] { 3, 2 };

                        using (dset2d <double> DSET = ROOT.CreateDataset("dataset", rank, dims, typeof(double)) as dset2d <double>)
                        {
                            Assert.NotNull(DSET);
                            Assert.Equal(dims, DSET.Dims);

                            DSET[0, 0] = 3.14;
                            DSET[2, 1] = 3.14;
                            DSET[1]    = new double[] { 1.2, 3.4 };

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 0] = 3.14);

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3, 2] = 3.14);

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, 7] = 3.14);

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[1, -3] = 3.14);

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[3] = new double[] { 1.0, 2.0 });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1]);
                            Assert.Throws <IndexOutOfRangeException>(() => DSET[-1] = new double[] { 1.0, 2.0 });

                            Assert.Throws <IndexOutOfRangeException>(() => DSET[0] = new double[] { 1.0, 2.0, 3.0 });
                        }
                    }
                }
Example #22
0
            public void TestAdvancedInjection()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

                    using (MyObject myo = new MyObject(hf.Root))
                    {
                        Assert.True(H5Link.Exists(hf.Root.ID, "alternative_path"));

                        dset2d <float> dset = myo.advancedset as dset2d <float>;
                        Assert.NotNull(dset);

                        Assert.Equal(2, dset.Rank);
                        Assert.Equal(new long[] { 3, 5 }, dset.Dims);
                        Assert.Equal(15L, dset.Length);
                        Assert.Equal(new float[5], dset[2]);

                        if (H5Library.LibVersion == "1.8.12")
                        {
                            Assert.Throws <NotImplementedException>(() => dset.Resize(new long[] { 6, 9 }));
                        }
                        else
                        {
                            dset.Resize(new long[] { 6, 5 });

                            Assert.Equal(30L, dset.Length);
                            dset[5] = new float[5] {
                                1, 2, 3, 4, 5
                            };

                            dset.Resize(new long[] { 6, 9 });

                            dset[3] = new float[9] {
                                1, 2, 3, 4, 5, 6, 7, 8, 9
                            };
                        }
                    }
                }
            }
Example #23
0
            public void CreateNestedSubGroups()
            {
                using (var container = new TempH5FileContainer())
                {
                    H5File hf = container.Content();

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

                    H5Group GRP = hf.Root;

                    for (int i = 0; i < 3; i++)
                    {
                        GRP = GRP.CreateGroup("zoom");
                    }

                    GRP.Dispose();

                    Assert.True(H5Link.Exists(hf.ID, "zoom/zoom/zoom"));
                }
            }
Example #24
0
                public void float2d()
                {
                    using (var Container = new TempH5FileContainer())
                    {
                        var hf = Container.Content();

                        var dims = new long[] { 3L, 5L };

                        dset2d <float> DSET = hf.Root.CreateDataset("tempdata", 2, dims, typeof(float)) as dset2d <float>;

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        var expect = new float[3, 5] {
                            { 0, 0, 2, 0, 5 },
                            { 1, 3, 0, 8, 9 },
                            { 4, 0, 7, 0, 2 },
                        };

                        DSET.Values = expect;

                        var actual = DSET.Values;

                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                Assert.Equal(expect[i, j], actual[i, j]);
                            }
                        }

                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1, 1]);
                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new float[1, 5]);

                        DSET.Dispose();
                    }
                }
Example #25
0
                public void string2d()
                {
                    using (var Container = new TempH5FileContainer())
                    {
                        var hf = Container.Content();

                        var dims = new long[] { 3L, 2L };

                        string2d DSET = hf.Root.CreateDataset("tempdata", 2, dims, typeof(string)) as string2d;

                        Assert.NotNull(DSET);
                        Assert.Equal(dims, DSET.Dims);

                        var expect = new string[3, 2] {
                            { "foo", "bar" },
                            { "zoom", "grok" },
                            { "", "a;seoliruo345uta;gojasd;gljasdlkfjas;eitj;lefgj" },
                        };

                        DSET.Values = expect;

                        var actual = DSET.Values;

                        for (int i = 0; i < 3; i++)
                        {
                            for (int j = 0; j < 2; j++)
                            {
                                Assert.Equal(expect[i, j], actual[i, j]);
                            }
                        }

                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[1, 1]);
                        Assert.Throws <InvalidOperationException>(() => DSET.Values = new string[1, 5]);

                        DSET.Dispose();
                    }
                }