示例#1
0
        public void SetDataNull()
        {
            string filename = GetFilename("setdatatnull.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 100
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Int8, properties);

            Assert.IsNotNull(dataset);

            try
            {
                sbyte[] value = null;
                dataset.SetData(value);
                Assert.Fail("Exception was expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentNullException>(ex);
            }

            file.Close();
        }
示例#2
0
        public void OpenFileWithException()
        {
            string filename = GetFilename("openfilewithexception.h5");

            Hdf5File file = Hdf5File.Create(filename);

            Assert.IsNotNull(file);

            file.Close();

            //Lock the file so can't be opened
            using (FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                try
                {
                    //Try to open it
                    file = new Hdf5File(filename);

                    Assert.Fail("Should have thrown an exception");
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOf <Hdf5UnknownException>(ex);
                }

                fs.Close();
            }
        }
示例#3
0
        public void SetArrayDimensionMismatch1()
        {
            string filename = GetFilename("setarraydimensionmismatch1.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 5
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Int32, properties);

            Assert.IsNotNull(dataset);

            try
            {
                //2 dimensions sent, only one expected
                Int32[,] value = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 } };
                dataset.SetData(value);
                Assert.Fail("Exception was expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <Hdf5ArrayDimensionsMismatchException>(ex);
            }

            file.Close();
        }
示例#4
0
        public void SetDataMismatch()
        {
            string filename = GetFilename("setdatamismatch.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 3
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Int8, properties);

            Assert.IsNotNull(dataset);

            try
            {
                Int32[] value = { 1, 2, 3 };
                dataset.SetData(value);
                Assert.Fail("Exception was expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <Hdf5TypeMismatchException>(ex);
            }

            file.Close();
        }
示例#5
0
        public void SetUInt64()
        {
            string filename = GetFilename("setuint64.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 5
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.UInt64, properties);

            Assert.IsNotNull(dataset);

            UInt64[] value = { UInt64.MinValue, 1, 2, 3, UInt64.MaxValue };
            dataset.SetData(value);

            var array = dataset.GetData();

            Assert.AreEqual(1, array.Rank);
            Assert.AreEqual(5, array.GetLength(0));
            Assert.AreEqual(UInt64.MinValue, array.GetValue(0));
            Assert.AreEqual(UInt64.MaxValue, array.GetValue(4));

            file.Close();
        }
示例#6
0
        public void UpdateAttributeWithMismatchOnDataset()
        {
            string fileName = GetFilename("updateattributewithmistmachondataset.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group");

            List <Hdf5DimensionProperty> dimensionProps = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        prop           = new Hdf5DimensionProperty {
                CurrentSize = 1
            };

            dimensionProps.Add(prop);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int32, dimensionProps);

            Hdf5Attribute attribute = dataset.Attributes.Add("attribute1", "test");

            try
            {
                attribute.Value = 5;

                dataset.Attributes.Update(attribute);

                Assert.Fail("Should have thrown an exception");
            }
            catch (Exception ex)
            {
                file.Close();
                Assert.IsInstanceOf <Hdf5TypeMismatchException>(ex);
            }
        }
示例#7
0
        public void UpdateStringAttributeOnDataset()
        {
            string fileName = GetFilename("updatestringattributeondataset.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group");

            List <Hdf5DimensionProperty> dimensionProps = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        prop           = new Hdf5DimensionProperty {
                CurrentSize = 1
            };

            dimensionProps.Add(prop);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int32, dimensionProps);

            Hdf5Attribute attribute = dataset.Attributes.Add("attribute1", "test");

            attribute.Value = "test2";
            dataset.Attributes.Update(attribute);
            file.Close();

            file      = new Hdf5File(fileName);
            group     = file.Groups[0];
            dataset   = group.Datasets[0];
            attribute = dataset.Attributes[0];
            Assert.AreEqual("test2", attribute.Value);
        }
示例#8
0
        public void CreateAttributeTwiceOnDataset()
        {
            string fileName = GetFilename("createattributetwiceondataset.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("test");
            List <Hdf5DimensionProperty> dimensionProps = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        prop           = new Hdf5DimensionProperty {
                CurrentSize = 1
            };

            dimensionProps.Add(prop);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int32, dimensionProps);

            dataset.Attributes.Add("attribute1", "test");

            try
            {
                dataset.Attributes.Add("attribute1", "test2");
                Assert.Fail("Should have thrown an exception");
            }
            catch (Exception ex)
            {
                file.Close();
                Assert.IsInstanceOf <Hdf5AttributeAlreadyExistException>(ex);
            }
        }
