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); } }
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(); }
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); }
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(); }
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(); }
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(); }
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); } }
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(); }
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); }
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); }
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(); } }
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(); }
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(); }
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); }
public void CreateFile() { string filename = GetFilename("createfile.h5"); Hdf5File file = Hdf5File.Create(filename); Assert.IsNotNull(file); file.Close(); }
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(); }
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(); }
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(); }
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(); }
public void CopyToTest() { string fileName = GetFilename("copyto.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"); Hdf5Group[] groups = new Hdf5Group[5]; file.Groups.CopyTo(groups, 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); }
public void DeleteGroup() { string fileName = GetFilename("deletegroup.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); //TODO - delete }
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); } }
public void ContainsTest() { string fileName = GetFilename("contains.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.IsTrue(file.Groups.Contains(group1)); Assert.IsTrue(file.Groups.Contains(group2)); Assert.IsTrue(file.Groups.Contains(group3)); Assert.IsTrue(file.Groups.Contains(group4)); Assert.IsTrue(file.Groups.Contains(group5)); }
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"); }
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); } }
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); }
public void AttemptMoney() { string filename = GetFilename("attemptmoney.hdf5"); var file = Hdf5File.Create(filename); try { decimal money = 123.33m; file.Attributes.Add("moneyvalue", money); Assert.Fail("Exception was expected"); } catch (Exception ex) { Assert.IsInstanceOf <Hdf5UnsupportedDataTypeException>(ex); } file.Close(); }
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); } }
public void GetEnumeratorTest() { string fileName = GetFilename("getenumerator.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"); var groups = file.Groups; var test = groups as IEnumerable; int i = 0; foreach (object testGroup in test) { i++; } Assert.AreEqual(5, i); }