forked from LiorBanai/HDF5-CSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHdf5StringsTests.cs
133 lines (110 loc) · 4.03 KB
/
Hdf5StringsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace HDF5CSharp.UnitTests
{
public partial class Hdf5UnitTests
{
[TestMethod]
public void WriteAndReadOneString()
{
try
{
string[] str = new[] { "test" };
string filename = Path.Combine(folder, "testOneStringList.H5");
// Open file and write the strings
var fileId = Hdf5.CreateFile(filename);
Assert.IsTrue(fileId > 0);
Hdf5.WriteStrings(fileId, "/test", str);
// Read the strings and close file
Assert.IsTrue(fileId > 0);
IEnumerable<string> strs2 = Hdf5.ReadStrings(fileId, "/test", "", true).result;
Assert.IsTrue(strs2.Count() == 1);
foreach (var s in strs2)
{
Assert.IsTrue(str[0] == s);
};
Hdf5.CloseFile(fileId);
}
catch (Exception ex)
{
CreateExceptionAssert(ex);
}
}
[TestMethod]
public void WriteAndReadListOfStrings()
{
try
{
List<string> strs = new List<string>
{
"t",
"tst",
"test1",
"small test"
};
string filename = Path.Combine(folder, "testStringList.H5");
// Open file and write the strings
var fileId = Hdf5.CreateFile(filename);
Assert.IsTrue(fileId > 0);
Hdf5.WriteStrings(fileId, "/test", strs);
// Read the strings and close file
Assert.IsTrue(fileId > 0);
IEnumerable<string> strs2 = Hdf5.ReadStrings(fileId, "/test", "", true).result;
Assert.IsTrue(strs.Count() == strs2.Count());
foreach (var item in strs2.Select((str, i) => new { i, str }))
{
Assert.IsTrue(item.str == strs[item.i]);
}
Hdf5.CloseFile(fileId);
}
catch (Exception ex)
{
CreateExceptionAssert(ex);
}
}
[TestMethod]
public void WriteAndReadOneAsciiString()
{
try
{
string test = "This is a test string";
string filename = Path.Combine(folder, "testOneString.H5");
var fileId = Hdf5.CreateFile(filename);
Hdf5.WriteAsciiString(fileId, "/test", test);
Assert.IsTrue(Hdf5.CloseFile(fileId) == 0);
fileId = Hdf5.OpenFile(filename);
string readStr = Hdf5.ReadAsciiString(fileId, "/test");
Assert.IsTrue(test == readStr);
Assert.IsTrue(Hdf5.CloseFile(fileId) == 0);
}
catch (Exception ex)
{
CreateExceptionAssert(ex);
}
}
[TestMethod]
public void WriteAndReadOneUnicodeString()
{
try
{
string test = "Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο";
string filename = Path.Combine(folder, "testUnicodeString.H5");
var fileId = Hdf5.CreateFile(filename);
Hdf5.WriteUnicodeString(fileId, "/test", test);
Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0);
fileId = Hdf5.OpenFile(filename);
string readStr = Hdf5.ReadUnicodeString(fileId, "/test");
//var readStr = Hdf5.ReadStrings(fileId, "/test");
Assert.IsTrue(test == readStr);
Assert.IsTrue(Hdf5.CloseFile(fileId) >= 0);
}
catch (Exception ex)
{
CreateExceptionAssert(ex);
}
}
}
}