示例#9
0
        public void OpeningGroupInGroup()
        {
            string fileName = GetFilename("opengroupingroup.h5");

            Hdf5File  file   = Hdf5File.Create(fileName);
            Hdf5Group group1 = file.Groups.Add("group1");

            Assert.IsNotNull(group1);
            Assert.AreEqual(1, file.Groups.Count);

            Hdf5Group group2 = group1.Groups.Add("group2");

            Assert.AreEqual(1, file.Groups.Count);
            Assert.AreEqual(1, group1.Groups.Count);

            file.Close();

            file   = new Hdf5File(fileName);
            group1 = file.Groups[0];
            Assert.IsNotNull(group1);
            Assert.AreEqual("group1", group1.Name);

            group2 = group1.Groups[0];
            Assert.IsNotNull(group2);
            Assert.AreEqual("group2", group2.Name);
        }
示例#10
0
        public void LoopThrougGroups()
        {
            string fileName = GetFilename("loopthroughgroups.h5");

            Hdf5File  file   = Hdf5File.Create(fileName);
            Hdf5Group group1 = file.Groups.Add("group1");
            Hdf5Group group2 = file.Groups.Add("group2");
            Hdf5Group group3 = file.Groups.Add("group3");
            Hdf5Group group4 = file.Groups.Add("group4");
            Hdf5Group group5 = file.Groups.Add("group5");

            Assert.AreEqual(5, file.Groups.Count);

            foreach (Hdf5Group hdf5Group in file.Groups)
            {
                Assert.IsNotNull(hdf5Group);
            }

            for (int i = 0; i < 5; i++)
            {
                var group = file.Groups[i];
            }

            file.Close();
        }
示例#11
0
        public void SetDouble()
        {
            string filename = GetFilename("setdouble.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 5
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Double, properties);

            Assert.IsNotNull(dataset);

            Double[] value = { Double.MinValue, -1.1d, 0.0d, -1.3d, Double.MaxValue };
            dataset.SetData(value);

            var array = dataset.GetData();

            Assert.AreEqual(1, array.Rank);
            Assert.AreEqual(5, array.GetLength(0));
            Assert.AreEqual(Double.MinValue, array.GetValue(0));
            Assert.AreEqual(Double.MaxValue, array.GetValue(4));

            file.Close();
        }
示例#12
0
        public void OpenDatasetInFile()
        {
            string filename = GetFilename("opendatasetinfile.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 100
            };

            properties.Add(property);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Int8, properties);

            Assert.IsNotNull(dataset);
            Assert.AreEqual(1, file.Datasets.Count);
            file.Close();

            file    = new Hdf5File(filename);
            dataset = file.Datasets[0];
            Assert.IsNotNull(dataset);
            Assert.AreEqual("dataset1", dataset.Name);
            Assert.AreEqual(Hdf5DataTypes.Int8, dataset.DataType.Type);
            file.Close();
        }
示例#13
0
        public void GetAttributeOnGroup()
        {
            string fileName = GetFilename("getattributeongroup.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group1");

            group.Attributes.Add("attribute1", "test");
            group.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, group.Attributes.Count);

            file.Close();

            file  = new Hdf5File(fileName);
            group = file.Groups[0];
            var attibutes = group.Attributes;

            Assert.AreEqual(2, attibutes.Count);

            var attribute1 = attibutes[0];

            Assert.AreEqual("attribute1", attribute1.Name);
            Assert.AreEqual("test", attribute1.Value);

            var attribute2 = attibutes[1];

            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);
        }
示例#14
0
        public void DeleteAttributeOnDataset()
        {
            string fileName = GetFilename("deleteattributeondataset.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group1");

            List <Hdf5DimensionProperty> dimensionProps = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        prop           = new Hdf5DimensionProperty {
                CurrentSize = 1
            };

            dimensionProps.Add(prop);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int32, dimensionProps);

            dataset.Attributes.Add("attribute1", "test");
            dataset.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, dataset.Attributes.Count);

            file.Close();

            file    = new Hdf5File(fileName);
            group   = file.Groups[0];
            dataset = group.Datasets[0];
            var attibutes = dataset.Attributes;

            Assert.AreEqual(2, attibutes.Count);

            var attribute1 = attibutes[0];

            Assert.AreEqual("attribute1", attribute1.Name);
            Assert.AreEqual("test", attribute1.Value);

            var attribute2 = attibutes[1];

            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);

            dataset.Attributes.Delete(attribute1);
            Assert.AreEqual(1, attibutes.Count);
            attribute2 = attibutes[0];
            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);

            file.Close();

            file      = new Hdf5File(fileName);
            group     = file.Groups[0];
            dataset   = group.Datasets[0];
            attibutes = dataset.Attributes;
            Assert.AreEqual(1, attibutes.Count);
            attribute2 = attibutes[0];
            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);
        }
