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)); }
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"]); }
public void Dispose() { string path = hf.Path; hf.Dispose(); File.Delete(path); }
public void CreateAndRead() { string path = Path.GetTempFileName(); File.Delete(path); Assert.False(File.Exists(path)); H5File FILE = null; // 1) create.. FILE = H5File.Open(path, mode: "x"); Assert.NotNull(FILE.Root); Assert.True(FILE.Root.IsWritable); FILE.Dispose(); // 1a) truncate.. FILE = H5File.Open(path, mode: "w"); Assert.NotNull(FILE.Root); Assert.True(FILE.Root.IsWritable); FILE.Dispose(); // 2a) ..reopen in r mode.. FILE = H5File.Open(path, mode: "r"); Assert.NotNull(FILE.Root); Assert.False(FILE.Root.IsWritable); FILE.Dispose(); // 2b) ..and in r+ mode.. FILE = H5File.Open(path, mode: "r+"); Assert.NotNull(FILE.Root); Assert.True(FILE.Root.IsWritable); FILE.Dispose(); // cleanup.. File.Delete(path); }
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); }
public void OverwriteExisting() { string path = Path.GetTempFileName(); Assert.True(File.Exists(path)); // A) truncate file works.. H5File hf = H5File.Open(path, mode: "w"); hf.Dispose(); // B) ..but x-mode will fail on existing file: Assert.Throws <ApplicationException>(() => H5File.Open(path, mode: "x")); File.Delete(path); }
public void ReOpenFails() { string path = Path.GetTempFileName(); H5File FILE0 = H5File.Open(path, mode: "w"); FILE0.Dispose(); H5File FILE = H5File.Open(path, mode: "r"); Assert.Throws <H5LibraryException>(() => H5File.Open(path, mode: "r+")); Assert.Throws <H5LibraryException>(() => H5File.Open(path, mode: "w")); FILE.Dispose(); File.Delete(path); }
public void OpenExisting() { string path = Path.GetTempFileName(); H5File FILE0 = H5File.Open(path, mode: "w"); FILE0.Dispose(); H5File FILE1 = H5File.Open(path, mode: "r"); FILE1.Dispose(); H5File FILE2 = H5File.Open(path, mode: "r+"); FILE2.Dispose(); File.Delete(path); }
public void CloseEmptyFile() { string path = Path.GetTempFileName(); H5File FILE = H5File.Open(path, mode: "w"); Assert.True(FILE.ID > 0); FILE.Dispose(); Assert.Equal((hid_t)0, FILE.ID); // trying to re-open is a surefire way to check if FILE was closed correctly: H5File FILE2 = H5File.Open(path, mode: "w"); FILE2.Dispose(); File.Delete(path); Assert.False(File.Exists(FILE.Path)); }