Exemple #1
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));
                        }
                    }
                }
            }
Exemple #2
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);
                    }
                }
            }
Exemple #3
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);
                        }
                    }
                }
            }
Exemple #4
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");
                        }
                    }
                }
Exemple #5
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);
                        }
                    }
                }
Exemple #6
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);
                        }
                    }
                }
            }
Exemple #7
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"]);
            }
Exemple #8
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
                }
            }
Exemple #9
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" });
                        }
                    }
                }
Exemple #10
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 });
                        }
                    }
                }