示例#15
0
        public void CreateFile()
        {
            string filename = GetFilename("createfile.h5");

            Hdf5File file = Hdf5File.Create(filename);

            Assert.IsNotNull(file);

            file.Close();
        }
示例#16
0
        public void CreateGroup()
        {
            string fileName = GetFilename("creategroup.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group1");

            Assert.IsNotNull(group);
            Assert.AreEqual(1, file.Groups.Count);

            file.Close();
        }
示例#17
0
        public void CreateAttributeOnFile()
        {
            string fileName = GetFilename("createattributeonfile.h5");

            Hdf5File file = Hdf5File.Create(fileName);

            file.Attributes.Add("attribute1", "test");
            file.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, file.Attributes.Count);

            file.Close();
        }
示例#18
0
        public void OpenFile()
        {
            string   filename = GetFilename("openfile.h5");
            Hdf5File file     = Hdf5File.Create(filename);

            Assert.IsNotNull(file);
            file.Close();

            file = new Hdf5File(filename);
            Assert.IsNotNull(file);

            file.Dispose();
        }
示例#19
0
        public void CreateAttributeOnGroup()
        {
            string fileName = GetFilename("createattributeongroup.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group1");

            group.Attributes.Add("attribute1", "test");
            group.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, group.Attributes.Count);

            file.Close();
        }
示例#20
0
        public void UpdateStringAttributeOnFile()
        {
            string fileName = GetFilename("updatestringattributeonfile.h5");

            Hdf5File      file      = Hdf5File.Create(fileName);
            Hdf5Attribute attribute = file.Attributes.Add("attribute1", "test");

            attribute.Value = "test2";
            file.Attributes.Update(attribute);
            file.Close();

            file      = new Hdf5File(fileName);
            attribute = file.Attributes[0];
            Assert.AreEqual("test2", attribute.Value);
        }
示例#21
0
        public void CreateFileWithException()
        {
            //Drive that doesn't exist
            string filename = @"q:\createfilewithexception.h5";

            try
            {
                Hdf5File file = Hdf5File.Create(filename);
                file.Close();
                Assert.Fail("Should have caused an exception");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <Hdf5UnknownException>(ex);
            }
        }
示例#22
0
        public void OpenAttemptMissingFile()
        {
            string filename = GetFilename("missingfile.h5");

            try
            {
                Hdf5File file = new Hdf5File(filename);
                file.Close();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <FileNotFoundException>(ex);
                return;
            }

            Assert.Fail("Should have caused an exception");
        }
示例#23
0
        public void CreateAttributeTwiceOnFile()
        {
            string fileName = GetFilename("createattributetwiceonfile.h5");

            Hdf5File file = Hdf5File.Create(fileName);

            file.Attributes.Add("attribute1", "test");

            try
            {
                file.Attributes.Add("attribute1", "test2");
                Assert.Fail("Should have thrown an exception");
            }
            catch (Exception ex)
            {
                file.Close();
                Assert.IsInstanceOf <Hdf5AttributeAlreadyExistException>(ex);
            }
        }
示例#24
0
        public void CreateAttemptExistingFile()
        {
            string filename = GetFilename("existingfile.h5");

            File.WriteAllText(filename, "");

            try
            {
                Hdf5File file = Hdf5File.Create(filename);
                file.Close();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <Hdf5FileExistsException>(ex);
                return;
            }

            Assert.Fail("Should have caused an exception");
        }
示例#25
0
        public void DeleteAttributeOnFile()
        {
            string fileName = GetFilename("deleteattributeonfile.h5");

            Hdf5File file = Hdf5File.Create(fileName);

            file.Attributes.Add("attribute1", "test");
            file.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, file.Attributes.Count);

            file.Close();

            file = new Hdf5File(fileName);
            var attibutes = file.Attributes;

            Assert.AreEqual(2, attibutes.Count);

            var attribute1 = attibutes[0];

            Assert.AreEqual("attribute1", attribute1.Name);
            Assert.AreEqual("test", attribute1.Value);

            var attribute2 = attibutes[1];

            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);

            file.Attributes.Delete(attribute1);
            Assert.AreEqual(1, attibutes.Count);
            attribute2 = attibutes[0];
            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);

            file.Close();

            file      = new Hdf5File(fileName);
            attibutes = file.Attributes;
            Assert.AreEqual(1, attibutes.Count);
            attribute2 = attibutes[0];
            Assert.AreEqual("attribute2", attribute2.Name);
            Assert.AreEqual(5, attribute2.Value);
        }
示例#26
0
        public void UpdateAttributeWithMismatchOnFile()
        {
            string fileName = GetFilename("updateattributewithmistmachonfile.h5");

            Hdf5File      file      = Hdf5File.Create(fileName);
            Hdf5Attribute attribute = file.Attributes.Add("attribute1", "test");

            try
            {
                attribute.Value = 5;

                file.Attributes.Update(attribute);

                Assert.Fail("Should have thrown an exception");
            }
            catch (Exception ex)
            {
                file.Close();
                Assert.IsInstanceOf <Hdf5TypeMismatchException>(ex);
            }
        }
示例#27
0
        public void CreateAttributeOnDataset()
        {
            string fileName = GetFilename("createattributeondataset.h5");

            Hdf5File  file  = Hdf5File.Create(fileName);
            Hdf5Group group = file.Groups.Add("group1");

            List <Hdf5DimensionProperty> dimensionProps = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        prop           = new Hdf5DimensionProperty {
                CurrentSize = 1
            };

            dimensionProps.Add(prop);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int32, dimensionProps);

            dataset.Attributes.Add("attribute1", "test");
            dataset.Attributes.Add("attribute2", 5);
            Assert.AreEqual(2, dataset.Attributes.Count);

            file.Close();
        }
示例#28
0
        public void Set2DuInt64()
        {
            string filename = GetFilename("set2duint64.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property1  = new Hdf5DimensionProperty {
                CurrentSize = 2
            };

            properties.Add(property1);
            Hdf5DimensionProperty property2 = new Hdf5DimensionProperty {
                CurrentSize = 3
            };

            properties.Add(property2);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.UInt64, properties);

            Assert.IsNotNull(dataset);

            UInt64[,] value = { { UInt64.MinValue, 0, UInt64.MaxValue }, { UInt64.MaxValue, 0, UInt64.MinValue } };
            dataset.SetData(value);

            var array = dataset.GetData();

            Assert.AreEqual(2, array.Rank);
            Assert.AreEqual(2, array.GetLength(0));
            Assert.AreEqual(3, array.GetLength(1));
            Assert.AreEqual(UInt64.MinValue, array.GetValue(0, 0));
            Assert.AreEqual(0, array.GetValue(0, 1));
            Assert.AreEqual(UInt64.MaxValue, array.GetValue(0, 2));
            Assert.AreEqual(UInt64.MaxValue, array.GetValue(1, 0));
            Assert.AreEqual(0, array.GetValue(1, 1));
            Assert.AreEqual(UInt64.MinValue, array.GetValue(1, 2));

            file.Close();
        }
示例#29
0
        public void CreateDatasetInGroup()
        {
            string filename = GetFilename("createdatasetingroup.h5");

            Hdf5File file = Hdf5File.Create(filename);

            Hdf5Group group = file.Groups.Add("group1");

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property   = new Hdf5DimensionProperty {
                CurrentSize = 100
            };

            properties.Add(property);

            Hdf5Dataset dataset = group.Datasets.Add("dataset1", Hdf5DataTypes.Int8, properties);

            Assert.IsNotNull(dataset);
            Assert.AreEqual(0, file.Datasets.Count);
            Assert.AreEqual(1, group.Datasets.Count);

            file.Close();
        }
示例#30
0
        public void Set2DArraySizeMismatch2()
        {
            string filename = GetFilename("set2darraysizemismatch2.h5");

            Hdf5File file = Hdf5File.Create(filename);

            List <Hdf5DimensionProperty> properties = new List <Hdf5DimensionProperty>();
            Hdf5DimensionProperty        property1  = new Hdf5DimensionProperty {
                CurrentSize = 3
            };

            properties.Add(property1);
            Hdf5DimensionProperty property2 = new Hdf5DimensionProperty {
                CurrentSize = 5
            };

            properties.Add(property2);

            Hdf5Dataset dataset = file.Datasets.Add("dataset1", Hdf5DataTypes.Int32, properties);

            Assert.IsNotNull(dataset);

            try
            {
                //Only 3x4
                Int32[,] value = { { 1, 2, 3 }, { 4, 5, 6, }, { 7, 8, 9, }, { 10, 11, 12, } };
                dataset.SetData(value);
                Assert.Fail("Exception was expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <Hdf5ArraySizeMismatchException>(ex);
            }

            file.Close();
        }